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


Public Types | |
| using | Ptr = std::unique_ptr<BasicStreamSocket<Protocol>> |
| using | Mode = typename BasicRawSocket<Protocol>::Mode |
| using | Option = typename BasicRawSocket<Protocol>::Option |
| using | State = typename BasicRawSocket<Protocol>::State |
| using | Endpoint = typename Protocol::Endpoint |
| using | TimePoint = typename BasicRawSocket<Protocol>::TimePoint |
Public Types inherited from join::BasicRawSocket< Protocol > | |
| enum | Option { NoDelay , KeepAlive , KeepIdle , KeepIntvl , KeepCount , SndBuffer , RcvBuffer , TimeStamp , ReuseAddr , ReusePort , Broadcast , Ttl , MulticastLoop , MulticastTtl , PathMtuDiscover , RcvError , AuxData } |
| socket options. More... | |
| using | Ptr = std::unique_ptr<BasicRawSocket<Protocol>> |
| using | Mode = typename BasicSocket<Protocol>::Mode |
| using | State = typename BasicSocket<Protocol>::State |
| using | Endpoint = typename Protocol::Endpoint |
Public Types inherited from join::BasicSocket< Protocol > | |
| enum | Mode { Blocking , NonBlocking } |
| socket modes. More... | |
| enum | State { Connecting , Connected , Disconnecting , Disconnected , Closed } |
| socket states. More... | |
| using | Ptr = std::unique_ptr<BasicSocket<Protocol>> |
| using | Endpoint = typename Protocol::Endpoint |
| using | TimePoint = std::chrono::steady_clock::time_point |
Public Member Functions | |
| BasicStreamSocket () noexcept | |
| default constructor. | |
| BasicStreamSocket (Mode mode) noexcept | |
| create instance specifying the mode. | |
| BasicStreamSocket (int fd, const Endpoint &remote, Mode mode=Mode::NonBlocking) | |
| create the socket instance adopting an accepted file descriptor. | |
| BasicStreamSocket (const BasicStreamSocket &other)=delete | |
| copy constructor. | |
| BasicStreamSocket & | operator= (const BasicStreamSocket &other)=delete |
| copy assignment operator. | |
| BasicStreamSocket (BasicStreamSocket &&other) noexcept | |
| move constructor. | |
| BasicStreamSocket & | operator= (BasicStreamSocket &&other) noexcept |
| move assignment operator. | |
| ~BasicStreamSocket ()=default | |
| destroy the instance. | |
| int | connect (const Endpoint &endpoint) noexcept |
| make a connection to the given endpoint. | |
| bool | waitConnected () |
| block until connected. | |
| bool | waitConnected (std::chrono::nanoseconds timeout) |
| block until connected, giving up after the given duration. | |
| bool | waitConnected (TimePoint deadline) |
| block until connected, giving up at the given time point. | |
| int | disconnect () noexcept |
| shutdown the connection. | |
| bool | waitDisconnected () |
| wait until the connection as been shut down. return true if the connection as been shut down, false otherwise. | |
| bool | waitDisconnected (std::chrono::nanoseconds timeout) |
| wait until the connection as been shut down, giving up after the given duration. | |
| bool | waitDisconnected (TimePoint deadline) |
| wait until the connection as been shut down, giving up at the given time point. | |
| void | close () noexcept override |
| close the socket handle. | |
| ssize_t | read (char *data, size_t maxSize) noexcept |
| read data. | |
| int | readExactly (char *data, size_t size) noexcept |
| read data until size is reached or an error occurred. | |
| int | readExactly (char *data, size_t size, std::chrono::nanoseconds timeout) noexcept |
| read data until size is reached, an error occurred or the given duration elapsed. | |
| int | readExactly (char *data, size_t size, TimePoint deadline) noexcept |
| read data until size is reached, an error occurred or the deadline expired. | |
| int | writeExactly (const char *data, size_t size) noexcept |
| write data until size is reached or an error occurred. | |
| int | writeExactly (const char *data, size_t size, std::chrono::nanoseconds timeout) noexcept |
| write data until size is reached, an error occurred or the given duration elapsed. | |
| int | writeExactly (const char *data, size_t size, TimePoint deadline) noexcept |
| write data until size is reached, an error occurred or the deadline expired. | |
| int | setOption (Option option, int value) noexcept override |
| set the given option to the given value. | |
| const Endpoint & | remoteEndpoint () const noexcept |
| determine the remote endpoint associated with this socket. | |
| bool | connecting () const noexcept |
| check if the socket is connecting. | |
| bool | connected () noexcept |
| check if the socket is connected. | |
| int | mtu () const noexcept |
| get socket mtu. | |
Public Member Functions inherited from join::BasicRawSocket< Protocol > | |
| BasicRawSocket () noexcept | |
| default constructor. | |
| BasicRawSocket (Mode mode) noexcept | |
| create socket instance specifying the mode. | |
| BasicRawSocket (const BasicRawSocket &other)=delete | |
| copy constructor. | |
| BasicRawSocket & | operator= (const BasicRawSocket &other)=delete |
| copy assignment operator. | |
| BasicRawSocket (BasicRawSocket &&other) noexcept=default | |
| move constructor. | |
| BasicRawSocket & | operator= (BasicRawSocket &&other) noexcept=default |
| move assignment operator. | |
| virtual | ~BasicRawSocket ()=default |
| destroy the socket instance. | |
| int | bind (const Endpoint &endpoint) noexcept override |
| assigns the specified endpoint to the socket. | |
| int | bindToDevice (const std::string &device) noexcept |
| assigns the specified device to the socket. | |
| ssize_t | canRead () const noexcept |
| get the number of readable bytes. | |
| ssize_t | read (char *data, size_t maxSize) noexcept |
| read data. | |
| ssize_t | write (const char *data, size_t maxSize) noexcept |
| write data. | |
Public Member Functions inherited from join::BasicSocket< Protocol > | |
| BasicSocket () noexcept | |
| default constructor. | |
| BasicSocket (Mode mode) noexcept | |
| 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) noexcept | |
| move constructor. | |
| BasicSocket & | operator= (BasicSocket &&other) noexcept |
| move assignment operator. | |
| virtual | ~BasicSocket () |
| destroy the socket instance. | |
| virtual int | open (const Protocol &protocol=Protocol()) noexcept |
| open socket using the given protocol. | |
| bool | waitReadyRead () const noexcept |
| block until new data is available for reading. | |
| bool | waitReadyRead (std::chrono::nanoseconds timeout) const noexcept |
| block until new data is available for reading, giving up after the given duration. | |
| bool | waitReadyRead (TimePoint deadline) const noexcept |
| block until new data is available for reading, giving up at the given time point. | |
| bool | waitReadyWrite () const noexcept |
| block until at least one byte can be written. | |
| bool | waitReadyWrite (std::chrono::nanoseconds timeout) const noexcept |
| block until at least one byte can be written, giving up after the given duration. | |
| bool | waitReadyWrite (TimePoint deadline) const noexcept |
| block until at least one byte can be written, giving up at the given time point. | |
| void | setMode (Mode mode) noexcept |
| set the socket to the non-blocking or blocking mode. | |
| Endpoint | localEndpoint () const noexcept |
| determine the local endpoint associated with this socket. | |
| bool | opened () const noexcept |
| check if the socket is opened. | |
| int | family () const noexcept |
| get socket address family. | |
| int | type () const noexcept |
| get the protocol communication semantic. | |
| int | protocol () const noexcept |
| get socket protocol. | |
| Mode | mode () const noexcept |
| get the blocking mode of the socket. | |
| int | handle () const noexcept |
| get socket native handle. | |
| int | wait (bool wantRead, bool wantWrite) const noexcept |
| wait for the socket handle to become ready. | |
| int | waitFor (bool wantRead, bool wantWrite, std::chrono::nanoseconds timeout) const noexcept |
| wait for the socket handle to become ready, giving up after the given duration. | |
| int | waitUntil (bool wantRead, bool wantWrite, TimePoint deadline) const noexcept |
| wait for the socket handle to become ready, giving up at the given time point. | |
Protected Attributes | |
| Endpoint | _remote |
| remote endpoint. | |
Protected Attributes inherited from join::BasicSocket< Protocol > | |
| State | _state = State::Closed |
| socket state. | |
| Mode | _mode = Mode::NonBlocking |
| socket mode. | |
| int | _handle = -1 |
| socket handle. | |
| Protocol | _protocol |
| protocol. | |
Friends | |
| template<class P , class E , size_t N> | |
| class | BasicAsyncStreamSocket |
| friendship with basic asynchronous stream socket | |
basic stream socket class.
| using join::BasicStreamSocket< Protocol >::Endpoint = typename Protocol::Endpoint |
| using join::BasicStreamSocket< Protocol >::Mode = typename BasicRawSocket<Protocol>::Mode |
| using join::BasicStreamSocket< Protocol >::Option = typename BasicRawSocket<Protocol>::Option |
| using join::BasicStreamSocket< Protocol >::Ptr = std::unique_ptr<BasicStreamSocket<Protocol>> |
| using join::BasicStreamSocket< Protocol >::State = typename BasicRawSocket<Protocol>::State |
| using join::BasicStreamSocket< Protocol >::TimePoint = typename BasicRawSocket<Protocol>::TimePoint |
|
inlinenoexcept |
default constructor.
|
inlineexplicitnoexcept |
create instance specifying the mode.
| mode | Set the socket blocking mode. |
|
inlineexplicit |
create the socket instance adopting an accepted file descriptor.
| fd | accepted file descriptor. |
| remote | endpoint of the connected peer, as reported by the accept. |
| mode | blocking mode the file descriptor was accepted with. |
|
delete |
copy constructor.
| other | other object to copy. |
|
inlinenoexcept |
move constructor.
| other | other object to move. |
|
default |
destroy the instance.
|
inlineoverridevirtualnoexcept |
close the socket handle.
Reimplemented from join::BasicSocket< Protocol >.
|
inlinenoexcept |
make a connection to the given endpoint.
| endpoint | endpoint to connect to. |
|
inlinenoexcept |
check if the socket is connected.
|
inlinenoexcept |
check if the socket is connecting.
|
inlinenoexcept |
shutdown the connection.
|
inlinenoexcept |
get socket mtu.
|
inlinenoexcept |
move assignment operator.
| other | other object to assign. |
|
delete |
copy assignment operator.
| other | other object to assign. |
|
inlinenoexcept |
read data.
| data | buffer used to store the data received. |
| maxSize | maximum number of bytes to read. |
|
inlinenoexcept |
read data until size is reached or an error occurred.
| data | buffer used to store the data received. |
| size | number of bytes to read. |
|
inlinenoexcept |
read data until size is reached, an error occurred or the given duration elapsed.
| data | buffer used to store the data received. |
| size | number of bytes to read. |
| timeout | maximum time granted to the whole read. |
|
inlinenoexcept |
read data until size is reached, an error occurred or the deadline expired.
| data | buffer used to store the data received. |
| size | number of bytes to read. |
| deadline | time point at which to give up, max to wait indefinitely. |
|
inlinenoexcept |
determine the remote endpoint associated with this socket.
|
inlineoverridevirtualnoexcept |
set the given option to the given value.
| option | socket option. |
| value | option value. |
Reimplemented from join::BasicRawSocket< Protocol >.
|
inline |
block until connected.
|
inline |
block until connected, giving up after the given duration.
| timeout | maximum time to wait. |
|
inline |
block until connected, giving up at the given time point.
| deadline | time point at which to give up, max to wait indefinitely. |
|
inline |
wait until the connection as been shut down. return true if the connection as been shut down, false otherwise.
|
inline |
wait until the connection as been shut down, giving up after the given duration.
| timeout | maximum time to wait. return true if the connection as been shut down, false otherwise. |
|
inline |
wait until the connection as been shut down, giving up at the given time point.
| deadline | time point at which to give up, max to wait indefinitely. return true if the connection as been shut down, false otherwise. |
|
inlinenoexcept |
write data until size is reached or an error occurred.
| data | data buffer to send. |
| size | number of bytes to write. |
|
inlinenoexcept |
write data until size is reached, an error occurred or the given duration elapsed.
| data | data buffer to send. |
| size | number of bytes to write. |
| timeout | maximum time granted to the whole write. |
|
inlinenoexcept |
write data until size is reached, an error occurred or the deadline expired.
| data | data buffer to send. |
| size | number of bytes to write. |
| deadline | time point at which to give up, max to wait indefinitely. |
|
friend |
friendship with basic asynchronous stream socket
|
mutableprotected |
remote endpoint.