1 /***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License version *
7 * 2.1 as published by the Free Software Foundation. *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
19 #ifndef __LIBT2N_SERVER
20 #define __LIBT2N_SERVER
30 Basic connection class
41 connection(int _timeout)
43 set_timeout(_timeout);
54 void set_timeout(int _timeout)
63 virtual void fill_buffer(void)=0;
65 bool get_packet(std::string& data, unsigned int& conn_id);
66 virtual void write(const std::string& data)=0;
75 enum log_level_values { none=0, error=1, debug=2 };
79 log_level_values log_level;
80 std::ostream *logstream;
83 std::map<unsigned int, connection*> connections;
88 set_default_timeout(30);
89 set_logging(NULL,none);
93 int add_connection(connection* newconn);
98 void set_default_timeout(int _default_timeout)
99 { default_timeout=_default_timeout; }
100 int get_default_timeout(void)
101 { return default_timeout; }
103 void set_logging(std::ostream *_logstream, log_level_values _log_level)
105 log_level=_log_level;
106 logstream=_logstream;
109 connection* get_connection(unsigned int conn_id);
111 virtual void fill_buffer(long long usec_timeout=-1)=0;
112 void check_timeout();
114 bool get_packet(std::string& data, unsigned int& conn_id);
116 void fill_connection_buffers(void);
119 void log(log_level_values level, const std::string& message)
120 { log(level,message.c_str()); }
121 void log(log_level_values level, const char* message);