6
6
# Modified Work Copyright (c) 2019 Bradley Beach, esp32spi_mqtt
7
7
# Modified Work Copyright (c) 2012-2019 Roger Light and others, Paho MQTT Python
8
8
9
+ # pylint: disable=too-many-lines
10
+
9
11
"""
10
12
`adafruit_minimqtt`
11
13
================================================================================
@@ -129,6 +131,8 @@ class MQTT:
129
131
:param socket socket_pool: A pool of socket resources available for the given radio.
130
132
:param ssl_context: SSL context for long-lived SSL connections.
131
133
:param bool use_binary_mode: Messages are passed as bytearray instead of string to callbacks.
134
+ :param int socket_timeout: How often to check socket state for read/write/connect operations,
135
+ in seconds.
132
136
133
137
"""
134
138
@@ -145,13 +149,15 @@ def __init__(
145
149
socket_pool = None ,
146
150
ssl_context = None ,
147
151
use_binary_mode = False ,
152
+ socket_timeout = 1 ,
148
153
):
149
154
150
155
self ._socket_pool = socket_pool
151
156
self ._ssl_context = ssl_context
152
157
self ._sock = None
153
158
self ._backwards_compatible_sock = False
154
159
self ._use_binary_mode = use_binary_mode
160
+ self ._socket_timeout = socket_timeout
155
161
156
162
self .keep_alive = keep_alive
157
163
self ._user_data = None
@@ -214,7 +220,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
214
220
215
221
:param str host: Desired broker hostname
216
222
:param int port: Desired broker port
217
- :param int timeout: Desired socket timeout
223
+ :param int timeout: Desired socket timeout, in seconds
218
224
"""
219
225
# For reconnections - check if we're using a socket already and close it
220
226
if self ._sock :
@@ -444,7 +450,9 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
444
450
self .logger .debug ("Attempting to establish MQTT connection..." )
445
451
446
452
# Get a new socket
447
- self ._sock = self ._get_connect_socket (self .broker , self .port )
453
+ self ._sock = self ._get_connect_socket (
454
+ self .broker , self .port , timeout = self ._socket_timeout
455
+ )
448
456
449
457
# Fixed Header
450
458
fixed_header = bytearray ([0x10 ])
0 commit comments