dodo  0.0.1
A C++ library to create containerized Linux services
dodo::network::BaseSocket Class Referenceabstract

Interface to and common implementation of concrete sockets (Socket, TLSSocket). More...

#include <basesocket.hpp>

Inheritance diagram for dodo::network::BaseSocket:
Collaboration diagram for dodo::network::BaseSocket:

Public Member Functions

 BaseSocket ()
 Default constructor creates an invalid socket. More...
 
 BaseSocket (bool blocking, SocketParams params)
 Construct from SocketParams. More...
 
 BaseSocket (int socket)
 Construct from a socket descriptor. More...
 
virtual ~BaseSocket ()
 Destructs this Socket, but does not call close(). More...
 
virtual BaseSocketaccept ()=0
 Accepts a connection request and return a pointer to a new Socket for the new connection, the caller will own the new Socket object. More...
 
common::SystemError bind (const Address &address)
 Bind the socket to the Address. More...
 
virtual void close ()
 Closes the socket, causing the connection, if it exists, to be terminated. More...
 
virtual common::SystemError connect (const Address &address)
 Connect to the address. More...
 
virtual std::string debugDetail () const
 Return debug object state as a string. More...
 
Address getAddress () const
 Get the local address for this socket. More...
 
SocketParams::AddressFamily getAddressFamily () const
 Get the SocketParams::AddressFamily of the socket. More...
 
virtual bool getBlocking () const
 Rerurn true if the socket is operating in blocking mode. More...
 
int getFD () const
 Return the socket file descriptor. More...
 
Address getPeerAddress () const
 Get the peer (remote) address for this socket. More...
 
SocketParams::ProtocolNumber getProtocolNumber () const
 Get the SocketParams::ProtocolNumber of the socket. More...
 
virtual socklen_t getReceiveBufSize () const
 Get the maximum buffer length for receive. More...
 
socklen_t getSendBufSize () const
 Get the maximum buffer length for send. More...
 
SocketParams getSocketParams () const
 Return the SocketParams. More...
 
SocketParams::SocketType getSocketType () const
 Get the SocketParams::SocketType of the socket. More...
 
int getTTL () const
 Get the Socket TTL (time to live) or the max number of packet hops. More...
 
bool isValid () const
 Return true when the socket descriptor is a valid, hence 'possible' descriptor. More...
 
common::SystemError listen (const Address &address, int backlog)
 Sets up a listening socket on Address. More...
 
bool operator< (const BaseSocket &socket) const
 Add ordering. More...
 
BaseSocketoperator= (const BaseSocket &socket)
 Assign from Socket. More...
 
BaseSocketoperator= (int socket)
 Assign from existing socket descriptor (int). More...
 
bool operator== (const BaseSocket &socket) const
 Add identity. More...
 
virtual common::SystemError receive (void *buf, ssize_t request, ssize_t &received)=0
 Receive bytes from the socket. More...
 
common::SystemError receiveInt16 (int16_t &value)
 receive an int16_t More...
 
common::SystemError receiveInt32 (int32_t &value)
 receive an int32_t More...
 
common::SystemError receiveInt64 (int64_t &value)
 receive an int64_t More...
 
common::SystemError receiveInt8 (int8_t &value)
 receive an int8_t More...
 
common::SystemError receiveLine (std::string &s)
 receive a stream of characters until a '
' is read (consumed from the socket read buffer but not added to s). More...
 
common::SystemError receiveString (std::string &s)
 Receive a std::string as sent by sendString( const std::string& ). More...
 
common::SystemError receiveUInt16 (uint16_t &value)
 receive an uint16_t More...
 
common::SystemError receiveUInt32 (uint32_t &value)
 receive an uint32_t More...
 
common::SystemError receiveUInt64 (uint64_t &value)
 receive an uint64_t More...
 
common::SystemError receiveUInt8 (uint8_t &value)
 receive an uint8_t More...
 
