]> git.tdb.fi Git - libs/net.git/blob - source/communicator.h
Fix a comparison operator on win32
[libs/net.git] / source / communicator.h
1 /* $Id$
2
3 This file is part of libmspnet
4 Copyright © 2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_NET_COMMUNICATOR_H_
9 #define MSP_NET_COMMUNICATOR_H_
10
11 #include "protocol.h"
12 #include "streamsocket.h"
13
14 namespace Msp {
15 namespace Net {
16
17 class Communicator
18 {
19 public:
20         sigc::signal<void> signal_handshake_done;
21
22 private:
23         StreamSocket &socket;
24         const Protocol &protocol;
25         ReceiverBase &receiver;
26         int handshake_status;
27         unsigned buf_size;
28         char *in_buf;
29         char *in_begin;
30         char *in_end;
31         char *out_buf;
32
33 public:
34         Communicator(StreamSocket &, const Protocol &, ReceiverBase &);
35         ~Communicator();
36
37         void initiate_handshake();
38
39         template<typename P>
40         void send(const P &pkt)
41         {
42                 if(handshake_status!=2)
43                         throw InvalidState("Handshaking is not done");
44                 unsigned size=protocol.assemble(pkt, out_buf, buf_size);
45                 socket.write(out_buf, size);
46         }
47
48 private:
49         void data_available();
50         bool receive_packet(const Protocol &, ReceiverBase &);
51         void send_handshake();
52 };
53
54 } // namespace Net
55 } // namespace Msp
56
57 #endif