TCP/IP or UDP/Datagram IPv4 socket. More...
Public Types | |
| enum | Errors |
| Socket errors. More... | |
Public Member Functions | |
| GNatSocket (int type=SOCK_STREAM) | |
| Creates a new Socket. More... | |
| GNatSocket (int type, SOCKET sockfd) | |
| Creates a Socket from an existing socket file descriptor. | |
| ~GNatSocket () | |
| Destructor (closes the socket). | |
| int | connect (const std::string &host, int port) |
| Connects the socket to an address. More... | |
| int | bind (int port) |
| Assigns the socket to localhost. More... | |
| int | bind (const std::string &host, int port) |
| Assigns the socket to an IP address. More... | |
| int | close () |
| Closes the socket. | |
| bool | isClosed () const |
| Returns true if the socket has been closed. | |
| SOCKET | descriptor () |
| Returns the descriptor of the socket. | |
| void | shutdownInput () |
| Disables further receive operations. | |
| void | shutdownOutput () |
| Disables further send operations. | |
| SOCKSIZE | send (const SOCKDATA *buf, size_t len, int flags=0) |
| Send sdata to a connected (TCP/IP) socket. More... | |
| SOCKSIZE | receive (SOCKDATA *buf, size_t len, int flags=0) |
| Receives data from a connected (TCP/IP) socket. More... | |
| SOCKSIZE | sendTo (void const *buf, size_t len, int flags, SOCKADDR const *to, socklen_t addrlen) |
| Sends data to a datagram socket. | |
| SOCKSIZE | receiveFrom (void *buf, size_t len, int flags, SOCKADDR *from, socklen_t *addrlen) |
| Receives data from datagram socket. | |
| int | setReceiveBufferSize (int size) |
| Set the size of the TCP/IP input buffer. | |
| int | setReuseAddress (bool) |
| Enable/disable the SO_REUSEADDR socket option. | |
| int | setSendBufferSize (int size) |
| Set the size of the TCP/IP output buffer. | |
| int | setSoLinger (bool, int linger) |
| Enable/disable SO_LINGER with the specified linger time in seconds. | |
| int | setSoTimeout (int timeout) |
| Enable/disable SO_TIMEOUT with the specified timeout (in milliseconds). | |
| int | setTcpNoDelay (bool) |
| Enable/disable TCP_NODELAY (turns on/off TCP coalescence). | |
| int | getReceiveBufferSize () const |
| Return the size of the TCP/IP input buffer. | |
| bool | getReuseAddress () const |
| Return SO_REUSEADDR state. | |
| int | getSendBufferSize () const |
| Return the size of the TCP/IP output buffer. | |
| bool | getSoLinger (int &linger) const |
| Return SO_LINGER state and the specified linger time in seconds. | |
| int | getSoTimeout () const |
| Return SO_TIMEOUT value. | |
| bool | getTcpNoDelay () const |
| Return TCP_NODELAY state. | |
Static Public Member Functions | |
| static void | startup () |
| initialisation and cleanup of sockets on Widows. More... | |
TCP/IP or UDP/Datagram IPv4 socket.
AF_INET connections following the IPv4 Internet protocol are supported.
| enum GNatSocket::Errors |
Socket errors.
| GNatSocket::GNatSocket | ( | int | type = SOCK_STREAM) |
Creates a new Socket.
Creates a AF_INET socket using the IPv4 Internet protocol. Type can be:
|
static |
initialisation and cleanup of sockets on Widows.
| int GNatSocket::connect | ( | const std::string & | host, |
| int | port | ||
| ) |
Connects the socket to an address.
Typically used for connecting TCP/IP clients to a ServerSocket. On Unix/Linux host can be a hostname, on Windows it can only be an IP address.
| int GNatSocket::bind | ( | int | port) |
Assigns the socket to localhost.
| int GNatSocket::bind | ( | const std::string & | host, |
| int | port | ||
| ) |
Assigns the socket to an IP address.
On Unix/Linux host can be a hostname, on Windows it can only be an IP address.
|
inline |
Send sdata to a connected (TCP/IP) socket.
Sends the first len bytes in buf.
|
inline |
Receives data from a connected (TCP/IP) socket.
Reads at most len bytes fand stores them in buf. By default, this function blocks the caller until thre is availbale data.
1.8.4