virtual common::SystemError send (const void *buf, ssize_t len, bool more=false)=0
 Send bytes on the socket. More...
 
common::SystemError sendInt16 (int16_t value, bool more=false)
 Send an int16_t. More...
 
common::SystemError sendInt32 (int32_t value, bool more=false)
 Send an int32_t. More...
 
common::SystemError sendInt64 (int64_t value, bool more=false)
 Send an int64_t. More...
 
common::SystemError sendInt8 (int8_t value, bool more=false)
 Send an int8_t. More...
 
common::SystemError sendLine (const std::string &s, bool more)
 Sends the std::string terminated by a '
'. More...
 
common::SystemError sendString (const std::string &s, bool more=false)
 Sends the std::string as understood by receiveString(). More...
 
common::SystemError sendUInt16 (uint16_t value, bool more=false)
 Send an uint16_t. More...
 
common::SystemError sendUInt32 (uint32_t value, bool more=false)
 Send an uint32_t. More...
 
common::SystemError sendUInt64 (uint64_t value, bool more=false)
 Send an sendUInt64. More...
 
common::SystemError sendUInt8 (uint8_t value, bool more=false)
 Send an uint8_t. More...
 
void setBlocking (bool blocking)
 Set the Socket blocking mode. More...
 
void setReceiveBufSize (socklen_t size)
 Set the size of the receive buffer. More...
 
void setReceiveTimeout (double sec)
 Set the receive timeout - a receive will fail if there is no data received before the timeout expires. More...
 
void setReUseAddress ()
 Enable the socket to re-use an address when listen/bind is called. More...
 
void setReUsePort ()
 Make the socket re-use a port when listen is called. More...
 
void setSendBufSize (socklen_t size)
 Set the size of the send buffer. More...
 
void setSendTimeout (double sec)
 Set the send timeout - a send will fail if there is no data send before the timeout expires. More...
 
void setTCPKeepAlive (bool enable)
 Enable or disable TCP keep-alive on the socket. More...
 
void setTCPNoDelay (bool set)
 Set TCP_NODELAY. More...
 
void setTTL (int ttl)
 Set the Socket TTL (Time to Live). More...
 
- Public Member Functions inherited from dodo::common::DebugObject
 DebugObject ()
 Default constructor does nothing. More...
 
virtual ~DebugObject ()
 Destructor does nothing. More...
 
std::string debugString () const
 Return the object dump to string. More...
 

Protected Attributes

int socket_
 The socket file decsriptor. More...
 

Additional Inherited Members

