Commits

Anonymous committed 4e9ad90

Added threading event to coordinate send/read and disconnects.

  • Participants
  • Parent commits 8ab9aab

Comments (0)

Files changed (1)

stompclient/connection.py

         self.socket_timeout = socket_timeout
         self._sock = None
         self._buffer = FrameBuffer()
+        self._disconnected = threading.Event()
 
     def connect(self):
         """
         sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
         sock.settimeout(self.socket_timeout)
         self._sock = sock
-
+        self._disconnected.clear()
+        
     def disconnect(self, conf=None):
         """
         Disconnect from the server, if connected.
             pass
         self._sock = None
         self._buffer.clear()
+        self._disconnected.set()
     
     def send(self, frame):
         """
             # Read bytes from socket until we have read a frame (or timeout out) and then return it.
             received_frame = None
             try:
-                while True:
+                while not self._disconnected.is_set():
                     bytes = self._sock.recv(8192)
                     self._buffer.append(bytes)
                     received_frame = self._buffer.extract_frame()