In file socket.hxx:

class OSocket : public ISocketTypes, public OReferenceCounter

Represents a socket

Inheritance:


Public Methods

Boolean bind (const OSocketAddr& LocalInterface)
Binds the socket to the specified (local) interface
int clearError ()
Gets and clears the error status of the socket
void close ()
Closes the socket
Boolean enableNonBlockingMode (Boolean On= True)
Enables/disables non-blocking mode of the socket
void getError (char* pBuffer, int nSize)
Builds a string with the last error-message for the socket
TSocketError getError ()
Delivers a constant decribing the last error for the socket system
void getLocalAddr (OSocketAddr& Addr)
Retrieves the address of the local interface of this socket
const char* getLocalHost ()
Get the hostname for the local interface
int getLocalPort ()
Get the local port of the socket
int getOption (TSocketOption Option, void* pBuffer, int BufferLen, TSocketOptionLevel Level= sol_socket)
Retrieves option-attributes associated with the socket
void getPeerAddr (OSocketAddr& Addr)
Retrieves the address of the remote host of this socket
const char* getPeerHost ()
Get the hostname for the remote interface
int getPeerPort ()
Get the remote port of the socket
TSocketType getType ()
Queries the socket for its type
Boolean isExceptionPending (int wp_sec, int wp_usec = 0)
Checks if a request for out-of-band data will block
Boolean isRecvReady (int wp_sec, int wp_usec = 0)
Checks if read operations will block
Boolean isSendReady (int wp_sec, int wp_usec = 0)
Checks if send operations will block
Boolean isValid ()
Checks if the socket is valid
operator oslSocket ()
Allow cast to underlying oslSocket
operator oslSocket ()
Allow cast to underlying oslSocket
OSocket (const OSocket& sock)
Copy constructor
OSocket (oslSocket Socket)
Creates socket as wrapper around the underlying oslSocket
OSocket (TSocketType Type = sock_stream, TAddrFamily Family = af_inet, TProtocol Protocol = protocol_ip)
Creates a socket
int setBroadcast (int opt = -1)
Allow transmission of broadcast messages on the socket
int setDebug (int opt = -1)
Enables/Disables debugging
int setDontRoute (int opt = -1)
Do not route: send directly to interface
int setKeepAlive (int opt = -1)
Send keepalive-packets
int setLinger (int time = -1)
Linger on close if unsent data is present
int setOobinline (int opt = -1)
Receive out-of-band data in the normal data stream
Boolean setOption (TSocketOption Option, void* pBuffer, int BufferLen, TSocketOptionLevel Level= sol_socket)
Sets the sockets attributes
int setRecvBufSize (int size =-1)
Specify buffer size for receives
int setRecvTimeout (int time= -1)
Blocking receive operations will unblock after the send-timeout
int setReuseAddr (int opt = -1)
Allow the socket to be bound to an address that is already in use
int setSendBufSize (int size =-1)
Specify buffer size for sends
int setSendTimeout (int time= -1)
Blocking send operations will unblock after the send-timeout
int setTcpNoDelay (int sz =-1)
Disables the Nagle algorithm for send coalescing
virtual ~OSocket ()
Destructor

Inherited from ISocketTypes:


Documentation

Represents a socket
OSocket(TSocketType Type = sock_stream, TAddrFamily Family = af_inet, TProtocol Protocol = protocol_ip)
Creates a socket
Parameters:
Family -
Type -
Protocol -

OSocket(const OSocket& sock)
Copy constructor

OSocket(oslSocket Socket)
Creates socket as wrapper around the underlying oslSocket
Parameters:
Socket -

virtual ~OSocket()
Destructor. Destroys the underlying oslSocket.

operator oslSocket()
Allow cast to underlying oslSocket

operator oslSocket()
Allow cast to underlying oslSocket

Boolean isValid()
Checks if the socket is valid
Returns:
True if the object represents a valid socket.

