|
simple-socket library 1.2.0
|
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) |
| assignment operator using move semantics | |
| SocketHandle () | |
| constructs an invalid socket handle | |
| SocketHandle (SocketHandle &other) | |
| copy constructor using move semantics | |
| ~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.
The move implementation does not need C++11, and is implemented without the need for r-value references. This also means that moving is not done like in C++11 (using std::move and std::forward) it is instead done silently and implicitly when copying the SocketHandle object.
After a SocketHandle gets returned from an accept() call, the SocketHandle has to be checked wheter it is valid or not.
Usage example:
Definition at line 48 of file SocketHandle.h.
| typedef Socket NET::SocketHandle< Socket >::socket_type |
socket type that was provided as template argument
Definition at line 55 of file SocketHandle.h.
|
inline |
constructs an invalid socket handle
Definition at line 58 of file SocketHandle.h.
|
inline |
copy constructor using move semantics
Definition at line 61 of file SocketHandle.h.
|
inline |
Definition at line 89 of file SocketHandle.h.
|
inline |
assignment operator using move semantics
Definition at line 74 of file SocketHandle.h.
|
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.
| SocketException | if trying to use an invalid SocketHandle to create socket |
Definition at line 99 of file SocketHandle.h.
|
friend |
Definition at line 51 of file SocketHandle.h.
|
friend |
Definition at line 52 of file SocketHandle.h.