dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
23 #ifndef network_basesocket_hpp
24 #define network_basesocket_hpp
void setReceiveTimeout(double sec)
Set the receive timeout - a receive will fail if there is no data received before the timeout expires...
common::SystemError sendInt8(int8_t value, bool more=false)
Send an int8_t.
void setTCPNoDelay(bool set)
Set TCP_NODELAY.
Address getPeerAddress() const
Get the peer (remote) address for this socket.
common::SystemError listen(const Address &address, int backlog)
Sets up a listening socket on Address.
virtual common::SystemError connect(const Address &address)
Connect to the address.
bool operator==(const BaseSocket &socket) const
Add identity.
common::SystemError sendLine(const std::string &s, bool more)
Sends the std::string terminated by a ' '.
Interface to objects that support dumping their state to a string.
common::SystemError receiveInt64(int64_t &value)
receive an int64_t
void setBlocking(bool blocking)
Set the Socket blocking mode.
virtual socklen_t getReceiveBufSize() const
Get the maximum buffer length for receive.
virtual void close()
Closes the socket, causing the connection, if it exists, to be terminated.
void setReUseAddress()
Enable the socket to re-use an address when listen/bind is called.
common::SystemError sendInt16(int16_t value, bool more=false)
Send an int16_t.
AddressFamily
Addres family type.
Generic network Address, supporting ipv4 and ipv6 transparently.
void setTTL(int ttl)
Set the Socket TTL (Time to Live).
SocketParams::SocketType getSocketType() const
Get the SocketParams::SocketType of the socket.
common::SystemError sendUInt8(uint8_t value, bool more=false)
Send an uint8_t.
common::SystemError receiveInt8(int8_t &value)
receive an int8_t
common::SystemError receiveLine(std::string &s)
receive a stream of characters until a ' ' is read (consumed from the socket read buffer but not adde...
common::SystemError sendUInt32(uint32_t value, bool more=false)
Send an uint32_t.
common::SystemError sendInt64(int64_t value, bool more=false)
Send an int64_t.
common::SystemError sendInt32(int32_t value, bool more=false)
Send an int32_t.
socklen_t getSendBufSize() const
Get the maximum buffer length for send.
common::SystemError sendUInt16(uint16_t value, bool more=false)
Send an uint16_t.
void setTCPKeepAlive(bool enable)
Enable or disable TCP keep-alive on the socket.
virtual BaseSocket * accept()=0
Accepts a connection request and return a pointer to a new Socket for the new connection,...
BaseSocket()
Default constructor creates an invalid socket.
common::SystemError receiveUInt16(uint16_t &value)
receive an uint16_t
SocketParams::AddressFamily getAddressFamily() const
Get the SocketParams::AddressFamily of the socket.
Socket parameters - the family (domain), socket type and protocol triplet.
common::SystemError sendUInt64(uint64_t value, bool more=false)
Send an sendUInt64.
int socket_
The socket file decsriptor.
int getTTL() const
Get the Socket TTL (time to live) or the max number of packet hops.
virtual bool getBlocking() const
Rerurn true if the socket is operating in blocking mode.
virtual common::SystemError receive(void *buf, ssize_t request, ssize_t &received)=0
Receive bytes from the socket.
Address getAddress() const
Get the local address for this socket.
int getFD() const
Return the socket file descriptor.
common::SystemError receiveString(std::string &s)
Receive a std::string as sent by sendString( const std::string& ).
Interface for network communication.
SocketParams getSocketParams() const
Return the SocketParams.
void setSendBufSize(socklen_t size)
Set the size of the send buffer.
bool operator<(const BaseSocket &socket) const
Add ordering.
bool isValid() const
Return true when the socket descriptor is a valid, hence 'possible' descriptor.
common::SystemError receiveUInt8(uint8_t &value)
receive an uint8_t
virtual std::string debugDetail() const
Return debug object state as a string.
common::SystemError receiveUInt64(uint64_t &value)
receive an uint64_t
Linux system error primitive to provide a consistent interface to Linux error codes.
SocketParams::ProtocolNumber getProtocolNumber() const
Get the SocketParams::ProtocolNumber of the socket.
void setReceiveBufSize(socklen_t size)
Set the size of the receive buffer.
common::SystemError sendString(const std::string &s, bool more=false)
Sends the std::string as understood by receiveString().
BaseSocket & operator=(int socket)
Assign from existing socket descriptor (int).
ProtocolNumber
IANA Protocol number.
SocketType
Socket Type type.
void setReUsePort()
Make the socket re-use a port when listen is called.
common::SystemError receiveInt32(int32_t &value)
receive an int32_t
common::SystemError receiveUInt32(uint32_t &value)
receive an uint32_t
virtual ~BaseSocket()
Destructs this Socket, but does not call close().
void setSendTimeout(double sec)
Set the send timeout - a send will fail if there is no data send before the timeout expires.
common::SystemError receiveInt16(int16_t &value)
receive an int16_t
common::SystemError bind(const Address &address)
Bind the socket to the Address.
Interface to and common implementation of concrete sockets (Socket, TLSSocket).
virtual common::SystemError send(const void *buf, ssize_t len, bool more=false)=0
Send bytes on the socket.