This class is for easily setting up listening socket, either TCP or Unix.
More...
#include <socket.h>
|
bool | IPv4bind (int port, std::string hostname, bool nonblock) |
| Attempt to bind an IPv4 socket. More...
|
|
bool | IPv4bind (int port, std::string hostname, bool nonblock) |
| Attempt to bind an IPv4 socket. More...
|
|
bool | IPv6bind (int port, std::string hostname, bool nonblock) |
| Attempt to bind an IPv6 socket. More...
|
|
bool | IPv6bind (int port, std::string hostname, bool nonblock) |
| Attempt to bind an IPv6 socket. More...
|
|
This class is for easily setting up listening socket, either TCP or Unix.
Socket::Server::Server |
( |
| ) |
|
Create a new base Server.
Create a new base Server. The socket is never connected, and a placeholder for later connections.
Socket::Server::Server |
( |
int |
port, |
|
|
std::string |
hostname = "0.0.0.0" , |
|
|
bool |
nonblock = false |
|
) |
| |
Create a new TCP Server.
The socket is immediately bound and set to listen. A maximum of 100 connections will be accepted between accept() calls. Any further connections coming in will be dropped.
- Parameters
-
port | The TCP port to listen on |
hostname | (optional) The interface to bind to. The default is 0.0.0.0 (all interfaces). |
nonblock | (optional) Whether accept() calls will be nonblocking. Default is false (blocking). |
Socket::Server::Server |
( |
std::string |
address, |
|
|
bool |
nonblock = false |
|
) |
| |
Create a new Unix Server.
The socket is immediately bound and set to listen. A maximum of 100 connections will be accepted between accept() calls. Any further connections coming in will be dropped. The address used will first be unlinked - so it succeeds if the Unix socket already existed. Watch out for this behaviour - it will delete any file located at address!
- Parameters
-
address | The location of the Unix socket to bind to. |
nonblock | (optional) Whether accept() calls will be nonblocking. Default is false (blocking). |
Socket::Server::Server |
( |
| ) |
|
Socket::Server::Server |
( |
int |
port, |
|
|
std::string |
hostname = "0.0.0.0" , |
|
|
bool |
nonblock = false |
|
) |
| |
Socket::Server::Server |
( |
std::string |
adres, |
|
|
bool |
nonblock = false |
|
) |
| |
Accept any waiting connections.
If the Socket::Server is blocking, this function will block until there is an incoming connection. If the Socket::Server is nonblocking, it might return a Socket::Connection that is not connected, so check for this.
- Parameters
-
nonblock | (optional) Whether the newly connected socket should be nonblocking. Default is false (blocking). |
- Returns
- A Socket::Connection, which may or may not be connected, depending on settings and circumstances.
Connection Socket::Server::accept |
( |
bool |
nonblock = false | ) |
|
Accept any waiting connections.
void Socket::Server::close |
( |
| ) |
|
void Socket::Server::close |
( |
| ) |
|
Close connection.
The internal socket is closed and then set to -1. If the connection is already closed, nothing happens. This function calls shutdown, thus making the socket unusable in all other processes as well. Do not use on shared sockets that are still in use.
bool Socket::Server::connected |
( |
| ) |
const |
Returns the connected-state for this socket.
Note that this function might be slightly behind the real situation. The connection status is updated after every accept attempt, when errors occur and when the socket is closed manually.
- Returns
- True if socket is connected, false otherwise.
bool Socket::Server::connected |
( |
| ) |
const |
Returns the connected-state for this socket.
void Socket::Server::drop |
( |
| ) |
|
Close connection without shutdown.
void Socket::Server::drop |
( |
| ) |
|
Close connection without shutdown.
Close connection.
The internal socket is closed and then set to -1. If the connection is already closed, nothing happens. This function does not call shutdown, allowing continued use in other processes.
int Socket::Server::getSocket |
( |
| ) |
|
Returns internal socket number.
int Socket::Server::getSocket |
( |
| ) |
|
Returns internal socket number.
bool Socket::Server::IPv4bind |
( |
int |
port, |
|
|
std::string |
hostname, |
|
|
bool |
nonblock |
|
) |
| |
|
private |
Attempt to bind an IPv4 socket.
bool Socket::Server::IPv4bind |
( |
int |
port, |
|
|
std::string |
hostname, |
|
|
bool |
nonblock |
|
) |
| |
|
private |
Attempt to bind an IPv4 socket.
- Parameters
-
port | The TCP port to listen on |
hostname | The interface to bind to. The default is 0.0.0.0 (all interfaces). |
nonblock | Whether accept() calls will be nonblocking. Default is false (blocking). |
- Returns
- True if successful, false otherwise.
bool Socket::Server::IPv6bind |
( |
int |
port, |
|
|
std::string |
hostname, |
|
|
bool |
nonblock |
|
) |
| |
|
private |
Attempt to bind an IPv6 socket.
- Parameters
-
port | The TCP port to listen on |
hostname | The interface to bind to. The default is 0.0.0.0 (all interfaces). |
nonblock | Whether accept() calls will be nonblocking. Default is false (blocking). |
- Returns
- True if successful, false otherwise.
bool Socket::Server::IPv6bind |
( |
int |
port, |
|
|
std::string |
hostname, |
|
|
bool |
nonblock |
|
) |
| |
|
private |
Attempt to bind an IPv6 socket.
bool Socket::Server::isBlocking |
( |
| ) |
|
Check if this socket is blocking (true) or nonblocking (false).
bool Socket::Server::isBlocking |
( |
| ) |
|
Check if this socket is blocking (true) or nonblocking (false).
Set this socket to be blocking (true) or nonblocking (false).
void Socket::Server::setBlocking |
( |
bool |
blocking | ) |
|
Set this socket to be blocking (true) or nonblocking (false).
void Socket::Server::setBlocking |
( |
bool |
blocking | ) |
|
Set this socket to be blocking (true) or nonblocking (false).
std::string Socket::Server::errors |
|
private |
Stores errors that may have occured.
Internally saved socket number.
The documentation for this class was generated from the following files: