X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fserver.hxx;h=40113b8deef3dbb6597b72abe3810c8b2fcf6cdd;hp=7b45ac6a8a336a15c87c60fa5b92d8ea4af768fd;hb=aa499d2034964a4c125794b7e8ea768cb7471411;hpb=0cf4dc9bf7fa527751fd7dc425f882fc86888132 diff --git a/src/server.hxx b/src/server.hxx index 7b45ac6..40113b8 100644 --- a/src/server.hxx +++ b/src/server.hxx @@ -26,13 +26,18 @@ namespace libt2n { +class server; + +/** + Basic connection class +*/ class connection { private: int timeout; int last_action_time; bool closed; - std::string buffer; + unsigned int connection_id; protected: connection(int _timeout) @@ -40,8 +45,15 @@ class connection set_timeout(_timeout); reset_timeout(); closed=false; + connection_id=0; + my_server=0; } + server *my_server; + std::string buffer; + + typedef unsigned int packet_size_indicator; + public: ~connection() { this->close(); } @@ -54,15 +66,25 @@ class connection bool is_closed() { return closed; } + void set_server(server* _my_server) + { my_server=_my_server; } + + void set_id(unsigned int _connection_id) + { connection_id=_connection_id; } + unsigned int get_id() + { return connection_id; } + std::string get_id_string(); + virtual void close() { closed=true; } - virtual void fill_buffer(void)=0; - bool get_packet(std::string& data, unsigned int& conn_id); virtual void write(const std::string& data)=0; }; +/** + Basic server class +*/ class server { public: @@ -74,21 +96,26 @@ class server std::ostream *logstream; unsigned int next_id; - std::map connections; protected: + std::map connections; + server() { set_default_timeout(30); set_logging(NULL,none); - next_id=0; + next_id=1; } + int add_connection(connection* newconn); + public: virtual ~server(); void set_default_timeout(int _default_timeout) { default_timeout=_default_timeout; } + int get_default_timeout(void) + { return default_timeout; } void set_logging(std::ostream *_logstream, log_level_values _log_level) { @@ -103,9 +130,8 @@ class server bool get_packet(std::string& data, unsigned int& conn_id); - void fill_connection_buffers(void); + virtual void fill_connection_buffers(void)=0; - 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);