ADTF
|
TCP Client socket class. More...
Public Member Functions | |
cStreamSocket () | |
Default constructor. | |
virtual | ~cStreamSocket () |
Destructor. | |
tResult | Connect (const cString &strDest, tInt nPort, tUInt32 dwMode=OM_Block) |
Connects the socket with a remote listening socket. More... | |
tResult | Connect (tUInt32 dwDest, tInt nPort, tUInt32 dwMode=OM_Block) |
Connects the socket with a remote listening socket. More... | |
tBool | IsConnected (tTimeStamp nTimeout=0) |
Polls the socket for its connection state. More... | |
tResult | Write (const void *pData, tInt nDataLength, tInt *pnBytesWritten=nullptr) |
Sends a data over the socket. More... | |
tResult | Read (void *pBuffer, tInt nBufferSize, tInt *pnBytesRead=nullptr) |
Read incoming data. More... | |
![]() | |
cSocket () | |
Default constructor. | |
virtual | ~cSocket () |
Default destructor. | |
tVoid | Close () |
Closes the socket and frees all resources. More... | |
tVoid | Close (tShutdownMode nHow) |
Closes the socket and frees all resources. More... | |
tUInt32 | GetAddress () const |
Retrieves the IP address of the socket. More... | |
tInt | GetPort () const |
Retrieves the port of the socket. More... | |
tSocketHandle | GetHandle () const |
Get the internal socket handle. More... | |
tBool | SetTimeout (tTimeStamp nReadTimeout=-1, tTimeStamp nWriteTimeout=-1) |
Sets timouts fo the read and write socket operations. More... | |
tBool | DataAvailable () |
Check if data is available for reading (a subsequent read succeed immediately). More... | |
tBool | WaitForData (tTimeStamp nTimeout=-1) |
Blocks the current process until data is available for reading. More... | |
tInt | SetOption (tInt nLevel, tInt nOptionId, const tVoid *pValue, tInt nValueLen) |
Sets a specific option for the socket. More... | |
tInt | SetOption (cSocket::tOptionLevel eLevel, cSocket::tOptionId eId, const tVoid *pValue, tInt nValueLen) |
Equivalent to SetOption (tInt, tInt, const tVoid*, tInt) Instead of the system specific constants (e.g. More... | |
tResult | GetOption (tInt nLevel, tInt nOptionId, tVoid *o_pValue, tInt *o_pValueLen) |
gets a specific option for the socket. More... | |
tResult | GetOption (cSocket::tOptionLevel eLevel, cSocket::tOptionId eId, tVoid *o_pValue, tInt *o_pValueLen) |
Equivalent with GetOption(tInt, tInt, tVoid*, tInt*). More... | |
Additional Inherited Members | |
![]() | |
enum | tOpenMode { OM_Block = 0x0 , OM_NonBlock = 0x01 } |
The mode in which to run the sockets during and after a connection. More... | |
enum | tShutdownMode { SM_Read = 0 , SM_Write = 1 , SM_ReadWrite = 2 } |
The mode in which to switch the sockets to on shutdown. More... | |
enum | tOptionLevel { OL_SOCKET = 1 , OL_IPPROTO_TCP = 2 , OL_IPPROTO_IP = 3 } |
Abstraction of the system specific socket option levels (e.g. More... | |
enum | tOptionId { OI_DEBUG , OI_BROADCAST , OI_REUSEADDR , OI_KEEPALIVE , OI_LINGER , OI_SNDBUF , OI_RCVBUF , OI_DONTROUTE , OI_TCP_NODELAY , OI_IP_MULTICAST_LOOP } |
Abstraction of the system specific socket options (e.g. More... | |
![]() | |
static tVoid | AddLibraryRef () |
for the work with the static methods you have to use this function to load the nessessary libs, after work ReleaseLibraryRef has to be called. | |
static tVoid | ReleaseLibraryRef () |
to correctly unload the socket-libs you have to call this function | |
static cString | GetHostName (tUInt32 dwHostAddress=0) |
Returns the hostname for a given address. More... | |
static tUInt32 | GetHostAddress (const cString &strHostName=cString()) |
Returns the address for a given hostname. More... | |
static tUInt32 | AddressToUInt32 (const cString &strAddress) |
Converts a aaa.bbb.ccc.ddd formated address string to an integer. More... | |
static cString | UInt32ToAddress (tUInt32 ui32Address) |
Converts an integer to an aaa.bbb.ccc.ddd formated address string. More... | |
static tInt | GetLastErrorCode () |
Gets the error code of the last failure. More... | |
static tResult | GetLocalAddresses (std::set< tUInt32, std::less< tUInt32 >, std::allocator< tUInt32 > > &oAddresses) |
Returns a list of addresses from all local interfaces. More... | |
static tResult | SocketError (tInt nSocketError) |
Maps a socket error to an A_UTILS error. More... | |
static tResult | FindInterfaceForAddress (tUInt32 ui32FarAddress, tUInt32 &ui32LocalAddress) |
If more than one network interface is used in the host the FindInterfaceForAddress finds out the local address of the interface where the far address is reachable. More... | |
static tResult | WaitForData (const std::list< cSocket * > &i_lstSockets, cSocket **o_ppSocket, tTimeStamp tmTimeOut=-1) |
Blocks the current thread until data are available for reading in at least one of i_lstSockets . More... | |
![]() | |
static const tUInt32 | SOCKET_NO_ADDRESS |
Constance for check No Address. | |
![]() | |
tBool | Initialize () |
Sets the params for the socket with 0/nullptr. More... | |
tInt | ResolveOptionLevel (tOptionLevel level) const |
Resolve the option value of the socket. More... | |
tInt | ResolveOptionId (tOptionId id) const |
Resolve the option id of the socket. More... | |
![]() | |
tSocketHandle | m_hSocket |
this is internal handle of the socket, only use it if you really need that!! | |
tUInt32 | m_ui32Address |
Address of the socket (valid only if opened) | |
tInt | m_nPort |
Port of the socket (valid only if opened) | |
TCP Client socket class.
This class provides a client implementation for TCP sockets. For the TCP server counterpart see cServerSocket
Definition at line 21 of file streamsocket.h.
Connects the socket with a remote listening socket.
[in] | strDest | The destination host. |
[in] | nPort | The destination port. |
dwMode | The mode in which to drive the socket instance (blocking or non-blocking mode, see tOpenMode). |
ERR_ACCESS_DENIED | Permission to create a socket of the specified type and/or protocol is denied (EACCES ). |
ERR_NOT_SUPPORTED | The implementation does not support the specified address family or the protocol type or the specified protocol is not supported within this domain (EAFNOSUPPORT or EPROTONOSUPPORT ). |
ERR_INVALID_FLAGS | Unknown protocol or protocol family not available (EINVAL ). |
ERR_MEMORY | Process file table overflow or the system limit on the total number of open files has been reached or insufficient memory is available (EMFILE or ENFILE or ENOBUFS or ENOMEM ). |
ERR_DEVICE_IO | Other socket-related error |
ERR_NOT_FOUND | Resolving of host failed |
ERR_DEVICE_NOT_READY | Connecting failed |
ERR_TIMEOUT | A connection could not be established immediately. (Non-blocking only!) |
Connects the socket with a remote listening socket.
[in] | dwDest | The destination host. |
[in] | nPort | The destination port. |
dwMode | The mode in which to drive the socket instance (blocking or non-blocking mode, see tOpenMode). |
ERR_ACCESS_DENIED | Permission to create a socket of the specified type and/or protocol is denied (EACCES ). |
ERR_NOT_SUPPORTED | The implementation does not support the specified address family or the protocol type or the specified protocol is not supported within this domain (EAFNOSUPPORT or EPROTONOSUPPORT ). |
ERR_INVALID_FLAGS | Unknown protocol or protocol family not available (EINVAL ). |
ERR_MEMORY | Process file table overflow or the system limit on the total number of open files has been reached or insufficient memory is available (EMFILE or ENFILE or ENOBUFS or ENOMEM ). |
ERR_DEVICE_IO | Other socket-related error |
ERR_NOT_FOUND | Resolving of host failed |
ERR_DEVICE_NOT_READY | Connecting failed |
ERR_TIMEOUT | A connection could not be established immediately. (Non-blocking only!) |
|
virtual |
Polls the socket for its connection state.
This is particularly useful when running the sockets in non-blocking mode and Connect() has returned with ERR_TIMEOUT (which does not necessarily imply a failed connection).
nTimeout | The timeout after which the connection is deemed to have failed. |
Reimplemented from cSocket.
Read incoming data.
[in] | pBuffer | The buffer where the data should be stored. |
[in] | nBufferSize | The size of the buffer. |
[out] | pnBytesRead | If specified, this value is filled with the actual amount of bytes copied into the buffer. |
ERR_POINTER | Null-pointer committed |
ERR_INVALID_ARG | Negative data length committed |
ERR_TIMEOUT | Receive command timed out or the receive command would block on a socket marked as non-blocking (EAGAIN or EWOULDBLOCK ; Non-blocking only!). In normal mode, this simply implies a read timeout. |
ERR_INVALID_HANDLE | The file descriptor was invalid (EBADF ). |
ERR_ACCESS_DENIED | A remote host refused to allow the network connection (ECONNREFUSED ). |
ERR_MEMORY | The receive buffer pointer points outside the process's address space or memory could not be allocated (EFAULT or ENOMEM ). |
ERR_NOT_CONNECTED | The socket has not been connected (ENOTCONN ) or the peer has performed an orderly shutdown. |
ERR_BAD_DEVICE | The descriptor does not refer to a socket (ENOTSOCK ). |
ERR_DEVICE_IO | Other error detected |
Sends a data over the socket.
[in] | pData | The data which is to be sent. |
[in] | nDataLength | The size of the data. |
[out] | pnBytesWritten | If specified, this value is filled with the actual amount of bytes sent. |
ERR_POINTER | Null-pointer committed |
ERR_INVALID_ARG | Negative data length committed |
ERR_ACCESS_DENIED | Write permission is denied on the destination socket file (EACCES ). |
ERR_TIMEOUT | The socket is marked non-blocking and the requested operation would block (EAGAIN or EWOULDBLOCK ; Non-blocking only!). In normal mode, this simply implies a write timeout. |
ERR_INVALID_HANDLE | The file descriptor was invalid (EABDF ). |
ERR_CANCELED | Connection reset by peer or a signal occurred before any data was transmitted (ECONNRESET or EINTR ). |
ERR_INVALID_STATE | The socket was connected already or the local end has been shut down (EISCONN or EPIPE ). |
ERR_MEMORY | An invalid user space address was specified or the size of the message to be sent made automatic send impossible or the output queue for a network interface was full or no memory available (EFAULT or EMSGSIZE or ENOBUFS or ENOMEM ). |
ERR_INVALID_FLAGS | Invalid argument passed or some bit of the flags is inappropriate for the socket type (EINVAL or EOPNOTSUPP ). |
ERR_NOT_CONNECTED | The socket is not connected (ENOTCONN ). |
ERR_BAD_DEVICE | The descriptor does not refer to a socket (ENOTSOCK ). |
ERR_DEVICE_IO | Other error detected |