libt2n: (gerd) small improvements, resolve doxygen conflicts
[libt2n] / src / server.hxx
index c93e43b..40113b8 100644 (file)
@@ -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<unsigned int, connection*> connections;
 
     protected:
+        std::map<unsigned int, connection*> 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);