Wizard
Software Engineering Project - Wizard
|
#include <stream_socket.h>
Public Member Functions | |
stream_socket () | |
stream_socket (socket_t handle) | |
stream_socket (stream_socket &&sock) | |
stream_socket & | operator= (stream_socket &&rhs) |
stream_socket | clone () const |
virtual ssize_t | read (void *buf, size_t n) |
virtual ssize_t | read_n (void *buf, size_t n) |
ssize_t | read (const std::vector< iovec > &ranges) |
virtual bool | read_timeout (const std::chrono::microseconds &to) |
template<class Rep , class Period > | |
bool | read_timeout (const std::chrono::duration< Rep, Period > &to) |
virtual ssize_t | write (const void *buf, size_t n) |
virtual ssize_t | write_n (const void *buf, size_t n) |
virtual ssize_t | write (const std::string &s) |
virtual ssize_t | write (const std::vector< iovec > &ranges) |
virtual bool | write_timeout (const std::chrono::microseconds &to) |
template<class Rep , class Period > | |
bool | write_timeout (const std::chrono::duration< Rep, Period > &to) |
![]() | |
socket () | |
socket (socket_t h) | |
socket (socket &&sock) noexcept | |
virtual | ~socket () |
bool | is_open () const |
bool | operator! () const |
operator bool () const | |
socket_t | handle () const |
virtual sa_family_t | family () const |
socket | clone () const |
void | clear (int val=0) |
socket_t | release () |
void | reset (socket_t h=INVALID_SOCKET) |
socket & | operator= (socket &&sock) noexcept |
bool | bind (const sock_address &addr) |
sock_address_any | address () const |
sock_address_any | peer_address () const |
bool | get_option (int level, int optname, void *optval, socklen_t *optlen) const |
template<typename T > | |
bool | get_option (int level, int optname, T *val) const |
bool | set_option (int level, int optname, const void *optval, socklen_t optlen) |
template<typename T > | |
bool | set_option (int level, int optname, const T &val) |
bool | set_non_blocking (bool on=true) |
int | last_error () const |
std::string | last_error_str () const |
bool | shutdown (int how=SHUT_RDWR) |
bool | close () |
Static Public Member Functions | |
static stream_socket | create (int domain, int protocol=0) |
![]() | |
static void | initialize () |
static void | destroy () |
static socket | create (int domain, int type, int protocol=0) |
static std::tuple< socket, socket > | pair (int domain, int type, int protocol=0) |
static std::string | error_str (int errNum) |
Static Public Attributes | |
static constexpr int | COMM_TYPE = SOCK_STREAM |
Static Protected Member Functions | |
static socket_t | create_handle (int domain) |
![]() | |
static int | get_last_error () |
Friends | |
class | acceptor |
Additional Inherited Members | |
![]() | |
bool | close_on_err () |
void | set_last_error () |
template<typename T > | |
T | check_ret (T ret) const |
template<typename T > | |
bool | check_ret_bool (T ret) const |
socket_t | check_socket (socket_t ret) const |
bool | check_socket_bool (socket_t ret) const |
Base class for streaming sockets, such as TCP and Unix Domain. This is the streaming connection between two peers. It looks like a readable/writeable device.
|
inline |
Creates an unconnected streaming socket.
|
inlineexplicit |
Creates a streaming socket from an existing OS socket handle and claims ownership of the handle.
handle | A socket handle from the operating system. |
|
inline |
Creates a stream socket by copying the socket handle from the specified socket object and transfers ownership of the socket.
|
inline |
Creates a new stream_socket that refers to this one. This creates a new object with an independent lifetime, but refers back to this same socket. On most systems, this duplicates the file handle using the dup() call. A typical use of this is to have separate threads for reading and writing the socket. One thread would get the original socket and the other would get the cloned one.
|
static |
Creates a socket with the specified communications characterics. Not that this is not normally how a socket is creates in the sockpp library. Applications would typically create a connector (client) or acceptor (server) socket which would take care of the details.
This is included for completeness or for creating different types of sockets than are supported by the library.
domain | The communications domain for the sockets (i.e. the address family) |
protocol | The particular protocol to be used with the sockets |
|
inlinestaticprotected |
Creates a streaming socket.
|
inline |
Move assignment.
rhs | The other socket to move into this one. |
ssize_t sockpp::stream_socket::read | ( | const std::vector< iovec > & | ranges | ) |
Reads discontiguous memory ranges from the socket.
ranges | The vector of memory ranges to fill |
|
virtual |
Reads from the port
buf | Buffer to get the incoming data. |
n | The number of bytes to try to read. |
|
virtual |
Best effort attempts to read the specified number of bytes. This will make repeated read attempts until all the bytes are read in or until an error occurs.
buf | Buffer to get the incoming data. |
n | The number of bytes to try to read. |
|
inline |
Set a timeout for read operations. Sets the timout that the device uses for read operations. Not all devices support timouts, so the caller should prepare for failure.
to | The amount of time to wait for the operation to complete. |
|
virtual |
Set a timeout for read operations. Sets the timeout that the device uses for read operations. Not all devices support timeouts, so the caller should prepare for failure.
to | The amount of time to wait for the operation to complete. |
|
inlinevirtual |
Best effort attempt to write a string to the socket.
s | The string to write. |
|
virtual |
Writes discontiguous memory ranges to the socket.
ranges | The vector of memory ranges to write |
|
virtual |
Writes the buffer to the socket.
buf | The buffer to write |
n | The number of bytes in the buffer. |
|
virtual |
Best effort attempt to write the whole buffer to the socket.
buf | The buffer to write |
n | The number of bytes in the buffer. |
|
inline |
Set a timeout for write operations. Sets the timout that the device uses for write operations. Not all devices support timouts, so the caller should prepare for failure.
to | The amount of time to wait for the operation to complete. |
|
virtual |
Set a timeout for write operations. Sets the timout that the device uses for write operations. Not all devices support timouts, so the caller should prepare for failure.
to | The amount of time to wait for the operation to complete. |
|
friend |
Acceptor can create stream sockets.
|
staticconstexpr |
The socket 'type' for communications semantics.