OWLNext 7.0
Borland's Object Windows Library for the modern age
|
TSocket encapsulates the basic attributes of a socket. More...
#include <owl/wsksock.h>
Public Types | |
enum | TShutMode { ShutModeNoRecv = 0 , ShutModeNoSend = 1 , ShutModeNoRecvSend = 2 } |
How to shutdown the socket. More... | |
Public Member Functions | |
TSocket () | |
Default constructor for a socket. | |
TSocket (SOCKET &newS) | |
TSocket(SOCKET&) is a constructor based on a Winsock SOCKET descriptor. | |
TSocket (TSocketAddress &newSocketAddress, int nNewFamily=PF_INET, int nNewType=SOCK_STREAM, int nNewProtocol=0) | |
This is the standard constructor for a TSocket. | |
virtual | ~TSocket () |
This TSocket destructor will close the socket it if has not be closed already. | |
operator SOCKET () const | |
Returns the handle of the socket. | |
virtual int | CloseSocket () |
The CloseSocket() function is much like the Winsock closesocket() function. | |
virtual int | ShutDownSocket (TShutMode shutMode=ShutModeNoRecvSend) |
The ShutDownSocket() function is much like the Winsock shutdown() function. | |
TSocket & | operator= (TSocket &newSocket) |
virtual void | SetNotificationSet (int notificationSet) |
Assigns new set of notifications socket will catch. | |
virtual void | SetNotificationWindow (TWindow *windowNotification) |
Sets the new notification window. | |
virtual int | CreateSocket () |
The CreateSocket function is much like the Winsock socket() function. | |
virtual int | BindSocket (const TSocketAddress &addressToBindTo) |
binds to a given address | |
virtual int | BindSocket () |
binds to our address | |
virtual void | SetMyAddress (TSocketAddress &newSocketAddress) |
This may be useful for changing the address or setting the address before binding. | |
virtual void | SetPeerSocketAddress (TSocketAddress &newPeerSocketAddress) |
The 'myPeerSocketAddress' member variable is useful for Datagram sockets because it allows them to specify a default destination to send datagrams to. | |
virtual void | SetSocketStyle (int nNewFamily=PF_INET, int nNewType=SOCK_STREAM, int nNewProtocol=0) |
The SetSocketStyle function can be used to set or change some TSocket member data. | |
virtual int | StartAcceptNotification () |
This function says to listen only to FD_ACCEPT messages. | |
virtual int | StartRegularNotification () |
This function turns on all Winsock notifications except FD_ACCEPT. | |
virtual int | StartCustomNotification (int nSelectionOptions) |
The return value is WINSOCK_ERROR or WINSOCK_NOERROR. | |
virtual int | CancelNotification () |
CancelNotification() turns off the notification to this window. | |
bool | SetSaveSocketOnDelete (bool saveSocket=true) |
Saves the socket on deletion. | |
virtual int | ConvertProtocol (char *protocol) |
Converts a string protocol to integer value. | |
int | GetLastError () |
Returns the last error of the socket. | |
virtual ulong | GetDriverWaitingSize () |
GetDriverWaitingSize() is much like calling ioctlsocket(s, FIONREAD,...) in Winsock. | |
virtual ulong | GetTotalWaitingSize () |
Returns the total number of bytes waiting to be read. | |
virtual int | GetMyAddress (TSocketAddress &socketAddress, int &nAddressLength, SOCKET &socket) |
This function stores the address into the reference argument 'socketAddress'. | |
virtual int | GetMyAddress (TSocketAddress &socketAddress, int &nAddressLength) |
This function stores the address into the reference argument 'socketAddress'. | |
virtual int | GetPeerAddress (TSocketAddress &socketAddress, int &nAddressLength, SOCKET &socket) |
The GetPeerAddress() function is much like the Winsock getpeername() function. | |
virtual int | GetPeerAddress (TSocketAddress &socketAddress, int &nAddressLength) |
This version of GetPeerAddress() works on our own socket descriptor. | |
virtual void | SetMaxReadBufferSize (int nNewMaxReadBufferSize) |
This should be called by someone who knows what the correct value is. | |
int | SetBroadcastOption (bool bBroadcast) |
Allows transmission of broadcast messages. | |
int | SetDebugOption (bool bDebug) |
Records debugging info. | |
int | SetLingerOption (bool bLinger, ushort nLingerTime=0) |
If you set 'linger' to true, then that means to linger for 'lingerTime' seconds. | |
int | SetRouteOption (bool bRoute) |
A false argument means don't route. | |
int | SetKeepAliveOption (bool bKeepAlive) |
Sends keepAlive messages. | |
int | SetOOBOption (bool bSendOOBDataInline) |
Receives out-of-band (OOB) data in the normal data stream. | |
int | SetReceiveBufferOption (int nReceiveBufferSize) |
Sets the buffer size for receiving messages. | |
int | SetSendBufferOption (int nSendBufferSize) |
Sets the buffer size for sending messages. | |
int | SetReuseAddressOption (bool bAllowReuseAddress) |
Allows the socket to bind to an already-bound address. | |
int | GetBroadcastOption (bool &bBroadcast) |
Retrieves the current broadcast option. | |
int | GetDebugOption (bool &bDebug) |
Retrieves the current debugging option. | |
int | GetLingerOption (bool &bLinger, ushort &nLingerTime) |
Retreives the current linger option. | |
int | GetRouteOption (bool &bRoute) |
Retrieves the routing option. | |
int | GetKeepAliveOption (bool &bKeepAlive) |
Retrieves the keepAlive option. | |
int | GetOOBOption (bool &bSendOOBDataInline) |
Retrieves the out-of-band (OOB) option. | |
int | GetReceiveBufferOption (int &nReceiveBufferSize) |
Retrieves the current receiving buffer size. | |
int | GetSendBufferOption (int &nSendBufferSize) |
Retrieves the current sending buffer size. | |
int | GetReuseAddressOption (bool &bAllowReuseAddress) |
Retrieves the reusable address option. | |
Protected Member Functions | |
void | Init () |
This function is an intitialization function called by the TSocket constructors. | |
int | SocketsCallCheck (int error) |
Checks the return error value from a sockets call, caching the last error if one occured (i.e., error is non-zero). | |
virtual int | DoReadNotification (const SOCKET &s, int nError) |
This function gets called whenever the socket gets a read notification. | |
virtual int | DoWriteNotification (const SOCKET &s, int nError) |
The generic socket doesn't know how many bytes it can send, since this limit is dependent on whether the socket is a stream or datagram socket. | |
virtual int | DoOOBNotification (const SOCKET &s, int nError) |
This isn't responded to in the generic TSocket class. | |
virtual int | DoAcceptNotification (const SOCKET &s, int nError) |
This isn't responded to in the generic TSocket class. | |
virtual int | DoConnectNotification (const SOCKET &s, int nError) |
This isn't responded to in the generic TSocket class. | |
virtual int | DoCloseNotification (const SOCKET &s, int nError) |
This isn't responded to in the generic TSocket class. | |
Protected Attributes | |
int | Family |
PF_INET, etc. (this is the protocol family) | |
int | Type |
SOCK_STREAM, etc. | |
int | Protocol |
IPPROTO_TCP, etc. | |
int | LastError |
Last Error. | |
int | MaxReadBufferSize |
Maximum buffer size. | |
short | SaveSocket |
Save the socket on deletion? | |
TSocketWindow | Window |
Will receive internal notifications and pass them to this class. | |
Friends | |
class | TSocketWindow |
bool | operator== (const TSocket &socket1, const TSocket &socket2) |
While it's possible that two sockets could refer to the same SOCKET (though this would likely create a mess if not governed with care), it's defined as not possible that two Sockets could have the same window member. | |
TSocket encapsulates the basic attributes of a socket.
A socket is an endpoint of communication to which a name may be bound. Each socket in use has a type and an associated process.
owl::TSocket::TSocket | ( | ) |
Default constructor for a socket.
The individual members of the TSocket can be set later.
Definition at line 21 of file wsksock.cpp.
References Init().
owl::TSocket::TSocket | ( | SOCKET & | newS | ) |
TSocket(SOCKET&) is a constructor based on a Winsock SOCKET descriptor.
Definition at line 39 of file wsksock.cpp.
References Family, GetMyAddress(), GetPeerAddress(), and Init().
owl::TSocket::TSocket | ( | TSocketAddress & | newSocketAddress, |
int | newFamily = PF_INET, | ||
int | newType = SOCK_STREAM, | ||
int | newProtocol = 0 ) |
This is the standard constructor for a TSocket.
It doesn't call socket() or bind(). These must be done independently.
Definition at line 59 of file wsksock.cpp.
References Init().
|
virtual |
This TSocket destructor will close the socket it if has not be closed already.
It will also delete the friend notification window.
Definition at line 79 of file wsksock.cpp.
References CloseSocket(), SaveSocket, and SetLingerOption().
|
virtual |
binds to our address
This BindSocket simply binds with the previously defined member data socket address.
Definition at line 333 of file wsksock.cpp.
References BindSocket().
|
virtual |
binds to a given address
BindSocket is much like the Winsock bind() function.
Regardless of what mySocketAddress may have been previously, a call to 'bind()' immediately makes the socket's address the one put into the bind() call. Thus, mySocketAddress is always assigned to be boundSocketAddress. The address argument must be in network byte ordering. On the other hand, the SocketAddress class always keeps its addresses in network byte ordering.
Definition at line 315 of file wsksock.cpp.
References owl::TWinSockDll::bind(), LastError, WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
|
virtual |
CancelNotification() turns off the notification to this window.
This also changes the socket to be blocking. The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine GetLastError().
Definition at line 218 of file wsksock.cpp.
References owl::TSocketWindow::CancelNotification(), owl::TSocketWindow::GetLastError(), LastError, Window, and WINSOCK_ERROR.
|
virtual |
The CloseSocket() function is much like the Winsock closesocket() function.
Definition at line 270 of file wsksock.cpp.
References owl::TWinSockDll::closesocket(), LastError, WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
Converts a string protocol to integer value.
Makes assumptions about the protocol string. Only "tcp" and udp return valid values.
Definition at line 243 of file wsksock.cpp.
|
virtual |
The CreateSocket function is much like the Winsock socket() function.
This function assumes that nFamily, nType, and nProtocol are already set properly. Note also that since the return of socket() is assigned to 's', that 's' must not already be used. This is another way of saying that there can only be one SOCKET for each TSocket object.
Definition at line 261 of file wsksock.cpp.
References Family, Protocol, owl::TWinSockDll::socket(), SocketsCallCheck(), and Type.
This isn't responded to in the generic TSocket class.
Reimplemented in owl::TStreamSocket.
Definition at line 469 of file wsksock.cpp.
This isn't responded to in the generic TSocket class.
Reimplemented in owl::TStreamSocket.
Definition at line 485 of file wsksock.cpp.
This isn't responded to in the generic TSocket class.
Reimplemented in owl::TStreamSocket.
Definition at line 477 of file wsksock.cpp.
This isn't responded to in the generic TSocket class.
Reimplemented in owl::TStreamSocket.
Definition at line 461 of file wsksock.cpp.
This function gets called whenever the socket gets a read notification.
This means that data on the port is ready to be read. Thus this function must be subclassed by a DatagramSocket and StreamSocket.
Reimplemented in owl::TDatagramSocket, and owl::TStreamSocket.
Definition at line 443 of file wsksock.cpp.
The generic socket doesn't know how many bytes it can send, since this limit is dependent on whether the socket is a stream or datagram socket.
Thus this function must be subclassed by a DatagramSocket and StreamSocket.
Reimplemented in owl::TDatagramSocket, and owl::TStreamSocket.
Definition at line 453 of file wsksock.cpp.
Retrieves the current broadcast option.
Definition at line 596 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
Retrieves the current debugging option.
Definition at line 608 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
|
virtual |
GetDriverWaitingSize() is much like calling ioctlsocket(s, FIONREAD,...) in Winsock.
It returns the number of bytes waiting to be read on the socket. For datagrams, it is the size of the next datagram. For streams, it should be the total waiting bytes.
Definition at line 418 of file wsksock.cpp.
References owl::TWinSockDll::ioctlsocket().
Retrieves the keepAlive option.
Definition at line 653 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
|
inline |
Retreives the current linger option.
Definition at line 620 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), SocketsCallCheck(), WINSOCK_ERROR, and WINSOCK_NOERROR.
|
virtual |
This function stores the address into the reference argument 'socketAddress'.
'addressLength' will hold the length of the address. Uses the SOCKET in my member data as the socket to get the address of.
Definition at line 353 of file wsksock.cpp.
References GetMyAddress().
|
virtual |
This function stores the address into the reference argument 'socketAddress'.
'addressLength' will hold the length of the address. 'socket' refers to the socket whose address will be examined.
Definition at line 343 of file wsksock.cpp.
References owl::TWinSockDll::getsockname(), and SocketsCallCheck().
Retrieves the out-of-band (OOB) option.
Definition at line 665 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
|
virtual |
This version of GetPeerAddress() works on our own socket descriptor.
Definition at line 379 of file wsksock.cpp.
References GetPeerAddress().
|
virtual |
The GetPeerAddress() function is much like the Winsock getpeername() function.
The Winsock getpeername() function is misnamed; it should be getpeeraddress(). socketAddress will be changed to have the right addressing info, and nAddressLength will be set to be the address length. Note that this function can be used to get the address for any socket descriptor, not just our own socket descriptor.
Definition at line 366 of file wsksock.cpp.
References owl::TWinSockDll::getpeername(), and SocketsCallCheck().
Retrieves the current receiving buffer size.
Definition at line 677 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
Retrieves the reusable address option.
Definition at line 695 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
Retrieves the routing option.
Definition at line 636 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), SocketsCallCheck(), WINSOCK_ERROR, and WINSOCK_NOERROR.
Retrieves the current sending buffer size.
Definition at line 686 of file wsksock.cpp.
References owl::TWinSockDll::getsockopt(), and SocketsCallCheck().
|
virtual |
Returns the total number of bytes waiting to be read.
Definition at line 433 of file wsksock.cpp.
References GetDriverWaitingSize().
|
protected |
This function is an intitialization function called by the TSocket constructors.
It simply creates the friend window that the TSocket needs for Winsock notifications.
Definition at line 92 of file wsksock.cpp.
References owl::TWindow::Create(), and Window.
|
inline |
Definition at line 120 of file wsksock.cpp.
References Family, LastError, Protocol, SaveSocket, owl::TSocketWindow::SetSocketParent(), Type, and Window.
Allows transmission of broadcast messages.
Definition at line 502 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
Records debugging info.
Definition at line 513 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
Sends keepAlive messages.
Definition at line 553 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
If you set 'linger' to true, then that means to linger for 'lingerTime' seconds.
Examples:
Definition at line 531 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
This should be called by someone who knows what the correct value is.
Definition at line 493 of file wsksock.cpp.
References MaxReadBufferSize.
|
virtual |
This may be useful for changing the address or setting the address before binding.
It's no good to change this after binding, as a binding is a permanent association between a socket descriptor and a full address (for IP, this is a ushort port and ulong address).
Definition at line 390 of file wsksock.cpp.
Assigns new set of notifications socket will catch.
Definition at line 277 of file wsksock.h.
References owl::TSocketWindow::SetNotificationSet(), and Window.
Sets the new notification window.
Definition at line 286 of file wsksock.h.
References owl::TSocketWindow::SetNotificationWindow(), and Window.
Receives out-of-band (OOB) data in the normal data stream.
Definition at line 562 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
|
virtual |
The 'myPeerSocketAddress' member variable is useful for Datagram sockets because it allows them to specify a default destination to send datagrams to.
With a default destination, a datagram socket that always or often sends to one address can simply call the Write or Send functions with no address arguments and the data will send to the default address. This function can also be used by a stream socket to set the address for a peer that it wants to connect to.
Definition at line 403 of file wsksock.cpp.
Sets the buffer size for receiving messages.
Definition at line 571 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
Allows the socket to bind to an already-bound address.
Definition at line 587 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
A false argument means don't route.
Definition at line 544 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
Sets the buffer size for sending messages.
Definition at line 579 of file wsksock.cpp.
References owl::TWinSockDll::setsockopt(), and SocketsCallCheck().
|
virtual |
The SetSocketStyle function can be used to set or change some TSocket member data.
Note that the newFamily is also represented in the TSocketAddress member, and so they should match.
Definition at line 232 of file wsksock.cpp.
|
virtual |
The ShutDownSocket() function is much like the Winsock shutdown() function.
Note that shutting down a socket essentially means that you can't un-shut it down. It's a graceful way of preparing to end a session, somewhat like a yellow stoplight. Use this function to close your socket, while still allowing data be received from the network. This is as opposed to CloseSocket(), which kills all transfers in both directions. shutMode is one of the enumerations: ShutModeNoRecv, ShutModeNoSend, or ShutModeNoRecvSend.
Definition at line 293 of file wsksock.cpp.
References LastError, owl::TWinSockDll::shutdown(), WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
Checks the return error value from a sockets call, caching the last error if one occured (i.e., error is non-zero).
Returns a Winsock error/noerror code.
Definition at line 108 of file wsksock.cpp.
References LastError, WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
|
virtual |
This function says to listen only to FD_ACCEPT messages.
Note that a socket set up to be a listening socket will never be a connected socket, and a connected socket will never receive FD_ACCEPT messages. Thus all stream sockets are implicitly either connected sockets or listening sockets. Since the accepted socket needs a different notification window from the listening socket, and the sockets specification says that an accepted socket inherits the notification properties of the listening socket, the listening socket must not be set to receive FD_READ, etc, notifications. This is because it's possible that between the accept() call for the new socket and the WSAAsyncSelect() call for the new socket, data may be received for the new socket. Thus the listening socket may get sent the message and it would never get routed to the new socket. Calling this function is saying that this SocketWindow is for listening for connections.
The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine GetLastError().
Definition at line 171 of file wsksock.cpp.
References owl::TSocketWindow::GetLastError(), LastError, owl::TSocketWindow::StartAcceptNotification(), Window, and WINSOCK_ERROR.
The return value is WINSOCK_ERROR or WINSOCK_NOERROR.
You can then examine GetLastError().
Definition at line 203 of file wsksock.cpp.
References owl::TSocketWindow::GetLastError(), LastError, owl::TSocketWindow::StartCustomNotification(), Window, and WINSOCK_ERROR.
|
virtual |
This function turns on all Winsock notifications except FD_ACCEPT.
Calling this function is saying that this SocketWindow is for connections rather than for listening. Since a Winsock socket cannot be a listening socket and a connected socket at the same time, the notification functions are separated from each other: StartAcceptNotification() and StartRegularNotification().
The return value is WINSOCK_ERROR or WINSOCK_NOERROR. You can then examine GetLastError().
Definition at line 190 of file wsksock.cpp.
References owl::TSocketWindow::GetLastError(), LastError, owl::TSocketWindow::StartRegularNotification(), Window, and WINSOCK_ERROR.
While it's possible that two sockets could refer to the same SOCKET (though this would likely create a mess if not governed with care), it's defined as not possible that two Sockets could have the same window member.
This is because the window is created uniquely on construction for each TSocket.
Definition at line 149 of file wsksock.cpp.
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |