Roger Light avatar Roger Light committed fca1d68

Add loop -> loop_read/loop_write changes to python client.

Comments (0)

Files changed (1)

lib/python/mosquitto.py

 
         if self.socket() in socklist[0]:
             rc = self.loop_read(max_packets)
-            if rc != MOSQ_ERR_SUCCESS:
-                if self._ssl:
-                    self._ssl.close()
-                    self._ssl = None
-                elif self._sock:
-                    self._sock.close()
-                    self._sock = None
-
-                self._state_mutex.acquire()
-                if self._state == mosq_cs_disconnecting:
-                    rc = MOSQ_ERR_SUCCESS
-                self._state_mutex.release()
-                self._callback_mutex.acquire()
-                if self.on_disconnect:
-                    self._in_callback = True
-                    self.on_disconnect(self, self._userdata, rc)
-                    self._in_callback = False
-
-                self._callback_mutex.release()
+            if rc or (self._ssl == None and self._sock == None):
                 return rc
 
         if self.socket() in socklist[1]:
             rc = self.loop_write(max_packets)
-            if rc != MOSQ_ERR_SUCCESS:
-                if self._ssl:
-                    self._ssl.close()
-                    self._ssl = None
-                else:
-                    self._sock.close()
-                    self._sock = None
-
-                self._state_mutex.acquire()
-                if self._state == mosq_cs_disconnecting:
-                    rc = MOSQ_ERR_SUCCESS
-                self._state_mutex.release()
-                self._callback_mutex.acquire()
-                if self.on_disconnect:
-                    self._in_callback = True
-                    self.on_disconnect(self, self._userdata, rc)
-                    self._in_callback = False
-                self._callback_mutex.release()
+            if rc or (self._ssl == None and self._sock == None):
                 return rc
 
         return self.loop_misc()
         for i in range(0, max_packets):
             rc = self._packet_read()
             if rc > 0:
-                return rc
+                return self._loop_rc_handle(rc)
             elif rc == MOSQ_ERR_AGAIN:
                 return MOSQ_ERR_SUCCESS
         return MOSQ_ERR_SUCCESS
         for i in range(0, max_packets):
             rc = self._packet_write()
             if rc > 0:
-                return rc
+                return self._loop_rc_handle(rc)
             elif rc == MOSQ_ERR_AGAIN:
                 return MOSQ_ERR_SUCCESS
         return MOSQ_ERR_SUCCESS
     # Private functions
     # ============================================================
 
+    def _loop_rc_handle(self, rc):
+        if rc:
+            if self._ssl:
+                self._ssl.close()
+                self._ssl = None
+            elif self._sock:
+                self._sock.close()
+                self._sock = None
+
+            self._state_mutex.acquire()
+            if self._state == mosq_cs_disconnecting:
+                rc = MOSQ_ERR_SUCCESS
+            self._state_mutex.release()
+            self._callback_mutex.acquire()
+            if self.on_disconnect:
+                self._in_callback = True
+                self.on_disconnect(self, self._userdata, rc)
+                self._in_callback = False
+
+            self._callback_mutex.release()
+        return rc
+
     def _packet_read(self):
         # This gets called if pselect() indicates that there is network data
         # available - ie. at least one byte.  What we do depends on what data we
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.