void close()
Closes the socket. If the socket is connected, you should use shutdown before.

void getLocalAddr(OSocketAddr& Addr)
Retrieves the address of the local interface of this socket
Parameters:
Addr - [out] receives the address.

int getLocalPort()
Get the local port of the socket
Returns:
the port number or OSL_INVALID_PORT on errors.

const char* getLocalHost()
Get the hostname for the local interface
Returns:
the hostname or an empty string ("").

void getPeerAddr(OSocketAddr& Addr)
Retrieves the address of the remote host of this socket
Parameters:
Addr - [out] receives the address.

int getPeerPort()
Get the remote port of the socket
Returns:
the port number or OSL_INVALID_PORT on errors.

const char* getPeerHost()
Get the hostname for the remote interface
Returns:
the hostname or an empty string ("").

Boolean bind(const OSocketAddr& LocalInterface)
Binds the socket to the specified (local) interface
Returns:
True if bind was successful.
Parameters:
LocalInterface - Address of the Interface

int setSendTimeout(int time= -1)
Blocking send operations will unblock after the send-timeout
Returns:
the old timeout.
Parameters:
time - Time == -1 disables timeout. Time == 0 is polling mode. Time > 0 sets timeout value.

int setRecvTimeout(int time= -1)
Blocking receive operations will unblock after the send-timeout
Returns:
the old timeout.
Parameters:
time - Time == -1 disables timeout. Time == 0 is polling mode. Time > 0 sets timeout value.

Boolean isRecvReady(int wp_sec, int wp_usec = 0)
Checks if read operations will block. You can specify a timeout-value in seconds/microseconds that denotes how long the operation will block if the Socket is not ready.
Returns:
True if read operations (recv, recvFrom, accept) on the Socket will NOT block; False if it would block or if an error occured.
Parameters:
wp_sec - if -1, the operation will block without a timeout. Otherwise the timeout in seconds.
wp_usec - adds microsecond resolution to the timeout given by wp_sec.

Boolean isSendReady(int wp_sec, int wp_usec = 0)
Checks if send operations will block. You can specify a timeout-value in seconds/microseconds that denotes how long the operation will block if the Socket is not ready.
Returns:
True if send operations (send, sendTo) on the Socket will NOT block; False if it would block or if an error occured.
Parameters:
wp_sec - if -1, the operation will block without a timeout. Otherwise the timeout in seconds.
wp_usec - adds microsecond resolution to the timeout given by wp_sec.

Boolean isExceptionPending(int wp_sec, int wp_usec = 0)
Checks if a request for out-of-band data will block. You can specify a timeout-value in seconds/microseconds that denotes how long the operation will block if the Socket has no pending OOB data.
Returns:
True if OOB-request operations (recv with appropriate flags) on the Socket will NOT block; False if it would block or if an error occured.
Parameters:
wp_sec - if -1, the operation will block without a timeout. Otherwise the timeout in seconds.
wp_usec - adds microsecond resolution to the timeout given by wp_sec.

int getOption(TSocketOption Option, void* pBuffer, int BufferLen, TSocketOptionLevel Level= sol_socket)
Retrieves option-attributes associated with the socket
Returns:
The size of the attribute copied into pBuffer ot -1 if an error occured.
Parameters:
Option - The attribute to query. Valid values (depending on the Level) are:
  • so_debug,
  • so_acceptconn,
  • so_reuseaddr,
  • so_keepalive,
  • so_dontroute,
  • so_broadcast,
  • so_useloopback,
  • so_linger,
  • so_oobinline,
  • so_sndbuf,
  • so_rcvbuf,
  • so_sndlowat,
  • so_rcvlowat,
  • so_sndtimeo,
  • so_rcvtimeo,
  • so_error,
  • so_type,
  • so_tcp_nodelay, (sol_tcp)
If not above mentioned otherwise, the options are only valid for level sol_socket.
pBuffer - The Buffer will be filled with the attribute.
BufferSize - The size of pBuffer.
Level - The option level. Valid values are:
  • sol_socket: Socket Level
  • sol_tcp: Level of Transmission Control Protocol