- Protected Member Functions inherited from dodo::common::DebugObject
std::string debugHeader () const
 Generates a debug header (address of this object and a demangled class name. More...
 

Detailed Description

Interface to and common implementation of concrete sockets (Socket, TLSSocket).

Definition at line 36 of file basesocket.hpp.

Constructor & Destructor Documentation

◆ BaseSocket() [1/3]

dodo::network::BaseSocket::BaseSocket ( )

Default constructor creates an invalid socket.

Definition at line 31 of file basesocket.cpp.

References socket_.

◆ BaseSocket() [2/3]

dodo::network::BaseSocket::BaseSocket ( int  socket)

Construct from a socket descriptor.

Parameters
socketThe socket file descriptor.

Definition at line 35 of file basesocket.cpp.

References socket_.

◆ BaseSocket() [3/3]

dodo::network::BaseSocket::BaseSocket ( bool  blocking,
SocketParams  params 
)
explicit

Construct from SocketParams.

Parameters
blockingIf true, create the socket in blocking mode.
paramsThe SocketParams to use.

Definition at line 39 of file basesocket.cpp.

References dodo::network::SocketParams::getAddressFamily(), dodo::network::SocketParams::getProtocol(), dodo::network::SocketParams::getSocketType(), setBlocking(), setTCPNoDelay(), socket_, and throw_SystemExceptionObject.

Here is the call graph for this function:

◆ ~BaseSocket()

virtual dodo::network::BaseSocket::~BaseSocket ( )
inlinevirtual

Destructs this Socket, but does not call close().

Definition at line 60 of file basesocket.hpp.

Member Function Documentation

◆ accept()

virtual BaseSocket* dodo::network::BaseSocket::accept ( )
pure virtual

Accepts a connection request and return a pointer to a new Socket for the new connection, the caller will own the new Socket object.

Returns
The accepted socket.

Implemented in dodo::network::Socket, and dodo::network::TLSSocket.

Referenced by dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ bind()

common::SystemError dodo::network::BaseSocket::bind ( const Address address)

Bind the socket to the Address.

Parameters
addressThe address to bind to.
Returns
SystemError::ecOK or
  • SystemError::ecEACCES
  • SystemError::ecEADDRINUSE
  • SystemError::ecEBADF
  • SystemError::ecEINVAL
  • SystemError::ecENOTSOCK

Definition at line 103 of file basesocket.cpp.

References dodo::network::Address::addr_, dodo::network::Address::asString(), dodo::common::SystemError::ecEACCES, dodo::common::SystemError::ecEADDRINUSE, dodo::common::SystemError::ecOK, socket_, and throw_SystemExceptionObject.

Referenced by listen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

void dodo::network::BaseSocket::close ( )
virtual

Closes the socket, causing the connection, if it exists, to be terminated.

Definition at line 71 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::closeSocket(), and dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ connect()

common::SystemError dodo::network::BaseSocket::connect ( const Address address)
virtual

Connect to the address.

These common::SystemError may be returned:

  • SystemError::ecOK
  • SystemError::ecEACCES
  • SystemError::ecEADDRINUSE
  • SystemError::ecEADDRNOTAVAIL
  • SystemError::ecEALREADY
  • SystemError::ecECONNREFUSED
  • SystemError::ecEINPROGRESS
  • SystemError::ecEISCONN
  • SystemError::ecENETUNREACH
  • SystemError::ecETIMEDOUT

In case the system returns other system errors on connect, a common::Exception is thrown.

Parameters
addressThe address to connect to.
Returns
The SystemError

Reimplemented in dodo::network::TLSSocket.

Definition at line 52 of file basesocket.cpp.

References dodo::common::SystemError::ecEACCES, dodo::common::SystemError::ecEADDRINUSE, dodo::common::SystemError::ecEADDRNOTAVAIL, dodo::common::SystemError::ecEALREADY, dodo::common::SystemError::ecECONNREFUSED, dodo::common::SystemError::ecEINPROGRESS, dodo::common::SystemError::ecEISCONN, dodo::common::SystemError::ecENETUNREACH, dodo::common::SystemError::ecETIMEDOUT, dodo::common::SystemError::ecOK, dodo::network::Address::getAddress(), socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TLSSocket::connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ debugDetail()

std::string dodo::network::BaseSocket::debugDetail ( ) const
virtual

Return debug object state as a string.

Returns
The string.

Reimplemented from dodo::common::DebugObject.

Definition at line 46 of file basesocket.cpp.

References socket_.

◆ getAddress()

Address dodo::network::BaseSocket::getAddress ( ) const

Get the local address for this socket.

Returns
The local Address.

Definition at line 236 of file basesocket.cpp.

References socket_.

◆ getAddressFamily()

SocketParams::AddressFamily dodo::network::BaseSocket::getAddressFamily ( ) const

Get the SocketParams::AddressFamily of the socket.

Returns
The address family.

Definition at line 244 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by getSocketParams(), and getTTL().

Here is the caller graph for this function:

◆ getBlocking()

bool dodo::network::BaseSocket::getBlocking ( ) const
virtual

Rerurn true if the socket is operating in blocking mode.

Returns
The mode.

Definition at line 125 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by receiveString(), sendString(), and dodo::network::SocketReadBuffer::SocketReadBuffer().

Here is the caller graph for this function:

◆ getFD()

◆ getPeerAddress()

Address dodo::network::BaseSocket::getPeerAddress ( ) const

Get the peer (remote) address for this socket.

Returns
The peer Address.

Definition at line 273 of file basesocket.cpp.

References socket_.

Referenced by dodo::network::TCPServer::run(), and dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ getProtocolNumber()

SocketParams::ProtocolNumber dodo::network::BaseSocket::getProtocolNumber ( ) const

Get the SocketParams::ProtocolNumber of the socket.

Returns
The ProtocolNumber.

Definition at line 260 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by getSocketParams().

Here is the caller graph for this function:

◆ getReceiveBufSize()

socklen_t dodo::network::BaseSocket::getReceiveBufSize ( ) const
virtual

Get the maximum buffer length for receive.

Returns
The receive buffer size.
See also
setReceiveBufSize()

Definition at line 177 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by receiveString().

Here is the caller graph for this function:

◆ getSendBufSize()

socklen_t dodo::network::BaseSocket::getSendBufSize ( ) const

Get the maximum buffer length for send.

Returns
The send buffer size.
See also
setSendBufSize

Definition at line 169 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

◆ getSocketParams()

SocketParams dodo::network::BaseSocket::getSocketParams ( ) const

Return the SocketParams.

See also
getAddressFamily(), getSocketType(), getProtocolNumber()
Returns
the SocketParams.

Definition at line 268 of file basesocket.cpp.

References getAddressFamily(), getProtocolNumber(), and getSocketType().

Here is the call graph for this function:

◆ getSocketType()

SocketParams::SocketType dodo::network::BaseSocket::getSocketType ( ) const

Get the SocketParams::SocketType of the socket.

Returns
The SocketType.

Definition at line 252 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by getSocketParams().

Here is the caller graph for this function:

◆ getTTL()

int dodo::network::BaseSocket::getTTL ( ) const

Get the Socket TTL (time to live) or the max number of packet hops.

Returns
The current socket TTL value.

Definition at line 185 of file basesocket.cpp.

References getAddressFamily(), socket_, and throw_SystemExceptionObject.

Here is the call graph for this function:

◆ isValid()

bool dodo::network::BaseSocket::isValid ( ) const
inline

Return true when the socket descriptor is a valid, hence 'possible' descriptor.

A valid decsriptor does not have to be open/connected or even correct - a valid decsriptor is not -1.

Returns
true of the socket is a valid descriptor ( >= 0 );

Definition at line 128 of file basesocket.hpp.

References socket_.

Referenced by dodo::network::TCPListener::run(), setBlocking(), and setReUseAddress().

Here is the caller graph for this function:

◆ listen()

common::SystemError dodo::network::BaseSocket::listen ( const Address address,
int  backlog 
)

Sets up a listening socket on Address.

Parameters
addressThe Address (including a port) to listen on.
backlogThe size of the queue used to cache pending connections.
Returns
A common::SystemError, if not ecOK

or one of the common::SystemError returned by bind( const Address &address ).

Definition at line 89 of file basesocket.cpp.

References dodo::network::Address::asString(), bind(), dodo::common::SystemError::ecEADDRINUSE, dodo::common::SystemError::ecOK, socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<()

bool dodo::network::BaseSocket::operator< ( const BaseSocket socket) const
inline

Add ordering.

Parameters
socketThe socket to compare to.
Returns
True if this Socket has a smaller socket descriptor than socket.

Definition at line 281 of file basesocket.hpp.

References socket_.

◆ operator=() [1/2]

BaseSocket & dodo::network::BaseSocket::operator= ( const BaseSocket socket)

Assign from Socket.

Parameters
socketThe Socket to assign/copy to this Socket.
Returns
This Socket.

Definition at line 84 of file basesocket.cpp.

References socket_.

◆ operator=() [2/2]

BaseSocket & dodo::network::BaseSocket::operator= ( int  socket)

Assign from existing socket descriptor (int).

Parameters
socketThe socket value to assign to this Socket.
Returns
This Socket.

Definition at line 79 of file basesocket.cpp.

References socket_.

◆ operator==()

bool dodo::network::BaseSocket::operator== ( const BaseSocket socket) const
inline

Add identity.

Parameters
socketThe socket to compare to.
Returns
True if both sockets are equal and have the sxame value of socket_.

Definition at line 274 of file basesocket.hpp.

References socket_.

◆ receive()

virtual common::SystemError dodo::network::BaseSocket::receive ( void *  buf,
ssize_t  request,
ssize_t &  received 
)
pure virtual

Receive bytes from the socket.

Parameters
bufPut bytes received here
requestThe maximum number of bytes to receive
receivedThe number of bytes received
Returns
The SystemError.

Implemented in dodo::network::Socket, and dodo::network::TLSSocket.

Referenced by dodo::network::TCPConnectionData::readBuffer(), receiveInt16(), receiveInt32(), receiveInt64(), receiveInt8(), receiveLine(), receiveString(), receiveUInt16(), receiveUInt32(), receiveUInt64(), receiveUInt8(), and dodo::network::SocketReadBuffer::underflow().

Here is the caller graph for this function:

◆ receiveInt16()

common::SystemError dodo::network::BaseSocket::receiveInt16 ( int16_t &  value)

receive an int16_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendInt16( int16_t )*

Definition at line 349 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveInt32()

common::SystemError dodo::network::BaseSocket::receiveInt32 ( int32_t &  value)

receive an int32_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendInt32( int32_t )*

Definition at line 391 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveInt64()

common::SystemError dodo::network::BaseSocket::receiveInt64 ( int64_t &  value)

receive an int64_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendInt64( int64_t )*

Definition at line 433 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveInt8()

common::SystemError dodo::network::BaseSocket::receiveInt8 ( int8_t &  value)

receive an int8_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendInt8( int8_t )*

Definition at line 328 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveLine()

common::SystemError dodo::network::BaseSocket::receiveLine ( std::string &  s)

receive a stream of characters until a '
' is read (consumed from the socket read buffer but not added to s).

Parameters
sreceives the read string.
Returns
The SystemError.

Definition at line 488 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveString()

common::SystemError dodo::network::BaseSocket::receiveString ( std::string &  s)

Receive a std::string as sent by sendString( const std::string& ).

Parameters
sThe string to receive into.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )

