OWLNext 7.0
Borland's Object Windows Library for the modern age
|
The TStreamSocket encapsulates a Winsock stream socket. More...
#include <owl/wsksockd.h>
Public Types | |
enum | TConnectStatus { NotConnected , ConnectPending , Connected , Listening } |
Current status of this stream socket. More... | |
Public Types inherited from owl::TSocket | |
enum | TShutMode { ShutModeNoRecv = 0 , ShutModeNoSend = 1 , ShutModeNoRecvSend = 2 } |
How to shutdown the socket. More... | |
Public Member Functions | |
TStreamSocket () | |
This function calls TSocket constructor and initializes the state of the connection to not connected. | |
TStreamSocket (SOCKET &newS) | |
This function is an alias constructor. | |
TStreamSocket (TSocketAddress &socketAddress, int addressFormat=PF_INET, int Type=SOCK_STREAM, int protocol=0) | |
TStreamSocket & | operator= (TStreamSocket &src) |
This function copies the socket connection information. | |
int | Listen (int nMaxQueuedConnections=N_DEF_MAX_QUEUED_CONNECTIONS) |
This function puts this socket into a passive "listening" mode. | |
int | Connect () |
This function uses myPeerSocketAddress, which needs to be set before calling this function. | |
int | Connect (TSocketAddress &addressToConnectTo) |
This function sets myPeerSocketAddress to sAddressToConnectTo then calls Connect(). | |
int | Accept (TStreamSocket &socket) |
This function will try to accept a connection with the first connecting peer that is waiting in the queue. | |
int | Accept (SOCKET &socket, sockaddr &sAddress) |
This function tries to accept a connection with the first connecting peer that is waiting in the queue. | |
int | Read (char *data, int &charsToRead) |
This reads from the already received and queued data. | |
int | Write (char *data, int &charsToWrite, int flags=0, bool becomeOwnerOfData=true, bool copyData=true) |
This function writes the buffer into the stream. | |
int | ReadOOB (char *data, int &charsToRead) |
This function works just like the Read() function, but it works on the OOB queue. | |
int | WriteOOB (char *data, int &charsToWrite, int nFlags=MSG_OOB, bool becomeOwnerOfData=true, bool copyData=true) |
Works just like TStreamSocket::Write(), except it adds in the MSG_OOB into the flags. | |
Public Member Functions inherited from owl::TSocket | |
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. | |
Public Attributes | |
enum owl::TStreamSocket::TConnectStatus | ConnectStatus |
Protected Member Functions | |
int | DoReadNotification (const SOCKET &s, int nError) |
This function is called when the socket receives a read notification unless there is an error. | |
int | DoWriteNotification (const SOCKET &s, int nError) |
This function is called when the socket receives a write notification. | |
int | DoOOBNotification (const SOCKET &s, int nError) |
This notification appears when OOB data is ready to be received on the socket port. | |
int | DoAcceptNotification (const SOCKET &s, int nError) |
This notification occurs when a client socket on the network is attempting to connect to you. | |
int | DoConnectNotification (const SOCKET &s, int nError) |
This means that the connection attempted with a server on the network has completed. | |
int | DoCloseNotification (const SOCKET &s, int nError) |
This notification gets called when the socket has been closed. | |
Protected Member Functions inherited from owl::TSocket | |
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). | |
Additional Inherited Members | |
Protected Attributes inherited from owl::TSocket | |
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. | |
The TStreamSocket encapsulates a Winsock stream socket.
While Winsock version 1.1 is for TCP/IP, Winsock 2.0 and later will likely support other protocols. The TStreamSocket Windows Socket Class class is designed to be as forward-compatible with Winsock 2.0 as is currently possible; it contains no TCP/UDP-specific calls, and uses TSocketAddress and not TINetSocketAddress (IP addresses). In addition to supporting standard data reading and writing, the TStreamSocket also supports out-of-band reading and writing. Winsock calls such as accept() and listen() are implemented.
Definition at line 76 of file wsksockd.h.
Current status of this stream socket.
Enumerator | |
---|---|
NotConnected | This socket is not used. |
ConnectPending | Connection is pending. |
Connected | Currently connected. |
Listening | Waiting for a connection. |
Definition at line 80 of file wsksockd.h.
owl::TStreamSocket::TStreamSocket | ( | ) |
This function calls TSocket constructor and initializes the state of the connection to not connected.
Definition at line 179 of file wsksockd.cpp.
owl::TStreamSocket::TStreamSocket | ( | SOCKET & | newS | ) |
This function is an alias constructor.
!PP Important: Unless there is a way I haven't found yet, you can't tell
Definition at line 189 of file wsksockd.cpp.
owl::TStreamSocket::TStreamSocket | ( | TSocketAddress & | socketAddress, |
int | addressFormat = PF_INET, | ||
int | Type = SOCK_STREAM, | ||
int | protocol = 0 ) |
Definition at line 202 of file wsksockd.cpp.
This function tries to accept a connection with the first connecting peer that is waiting in the queue.
If successful, the socket reference argument is set to a new connected socket. The sAddress reference argument is set to the address of the connecting peer. The caller of this function may immediately use the new socket with data sends, etc.
Note that the caller may want to flag the socket as connected. If the socket belongs to a StreamSocket, its nConnectionStatus can be set as nConnected. The return value is either WINSOCK_ERROR or WINSOCK_NOERROR. If there is an error, then nLastError will be set with the appropriate error.
Note that this call could be made when no pending socket connections are in the queue. If this is the case, the call will block if the socket is marked as blocking, and will return WINSOCK_ERROR with WSAEWOULDBLOCK if the socket is marked as non-blocking. This function is usually called in response to an accept notification. A socket is set up as a stream socket and listen() is called. When a connection is ready, the driver notifies the listening socket with a DoAcceptNotification() call. (See the DoAcceptNotification() call documentation.) This Accept() function should be called as a result.
Definition at line 412 of file wsksockd.cpp.
References owl::TWinSockDll::accept(), owl::TSocket::LastError, WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
int owl::TStreamSocket::Accept | ( | TStreamSocket & | socket | ) |
This function will try to accept a connection with the first connecting peer that is waiting in the queue.
If successful, the TStreamSocket& socket will have a valid and connected socket, a proper status of nConnected, and the correct peer socket address. The caller usually calls this function in response to an Accept notification. The caller merely needs to create a new TStreamSocket and pass it to this function. The default constructor for TStreamSocket can be used, because this function fixes up the missing parts.
Definition at line 381 of file wsksockd.cpp.
References Accept(), Connected, ConnectStatus, owl::TSocket::Family, owl::TSocket::Protocol, owl::TSocket::SetSocketStyle(), owl::TSocket::Type, WINSOCK_ERROR, and WINSOCK_NOERROR.
int owl::TStreamSocket::Connect | ( | ) |
This function uses myPeerSocketAddress, which needs to be set before calling this function.
The connection attempt (and this function) should return right away, without blocking. When actually connected, a notification comes from the driver at the DoConnectNotification() function. Upon receiving that notification, the nConnectStatus is set to nConnected. Technically, a datagram socket can call connect; doing this sets the default address for future send()/recv() calls that the datagram socket might use. It's in the TStreamSocket class for simplicity, and because the TDatagramSocket class already supports its own default address system.
Definition at line 356 of file wsksockd.cpp.
References owl::TWinSockDll::connect(), ConnectPending, ConnectStatus, owl::TSocket::LastError, WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
int owl::TStreamSocket::Connect | ( | TSocketAddress & | addressToConnectTo | ) |
This function sets myPeerSocketAddress to sAddressToConnectTo then calls Connect().
(See Connect() for more details.)
Definition at line 339 of file wsksockd.cpp.
References Connect(), and owl::TSocket::SetPeerSocketAddress().
This notification occurs when a client socket on the network is attempting to connect to you.
Code needs to be written to intercept this notification.
Reimplemented from owl::TSocket.
Definition at line 483 of file wsksockd.cpp.
This notification gets called when the socket has been closed.
The socket is marked as not connected, so the user can find out about it. It is important to read any data that may be waiting in the queue before changing the status of the connection and doing any notification.
PP TWinSockDll::WSAGetLastError();
Reimplemented from owl::TSocket.
Definition at line 516 of file wsksockd.cpp.
References owl::TSocket::LastError, WINSOCK_ERROR, and WINSOCK_NOERROR.
This means that the connection attempted with a server on the network has completed.
This function gets called sometime after this object makes a connect() attempt. If the connect attempt was non-blocking, a notification is posted. When this function gets called, the nConnectStatus should be nConnecting.
PP TWinSockDll::WSAGetLastError();
Reimplemented from owl::TSocket.
Definition at line 495 of file wsksockd.cpp.
References Connected, ConnectStatus, owl::TSocket::LastError, NotConnected, WINSOCK_ERROR, and WINSOCK_NOERROR.
This notification appears when OOB data is ready to be received on the socket port.
Reimplemented from owl::TSocket.
Definition at line 463 of file wsksockd.cpp.
References owl::TSocket::LastError, WINSOCK_ERROR, and WINSOCK_NOERROR.
This function is called when the socket receives a read notification unless there is an error.
This means that data on the port is ready to be read. This function doesn't do much with the nError parameter. It doesn't do the read if there is an error value.
Reimplemented from owl::TSocket.
Definition at line 430 of file wsksockd.cpp.
References owl::TSocket::LastError, WINSOCK_ERROR, and WINSOCK_NOERROR.
This function is called when the socket receives a write notification.
This means that data on the port is ready to be written.
PP TWinSockDll::WSAGetLastError();
Reimplemented from owl::TSocket.
Definition at line 443 of file wsksockd.cpp.
References owl::TSocket::LastError, WINSOCK_ERROR, and WINSOCK_NOERROR.
int owl::TStreamSocket::Listen | ( | int | nMaxQueuedConnections = N_DEF_MAX_QUEUED_CONNECTIONS | ) |
This function puts this socket into a passive "listening" mode.
Definition at line 325 of file wsksockd.cpp.
References ConnectStatus, owl::TSocket::LastError, owl::TWinSockDll::listen(), Listening, WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
TStreamSocket & owl::TStreamSocket::operator= | ( | TStreamSocket & | src | ) |
This function copies the socket connection information.
Definition at line 212 of file wsksockd.cpp.
References owl::TSocket::operator=().
This reads from the already received and queued data.
This data has already been received from the socket driver.
PP I Need to allow the use of flags here.
Definition at line 222 of file wsksockd.cpp.
References owl::TSocket::LastError, owl::TWinSockDll::recv(), WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
This function works just like the Read() function, but it works on the OOB queue.
PP I Need to allow the use of flags here.
Definition at line 271 of file wsksockd.cpp.
References owl::TSocket::LastError, owl::TWinSockDll::recv(), WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
int owl::TStreamSocket::Write | ( | char * | data, |
int & | charsToWrite, | ||
int | flags = 0, | ||
bool | becomeOwnerOfData = true, | ||
bool | copyData = true ) |
This function writes the buffer into the stream.
Definition at line 247 of file wsksockd.cpp.
References owl::TSocket::LastError, owl::TWinSockDll::send(), WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
int owl::TStreamSocket::WriteOOB | ( | char * | data, |
int & | charsToWrite, | ||
int | flags = MSG_OOB, | ||
bool | becomeOwnerOfData = true, | ||
bool | copyData = true ) |
Works just like TStreamSocket::Write(), except it adds in the MSG_OOB into the flags.
Perform write operation using out-of-band data (i.e. via a logically independent tranmission channel between the connected sockets).
Definition at line 301 of file wsksockd.cpp.
References owl::TSocket::LastError, owl::TWinSockDll::send(), WINSOCK_ERROR, WINSOCK_NOERROR, and owl::TWinSockDll::WSAGetLastError().
enum owl::TStreamSocket::TConnectStatus owl::TStreamSocket::ConnectStatus |