Skip to content

Commit 28215be

Browse files
committed
allow to set socket timeout
fixes adafruit#112
1 parent 75ca1c5 commit 28215be

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ def __init__(
145145
socket_pool=None,
146146
ssl_context=None,
147147
use_binary_mode=False,
148+
socket_timeout=1,
148149
):
149150

150151
self._socket_pool = socket_pool
151152
self._ssl_context = ssl_context
152153
self._sock = None
153154
self._backwards_compatible_sock = False
154155
self._use_binary_mode = use_binary_mode
156+
self._socket_timeout = socket_timeout
155157

156158
self.keep_alive = keep_alive
157159
self._user_data = None
@@ -209,12 +211,12 @@ def __init__(
209211
self.on_unsubscribe = None
210212

211213
# pylint: disable=too-many-branches
212-
def _get_connect_socket(self, host, port, *, timeout=1):
214+
def _get_connect_socket(self, host, port, *, timeout):
213215
"""Obtains a new socket and connects to a broker.
214216
215217
:param str host: Desired broker hostname
216218
:param int port: Desired broker port
217-
:param int timeout: Desired socket timeout
219+
:param int timeout: Desired socket timeout in seconds
218220
"""
219221
# For reconnections - check if we're using a socket already and close it
220222
if self._sock:
@@ -444,7 +446,7 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
444446
self.logger.debug("Attempting to establish MQTT connection...")
445447

446448
# Get a new socket
447-
self._sock = self._get_connect_socket(self.broker, self.port)
449+
self._sock = self._get_connect_socket(self.broker, self.port, timeout=self._socket_timeout)
448450

449451
# Fixed Header
450452
fixed_header = bytearray([0x10])

0 commit comments

Comments
 (0)