Evo C++ Library v0.5.1
|
#include <evo/impl/sysio_sock.h>
Socket I/O device (used internally).
Classes | |
struct | Init |
Used internally to initialize system socket API. More... | |
Public Types | |
typedef ExceptionSocketIn | ExceptionInT |
Input exception type for socket stream. More... | |
typedef ExceptionSocketOut | ExceptionOutT |
Output exception type for socket stream. More... | |
typedef int | Handle |
System socket handle. More... | |
typedef int | OptNum |
General number type for socket options. More... | |
enum | Shutdown { sIN = SHUT_RD, sOUT = SHUT_WR, sINOUT = SHUT_RDWR } |
Used with shutdown(). More... | |
Public Member Functions | |
IoSocket () | |
Constructor. More... | |
IoSocket (Handle socket) | |
Constructor attaching to existing socket. More... | |
~IoSocket () | |
Destructor. More... | |
bool | accept (Error &err, IoSocket &client_socket, SocketAddressBase *client_address=NULL) |
Accept connection from listening socket. More... | |
bool | accept_nonblock (Error &err, IoSocket &client_socket, SocketAddressBase *client_address=NULL) |
Accept connection from listening socket and set the new connection as non-blocking. More... | |
void | attach (Handle socket) |
Attach new socket handle. More... | |
bool | bind (Error &err, struct sockaddr *address, socklen_t address_len, int socktype=SOCK_DGRAM, int protocol=0) |
Create and bind datagram socket to address. More... | |
bool | cast (Error &err, int family=AF_INET, int socktype=SOCK_DGRAM, int protocol=0) |
Create unbound datagram socket for casting. More... | |
void | close () |
Close connection and socket. More... | |
bool | connect (Error &err, struct addrinfo *address_info, bool all=true) |
Create and connect socket using address info. More... | |
bool | connect (Error &err, struct sockaddr *address, socklen_t address_len, int socktype=SOCK_STREAM, int protocol=0) |
Create and connect socket using address. More... | |
bool | connect_wait (Error &err, ulong timeout_ms) |
Wait until socket connection is established and ready to write. More... | |
Handle | detach () |
Detach and return socket handle. More... | |
Error | getopt (int level, int optname, void *buf, uint &size) |
Get socket option value. More... | |
bool | isopen () const |
Get whether socket is open. More... | |
bool | listen (Error &err, struct addrinfo *address_info, int backlog=SOMAXCONN, bool all=true) |
Create and bind socket using address info and listen for connections. More... | |
bool | listen (Error &err, struct sockaddr *address, socklen_t address_len, int backlog=SOMAXCONN, int socktype=SOCK_STREAM, int protocol=0) |
Create and bind socket to address and listen for connections. More... | |
ulongl | pos (Error &err) |
Not supported with sockets. More... | |
ulong | read (Error &err, void *buf, ulong size, ulong timeout_ms=0) |
Read input data from device. More... | |
ulong | read (Error &err, void *buf, ulong size) |
bool | read_wait (Error &err, ulong timeout_ms) |
Wait until socket is ready to read. More... | |
ulong | readfrom (Error &err, void *buf, ulong size, struct sockaddr *address=NULL, socklen_t *address_len=NULL, int flags=0) |
Read message from socket device. More... | |
ulongl | seek (Error &err, ulongl, Seek) |
Not supported with sockets. More... | |
Error | set_nonblock (bool enable=true) |
Enable/Disable non-blocking I/O. More... | |
Error | setopt (int level, int optname, const void *buf, uint size) |
Set socket option with new value. More... | |
bool | shutdown (Shutdown how=sINOUT) |
Shutdown socket communication. More... | |
ulong | write (Error &err, const void *buf, ulong size, ulong timeout_ms=0) |
Write output data to device. More... | |
ulong | write (Error &err, const void *buf, ulong size) |
bool | write_wait (Error &err, ulong timeout_ms) |
Wait until socket is ready to write. More... | |
ulong | writeto (Error &err, const void *buf, ulong size, const struct sockaddr *address, socklen_t address_len, int flags=0) |
Write message to device and socket address. More... | |
Static Public Member Functions | |
template<class TOut > | |
static TOut & | errormsg_out (TOut &out, Error err) |
Write detailed error message with errno to output stream/string. More... | |
static const Init & | init () |
Initialize socket library. More... | |
Public Attributes | |
bool | autoresume |
Whether to auto-resume I/O operation after signal received [Linux/Unix]. More... | |
Handle | handle |
Socket handle/descriptor. More... | |
bool | nonblock |
Whether non-blocking I/O is enabled. More... | |
ulong | timeout_ms |
Current timeout in milliseconds, 0 for indefinite. More... | |
Static Public Attributes | |
static const Handle | INVALID = -1 |
Invalid handle value (used internally) More... | |
static const int | SOCK_ERROR = -1 |
Socket error value (used internally) More... | |
static const bool | STREAM_SEEKABLE = false |
Socket streams are not seekable with Stream. More... | |
static const ulong | TIMEOUT_DEFAULT = 30000 |
Default timeout used in milliseconds. More... | |
typedef ExceptionSocketIn ExceptionInT |
Input exception type for socket stream.
typedef ExceptionSocketOut ExceptionOutT |
Output exception type for socket stream.
typedef int Handle |
System socket handle.
typedef int OptNum |
General number type for socket options.
enum Shutdown |
Used with shutdown().
Enumerator | |
---|---|
sIN | Shutdown input (reads) on socket. |
sOUT | Shutdown output (writes) on socket. |
sINOUT | Shutdown both input and output (reads and writes) on socket. |
|
inline |
Constructor.
|
inline |
Accept connection from listening socket.
err | Set to error code on failure, ETimeout on timeout |
client_socket | Attached to connected client socket on success (unchanged on error) |
client_address | Pointer to store client socket address on success (ignored on error), NULL to skip |
|
inline |
Accept connection from listening socket and set the new connection as non-blocking.
err | Set to error code on failure, ETimeout on timeout |
client_socket | Attached to connected client socket on success (unchanged on error) |
client_address | Pointer to store client socket address on success (ignored on error), NULL to skip |
|
inline |
|
inline |
Create and bind datagram socket to address.
err | Set to ENone on success, EExist if address/port already used, otherwise set to error code |
address | Socket address to bind to, must not be NULL |
address_len | Socket address length to bind to, must be positive |
socktype | Socket type |
protocol | Network protocol, 0 for default |
|
inline |
|
inline |
Close connection and socket.
|
inline |
Create and connect socket using address info.
err | Set to ENone on success, otherwise set to error code |
address_info | Pointer to addrinfo structure to use (first in linked list) |
all | Whether to try all addresses in addrinfo until successful, false to just try the first address |
|
inline |
Create and connect socket using address.
err | Set to ENone on success, otherwise set to error code |
address | Socket address to connect to, must not be NULL |
address_len | Socket address length to connect to, must be positive |
socktype | Socket type, usually SOCK_STREAM |
protocol | Network protocol, usually 0 for default |
|
inline |
Wait until socket connection is established and ready to write.
err | Set to error code on failure, ETimeout on timeout |
timeout_ms | Wait timeout in milliseconds, 0 for no wait (returns immediately, useful for polling) |
|
inlinestatic |
|
inline |
Get socket option value.
level | Option level, ex: SOL_SOCKET, IPPROTO_IP |
optname | Option identifier, depends on level |
buf | Buffer to store value |
size | Buffer size, updated with value size stored in buffer |
|
inlinestatic |
Initialize socket library.
|
inline |
Get whether socket is open.
|
inline |
Create and bind socket using address info and listen for connections.
err | Set to ENone on success, EExist if address/port already used, otherwise set to error code |
address_info | Pointer to addrinfo structure to bind to (first in linked list) |
backlog | Listener queue backlog size |
all | Whether to try all addresses in addrinfo until successful, false to just try the first address |
|
inline |
Create and bind socket to address and listen for connections.
err | Set to ENone on success, EExist if address/port already used, otherwise set to error code |
address | Socket address to bind to, must not be NULL |
address_len | Socket address length to bind to, must be positive |
backlog | Listener queue backlog size |
socktype | Socket type, usually SOCK_STREAM |
protocol | Network protocol, usually 0 for default |
|
inline |
Not supported with sockets.
err | Set to EInval [out] |
|
inlineinherited |
Read input data from device.
err | Stores ENone on success, error code on error [out] |
buf | Buffer to store data read |
size | Size to read in bytes |
timeout_ms | Read timeout in milliseconds, 0 for none (don't timeout) |
|
inline |
|
inline |
Wait until socket is ready to read.
err | Set to error code on failure, ETimeout on timeout |
timeout_ms | Wait timeout in milliseconds, 0 for indefinite |
|
inline |
Read message from socket device.
err | Stores ENone on success, error code on error [out] |
buf | Buffer to store data read |
size | Buffer size in bytes |
address | Pointer to store source socket address, NULL to ignore |
address_len | Pointer to address buffer length, updated to actual length used |
flags | Low-level flags to use with socket |
Not supported with sockets.
err | Set to EInval [out] |
|
inline |
Enable/Disable non-blocking I/O.
enable | Whether to enable non-blocking mode, false to disable |
|
inline |
Set socket option with new value.
level | Option level, ex: SOL_SOCKET, IPPROTO_IP |
optname | Option identifier, depends on level |
buf | Buffer with value to set |
size | Value size in buffer |
Shutdown socket communication.
how | Whether to shutdown input, output, or both – see Shutdown enum |
|
inlineinherited |
Write output data to device.
err | Stores ENone on success, error code on error [out] |
buf | Buffer to write from |
size | Size to write in bytes |
timeout_ms | Write timeout in milliseconds, 0 for none (don't timeout) |
|
inline |
|
inline |
Wait until socket is ready to write.
err | Set to error code on failure, ETimeout on timeout |
timeout_ms | Wait timeout in milliseconds, 0 for indefinite |
|
inline |
Write message to device and socket address.
err | Stores ENone on success, error code on error [out] |
buf | Buffer to write from |
size | Size to write in bytes, 0 sends an empty packet |
address | Socket address to write to, must not be NULL |
address_len | Socket address length to write to, must be positive |
flags | Low-level flags to use with socket |
bool autoresume |
Whether to auto-resume I/O operation after signal received [Linux/Unix].
|
static |
Invalid handle value (used internally)
bool nonblock |
Whether non-blocking I/O is enabled.
|
static |
Socket error value (used internally)
|
static |
Default timeout used in milliseconds.
ulong timeout_ms |
Current timeout in milliseconds, 0 for indefinite.