libt2n: (gerd) basic command handling (still some todos)
[libt2n] / src / connection.hxx
CommitLineData
a11e19b7
GE
1/***************************************************************************
2 * Copyright (C) 2006 by Gerd v. Egidy *
3 * gve@intra2net.com *
4 * *
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. *
8 * *
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. *
13 * *
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_CONNECTION
20#define __LIBT2N_CONNECTION
21
22#include <string>
23
24namespace libt2n
25{
26
94247295
GE
27/** @brief a connection between client and server. abstact.
28*/
a11e19b7
GE
29class connection
30{
31 private:
32 bool closed;
33
34 protected:
35 connection()
36 { closed=false; }
37
38 std::string buffer;
39
40 typedef unsigned int packet_size_indicator;
41
42 packet_size_indicator bytes_available();
43
44 virtual void real_write(const std::string& data)=0;
45
46 public:
07e98688 47 virtual ~connection()
a11e19b7
GE
48 { close(); }
49
94247295 50 /// is this connection closed or not
a11e19b7
GE
51 bool is_closed()
52 { return closed; }
53
94247295 54 /// close this connection
a11e19b7
GE
55 virtual void close()
56 { closed=true; }
57
94247295
GE
58 /** @brief look for new data and store it in the local buffer
59 @param usec_timeout wait until new data is found, max timeout usecs.
60 -1: wait endless
61 NULL: no timeout
62 @retval true if new data was found (does not mean that the received data
63 is a complete packet though)
64 */
07e98688 65 virtual bool fill_buffer(long long usec_timeout=-1)=0;
a11e19b7 66 bool get_packet(std::string& data);
94247295
GE
67
68 /// returns true if a complete data packet is in the buffer. retrieve it with get_packet().
a11e19b7
GE
69 bool packet_available()
70 { return bytes_available(); }
71
72 void write(const std::string& data);
73};
74
75}
76
77#endif