]> git.tdb.fi Git - libs/net.git/commitdiff
Don't close socket on Communicator error
authorMikko Rasa <tdb@tdb.fi>
Fri, 5 Aug 2011 21:50:08 +0000 (00:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 5 Aug 2011 21:50:08 +0000 (00:50 +0300)
source/communicator.cpp
source/communicator.h

index 0209f2d93e6783fd2a402dff1bfecad344da481b..c9b277d3748de137381b0df792d5230b0e8e0c62 100644 (file)
@@ -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;
        }
 }
index 0aa152cd6c803e37410bc641abeb17f0d5748a3f..8530db128d26c5d168d99fb0af34e7c874484ffc 100644 (file)
@@ -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<typename P>
        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);