connectable_socket


The os_connectable_socket class is an abstract base class that contains the functions common to os_tcp_socket and os_udp_socket , including read, write, and connection behaviors.

Library

Network<ToolKit>

Declaration

#include <ospace/network/connsock.h>

class os_connectable_socket : public os_socket

Interface

clear
void clear()
Resets the state to good.
connect_to
bool connect_to( const os_socket_address& address )
Connects to the socket with IP socket address address . If the socket is in non-blocking mode and the connection cannot be made immediately return false otherwise return true . On a false return wait for connection completion using the wait_to_connect() method.

Throws: os_network_toolkit_error

connected
bool connected() const
Returns true if the socket is connected to another socket.
eof
bool eof() const
Returns true if the socket is at the end of input.
event_on_eof
void event_on_eof( bool flag )
If flag is true , the socket generates an event on EOF.
event_on_eof
bool event_on_eof() const
Returns true if the socket will generate an event on EOF.
good
bool good() const
Returns true if the socket is in a good state and not at EOF.
ok
bool ok() const
Returns true if the socket is in a good state.
peer_address
os_socket_address peer_address() const
Returns an instance of os_socket_address that represents the name of the peer connected to this socket.

Throws: os_network_toolkit_error

print
void print( ostream& stream ) const
Prints the object to stream .
read
ssize_t read( void* buffer , size_t bytes )
Reads up to the specified number of bytes of data into buffer from the socket. Returns the number of bytes actually read or returns -1 on error.

Throws: os_network_toolkit_error

write
ssize_t write( const void* buffer , size_t bytes )
Writes up to the specified number of bytes of data from buffer to the socket. Returns the number of bytes actually written or returns -1 on error.

Throws: os_network_toolkit_error

wait_to_connect
bool wait_to_connect( timeval* time_out )
Waits for connection completion for non-blocking connects. This method must be called after a call to connect_to() in non-blocking mode returns false . If time_out is 0 (default), waits indefinitely until the connection is complete. If time_out is non zero, returns false if time_out time expires and the connection is still not complete. Returns true if the connection is complete.

Throws: os_network_toolkit_error

Non-Member Functions

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

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