X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fserver.hxx;h=40113b8deef3dbb6597b72abe3810c8b2fcf6cdd;hp=c93e43b2737a038fd82bdfbbb62ea3c726297dc3;hb=aa499d2034964a4c125794b7e8ea768cb7471411;hpb=04e6b2712bf0fdfdb6a74cf6d26f02e6a8d37ae2 diff --git a/src/server.hxx b/src/server.hxx index c93e43b..40113b8 100644 --- a/src/server.hxx +++ b/src/server.hxx @@ -26,6 +26,8 @@ namespace libt2n { +class server; + /** Basic connection class */ @@ -35,7 +37,7 @@ class connection int timeout; int last_action_time; bool closed; - std::string buffer; + unsigned int connection_id; protected: connection(int _timeout) @@ -43,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(); } @@ -57,11 +66,18 @@ 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; }; @@ -80,14 +96,15 @@ 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); @@ -113,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);