@@ -129,6 +129,7 @@ class MQTT:
129129 :param socket socket_pool: A pool of socket resources available for the given radio.
130130 :param ssl_context: SSL context for long-lived SSL connections.
131131 :param bool use_binary_mode: Messages are passed as bytearray instead of string to callbacks.
132+ :param int socket_timeout: socket timeout, in seconds
132133
133134 """
134135
@@ -145,13 +146,15 @@ def __init__(
145146 socket_pool = None ,
146147 ssl_context = None ,
147148 use_binary_mode = False ,
149+ socket_timeout = 1 ,
148150 ):
149151
150152 self ._socket_pool = socket_pool
151153 self ._ssl_context = ssl_context
152154 self ._sock = None
153155 self ._backwards_compatible_sock = False
154156 self ._use_binary_mode = use_binary_mode
157+ self ._socket_timeout = socket_timeout
155158
156159 self .keep_alive = keep_alive
157160 self ._user_data = None
@@ -209,12 +212,12 @@ def __init__(
209212 self .on_unsubscribe = None
210213
211214 # pylint: disable=too-many-branches
212- def _get_connect_socket (self , host , port , * , timeout = 1 ):
215+ def _get_connect_socket (self , host , port , * , timeout ):
213216 """Obtains a new socket and connects to a broker.
214217
215218 :param str host: Desired broker hostname
216219 :param int port: Desired broker port
217- :param int timeout: Desired socket timeout
220+ :param int timeout: Desired socket timeout in seconds
218221 """
219222 # For reconnections - check if we're using a socket already and close it
220223 if self ._sock :
@@ -444,7 +447,9 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
444447 self .logger .debug ("Attempting to establish MQTT connection..." )
445448
446449 # 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+ )
448453
449454 # Fixed Header
450455 fixed_header = bytearray ([0x10 ])
0 commit comments