diff options
Diffstat (limited to 'libcmix-network/acceptor.hpp')
| -rw-r--r-- | libcmix-network/acceptor.hpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/libcmix-network/acceptor.hpp b/libcmix-network/acceptor.hpp index 06b709d..6e4de63 100644 --- a/libcmix-network/acceptor.hpp +++ b/libcmix-network/acceptor.hpp @@ -1,6 +1,9 @@ #pragma once +#include "accept.hpp" + #include <boost/asio/ip/tcp.hpp> +#include <boost/asio/ssl.hpp> #include <functional> @@ -15,8 +18,8 @@ * Otherwise they would be side to side in the Server class. */ class Acceptor{ - boost::asio::ip::tcp::acceptor acceptor; - boost::asio::ip::tcp::endpoint endpoint; + boost::asio::ip::tcp::acceptor acceptor; ///< The acceptor + boost::asio::ip::tcp::endpoint endpoint; ///< The endpoint public: /*! @@ -26,25 +29,49 @@ public: * \param port The listen port */ Acceptor(boost::asio::io_service& io_service, boost::asio::ip::address address, uint16_t port); - + /*! * \brief get_address * \return The listening address */ - boost::asio::ip::address get_address() { return endpoint.address(); } + boost::asio::ip::address get_address(); + + /*! + * \brief is_open Checks if the acceptor socket is opened. + * \return true if the socket is open, false otherwise. + */ + bool is_open(); /*! - * \brief bind_v6_and_v4_any - * \param accept_handler Function to call when accepting an incoming connection. + * \brief listen_v6_and_v4_any * * If you want to accept on both ipv6 and ipv any you have to do some special setup. * This function handles that and starts listening. */ - void bind_v6_and_v4_any(std::function<void(boost::asio::ip::tcp::socket&&)> accept_handler); + void listen_v6_and_v4_any(); + + /*! + * \brief listen_socket + * + * start listening on the specified endpoint + */ + void listen_socket(); + + /*! + * \brief start_accepting + * \param accept_handler The function called on a succesful accepted connection. + * + * Asynchronously indefinitely accepts connections. + */ + void start_accepting(AcceptHandler accept_handler); /*! - * \brief setup_listen_socket - * \param accept_handler Function to call when accepting an incoming connection. + * \brief start_accepting + * \param ctx The SSL context + * \param accept_handler The function called on a succesful accepted ssl connection. + * + * Asynchronously indefinitely accepts SSL connections. */ - void setup_listen_socket(std::function<void(boost::asio::ip::tcp::socket&&)> accept_handler); + void start_accepting(std::shared_ptr<boost::asio::ssl::context> ctx, SSLAcceptHandler accept_handler); + }; |
