X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=blobdiff_plain;f=source%2Fnet%2Fcommunicator.cpp;h=b30a8e965c388c8457b26ae454ce6c399fe5f6fc;hp=c9b277d3748de137381b0df792d5230b0e8e0c62;hb=3c2a877580e234df5fcbe06bf2850cd29f875e28;hpb=50e9f9ea7f7385a2c5931fca2b8fb1103078e67c diff --git a/source/net/communicator.cpp b/source/net/communicator.cpp index c9b277d..b30a8e9 100644 --- a/source/net/communicator.cpp +++ b/source/net/communicator.cpp @@ -1,6 +1,8 @@ #include #include "communicator.h" +using namespace std; + namespace { using namespace Msp::Net; @@ -85,9 +87,10 @@ void Communicator::data_available() if(!good) return; - in_end += socket.read(in_end, in_buf+buf_size-in_end); try { + in_end += socket.read(in_end, in_buf+buf_size-in_end); + bool more = true; while(more) { @@ -114,10 +117,12 @@ void Communicator::data_available() } } } - catch(...) + catch(const exception &e) { good = false; - throw; + if(signal_error.empty()) + throw; + signal_error.emit(e); } } @@ -128,7 +133,7 @@ bool Communicator::receive_packet(const Protocol &proto, ReceiverBase &recv) { char *pkt = in_begin; in_begin += psz; - proto.disassemble(recv, pkt, psz); + proto.dispatch(recv, pkt, psz); return true; } else @@ -150,7 +155,7 @@ void Communicator::send_handshake() shake.hash = protocol.get_hash(); HandshakeProtocol hsproto; - unsigned size = hsproto.assemble(shake, out_buf, buf_size); + unsigned size = hsproto.serialize(shake, out_buf, buf_size); socket.write(out_buf, size); }