]> git.tdb.fi Git - libs/net.git/blobdiff - source/communicator.cpp
Don't close socket on Communicator error
[libs/net.git] / source / communicator.cpp
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;
        }
 }