Boolean setOption(TSocketOption Option, void* pBuffer, int BufferLen, TSocketOptionLevel Level= sol_socket)
Sets the sockets attributes.
Returns:
True if the option could be changed.
Parameters:
Option - denotes the option to modify. Valid values (depending on the Level) are:
  • so_debug,
  • so_acceptconn,
  • so_reuseaddr,
  • so_keepalive,
  • so_dontroute,
  • so_broadcast,
  • so_useloopback,
  • so_linger,
  • so_oobinline,
  • so_sndbuf,
  • so_rcvbuf,
  • so_sndlowat,
  • so_rcvlowat,
  • so_sndtimeo,
  • so_rcvtimeo,
  • so_error,
  • so_type,
  • so_tcp_nodelay, (sol_tcp)
If not above mentioned otherwise, the options are only valid for level sol_socket.
pBuffer - Pointer to a Buffer which contains the attribute-value.
BufferSize - contains the length of the Buffer.
Level - selects the level for which an option should be changed. Valid values are:
  • sol_socket: Socket Level
  • sol_tcp: Level of Transmission Control Protocol

Boolean enableNonBlockingMode(Boolean On= True)
Enables/disables non-blocking mode of the socket
Returns:
True if mode could be set.
Parameters:
On - If True, non-blocking mode will be switched on, if False socket will become a blocking socket, which is the default behaviour of a socket.

TSocketType getType()
Queries the socket for its type
Returns:
one of:
  • sock_stream,
  • sock_dgram,
  • sock_raw,
  • sock_rdm,
  • sock_seqpacket,
  • invalid_SocketType, if an error occured

int clearError()
Gets and clears the error status of the socket
Returns:
s the current error state.

int setDebug(int opt = -1)
Enables/Disables debugging
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

int setReuseAddr(int opt = -1)
Allow the socket to be bound to an address that is already in use
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

int setKeepAlive(int opt = -1)
Send keepalive-packets
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

int setDontRoute(int opt = -1)
Do not route: send directly to interface
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

int setBroadcast(int opt = -1)
Allow transmission of broadcast messages on the socket.
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

int setOobinline(int opt = -1)
Receive out-of-band data in the normal data stream
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

int setLinger(int time = -1)
Linger on close if unsent data is present
Returns:
the previous setting (0 == off, > 0 timeout-value in seconds).
Parameters:
time - values > 0 enable lingering with a timeout of time in seconds. If time is 0, lingering will be disabled. If time is -1 no changes will occur.

int setSendBufSize(int size =-1)
Specify buffer size for sends. You might want to use getOption() to check if the size changes were really successful.
Returns:
the previous setting
Parameters:
size - Size >= 0 sets the size, -1 won't change anything.

int setRecvBufSize(int size =-1)
Specify buffer size for receives. You might want to use getOption() to check if the size changes were really successful.
Returns:
the previous setting
Parameters:
size - Size >= 0 sets the size, -1 won't change anything.

int setTcpNoDelay(int sz =-1)
Disables the Nagle algorithm for send coalescing. (Do not collect data until a packet is full, instead send immediatly. This increases network traffic but might improve response-times.)
Returns:
the previous setting
Parameters:
opt - 1 sets, 0 resets, -1 won't change anything

void getError(char* pBuffer, int nSize)
Builds a string with the last error-message for the socket
Parameters:
pBuffer - is filled with the error message.
nSize - the size of pBuffer. The message will be cut short if the buffer isn't large enough, but still remains a valid zero-terminated string.

TSocketError getError()
Delivers a constant decribing the last error for the socket system
Returns:
ENONE if no error occured, invalid_SocketError if an unknown (unmapped) error occured, otherwise an enum describing the error.


Direct child classes:
OStreamSocket
ODatagramSocket
OAcceptorSocket

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de