Horizon Official Technical Documentation
|
|
Asynchronous acceptor for sockets. More...
#include <AsyncAcceptor.hpp>
Public Types | |
typedef std::function< void(std::shared_ptr< tcp::socket >, uint32_t thread_index)> | AcceptCallback |
Public Member Functions | |
~AsyncAcceptor () | |
AsyncAcceptor (boost::asio::io_context &io_context, std::string const &listen_ip, uint16_t port) | |
Constructor of the AsyncAcceptor object. More... | |
template<class T > | |
void | AsyncAccept () |
void | async_accept_with_callback (AcceptCallback callback) |
Asynchronously accepts sockets and executes a callback function. More... | |
bool | bind () |
Binds this instance to an endpoint, to listen for connections. More... | |
void | close () |
Closes the acceptor across all threads. More... | |
bool | is_open () |
void | set_socket_factory (std::function< std::pair< std::shared_ptr< tcp::socket >, uint32_t >()> &&func) |
Sets the socket factory for the acceptor. More... | |
Private Member Functions | |
std::pair< std::shared_ptr< tcp::socket >, uint32_t > | default_socket_factory () |
Private Attributes | |
tcp::endpoint | _endpoint |
std::shared_ptr< tcp::acceptor > | _acceptor |
std::shared_ptr< tcp::socket > | _socket |
std::atomic< bool > | _closed |
std::function< std::pair< std::shared_ptr< tcp::socket >, uint32_t >()> | _socket_factory |
Asynchronous acceptor for sockets.
typedef std::function<void(std::shared_ptr<tcp::socket>, uint32_t thread_index)> Horizon::Networking::AsyncAcceptor::AcceptCallback |
|
inline |
|
inline |
Constructor of the AsyncAcceptor object.
[in|out] | io_context reference to the io_context object. | |
[in] | listen_ip | const reference to the ip address string for the acceptor to bind on. |
[in] | port | port number for the acceptor to bind on. |
|
inline |
Asynchronously accepts sockets and executes a callback function.
This function is responsible for - 1) Listening for new connections on the main thread. 2) Executing the callback provided to this method whilst moving its ownership. 3) Execute recursively on successful acceptances until closed.
[in] | callback | the callback function to execute ( |
References _acceptor, _closed, _socket_factory, async_accept_with_callback(), and HLog.
Referenced by async_accept_with_callback().
void Horizon::Networking::AsyncAcceptor::AsyncAccept |
|
inline |
Binds this instance to an endpoint, to listen for connections.
|
inline |
|
inlineprivate |
|
inline |
|
inline |
Sets the socket factory for the acceptor.
References _socket_factory.
|
private |
Referenced by async_accept_with_callback(), AsyncAccept(), bind(), close(), and ~AsyncAcceptor().
|
private |
Referenced by async_accept_with_callback(), AsyncAccept(), close(), and is_open().
|
private |
Referenced by bind().
|
private |
Referenced by AsyncAccept(), close(), default_socket_factory(), and ~AsyncAcceptor().
|
private |
Referenced by async_accept_with_callback(), and set_socket_factory().