X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_server.hxx;h=e3a4f34c10581ab2809c176ab33774e9a9499960;hp=a9c7b3d0433d8d15d83c4784e5393d8acba43c6e;hb=cc68aabb16ec32278df8b071c4c9efec7e9f0dce;hpb=644c4d262aab14ee4ec1cfade83a2e99568098d3 diff --git a/src/socket_server.hxx b/src/socket_server.hxx index a9c7b3d..e3a4f34 100644 --- a/src/socket_server.hxx +++ b/src/socket_server.hxx @@ -29,17 +29,30 @@ namespace libt2n { -/** - Socket based server class +class socket_server_connection; + +/** @brief Socket based server class + + Use this class to instantiate a server listening for client connections. + Call fill_buffer() to read data from the network and get_packet() to retrieve + this data. Don't forget to call cleanup() from time to time to remove closed + connections and close idle ones. */ class socket_server : public socket_handler, public server { + friend class socket_server_connection; + private: fd_set connection_set; std::string unix_path; + void start_listening(); + void new_connection(); + bool fill_connection_buffers(); + void remove_connection_socket(int sock); + protected: void log(log_level_values level, const std::string& message) { log(level,message.c_str()); } @@ -52,14 +65,12 @@ class socket_server : public socket_handler, public server ~socket_server(); - void fill_buffer(long long usec_timeout=-1); - void fill_connection_buffers(); - - void remove_connection_socket(int sock); + bool fill_buffer(long long usec_timeout=-1); }; -/** - Socket based connection class +/** @brief Socket based connection + + This class is used within a socket_server to represent the connection to each client. */ class socket_server_connection : public socket_handler, public server_connection { @@ -76,8 +87,8 @@ class socket_server_connection : public socket_handler, public server_connection { socket_write(data); } public: - void fill_buffer(long long usec_timeout=-1) - { socket_handler::fill_buffer(buffer,usec_timeout); } + bool fill_buffer(long long usec_timeout=-1) + { return socket_handler::fill_buffer(buffer,usec_timeout); } void close(); };