Definition at line 459 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, getBlocking(), getReceiveBufSize(), receive(), receiveUInt64(), and throw_ExceptionObject.

Here is the call graph for this function:

◆ receiveUInt16()

common::SystemError dodo::network::BaseSocket::receiveUInt16 ( uint16_t &  value)

receive an uint16_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendUInt16( uint16_t )

Definition at line 307 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveUInt32()

common::SystemError dodo::network::BaseSocket::receiveUInt32 ( uint32_t &  value)

receive an uint32_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendUInt32( uint32_t )

Definition at line 370 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ receiveUInt64()

common::SystemError dodo::network::BaseSocket::receiveUInt64 ( uint64_t &  value)

receive an uint64_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendUInt64( uint64_t )*

Definition at line 412 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Referenced by receiveString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiveUInt8()

common::SystemError dodo::network::BaseSocket::receiveUInt8 ( uint8_t &  value)

receive an uint8_t

Parameters
valueThe value received.
Returns
Same as receive( void* buf, ssize_t request, ssize_t &received )
See also
sendUInt8( uint8_t )

Definition at line 286 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, and receive().

Here is the call graph for this function:

◆ send()

virtual common::SystemError dodo::network::BaseSocket::send ( const void *  buf,
ssize_t  len,
bool  more = false 
)
pure virtual

