Skip to content

Commit f3a96fd

Browse files
author
Your Name
committed
timeout for socket failure during sock operations
1 parent f13cc67 commit f3a96fd

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

micropython/umqtt.simple/umqtt/simple.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,10 @@ def set_last_will(self, topic, msg, retain=False, qos=0):
6060
self.lw_qos = qos
6161
self.lw_retain = retain
6262

63-
def settimeout(self, value):
64-
'''Blocking socket can cause non determinstic hang incase of n/w failure.
65-
Hence, by setting timeout, application programmer can get exception in case of failure.
66-
This enable him/her to take appropriate action like restarting the task etc.
67-
This works for async apps too.
68-
'''
69-
self._sock.settimeout(value)
70-
71-
def connect(self, clean_session=True):
63+
def connect(self, clean_session=True, timeout=None):
7264
self._sock = self.sock = socket.socket()
65+
if timeout:
66+
self.sock.settimeout(timeout)
7367
addr = socket.getaddrinfo(self.server, self.port)[0][-1]
7468
self.sock.connect(addr)
7569
if self.ssl:

0 commit comments

Comments
 (0)