socket


The abstract base of the Network<ToolKit> socket hierarchy. This class defines all behaviors common to all types of socket elements including the following.

The two derived classes of os_socket are os_tcp_connection_server and os_connectable_socket .

Library

Network<ToolKit>

Declaration

#include <ospace/network/socket.h>

class os_socket

Interface

Destructor
/* virtual */ ~os_socket()
Destroys the socket, closing the underlying descriptor if necessary.
<
bool operator<( const os_socket& socket ) const
Returns true if this socket's descriptor value is less than socket 's.
==
bool operator==( const os_socket& socket ) const
Returns true if this socket's descriptor value is the same as socket 's.
(os_sock_t)
operator os_sock_t() const
Returns the native socket descriptor.
auto_close
void auto_close( bool flag )
If flag is true , closes the descriptor on destruction.
auto_close
bool auto_close() const
Returns true if this socket will close its descriptor on destruction.
bind_to
void bind_to( const os_socket_address& address )
Binds this socket to the IP socket address address .

Throws: os_network_toolkit_error

close
void close()
Closes this socket.

Throws: os_network_toolkit_error

descriptor
void descriptor( os_sock_t descriptor )
Sets the native socket descriptor to descriptor .
descriptor
os_sock_t descriptor() const
Returns the value of the native socket descriptor.
get_and_clear_error
int get_and_clear_error()
Clears the error status and return its previous value. The kernel maintains this value using the same encoding scheme as errno .

Throws: os_network_toolkit_error

getsockopt
void getsockopt( int level , int code , void* storage , os_socklen_t& size ) const
Interface to the native getsockopt() "C" library function. For level level , store the socket option selected by code into the buffer pointed to by storage , which is size bytes long. Upon return, size is set to the actual size of the data returned in the structure pointed to storage . Refer the man pages of getsockopt() library function for information on different socket options.

Throws: os_network_toolkit_error

is_open
bool is_open() const
Returns true if this socket is open.
linger_information
void linger_information( bool flag , int seconds )
Affects the way that unsent messages are processed when the socket is closed. If flag is false , the socket immediately returns on close() and the system tries to deliver the unsent messages. If flag is true , the system tries to deliver unsent messages for up to seconds seconds and then discards any remaining unsent messages. If flag is true and seconds is 0 , the socket processes a close() by discarding unsent messages and returning immediately.

Throws: os_network_toolkit_error

linger_information
bool linger_information( int& seconds ) const
Returns the linger information in seconds .

Throws: os_network_toolkit_error

non_blocking
void non_blocking( bool flag )
If flag is true , set the socket to nonblocking.

Throws: os_network_toolkit_error

print
/* virtual */ void print( ostream& stream ) const
Prints the socket to stream .
receive_buffer_size
int receive_buffer_size() const
Returns the size, in bytes, of the socket receive buffer.

Throws: os_network_toolkit_error

receive_buffer_size
void receive_buffer_size( int size )
Sets the size of the socket receive buffer to size bytes. Increasing the size of this buffer above its default size can increase performance.

Throws: os_network_toolkit_error

reuse_local_addresses
void reuse_local_addresses( bool flag )
Sets local address reuse to flag .

Throws: os_network_toolkit_error

reuse_local_addresses
bool reuse_local_addresses() const
Returns true if this socket can reuse a local address.

Throws: os_network_toolkit_error

route
void route( bool flag )
Sets regular routing to flag .

Throws: os_network_toolkit_error

route
bool route() const
Returns true if regular routing is enabled. If regular routing is disabled, messages are sent directly to the network interface specified by the network portion of the destination address.

Throws: os_network_toolkit_error

send_buffer_size
int send_buffer_size() const
Returns the size, in bytes, of the send buffer.

Throws: os_network_toolkit_error

send_buffer_size
void send_buffer_size( int size )
Sets the size of the send buffer to size bytes. Increasing the size of this buffer above its default size can increase performance.

Throws: os_network_toolkit_error

setsockopt
void setsockopt( int level , int code , void* storage , os_socklen_t size )
Interface to the native setsockopt() "C" library function. For level level , set the socket option selected by code into the buffer pointed to by storage , which is size bytes long. Upon return, size is set to the actual size of the data returned in the structure pointed to storage . Refer the man pages of setsockopt() library function for information on different socket options.

Throws: os_network_toolkit_error

shutdown
void shutdown()
Shuts down the send and receive channels. Additional sends and receives are not permitted.

Throws: os_network_toolkit_error

shutdown
void shutdown( int code )
Shuts down according to code .

Throws: os_network_toolkit_error

shutdown_receives
void shutdown_receives()
Shuts down the receive channel. Additional receives are not permitted.

Throws: os_network_toolkit_error

shutdown_sends
void shutdown_sends()
Shuts down the send channel. Additional sends are not permitted.

Throws: os_network_toolkit_error

socket_address
os_socket_address socket_address() const
Returns the IP socket address.

Throws: os_network_toolkit_error

type
int type() const
Returns the standard encoding value ( SOCK_STREAM = 1 , SOCK_DGRAM = 2 , SOCK_RAW = 3 , SOCK_RDM = 4 , ... ).

Throws: os_network_toolkit_error

Non-Member Functions

<<
ostream& operator<<( ostream& stream , const os_socket& socket )
Prints socket to stream .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.