Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf1f3d4

Browse files
committed
Apply socket read fix from public gihub issue #296
1 parent a67eadf commit bf1f3d4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

AWSIoTPythonSDK/core/protocol/paho/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,15 @@ def loop(self, timeout=1.0, max_packets=1):
877877
self._out_packet_mutex.release()
878878
self._current_out_packet_mutex.release()
879879

880+
# used to check if there are any bytes left in the ssl socket
881+
pending_bytes = 0
882+
if self._ssl:
883+
pending_bytes = self._ssl.pending()
884+
885+
# if bytes are pending do not wait in select
886+
if pending_bytes > 0:
887+
timeout = 0.0
888+
880889
# sockpairR is used to break out of select() before the timeout, on a
881890
# call to publish() etc.
882891
rlist = [self.socket(), self._sockpairR]
@@ -892,7 +901,7 @@ def loop(self, timeout=1.0, max_packets=1):
892901
except:
893902
return MQTT_ERR_UNKNOWN
894903

895-
if self.socket() in socklist[0]:
904+
if self.socket() in socklist[0] or pending_bytes > 0:
896905
rc = self.loop_read(max_packets)
897906
if rc or (self._ssl is None and self._sock is None):
898907
return rc

0 commit comments

Comments
 (0)