Send bytes on the socket.

Parameters
bufTake bytes from here
lenThe number of bytes.
moreSet to true if more is to come (increases packet filling efficiency when accurate).
Returns
The SystemError.

Implemented in dodo::network::Socket, and dodo::network::TLSSocket.

Referenced by dodo::network::protocol::http::HTTPRequest::send(), dodo::network::protocol::http::HTTPResponse::send(), sendInt16(), sendInt32(), sendInt64(), sendInt8(), sendLine(), sendString(), sendUInt16(), sendUInt32(), sendUInt64(), sendUInt8(), and dodo::network::protocol::http::HTTPRequest::write().

Here is the caller graph for this function:

◆ sendInt16()

common::SystemError dodo::network::BaseSocket::sendInt16 ( int16_t  value,
bool  more = false 
)

Send an int16_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveInt16( int16_t& )

Definition at line 344 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendInt32()

common::SystemError dodo::network::BaseSocket::sendInt32 ( int32_t  value,
bool  more = false 
)

Send an int32_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveInt32( int32_t& )

Definition at line 386 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendInt64()

common::SystemError dodo::network::BaseSocket::sendInt64 ( int64_t  value,
bool  more = false 
)

Send an int64_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveInt64( int64_t& )

Definition at line 428 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendInt8()

