#include <CSocket.h>
Public Types | |
enum | State { Disconnected, Bound, Listening, Connected } |
Captures the state of the socket. See general remarks for more info. More... | |
Public Member Functions | |
CSocket (int am_Fd, CSocket::State am_State) | |
virtual | ~CSocket () |
int | getSocketFd () const |
Get accessor function socket file descriptor. | |
CSocket::State | getState () const |
Get accessor function for socket state. | |
void | Connect (const STD(string)&host, const STD(string)&service) |
void | Connect (unsigned long int IpAddress, unsigned short service) |
void | Bind (const STD(string)&service) |
void | Listen (unsigned int nBacklog=5) |
CSocket * | Accept (STD(string)&client) |
void | Shutdown () |
int | Read (void *pBuffer, size_t nBytes) |
int | Write (void *pBuffer, size_t nBytes) |
void | getPeer (unsigned short &port, STD(string)&peer) |
void | OOBInline (bool State=TRUE) |
bool | isOOBInline () |
void | setRcvLowWaterMark (size_t nBytes) |
size_t | getRcvLowWaterMark () |
void | setSndLowWaterMark (size_t nBytes) |
size_t | getSndLowWaterMark () |
void | setRcvTimeout (unsigned int nMs) |
unsigned int | getRcvTimeout () |
void | setSndTimeout (unsigned int nMs) |
unsigned int | getSndTimeout () |
void | Debug (bool fState=TRUE) |
bool | isDebug () |
void | SetNotRoutable (bool fRoutable=TRUE) |
bool | isNotRoutable () |
void | setSndBufSize (size_t nBufferSize) |
size_t | getSndBufSize () |
void | setRcvBufSize (size_t nBytes) |
size_t | getRcvBufSize () |
void | setLinger (bool lOn, int nLingerSeconds) |
void | getLinger (bool &isLingering, int &nLingerSeconds) |
Static Public Member Functions | |
CSocket () | |
< State name lookup tbl. | |
Protected Member Functions | |
void | setSocketFd (const int am_Fd) |
Set accessor function for Socket file descriptor. | |
void | setState (const CSocket::State am_State) |
Set accessor function for current socket state. | |
unsigned short | Service (const STD(string)&rService) |
STD (string) AddressToHostString(in_addr peer) | |
void | OpenSocket () |
Static Protected Member Functions | |
void | StockStateMap () |
Private Member Functions | |
CSocket (const CSocket &aCSocket) | |
Copy Constructor forbidden. | |
CSocket & | operator= (const CSocket &aCSocket) |
Assignment Operator Forbidden. | |
int | operator== (const CSocket &aCSocket) const |
Equality Operator Forbidden. | |
Private Attributes | |
int | m_Fd |
Socket. | |
CSocket::State | m_State |
State of socket. |
Definition at line 338 of file CSocket.h.
|
Captures the state of the socket. See general remarks for more info.
Definition at line 343 of file CSocket.h. Referenced by getState(). |
|
< State name lookup tbl. The default constructor initializes the fd to an illegal value and sets the state to Disconnected. The body of the constructor attempts to set the m_Fd member via a call to socket(2) to create an INET domain SOCK_STREAM, protocl tcp. It is up to the user to call Connect or alternatively set up the socket as a server by binding and listening. Exceptions:
Definition at line 371 of file CSocket.cpp. References OpenSocket(). |
|
This parameterized constructor is intended to allow a program which already has created a socket in some arbitrary state to wrap it inside a CSocket object. It must be used with care.. in the sense that the am_State parameter must match the actual socket state.
Definition at line 404 of file CSocket.cpp. References StockStateMap(). |
|
Destructor action depends on the state: sockets which are Connected are shutdown and then closed. Sockets which are in other states are just closed if the fd > 0. Definition at line 384 of file CSocket.cpp. References m_Fd, m_State, and Shutdown(). |
|
Copy Constructor forbidden.
|
|
|
|
|
|
Connects a socket as a client given numerical host, and port numbers in host byte order. For the host that means that an ip address of form: aa.bb.cc.dd is stored Hi->Low as aabbccdd in a longword. See Connect(const string&host, const string& service) for more information.
Definition at line 501 of file CSocket.cpp. References Disconnected, CApplicationSerializer::getInstance(), CThreadRecursiveMutex::Lock(), m_Fd, m_State, and CThreadRecursiveMutex::UnLock(). |
|
|
|
Purpose: Attempts to turn on Socket debugging. To support this. The user must have effective UID = 0. . Throws:
Definition at line 1207 of file CSocket.cpp. References m_Fd. |
|
Purpose: Retrieve the linger parameters. Throws:
Definition at line 1453 of file CSocket.cpp. References m_Fd. |
|
Referenced by CServerInstance::getPeerPort(). |
|
Purpose: Returns the maximum number of bytes which can be recieved in a single read(2) call. Throws:
Definition at line 1387 of file CSocket.cpp. References m_Fd. |
|
Returns the size of the current receive low water mark. See setRcvLowWaterMark for information about what this parameter does. Note that the value returned is inquired from the socket rather than stored in internal state. Throws:
Definition at line 1011 of file CSocket.cpp. References m_Fd. |
|
Purpose: Retrieve the protocol receive timeout. The time out is returned as an integer number of milliseconds. Throws:
Definition at line 1112 of file CSocket.cpp. References m_Fd. |
|
Purpose: Returns the number of bytes that can be written in a single write(2) call. Throws:
Definition at line 1340 of file CSocket.cpp. References m_Fd. |
|
Return the value of the current Send Low Water Mark Set setSndLowWaterMarrk for more information. Throws:
Definition at line 1058 of file CSocket.cpp. References m_Fd. |
|
Purpose: Returns the current send timeout in ms. Throws:
Definition at line 1173 of file CSocket.cpp. References m_Fd. |
|
Get accessor function socket file descriptor.
Definition at line 383 of file CSocket.h. Referenced by CTCPConnectionLost::Host(), and CTCPConnectionLost::Port(). |
|
Get accessor function for socket state.
Definition at line 388 of file CSocket.h. References State. Referenced by CServerInstance::Shutdown(), and CServerInstance::~CServerInstance(). |
|
Purpose: Returns TRUE if socket debugging is turned on and False otherwise. Exceptions:
Definition at line 1228 of file CSocket.cpp. |
|
Purpose: Returns the state of the routability flag. Throws:
Return values:
Definition at line 1286 of file CSocket.cpp. |
|
Purpose: Returns TRUE if OOBinline is set FALSE otherwise. Note that the underlying socket state is inquired, not some saved internal state. This function is valid in any socket state. Throws:
Definition at line 955 of file CSocket.cpp. |
|
Indicates that the specified server listener socket is ready to listen for connections. The Following exceptions can be thrown:
On success, m_State = Listening
Definition at line 624 of file CSocket.cpp. |
|
Purpose: Allows Out Of Band (OOB) data to be inserted in line with buffered data. OOB data is data with a higher delivery priority than 'normal data'. If this flag is not set, then by default OOB data must be read through normal socket interface functions by specifying it in the recv flags parameter. If this flag is set, oob data is queue at the front of the data to be read with the Read member. This is allowed in any socket state. Exceptions:
Definition at line 930 of file CSocket.cpp. References m_Fd. |
|
Opens the socket on a TCP/IP endpoint. Definition at line 1569 of file CSocket.cpp. References CApplicationSerializer::getInstance(), CThreadRecursiveMutex::Lock(), m_Fd, StockStateMap(), and CThreadRecursiveMutex::UnLock(). Referenced by CSocket(), and Shutdown(). |
|
Assignment Operator Forbidden.
|
|
Equality Operator Forbidden.
|
|
Purpose: Performs a read on the socket. The read will transfer all of the bytes currently waiting in the socket buffers or block until data is avaialble. The return valiue will be the number of bytes transferred. If the connection is lost, CTCPConnectionLost will be thrown. Multiple reads will not be performed so that any known messaging structure can be maintained. Throws:
Definition at line 763 of file CSocket.cpp. |
|
|
|
Purpose: Sets the socket linger parameters. Linger properties govern the way a shutdown, operates. Note that object destruction which requires a shutdown implicitly turns off linger. If linger is enabled, then the close will block until all pending data has been successfully sent or until the linger timeout is exceeded. Throws:
Definition at line 1419 of file CSocket.cpp. References m_Fd. |
|
Purpose: Allows the caller to control the routability of messages sent on the socket. If set, messages will not be sent through a gateway. Note: The socket need not be connected. Presumably, if this flag is set prior to Connect on a client socket the client will be unable to connect outside the local subnet, and if set prior to Bind for a server, the server will be unable to accept connections from outside the subnet. Exceptions: -CErrnoException if the setsockopt(2) call failed.
Definition at line 1261 of file CSocket.cpp. References m_Fd. |
|
Sets the maximum number of bytes which can be received in a single read(2) operation. Note that CTCPSocket::Read does >NOT< automatically segment or else you may block when you'd like to believe that a message has been received.
Definition at line 1365 of file CSocket.cpp. References m_Fd. |
|
Purpose: Sets the Receive low water mark for the socket. This is the number of bytes received by the protocol before any is made available to the user. Note that some systems do not allow this to be changed. It is not an error at this level to attempt to do so, however you will need to call getRcvlowWaterMark to be sure the change was actually made. Throws:
Definition at line 987 of file CSocket.cpp. References m_Fd. |
|
Set the protocol receive timeouts. Note that in some systems, these are not settable. However it is not an error to attempt to do so.
Definition at line 1081 of file CSocket.cpp. References m_Fd. |
|
Operation Type: Configuration Purpose: Sets the socket send buffer size. This has to do with how many bytes can be sent in a single write(2) service call. Messages larger than that must be segmented into multiple write(2) calls. Note howerver that CTCPSocket::Write automatically handles any necessary segmentation. Throws:
Definition at line 1319 of file CSocket.cpp. References m_Fd. |
|
Sets the new value of the Send Low water mark. This controls the number of bytes which must be written before transferring data to the protocol layers for transmission. Note that some systems don't allow this value to be changed. It is not an error to attempt to change this value on those systems, however you should use getSndLowWaterMark to determine the actual value negotiated by the system.
Definition at line 1040 of file CSocket.cpp. References m_Fd. |
|
Purpose: Set the number of milliseconds in the send timeout. Some systems may not allow this to be set, however it is not an error to try. Throws:
Definition at line 1145 of file CSocket.cpp. References m_Fd. |
|
Set accessor function for Socket file descriptor.
|
|
Set accessor function for current socket state.
|
|
Purpose: Shuts down a connection to a remote system. Unlike shutdown(2) this function does not support selectively shutting down reads or writes. Both are unconditionally shutdown. Note that the destructor will automatically call Shutdown if necessary. Exceptions:
Definition at line 722 of file CSocket.cpp. References Connected, m_Fd, m_State, and OpenSocket(). Referenced by CServerConnectionEvent::OnConnection(), CServerInstance::Shutdown(), CServerConnectionEvent::~CServerConnectionEvent(), CServerInstance::~CServerInstance(), and ~CSocket(). |
|
|
|
Purpose: Stocks the static member: m_StateNames with the states and their names. This is only done if the map is empty. This function must be updated if the set of states is modified. Definition at line 1556 of file CSocket.cpp. Referenced by CSocket(), and OpenSocket(). |
|
Purpose: Writes data to the socket. Note that this member will block as needed until all data has been queued to the socket buffers. This may require multiple write(2) function calls if the amount of data to be written is larger than the socket's blocking factor. Note that if the connection is lost during the write, CTCPConnectionLost will be thrown. Exceptions:
Definition at line 824 of file CSocket.cpp. |
|
Socket.
Definition at line 353 of file CSocket.h. Referenced by Connect(), Debug(), getLinger(), getRcvBufSize(), getRcvLowWaterMark(), getRcvTimeout(), getSndBufSize(), getSndLowWaterMark(), getSndTimeout(), isDebug(), isNotRoutable(), isOOBInline(), Listen(), OOBInline(), OpenSocket(), Read(), setLinger(), SetNotRoutable(), setRcvBufSize(), setRcvLowWaterMark(), setRcvTimeout(), setSndBufSize(), setSndLowWaterMark(), setSndTimeout(), Shutdown(), Write(), and ~CSocket(). |
|
State of socket.
Definition at line 354 of file CSocket.h. Referenced by Connect(), Listen(), Read(), Shutdown(), Write(), and ~CSocket(). |