X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_server.hxx;h=a9c7b3d0433d8d15d83c4784e5393d8acba43c6e;hp=5dfea1f0a57f1a0aa1e2763135e427f83a1cb652;hb=644c4d262aab14ee4ec1cfade83a2e99568098d3;hpb=04e6b2712bf0fdfdb6a74cf6d26f02e6a8d37ae2 diff --git a/src/socket_server.hxx b/src/socket_server.hxx index 5dfea1f..a9c7b3d 100644 --- a/src/socket_server.hxx +++ b/src/socket_server.hxx @@ -20,8 +20,11 @@ #define __LIBT2N_SOCKET_SERVER #include +#include #include "server.hxx" +#include "socket_handler.hxx" +#include "types.hxx" namespace libt2n { @@ -29,51 +32,54 @@ namespace libt2n /** Socket based server class */ -class socket_server : public server +class socket_server : public socket_handler, public server { - public: - enum socket_type_value { tcp_s, unix_s }; - private: - int sock; fd_set connection_set; - socket_type_value socket_type; std::string unix_path; - void set_socket_options(int sock); void new_connection(); + protected: + void log(log_level_values level, const std::string& message) + { log(level,message.c_str()); } + void log(log_level_values level, const char* message) + { server::log(level,message); } + public: - socket_server(int port, const char* ip="0.0.0.0"); - socket_server(const char* path, mode_t filemode, const char* user="", const char* group=""); + socket_server(int port, const std::string& ip="0.0.0.0"); + socket_server(const std::string& path, mode_t filemode=00770, const std::string& user="", const std::string& group=""); ~socket_server(); - socket_type_value get_type() - { return socket_type; } - void fill_buffer(long long usec_timeout=-1); + void fill_connection_buffers(); + + void remove_connection_socket(int sock); }; /** Socket based connection class */ -class socket_connection : public connection +class socket_server_connection : public socket_handler, public server_connection { friend class socket_server; private: - int sock; + socket_server_connection(int _sock, socket_type_value _stype, int _timeout) + : server_connection(_timeout), socket_handler(_sock,_stype) + { } + + void log(log_level_values level, const char* message); - socket_connection(int _sock, int _timeout); + void real_write(const std::string& data) + { socket_write(data); } public: + void fill_buffer(long long usec_timeout=-1) + { socket_handler::fill_buffer(buffer,usec_timeout); } void close(); - - void fill_buffer(void); - - void write(const std::string& data); }; }