wpaspy: Fix potentially referencing non existing attribute
[mech_eap.git] / wpaspy / wpaspy.py
index 861bee6..c2aace0 100644 (file)
@@ -44,6 +44,7 @@ class Ctrl:
                 raise
         else:
             try:
+                self.s = None
                 ai_list = socket.getaddrinfo(path, port, socket.AF_INET,
                                              socket.SOCK_DGRAM)
                 for af, socktype, proto, cn, sockaddr in ai_list:
@@ -109,6 +110,16 @@ class Ctrl:
             return None
         raise Exception("DETACH failed")
 
+    def terminate(self):
+        if self.attached:
+            try:
+                self.detach()
+            except Exception, e:
+                # Need to ignore this to allow the socket to be closed
+                self.attached = False
+        self.request("TERMINATE")
+        self.close()
+
     def pending(self, timeout=0):
         [r, w, e] = select.select([self.s], [], [], timeout)
         if r: