@@ -129,6 +129,7 @@ class MQTT:
129
129
:param socket socket_pool: A pool of socket resources available for the given radio.
130
130
:param ssl_context: SSL context for long-lived SSL connections.
131
131
:param bool use_binary_mode: Messages are passed as bytearray instead of string to callbacks.
132
+ :param int socket_timeout: socket timeout, in seconds
132
133
133
134
"""
134
135
@@ -145,13 +146,15 @@ def __init__(
145
146
socket_pool = None ,
146
147
ssl_context = None ,
147
148
use_binary_mode = False ,
149
+ socket_timeout = 1 ,
148
150
):
149
151
150
152
self ._socket_pool = socket_pool
151
153
self ._ssl_context = ssl_context
152
154
self ._sock = None
153
155
self ._backwards_compatible_sock = False
154
156
self ._use_binary_mode = use_binary_mode
157
+ self ._socket_timeout = socket_timeout
155
158
156
159
self .keep_alive = keep_alive
157
160
self ._user_data = None
@@ -209,12 +212,12 @@ def __init__(
209
212
self .on_unsubscribe = None
210
213
211
214
# pylint: disable=too-many-branches
212
- def _get_connect_socket (self , host , port , * , timeout = 1 ):
215
+ def _get_connect_socket (self , host , port , * , timeout ):
213
216
"""Obtains a new socket and connects to a broker.
214
217
215
218
:param str host: Desired broker hostname
216
219
:param int port: Desired broker port
217
- :param int timeout: Desired socket timeout
220
+ :param int timeout: Desired socket timeout in seconds
218
221
"""
219
222
# For reconnections - check if we're using a socket already and close it
220
223
if self ._sock :
@@ -444,7 +447,9 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
444
447
self .logger .debug ("Attempting to establish MQTT connection..." )
445
448
446
449
# Get a new socket
447
- self ._sock = self ._get_connect_socket (self .broker , self .port )
450
+ self ._sock = self ._get_connect_socket (
451
+ self .broker , self .port , timeout = self ._socket_timeout
452
+ )
448
453
449
454
# Fixed Header
450
455
fixed_header = bytearray ([0x10 ])
0 commit comments