Last active
August 29, 2015 14:04
-
-
Save dm8tbr/b36c6afca8904d15027a to your computer and use it in GitHub Desktop.
A quick and simple patch to ensure select() times out within 10s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py | |
index a28c81f..4dce403 100755 | |
--- a/src/paho/mqtt/client.py | |
+++ b/src/paho/mqtt/client.py | |
@@ -39,6 +39,10 @@ try: | |
import dns.resolver | |
except ImportError: | |
HAVE_DNS = False | |
+from ctypes import * | |
+iphb = CDLL("libiphb.so.0.0.0") | |
+hb = iphb.iphb_open() | |
+hbsock = iphb.iphb_get_fd(hb); | |
if platform.system() == 'Windows': | |
EAGAIN = errno.WSAEWOULDBLOCK | |
@@ -781,12 +785,16 @@ class Client(object): | |
# sockpairR is used to break out of select() before the timeout, on a | |
# call to publish() etc. | |
- rlist = [self.socket(), self._sockpairR] | |
+ # hbsock is used to break out of select() after a fixed timeout of 10s | |
+ # is reached. | |
+ rlist = [self.socket(), self._sockpairR, hbsock] | |
+ iphb.iphb_wait(hb, 10, 10, 0) | |
try: | |
socklist = select.select(rlist, wlist, [], timeout) | |
except TypeError: | |
# Socket isn't correct type, in likelihood connection is lost | |
return MQTT_ERR_CONN_LOST | |
+ iphb.iphb_discard_wakeups(hb) | |
if self.socket() in socklist[0]: | |
rc = self.loop_read(max_packets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment