dodo  0.0.1
A C++ library to create containerized Linux services
basesocket.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the dodo library (https://github.com/jmspit/dodo).
3  * Copyright (c) 2019 Jan-Marten Spit.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /**
19  * @file basesocket.hpp
20  * Defines the dodo::network::BaseSocket class.
21  */
22 
23 #ifndef network_basesocket_hpp
24 #define network_basesocket_hpp
25 
26 #include <fcntl.h>
27 
28 #include "common/exception.hpp"
29 #include "network/address.hpp"
30 
31 namespace dodo::network {
32 
33  /**
34  * Interface to and common implementation of concrete sockets (Socket, TLSSocket).
35  */
37  public:
38 
39  /**
40  * Default constructor creates an invalid socket.
41  */
42  BaseSocket();
43 
44  /**
45  * Construct from a socket descriptor.
46  * @param socket The socket file descriptor.
47  */
48  BaseSocket( int socket );
49 
50  /**
51  * Construct from SocketParams.
52  * @param blocking If true, create the socket in blocking mode.
53  * @param params The SocketParams to use.
54  */
55  explicit BaseSocket( bool blocking, SocketParams params );
56 
57  /**
58  * Destructs this Socket, but does not call close().
59  */
60  virtual ~BaseSocket() {};
61 
62  /**
63  * Return debug object state as a string.
64  * @return The string.
65  */
66  virtual std::string debugDetail() const;
67 
68  /**
69  * Connect to the address. These common::SystemError may be returned:
70  *
71  * - SystemError::ecOK
72  * - SystemError::ecEACCES
73  * - SystemError::ecEADDRINUSE
74  * - SystemError::ecEADDRNOTAVAIL
75  * - SystemError::ecEALREADY
76  * - SystemError::ecECONNREFUSED
77  * - SystemError::ecEINPROGRESS
78  * - SystemError::ecEISCONN
79  * - SystemError::ecENETUNREACH
80  * - SystemError::ecETIMEDOUT
81  *
82  * In case the system returns other system errors on connect, a common::Exception is thrown.
83  * @param address The address to connect to.
84  * @return The SystemError
85  */
86  virtual common::SystemError connect( const Address &address );
87 
88  /**
89  * Closes the socket, causing the connection, if it exists, to be terminated.
90  */
91  virtual void close();
92 
93  /**
94  * Send bytes on the socket.
95  * @param buf Take bytes from here
96  * @param len The number of bytes.
97  * @param more Set to true if more is to come (increases packet filling efficiency when accurate).
98  * @return The SystemError.
99  */
100  virtual common::SystemError send( const void* buf, ssize_t len, bool more = false ) = 0;
101 
102  /**
103  * Receive bytes from the socket.
104  * @param buf Put bytes received here
105  * @param request The maximum number of bytes to receive
106  * @param received The number of bytes received
107  * @return The SystemError.
108  */
109  virtual common::SystemError receive( void* buf, ssize_t request, ssize_t &received ) = 0;
110 
111  /**
112  * Rerurn true if the socket is operating in blocking mode.
113  * @return The mode.
114  */
115  virtual bool getBlocking() const;
116 
117  /**
118  * Return the socket file descriptor.
119  * @return The socket descriptor.
120  */
121  int getFD() const { return socket_; };
122 
123  /**
124  * Return true when the socket descriptor is a valid, hence 'possible' descriptor.
125  * A valid decsriptor does not have to be open/connected or even correct - a valid decsriptor is not -1.
126  * @return true of the socket is a valid descriptor ( >= 0 );
127  */
128  bool isValid() const { return socket_ >= 0; };
129 
130  /**
131  * Set the Socket blocking mode.
132  * @param blocking Blocking if true.
133  */
134  void setBlocking( bool blocking );
135 
136  /**
137  * Set TCP_NODELAY. If true, disable Nagle's algorithm.
138  * @param set If true, set TCP_NODELAY.
139  */
140  void setTCPNoDelay( bool set );
141 
142  /**
143  * Enable the socket to re-use an address when listen/bind is called.
144  * In transit TCP messages sent to a server previously listening on this address
145  * will not be picked up by the re-used address.
146  * @see setReUsePort()
147  */
148  void setReUseAddress();
149 
150  /**
151  * Make the socket re-use a port when listen is called.
152  * @see setReUseAddress()
153  */
154  void setReUsePort();
155 
156  /**
157  * Get the maximum buffer length for send.
158  * @return The send buffer size.
159  * @see setSendBufSize
160  */
161  socklen_t getSendBufSize() const;
162 
163  /**
164  * Get the maximum buffer length for receive.
165  * @return The receive buffer size.
166  * @see setReceiveBufSize()
167  */
168  virtual socklen_t getReceiveBufSize() const;
169 
170  /**
171  * Get the Socket TTL (time to live) or the max number of packet hops.
172  * @return The current socket TTL value.
173  */
174  int getTTL() const;
175 
176  /**
177  * Set the size of the send buffer. Linux will (at least) double the memory for socket accounting purposes.
178  * If size < system minimum size or size > system maximum size, the system will silently overrule.
179  * Also note that getSendBufSize() and getReceiveBufSize() return the size of the kernel send buffer divided by
180  * two, as the Linux man 7 socket states:
181  * "...Linux assumes that half of the send/receive buffer is used for internal kernel structures;"
182  * So getSendBufSize() and getReceiveBufSize() return the values from a programmer perspective - it is the number
183  * of bytes the programmer can actually send or receive in one go
184  * @code
185  * Socket s;
186  * s.setSendBufSize(8192); // kernel has set it to 16384
187  * int n = s.getSendBufSize(); // n = 8192
188  * char buffer[s.getSendBufSize()]; // which is what you asked for and will fit
189  * @endcode
190  * @param size The size to set the send buffer to.
191  */
192  void setSendBufSize( socklen_t size );
193 
194  /**
195  * Set the Socket TTL (Time to Live).
196  * @param ttl The ttl value to set.
197  * @see getTTL()
198  */
199  void setTTL( int ttl );
200 
201  /**
202  * Set the size of the receive buffer. Linux will (at least) double the memory for socket accounting purposes.
203  * If size < system minimum size, the system will set the latter.
204  * @see setSendBufSize( socklen_t size )
205  * @param size The size to set the receive buffer to.
206  */
207  void setReceiveBufSize( socklen_t size );
208 
209  /**
210  * Set the receive timeout - a receive will fail if there is no data received before the timeout expires.
211  * Note that the default is 0 seconds, meaning no timeout / wait forever.
212  * @param sec Timeout value, in seconds, fractions allowed.
213  */
214  void setReceiveTimeout( double sec );
215 
216  /**
217  * Set the send timeout - a send will fail if there is no data send before the timeout expires.
218  * Note that the default is 0 seconds, meaning no timeout / wait forever.
219  * @param sec Timeout value, in seconds, fractions allowed.
220  */
221  void setSendTimeout( double sec );
222 
223  /**
224  * Enable or disable TCP keep-alive on the socket. This might be useful to keep connections ope that run
225  * through a firewall that disconnects connections that are idle. Note that keep-alive itself is configured
226  * through the Linux kernel. Note that enabling keep-alive will not change the behavior of the socket
227  * from a developers perspective but ti does incur a bit of network overhead.
228  * @param enable If true enable, otherwise disable.
229  */
230  void setTCPKeepAlive( bool enable );
231 
232  /**
233  * Get the local address for this socket.
234  * @return The local Address.
235  */
236  Address getAddress() const;
237 
238  /**
239  * Get the SocketParams::AddressFamily of the socket.
240  * @return The address family.
241  */
243 
244  /**
245  * Get the SocketParams::SocketType of the socket.
246  * @return The SocketType.
247  */
249 
250  /**
251  * Get the SocketParams::ProtocolNumber of the socket.
252  * @return The ProtocolNumber.
253  */
255 
256  /**
257  * Return the SocketParams.
258  * @see getAddressFamily(), getSocketType(), getProtocolNumber()
259  * @return the SocketParams.
260  */
262 
263  /**
264  * Get the peer (remote) address for this socket.
265  * @return The peer Address.
266  */
267  Address getPeerAddress() const;
268 
269  /**
270  * Add identity
271  * @param socket The socket to compare to.
272  * @return True if both sockets are equal and have the sxame value of socket_.
273  */
274  bool operator==(const BaseSocket& socket ) const { return this->socket_ == socket.socket_; };
275 
276  /**
277  * Add ordering
278  * @param socket The socket to compare to.
279  * @return True if this Socket has a smaller socket descriptor than socket.
280  */
281  bool operator<(const BaseSocket& socket ) const { return this->socket_ < socket.socket_; };
282 
283  /**
284  * Assign from existing socket descriptor (int).
285  * @param socket The socket value to assign to this Socket.
286  * @return This Socket.
287  */
288  BaseSocket& operator=( int socket );
289 
290  /**
291  * Assign from Socket.
292  * @param socket The Socket to assign/copy to this Socket.
293  * @return This Socket.
294  */
295  BaseSocket& operator=( const BaseSocket& socket );
296 
297  /**
298  * Sets up a listening socket on Address.
299  * @param address The Address (including a port) to listen on.
300  * @param backlog The size of the queue used to cache pending connections.
301  * @return A common::SystemError, if not ecOK
302  * - common::SystemError::ecEADDRINUSE
303  * - common::SystemError::ecEBADF
304  * - common::SystemError::ecENOTSOCK
305  * - common::SystemError::ecEOPNOTSUPP
306  *
307  * or one of the common::SystemError returned by bind( const Address &address ).
308  */
309  common::SystemError listen( const Address &address, int backlog );
310 
311  /**
312  * Bind the socket to the Address.
313  * @param address The address to bind to.
314  * @return SystemError::ecOK or
315  * - SystemError::ecEACCES
316  * - SystemError::ecEADDRINUSE
317  * - SystemError::ecEBADF
318  * - SystemError::ecEINVAL
319  * - SystemError::ecENOTSOCK
320  */
321  common::SystemError bind( const Address &address );
322 
323  /**
324  * Accepts a connection request and return a pointer to a new Socket for the new connection, the caller will
325  * own the new Socket object.
326  * @return The accepted socket.
327  */
328  virtual BaseSocket* accept() = 0;
329 
330  /**
331  * Send an uint8_t.
332  * @param value The value to send.
333  * @param more If true, the caller indicates that more data will follow.
334  * @return Same as send( const void* buf, ssize_t len )
335  * @see receiveUInt8( uint8_t& )
336  */
337  common::SystemError sendUInt8( uint8_t value, bool more = false );
338 
339  /**
340  * receive an uint8_t
341  * @param value The value received.
342  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
343  * @see sendUInt8( uint8_t )
344  */
345  common::SystemError receiveUInt8( uint8_t &value );
346 
347  /**
348  * Send an uint16_t.
349  * @param value The value to send.
350  * @param more If true, the caller indicates that more data will follow.
351  * @return Same as send( const void* buf, ssize_t len )
352  * @see receiveUInt16( uint16_t& )
353  */
354  common::SystemError sendUInt16( uint16_t value, bool more = false );
355 
356  /**
357  * receive an uint16_t
358  * @param value The value received.
359  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
360  * @see sendUInt16( uint16_t )
361  */
362  common::SystemError receiveUInt16( uint16_t &value );
363 
364  /**
365  * Send an uint32_t.
366  * @param value The value to send.
367  * @param more If true, the caller indicates that more data will follow.
368  * @return Same as send( const void* buf, ssize_t len )
369  * @see receiveUInt32( uint32_t& )
370  */
371  common::SystemError sendUInt32( uint32_t value, bool more = false );
372 
373  /**
374  * receive an uint32_t
375  * @param value The value received.
376  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
377  * @see sendUInt32( uint32_t )
378  */
379  common::SystemError receiveUInt32( uint32_t &value );
380 
381  /**
382  * Send an sendUInt64.
383  * @param value The value to send.
384  * @param more If true, the caller indicates that more data will follow.
385  * @return Same as send( const void* buf, ssize_t len )
386  * @see receiveUInt64( uint64_t& )
387  */
388  common::SystemError sendUInt64( uint64_t value, bool more = false );
389 
390  /**
391  * receive an uint64_t
392  * @param value The value received.
393  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
394  * @see sendUInt64( uint64_t )*
395  */
396  common::SystemError receiveUInt64( uint64_t &value );
397 
398  /**
399  * Send an int8_t.
400  * @param value The value to send.
401  * @param more If true, the caller indicates that more data will follow.
402  * @return Same as send( const void* buf, ssize_t len )
403  * @see receiveInt8( int8_t& )
404  */
405  common::SystemError sendInt8( int8_t value, bool more = false );
406 
407  /**
408  * receive an int8_t
409  * @param value The value received.
410  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
411  * @see sendInt8( int8_t )*
412  */
413  common::SystemError receiveInt8( int8_t &value );
414 
415  /**
416  * Send an int16_t.
417  * @param value The value to send.
418  * @param more If true, the caller indicates that more data will follow.
419  * @return Same as send( const void* buf, ssize_t len )
420  * @see receiveInt16( int16_t& )
421  */
422  common::SystemError sendInt16( int16_t value, bool more = false );
423 
424  /**
425  * receive an int16_t
426  * @param value The value received.
427  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
428  * @see sendInt16( int16_t )*
429  */
430  common::SystemError receiveInt16( int16_t &value );
431 
432  /**
433  * Send an int32_t.
434  * @param value The value to send.
435  * @param more If true, the caller indicates that more data will follow.
436  * @return Same as send( const void* buf, ssize_t len )
437  * @see receiveInt32( int32_t& )
438  */
439  common::SystemError sendInt32( int32_t value, bool more = false );
440 
441  /**
442  * receive an int32_t
443  * @param value The value received.
444  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
445  * @see sendInt32( int32_t )*
446  */
447  common::SystemError receiveInt32( int32_t &value );
448 
449  /**
450  * Send an int64_t.
451  * @param value The value to send.
452  * @param more If true, the caller indicates that more data will follow.
453  * @return Same as send( const void* buf, ssize_t len )
454  * @see receiveInt64( int64_t& )
455  */
456  common::SystemError sendInt64( int64_t value, bool more = false );
457 
458  /**
459  * receive an int64_t
460  * @param value The value received.
461  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
462  * @see sendInt64( int64_t )*
463  */
464  common::SystemError receiveInt64( int64_t &value );
465 
466  /**
467  * Sends the std::string as understood by receiveString(). The send prefixes the string length in an uint64_t,
468  * the number of bytes (characters) that follow.
469  * @param s The string to send.
470  * @param more If true, the caller indicates that more data will follow.
471  * @return Same as send( const void* buf, ssize_t len )
472  */
473  common::SystemError sendString( const std::string &s, bool more = false );
474 
475  /**
476  * Receive a std::string as sent by sendString( const std::string& ).
477  * @param s The string to receive into.
478  * @return Same as receive( void* buf, ssize_t request, ssize_t &received )
479  */
480  common::SystemError receiveString( std::string &s );
481 
482  /**
483  * Sends the std::string terminated by a '\n'.
484  * @param s The string to send.
485  * @param more If true, the caller indicates that more data will follow.
486  * @return Same as send( const void* buf, ssize_t len )
487  */
488  common::SystemError sendLine( const std::string &s, bool more );
489 
490  /**
491  * receive a stream of characters until a '\n' is read (consumed from the socket read buffer but not
492  * added to s).
493  * @param s receives the read string.
494  * @return The SystemError.
495  */
496  common::SystemError receiveLine( std::string &s );
497 
498  protected:
499 
500  /**
501  * The socket file decsriptor.
502  */
503  int socket_;
504 
505  };
506 
507 }
508 
509 #endif
dodo::network::BaseSocket::setReceiveTimeout
void setReceiveTimeout(double sec)
Set the receive timeout - a receive will fail if there is no data received before the timeout expires...
Definition: basesocket.cpp:209
dodo::network::BaseSocket::sendInt8
common::SystemError sendInt8(int8_t value, bool more=false)
Send an int8_t.
Definition: basesocket.cpp:323
dodo::network::BaseSocket::setTCPNoDelay
void setTCPNoDelay(bool set)
Set TCP_NODELAY.
Definition: basesocket.cpp:115
dodo::network::BaseSocket::getPeerAddress
Address getPeerAddress() const
Get the peer (remote) address for this socket.
Definition: basesocket.cpp:273
dodo::network::BaseSocket::listen
common::SystemError listen(const Address &address, int backlog)
Sets up a listening socket on Address.
Definition: basesocket.cpp:89
dodo::network::BaseSocket::connect
virtual common::SystemError connect(const Address &address)
Connect to the address.
Definition: basesocket.cpp:52
dodo::network::BaseSocket::operator==
bool operator==(const BaseSocket &socket) const
Add identity.
Definition: basesocket.hpp:274
dodo::network::BaseSocket::sendLine
common::SystemError sendLine(const std::string &s, bool more)
Sends the std::string terminated by a ' '.
Definition: basesocket.cpp:480
dodo::common::DebugObject
Interface to objects that support dumping their state to a string.
Definition: exception.hpp:39
dodo::network::BaseSocket::receiveInt64
common::SystemError receiveInt64(int64_t &value)
receive an int64_t
Definition: basesocket.cpp:433
dodo::network::BaseSocket::setBlocking
void setBlocking(bool blocking)
Set the Socket blocking mode.
Definition: basesocket.cpp:131
dodo::network::BaseSocket::getReceiveBufSize
virtual socklen_t getReceiveBufSize() const
Get the maximum buffer length for receive.
Definition: basesocket.cpp:177
dodo::network::BaseSocket::close
virtual void close()
Closes the socket, causing the connection, if it exists, to be terminated.
Definition: basesocket.cpp:71
dodo::network::BaseSocket::setReUseAddress
void setReUseAddress()
Enable the socket to re-use an address when listen/bind is called.
Definition: basesocket.cpp:148
dodo::network::BaseSocket::sendInt16
common::SystemError sendInt16(int16_t value, bool more=false)
Send an int16_t.
Definition: basesocket.cpp:344
dodo::network::SocketParams::AddressFamily
AddressFamily
Addres family type.
Definition: socketparams.hpp:41
dodo::network::Address
Generic network Address, supporting ipv4 and ipv6 transparently.
Definition: address.hpp:90
dodo::network::BaseSocket::setTTL
void setTTL(int ttl)
Set the Socket TTL (Time to Live).
Definition: basesocket.cpp:229
dodo::network::BaseSocket::getSocketType
SocketParams::SocketType getSocketType() const
Get the SocketParams::SocketType of the socket.
Definition: basesocket.cpp:252
dodo::network::BaseSocket::sendUInt8
common::SystemError sendUInt8(uint8_t value, bool more=false)
Send an uint8_t.
Definition: basesocket.cpp:281
dodo::network::BaseSocket::receiveInt8
common::SystemError receiveInt8(int8_t &value)
receive an int8_t
Definition: basesocket.cpp:328
dodo::network::BaseSocket::receiveLine
common::SystemError receiveLine(std::string &s)
receive a stream of characters until a ' ' is read (consumed from the socket read buffer but not adde...
Definition: basesocket.cpp:488
dodo::network::BaseSocket::sendUInt32
common::SystemError sendUInt32(uint32_t value, bool more=false)
Send an uint32_t.
Definition: basesocket.cpp:365
dodo::network::BaseSocket::sendInt64
common::SystemError sendInt64(int64_t value, bool more=false)
Send an int64_t.
Definition: basesocket.cpp:428
dodo::network::BaseSocket::sendInt32
common::SystemError sendInt32(int32_t value, bool more=false)
Send an int32_t.
Definition: basesocket.cpp:386
dodo::network::BaseSocket::getSendBufSize
socklen_t getSendBufSize() const
Get the maximum buffer length for send.
Definition: basesocket.cpp:169
dodo::network::BaseSocket::sendUInt16
common::SystemError sendUInt16(uint16_t value, bool more=false)
Send an uint16_t.
Definition: basesocket.cpp:302
dodo::network::BaseSocket::setTCPKeepAlive
void setTCPKeepAlive(bool enable)
Enable or disable TCP keep-alive on the socket.
Definition: basesocket.cpp:120
dodo::network::BaseSocket::accept
virtual BaseSocket * accept()=0
Accepts a connection request and return a pointer to a new Socket for the new connection,...
dodo::network::BaseSocket::BaseSocket
BaseSocket()
Default constructor creates an invalid socket.
Definition: basesocket.cpp:31
dodo::network::BaseSocket::receiveUInt16
common::SystemError receiveUInt16(uint16_t &value)
receive an uint16_t
Definition: basesocket.cpp:307
dodo::network::BaseSocket::getAddressFamily
SocketParams::AddressFamily getAddressFamily() const
Get the SocketParams::AddressFamily of the socket.
Definition: basesocket.cpp:244
dodo::network::SocketParams
Socket parameters - the family (domain), socket type and protocol triplet.
Definition: socketparams.hpp:35
dodo::network::BaseSocket::sendUInt64
common::SystemError sendUInt64(uint64_t value, bool more=false)
Send an sendUInt64.
Definition: basesocket.cpp:407
dodo::network::BaseSocket::socket_
int socket_
The socket file decsriptor.
Definition: basesocket.hpp:503
dodo::network::BaseSocket::getTTL
int getTTL() const
Get the Socket TTL (time to live) or the max number of packet hops.
Definition: basesocket.cpp:185
dodo::network::BaseSocket::getBlocking
virtual bool getBlocking() const
Rerurn true if the socket is operating in blocking mode.
Definition: basesocket.cpp:125
address.hpp
dodo::network::BaseSocket::receive
virtual common::SystemError receive(void *buf, ssize_t request, ssize_t &received)=0
Receive bytes from the socket.
dodo::network::BaseSocket::getAddress
Address getAddress() const
Get the local address for this socket.
Definition: basesocket.cpp:236
dodo::network::BaseSocket::getFD
int getFD() const
Return the socket file descriptor.
Definition: basesocket.hpp:121
dodo::network::BaseSocket::receiveString
common::SystemError receiveString(std::string &s)
Receive a std::string as sent by sendString( const std::string& ).
Definition: basesocket.cpp:459
dodo::network
Interface for network communication.
Definition: address.hpp:37
dodo::network::BaseSocket::getSocketParams
SocketParams getSocketParams() const
Return the SocketParams.
Definition: basesocket.cpp:268
dodo::network::BaseSocket::setSendBufSize
void setSendBufSize(socklen_t size)
Set the size of the send buffer.
Definition: basesocket.cpp:199
dodo::network::BaseSocket::operator<
bool operator<(const BaseSocket &socket) const
Add ordering.
Definition: basesocket.hpp:281
dodo::network::BaseSocket::isValid
bool isValid() const
Return true when the socket descriptor is a valid, hence 'possible' descriptor.
Definition: basesocket.hpp:128
dodo::network::BaseSocket::receiveUInt8
common::SystemError receiveUInt8(uint8_t &value)
receive an uint8_t
Definition: basesocket.cpp:286
dodo::network::BaseSocket::debugDetail
virtual std::string debugDetail() const
Return debug object state as a string.
Definition: basesocket.cpp:46
exception.hpp
dodo::network::BaseSocket::receiveUInt64
common::SystemError receiveUInt64(uint64_t &value)
receive an uint64_t
Definition: basesocket.cpp:412
dodo::common::SystemError
Linux system error primitive to provide a consistent interface to Linux error codes.
Definition: systemerror.hpp:53
dodo::network::BaseSocket::getProtocolNumber
SocketParams::ProtocolNumber getProtocolNumber() const
Get the SocketParams::ProtocolNumber of the socket.
Definition: basesocket.cpp:260
dodo::network::BaseSocket::setReceiveBufSize
void setReceiveBufSize(socklen_t size)
Set the size of the receive buffer.
Definition: basesocket.cpp:204
dodo::network::BaseSocket::sendString
common::SystemError sendString(const std::string &s, bool more=false)
Sends the std::string as understood by receiveString().
Definition: basesocket.cpp:449
dodo::network::BaseSocket::operator=
BaseSocket & operator=(int socket)
Assign from existing socket descriptor (int).
Definition: basesocket.cpp:79
dodo::network::SocketParams::ProtocolNumber
ProtocolNumber
IANA Protocol number.
Definition: socketparams.hpp:73
dodo::network::SocketParams::SocketType
SocketType
Socket Type type.
Definition: socketparams.hpp:59
dodo::network::BaseSocket::setReUsePort
void setReUsePort()
Make the socket re-use a port when listen is called.
Definition: basesocket.cpp:159
dodo::network::BaseSocket::receiveInt32
common::SystemError receiveInt32(int32_t &value)
receive an int32_t
Definition: basesocket.cpp:391
dodo::network::BaseSocket::receiveUInt32
common::SystemError receiveUInt32(uint32_t &value)
receive an uint32_t
Definition: basesocket.cpp:370
dodo::network::BaseSocket::~BaseSocket
virtual ~BaseSocket()
Destructs this Socket, but does not call close().
Definition: basesocket.hpp:60
dodo::network::BaseSocket::setSendTimeout
void setSendTimeout(double sec)
Set the send timeout - a send will fail if there is no data send before the timeout expires.
Definition: basesocket.cpp:219
dodo::network::BaseSocket::receiveInt16
common::SystemError receiveInt16(int16_t &value)
receive an int16_t
Definition: basesocket.cpp:349
dodo::network::BaseSocket::bind
common::SystemError bind(const Address &address)
Bind the socket to the Address.
Definition: basesocket.cpp:103
dodo::network::BaseSocket
Interface to and common implementation of concrete sockets (Socket, TLSSocket).
Definition: basesocket.hpp:36
dodo::network::BaseSocket::send
virtual common::SystemError send(const void *buf, ssize_t len, bool more=false)=0
Send bytes on the socket.