common::SystemError dodo::network::BaseSocket::sendInt8 ( int8_t  value,
bool  more = false 
)

Send an int8_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveInt8( int8_t& )

Definition at line 323 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendLine()

common::SystemError dodo::network::BaseSocket::sendLine ( const std::string &  s,
bool  more 
)

Sends the std::string terminated by a '
'.

Parameters
sThe string to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )

Definition at line 480 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendString()

common::SystemError dodo::network::BaseSocket::sendString ( const std::string &  s,
bool  more = false 
)

Sends the std::string as understood by receiveString().

The send prefixes the string length in an uint64_t, the number of bytes (characters) that follow.

Parameters
sThe string to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )

Definition at line 449 of file basesocket.cpp.

References dodo::common::SystemError::ecOK, getBlocking(), send(), sendUInt64(), and throw_Exception.

Here is the call graph for this function:

◆ sendUInt16()

common::SystemError dodo::network::BaseSocket::sendUInt16 ( uint16_t  value,
bool  more = false 
)

Send an uint16_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveUInt16( uint16_t& )

Definition at line 302 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendUInt32()

common::SystemError dodo::network::BaseSocket::sendUInt32 ( uint32_t  value,
bool  more = false 
)

Send an uint32_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveUInt32( uint32_t& )

Definition at line 365 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ sendUInt64()

common::SystemError dodo::network::BaseSocket::sendUInt64 ( uint64_t  value,
bool  more = false 
)

Send an sendUInt64.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveUInt64( uint64_t& )

Definition at line 407 of file basesocket.cpp.

References send().

Referenced by sendString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendUInt8()

common::SystemError dodo::network::BaseSocket::sendUInt8 ( uint8_t  value,
bool  more = false 
)

Send an uint8_t.

Parameters
valueThe value to send.
moreIf true, the caller indicates that more data will follow.
Returns
Same as send( const void* buf, ssize_t len )
See also
receiveUInt8( uint8_t& )

Definition at line 281 of file basesocket.cpp.

References send().

Here is the call graph for this function:

◆ setBlocking()

void dodo::network::BaseSocket::setBlocking ( bool  blocking)

Set the Socket blocking mode.

Parameters
blockingBlocking if true.

Definition at line 131 of file basesocket.cpp.

References isValid(), socket_, throw_Exception, and throw_SystemExceptionObject.

Referenced by BaseSocket(), dodo::network::TCPListener::construct(), and dodo::network::TCPListener::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReceiveBufSize()

void dodo::network::BaseSocket::setReceiveBufSize ( socklen_t  size)

