Skip to content
Snippets Groups Projects
Commit 5b733302 authored by Leon Dietrich's avatar Leon Dietrich Committed by Benny Baumann
Browse files

add: Document TCP server class

parent 82f9f817
No related branches found
No related tags found
1 merge request!1First unit tests
...@@ -17,6 +17,14 @@ ...@@ -17,6 +17,14 @@
namespace rmrf::net { namespace rmrf::net {
/**
* This class awaits incomming TCP connections and submits them to the provided client listener callback.
* @class tcp_server_socket
* @author doralitze
* @date 14/01/21
* @file tcp_server_socket.hpp
* @brief A TCP server delivering incomming connections to you.
*/
class tcp_server_socket : public std::enable_shared_from_this<tcp_server_socket>{ class tcp_server_socket : public std::enable_shared_from_this<tcp_server_socket>{
public: public:
typedef std::function<void(tcp_client)> incoming_client_listener_type; typedef std::function<void(tcp_client)> incoming_client_listener_type;
...@@ -27,8 +35,30 @@ private: ...@@ -27,8 +35,30 @@ private:
std::atomic_uint32_t number_of_connected_clients; std::atomic_uint32_t number_of_connected_clients;
public: public:
/**
* This constructor accepts a port to bind to and the client listener that should be called when clients arrive.
* This constructor automatically binds to all avaliable IPv6 interfaces on the specified port.
* @brief Construct a TCP server that listens on all interfaces
* @param port The port to bind to
* @param client_listener_ The client listener to call when a client arrives.
*/
tcp_server_socket(const uint16_t port, incoming_client_listener_type client_listener_); tcp_server_socket(const uint16_t port, incoming_client_listener_type client_listener_);
/**
* This constructor accepts an interface description to bind to and the client listener that should be called when clients arrive.
* @brief Construct a TCP server that listens on the specified interface
* @param socket_identifier The socket to bind to
* @param port The port to bind to
* @param client_listener_ The client listener to call when a client arrives.
*/
tcp_server_socket(const socketaddr& socket_identifier, incoming_client_listener_type client_listener_); tcp_server_socket(const socketaddr& socket_identifier, incoming_client_listener_type client_listener_);
/**
* This method provides you with the current number of connected clients. When a client
* disconnects this number will be reduced. When a new client arrives this number will be incremented.
* @brief Get the current number of connected clients.
* @return The number of connected clients
*/
int get_number_of_connected_clients() const; int get_number_of_connected_clients() const;
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment