1 #ifndef MSP_NET_COMMUNICATOR_H_
2 #define MSP_NET_COMMUNICATOR_H_
4 #include <msp/core/except.h>
5 #include <sigc++/signal.h>
13 class sequence_error: public invalid_state
16 sequence_error(const std::string &w): invalid_state(w) { }
19 class incompatible_protocol: public std::runtime_error
22 incompatible_protocol(const std::string &w): std::runtime_error(w) { }
29 sigc::signal<void> signal_handshake_done;
30 sigc::signal<void, const std::exception &> signal_error;
34 const Protocol &protocol;
35 ReceiverBase &receiver;
45 Communicator(StreamSocket &, const Protocol &, ReceiverBase &);
48 void initiate_handshake();
49 bool is_handshake_done() const { return handshake_status==2; }
55 void send_data(std::size_t);
57 void data_available();
58 bool receive_packet(const Protocol &, ReceiverBase &);
59 void send_handshake();
63 void Communicator::send(const P &pkt)
65 send_data(protocol.serialize(pkt, out_buf, buf_size));