#include <socket_service.hpp>
|
| ~SocketService () noexcept |
|
template<Socket SocketType> |
std::shared_ptr< SocketType > | create_socket () |
|
void | remove_socket (socket_type handle) |
|
template<Socket SocketType, SocketNotification< SocketType > Callback> |
void | notify_when_writable (const std::shared_ptr< SocketType > &socket, Callback &&callback) |
|
template<Socket SocketType, SocketNotification< SocketType > Callback> |
void | notify_when_readable (const std::shared_ptr< SocketType > &socket, Callback &&callback) |
|
template<Socket SocketType, SocketNotification< SocketType > Callback> |
auto | wrap_callback (const std::shared_ptr< SocketType > &socket, Callback &&callback) -> Notification |
|
Class to monitor asynchronous socket handles for IO readiness. Sockets handles are monitored on a per-IO basis.
- Author
- Timothy Flynn (trfly.nosp@m.nn89.nosp@m.@pm.m.nosp@m.e)
- Version
- March 6, 2021
◆ ~SocketService()
fly::net::SocketService::~SocketService |
( |
| ) |
|
|
noexcept |
Destructor. Deinitialize the socket service.
◆ create()
Create a socket service.
- Parameters
-
task_runner | Task runner for posting socket service tasks onto. |
config | Reference to network configuration. |
- Returns
- The created socket service.
◆ create_socket()
template<Socket SocketType>
std::shared_ptr< SocketType > fly::net::SocketService::create_socket |
Create an asynchronous socket armed with this socket service for performing IO operations.
- Returns
- The created socket.
◆ notify_when_readable()
template<Socket SocketType, SocketNotification< SocketType > Callback>
void fly::net::SocketService::notify_when_readable |
( |
const std::shared_ptr< SocketType > & |
socket, |
|
|
Callback && |
callback |
|
) |
| |
Monitor a socket handle for readiness to be read from.
The provided callback may be any callable type which accepts a single argument, a strong pointer to the socket being monitored. The callback is protected by the provided strong socket pointer. When the monitor is queued, the strong pointer is stored as a weak pointer until the socket becomes ready for reading. It is then converted back to a strong pointer to invoke the callback; if the lock fails, the callback is dropped.
Note: The provided callback will be triggered directly on the sequence that is monitoring all sockets. Thus, the callback should not perform any blocking operations.
- Template Parameters
-
SocketType | Type of the socket to monitor. |
Callback | Type of the callback to invoke when the socket is ready for reading. |
- Parameters
-
socket | The socket to monitor. |
callback | The callback to invoke when the socket is ready for reading. |
◆ notify_when_writable()
template<Socket SocketType, SocketNotification< SocketType > Callback>
void fly::net::SocketService::notify_when_writable |
( |
const std::shared_ptr< SocketType > & |
socket, |
|
|
Callback && |
callback |
|
) |
| |
Monitor a socket handle for readiness to be written to.
The provided callback may be any callable type which accepts a single argument, a strong pointer to the socket being monitored. The callback is protected by the provided strong socket pointer. When the monitor is queued, the strong pointer is stored as a weak pointer until the socket becomes ready for writing. It is then converted back to a strong pointer to invoke the callback; if the lock fails, the callback is dropped.
Note: The provided callback will be triggered directly on the sequence that is monitoring all sockets. Thus, the callback should not perform any blocking operations.
- Template Parameters
-
SocketType | Type of the socket to monitor. |
Callback | Type of the callback to invoke when the socket is ready for writing. |
- Parameters
-
socket | The socket to monitor. |
callback | The callback to invoke when the socket is ready for writing. |
◆ remove_socket()
void fly::net::SocketService::remove_socket |
( |
socket_type |
handle | ) |
|
Remove a socket handle from the service if it is being monitored. This is not guaranteed to cancel a pending IO readiness notification. If the service is ready to notify a socket about IO readiness, that notification will still occur.
- Parameters
-
handle | The socket handle to remove. |
The documentation for this class was generated from the following files: