From 6102d830138013216241b6723527246764103fa0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 6 Aug 2011 00:50:08 +0300 Subject: [PATCH] Don't close socket on Communicator error --- source/communicator.cpp | 10 +++++++--- source/communicator.h | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/communicator.cpp b/source/communicator.cpp index 0209f2d..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)); } @@ -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; } } diff --git a/source/communicator.h b/source/communicator.h index 0aa152c..8530db1 100644 --- a/source/communicator.h +++ b/source/communicator.h @@ -30,6 +30,7 @@ private: char *in_begin; char *in_end; char *out_buf; + bool good; public: Communicator(StreamSocket &, const Protocol &, ReceiverBase &); @@ -41,6 +42,8 @@ public: template void send(const P &pkt) { + if(!good) + throw sequence_error("connection aborted"); if(handshake_status!=2) throw sequence_error("handshaking not done"); unsigned size = protocol.assemble(pkt, out_buf, buf_size); -- 2.45.2