X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcommunicator.cpp;h=c9b277d3748de137381b0df792d5230b0e8e0c62;hb=21c596567e3b6fd794ed6af73d304ce2bc70e58f;hp=1bb0fde49592f81d9f9c2fa91a22a52431f45e7a;hpb=a81c41acd873cda7f40bca634782230d9e57dc4f;p=libs%2Fnet.git diff --git a/source/communicator.cpp b/source/communicator.cpp index 1bb0fde..c9b277d 100644 --- a/source/communicator.cpp +++ b/source/communicator.cpp @@ -59,7 +59,8 @@ Communicator::Communicator(StreamSocket &s, const Protocol &p, ReceiverBase &r): in_buf(new char[buf_size]), in_begin(in_buf), in_end(in_buf), - out_buf(new char[buf_size]) + out_buf(new char[buf_size]), + good(true) { socket.signal_data_available.connect(sigc::mem_fun(this, &Communicator::data_available)); } @@ -73,7 +74,7 @@ Communicator::~Communicator() void Communicator::initiate_handshake() { if(handshake_status!=0) - throw InvalidState("Handshaking is already underway or done"); + throw sequence_error("handshaking already done"); send_handshake(); handshake_status = 1; @@ -81,6 +82,9 @@ void Communicator::initiate_handshake() void Communicator::data_available() { + if(!good) + return; + in_end += socket.read(in_end, in_buf+buf_size-in_end); try { @@ -105,14 +109,14 @@ void Communicator::data_available() signal_handshake_done.emit(); } else - socket.close(); + good = false; } } } } catch(...) { - socket.close(); + good = false; throw; } }