simple-socket library 1.1.5
|
A simple class to provide strict ownership of socket handles. More...
#include <SocketHandle.h>
Public Types | |
typedef Socket | socket_type |
socket type that was provided as template argument | |
Public Member Functions | |
operator bool () const | |
returns whether the socket handle is valid | |
SocketHandle & | operator= (SocketHandle &other) |
SocketHandle (SocketHandle &other) | |
copy constructor using move semantics | |
SocketHandle () | |
constructs an invalid socket handle | |
~SocketHandle () | |
Friends | |
class | SCTPSocket |
class | TCPSocket |
A simple class to provide strict ownership of socket handles.
SocketHandle is used to return accepted connections to the user, and not expose the socket file descriptor. It also ensures all an accepted socket is closed in the case no new socket is created with this handle.
SocketHandle implements move semantics, so only one SocketHandle can be active for the same connection at any given moment. If SocketHandle is copied/passed to a function, etc. the source/passed in SocketHandle is made invalid. The SocketHandle also gets invalid if an socket is constructed from the handle.
After a SocketHandle gets returned from an accept() call, the SocketHandle has to be checked wheter it is valid or not.
Usage example:
// socket is a TCPSocket listening for connections TCPSocket::Handle handle = socket.timedAccept(1000); if(!handle) { std::cout << "no one tried to connect in time" << std::endl; return; } TCPSocket acceptedSocket(handle); // use the socket
Definition at line 43 of file SocketHandle.h.
typedef Socket NET::SocketHandle< Socket >::socket_type |
socket type that was provided as template argument
Definition at line 50 of file SocketHandle.h.
NET::SocketHandle< Socket >::SocketHandle | ( | ) | [inline] |
constructs an invalid socket handle
Definition at line 53 of file SocketHandle.h.
NET::SocketHandle< Socket >::SocketHandle | ( | SocketHandle< Socket > & | other | ) | [inline] |
copy constructor using move semantics
Definition at line 56 of file SocketHandle.h.
NET::SocketHandle< Socket >::~SocketHandle | ( | ) | [inline] |
Definition at line 84 of file SocketHandle.h.
SocketHandle& NET::SocketHandle< Socket >::operator= | ( | SocketHandle< Socket > & | other | ) | [inline] |
assignment operator using move semantics
Definition at line 69 of file SocketHandle.h.
NET::SocketHandle< Socket >::operator bool | ( | ) | const [inline] |
returns whether the socket handle is valid
Checks whether a socket can be constructed from the handle or not. If accept() returned an invalid handle (e.g. timed out timedAccept() call) this should be used to verify the handle. Trying to construct a socket from an invalid handle will raise a SocketException.
Definition at line 93 of file SocketHandle.h.
friend class TCPSocket [friend] |
Definition at line 46 of file SocketHandle.h.
friend class SCTPSocket [friend] |
Definition at line 47 of file SocketHandle.h.