Set the size of the receive buffer.

Linux will (at least) double the memory for socket accounting purposes. If size < system minimum size, the system will set the latter.

See also
setSendBufSize( socklen_t size )
Parameters
sizeThe size to set the receive buffer to.

Definition at line 204 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct().

Here is the caller graph for this function:

◆ setReceiveTimeout()

void dodo::network::BaseSocket::setReceiveTimeout ( double  sec)

Set the receive timeout - a receive will fail if there is no data received before the timeout expires.

Note that the default is 0 seconds, meaning no timeout / wait forever.

Parameters
secTimeout value, in seconds, fractions allowed.

Definition at line 209 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct(), and dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ setReUseAddress()

void dodo::network::BaseSocket::setReUseAddress ( )

Enable the socket to re-use an address when listen/bind is called.

In transit TCP messages sent to a server previously listening on this address will not be picked up by the re-used address.

See also
setReUsePort()

Definition at line 148 of file basesocket.cpp.

References isValid(), socket_, throw_Exception, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setReUsePort()

void dodo::network::BaseSocket::setReUsePort ( )

Make the socket re-use a port when listen is called.

See also
setReUseAddress()

Definition at line 159 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct().

Here is the caller graph for this function:

◆ setSendBufSize()

void dodo::network::BaseSocket::setSendBufSize ( socklen_t  size)

Set the size of the send buffer.

Linux will (at least) double the memory for socket accounting purposes. If size < system minimum size or size > system maximum size, the system will silently overrule. Also note that getSendBufSize() and getReceiveBufSize() return the size of the kernel send buffer divided by two, as the Linux man 7 socket states: "...Linux assumes that half of the send/receive buffer is used for internal kernel structures;" So getSendBufSize() and getReceiveBufSize() return the values from a programmer perspective - it is the number of bytes the programmer can actually send or receive in one go

Socket s;
s.setSendBufSize(8192); // kernel has set it to 16384
int n = s.getSendBufSize(); // n = 8192
char buffer[s.getSendBufSize()]; // which is what you asked for and will fit
Parameters
sizeThe size to set the send buffer to.

Definition at line 199 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct().

Here is the caller graph for this function:

◆ setSendTimeout()

void dodo::network::BaseSocket::setSendTimeout ( double  sec)

Set the send timeout - a send will fail if there is no data send before the timeout expires.

Note that the default is 0 seconds, meaning no timeout / wait forever.

Parameters
secTimeout value, in seconds, fractions allowed.

Definition at line 219 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Referenced by dodo::network::TCPListener::construct(), and dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ setTCPKeepAlive()

void dodo::network::BaseSocket::setTCPKeepAlive ( bool  enable)

Enable or disable TCP keep-alive on the socket.

This might be useful to keep connections ope that run through a firewall that disconnects connections that are idle. Note that keep-alive itself is configured through the Linux kernel. Note that enabling keep-alive will not change the behavior of the socket from a developers perspective but ti does incur a bit of network overhead.

Parameters
enableIf true enable, otherwise disable.

Definition at line 120 of file basesocket.cpp.

References socket_.

Referenced by dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ setTCPNoDelay()

void dodo::network::BaseSocket::setTCPNoDelay ( bool  set)

Set TCP_NODELAY.

If true, disable Nagle's algorithm.

Parameters
setIf true, set TCP_NODELAY.

Definition at line 115 of file basesocket.cpp.

References socket_.

Referenced by BaseSocket(), and dodo::network::TCPListener::run().

Here is the caller graph for this function:

◆ setTTL()

void dodo::network::BaseSocket::setTTL ( int  ttl)

Set the Socket TTL (Time to Live).

Parameters
ttlThe ttl value to set.
See also
getTTL()

Definition at line 229 of file basesocket.cpp.

References socket_, and throw_SystemExceptionObject.

Field Documentation

◆ socket_


The documentation for this class was generated from the following files: