[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Do not let worker thread loop forever on closed tor.



Update of /home/or/cvsroot/control/python
In directory moria:/tmp/cvs-serv1914

Modified Files:
	TorCtl.py TorCtl0.py TorCtl1.py 
Log Message:
Do not let worker thread loop forever on closed tor.

Index: TorCtl.py
===================================================================
RCS file: /home/or/cvsroot/control/python/TorCtl.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- TorCtl.py	9 Nov 2005 22:24:24 -0000	1.11
+++ TorCtl.py	12 Nov 2005 21:42:27 -0000	1.12
@@ -16,6 +16,10 @@
     "Generic error raised by TorControl code."
     pass
 
+class TorCtlClosed(TorCtlError):
+    "Raised when the controller connection is closed by Tor (not by us.)"
+    pass
+
 class ProtocolError(TorCtlError):
     "Raised on violations in Tor controller protocol"
     pass

Index: TorCtl0.py
===================================================================
RCS file: /home/or/cvsroot/control/python/TorCtl0.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- TorCtl0.py	12 Nov 2005 21:22:25 -0000	1.5
+++ TorCtl0.py	12 Nov 2005 21:42:27 -0000	1.6
@@ -196,10 +196,15 @@
     """
     body = ""
     header = s.recv(4)
+    if not header:
+        raise TorCtl.TorCtlClosed()
     length,type = struct.unpack("!HH",header)
     if length:
         while length > len(body):
-            body += s.recv(length-len(body))
+            more = s.recv(length-len(body))
+            if not more:
+                raise TorCtl.TorCtlClosed()
+            body += more
     return length,type,body
 
 def _receive_message(s):

Index: TorCtl1.py
===================================================================
RCS file: /home/or/cvsroot/control/python/TorCtl1.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- TorCtl1.py	12 Nov 2005 21:22:25 -0000	1.8
+++ TorCtl1.py	12 Nov 2005 21:42:27 -0000	1.9
@@ -59,6 +59,8 @@
 
         while 1:
             s = self._s.recv(128)
+            if not s:
+                raise TorCtl.TorCtlClosed()
             idx = s.find('\n')
             if idx >= 0:
                 self._buf.append(s[:idx+1])