[tor-commits] [stem/master] Calling QUIT prior to disconnecting socket

atagar at torproject.org atagar at torproject.org
Mon Jul 23 17:11:45 UTC 2012


commit e2528b85f6b0bf1fb82c42599e71d1c925fcd6ae
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Jul 23 10:09:38 2012 -0700

    Calling QUIT prior to disconnecting socket
    
    Making the Controller's close() method try to be a nice controller by issuing a
    QUIT call before detaching the socket. This is a best-effort call (errors
    ignored) since the caller just wants the socket shut down and we don't need the
    QUIT to succeed to do that. Original change by gsathya and discussed on...
    https://trac.torproject.org/6234
---
 stem/control.py |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index d687e1a..16bcb10 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -454,6 +454,14 @@ class Controller(BaseController):
   from_port = staticmethod(from_port)
   from_socket_file = staticmethod(from_socket_file)
   
+  def close(self):
+    # making a best-effort attempt to quit before detaching the socket
+    if self.is_alive():
+      try: self.msg("QUIT")
+      except: pass
+    
+    super(Controller, self).close()
+  
   def get_info(self, param, default = UNDEFINED):
     """
     Queries the control socket for the given GETINFO option. If provided a



More information about the tor-commits mailing list