|
join 1.0
lightweight network framework library
|
basic socket class. More...
#include <socket.hpp>


Public Types | |
| enum | Mode { Blocking , NonBlocking } |
| socket modes. More... | |
| enum | Option { NoDelay , KeepAlive , KeepIdle , KeepIntvl , KeepCount , SndBuffer , RcvBuffer , TimeStamp , ReuseAddr , ReusePort , Broadcast , Ttl , MulticastLoop , MulticastTtl , PathMtuDiscover , RcvError , AuxData } |
| socket options. More... | |
| enum | State { Connecting , Connected , Disconnecting , Disconnected , Closed } |
| socket states. More... | |
| using | Ptr = std::unique_ptr <BasicSocket <Protocol>> |
| using | Endpoint = typename Protocol::Endpoint |
Public Member Functions | |
| BasicSocket () | |
| default constructor. | |
| BasicSocket (Mode mode) | |
| create socket instance specifying the mode. | |
| BasicSocket (const BasicSocket &other)=delete | |
| copy constructor. | |
| BasicSocket & | operator= (const BasicSocket &other)=delete |
| copy assignment operator. | |
| BasicSocket (BasicSocket &&other) | |
| move constructor. | |
| BasicSocket & | operator= (BasicSocket &&other) |
| move assignment operator. | |
| virtual | ~BasicSocket () |
| destroy the socket instance. | |
| virtual int | open (const Protocol &protocol=Protocol()) noexcept |
| open socket using the given protocol. | |
| virtual void | close () noexcept |
| close the socket. | |
| virtual int | bind (const Endpoint &endpoint) noexcept |
| assigns the specified endpoint to the socket. | |
| virtual int | canRead () const noexcept |
| get the number of readable bytes. | |
| virtual bool | waitReadyRead (int timeout=0) const noexcept |
| block until new data is available for reading. | |
| virtual int | read (char *data, unsigned long maxSize) noexcept |
| read data. | |
| virtual bool | waitReadyWrite (int timeout=0) const noexcept |
| block until at least one byte can be written. | |
| virtual int | write (const char *data, unsigned long maxSize) noexcept |
| write data. | |
| void | setMode (Mode mode) noexcept |
| set the socket to the non-blocking or blocking mode. | |
| virtual int | setOption (Option option, int value) noexcept |
| set the given option to the given value. | |
| Endpoint | localEndpoint () const |
| determine the local endpoint associated with this socket. | |
| bool | opened () const noexcept |
| check if the socket is opened. | |
| virtual bool | encrypted () const noexcept |
| check if the socket is secure. | |
| int | family () const noexcept |
| get socket address family. | |
| int | type () const noexcept |
| get the protocol communication semantic. | |
| int | protocol () const noexcept |
| get socket protocol. | |
| int | handle () const noexcept override |
| get socket native handle. | |
Public Member Functions inherited from join::EventHandler | |
| EventHandler ()=default | |
| create instance. | |
| virtual | ~EventHandler ()=default |
| destroy instance. | |
Static Public Member Functions | |
| static uint16_t | checksum (const uint16_t *data, size_t len, uint16_t current=0) |
| get standard 1s complement checksum. | |
Protected Member Functions | |
| int | wait (bool wantRead, bool wantWrite, int timeout) const noexcept |
| wait for the socket handle to become ready. | |
Protected Member Functions inherited from join::EventHandler | |
| virtual void | onReceive () |
| method called when data are ready to be read on handle. | |
| virtual void | onClose () |
| method called when handle is closed. | |
| virtual void | onError () |
| method called when an error occured on handle. | |
Protected Attributes | |
| State | _state = State::Closed |
| socket state. | |
| Mode | _mode = Mode::NonBlocking |
| socket mode. | |
| int | _handle = -1 |
| socket handle. | |
| Protocol | _protocol |
| protocol. | |
basic socket class.
| using join::BasicSocket< Protocol >::Endpoint = typename Protocol::Endpoint |
| using join::BasicSocket< Protocol >::Ptr = std::unique_ptr <BasicSocket <Protocol>> |
| enum join::BasicSocket::Mode |
| enum join::BasicSocket::Option |
socket options.
| enum join::BasicSocket::State |
|
inline |
default constructor.
|
inline |
create socket instance specifying the mode.
| mode | blocking mode. |
|
delete |
copy constructor.
| other | other object to copy. |
|
inline |
move constructor.
| other | other object to move. |
|
inlinevirtual |
destroy the socket instance.
|
inlinevirtualnoexcept |
assigns the specified endpoint to the socket.
| endpoint | endpoint to assign to the socket. |
|
inlinevirtualnoexcept |
get the number of readable bytes.
Reimplemented in join::BasicTlsSocket< Protocol >.
|
inlinestatic |
get standard 1s complement checksum.
| data | data pointer. |
| len | data len. |
| current | Current sum. |
|
inlinevirtualnoexcept |
close the socket.
Reimplemented in join::BasicDatagramSocket< Protocol >, and join::BasicTlsSocket< Protocol >.
|
inlinevirtualnoexcept |
check if the socket is secure.
Reimplemented in join::BasicTlsSocket< Protocol >.
|
inlinenoexcept |
get socket address family.
|
inlineoverridevirtualnoexcept |
|
inline |
determine the local endpoint associated with this socket.
|
inlinevirtualnoexcept |
open socket using the given protocol.
| protocol | protocol to use. |
Reimplemented in join::BasicDatagramSocket< Protocol >.
|
inlinenoexcept |
check if the socket is opened.
|
inline |
move assignment operator.
| other | other object to assign. |
|
delete |
copy assignment operator.
| other | other object to assign. |
|
inlinenoexcept |
get socket protocol.
|
inlinevirtualnoexcept |
read data.
| data | buffer used to store the data received. |
| maxSize | maximum number of bytes to read. |
Reimplemented in join::BasicDatagramSocket< Protocol >, and join::BasicTlsSocket< Protocol >.
|
inlinenoexcept |
set the socket to the non-blocking or blocking mode.
| mode | blocking mode. |
|
inlinevirtualnoexcept |
set the given option to the given value.
| option | socket option. |
| value | option value. |
Reimplemented in join::BasicDatagramSocket< Protocol >, and join::BasicStreamSocket< Protocol >.
|
inlinenoexcept |
get the protocol communication semantic.
|
inlineprotectednoexcept |
wait for the socket handle to become ready.
| wantRead | set to true if want read |
| wantWrite | set to true if want write. |
| timeout | timeout in milliseconds. |
|
inlinevirtualnoexcept |
block until new data is available for reading.
| timeout | timeout in milliseconds. |
Reimplemented in join::BasicTlsSocket< Protocol >.
|
inlinevirtualnoexcept |
block until at least one byte can be written.
| timeout | timeout in milliseconds. |
Reimplemented in join::BasicTlsSocket< Protocol >.
|
inlinevirtualnoexcept |
write data.
| data | data buffer to send. |
| maxSize | maximum number of bytes to write. |
Reimplemented in join::BasicDatagramSocket< Protocol >, and join::BasicTlsSocket< Protocol >.
|
protected |
socket handle.
|
protected |
socket mode.
|
protected |
protocol.
|
protected |
socket state.