A simple class to provide strict ownership of socket handles. More...
#include <simple_socket/SocketHandle.h>
Public Types | |
| typedef Socket | socket_type |
| socket type that was provided as template argument | |
Public Member Functions | |
| SocketHandle () noexcept | |
| constructs an invalid socket handle | |
| SocketHandle (const SocketHandle &)=delete | |
| SocketHandle & | operator= (const SocketHandle &)=delete |
| SocketHandle (SocketHandle &&other) noexcept | |
| move constructor: transfers ownership from other | |
| SocketHandle & | operator= (SocketHandle &&other) noexcept |
| move assignment: closes the currently owned descriptor first | |
| operator bool () const noexcept | |
| returns whether the socket handle is valid | |
Friends | |
| class | TCPSocket |
| class | SCTPSocket |
| class | UnixStreamSocket |
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 is move-only. Moving transfers ownership of the socket file descriptor and leaves the source handle invalid. Copying is not allowed. Constructing a socket from a handle also transfers ownership.
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 38 of file SocketHandle.h.
| typedef Socket NET::SocketHandle< Socket >::socket_type |
socket type that was provided as template argument
Definition at line 46 of file SocketHandle.h.
|
inlinenoexcept |
constructs an invalid socket handle
Definition at line 49 of file SocketHandle.h.
|
inlinenoexcept |
move constructor: transfers ownership from other
Definition at line 55 of file SocketHandle.h.
|
inlinenoexcept |
Definition at line 65 of file SocketHandle.h.
|
inlineexplicitnoexcept |
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 75 of file SocketHandle.h.
|
inlinenoexcept |
move assignment: closes the currently owned descriptor first
Definition at line 58 of file SocketHandle.h.
|
friend |
Definition at line 42 of file SocketHandle.h.
|
friend |
Definition at line 41 of file SocketHandle.h.
|
friend |
Definition at line 43 of file SocketHandle.h.