Skip to content

Commit 984c600

Browse files
author
brentru
committed
add shared buffer, connect tested
1 parent 8492a58 commit 984c600

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def __init__(
212212
self.on_subscribe = None
213213
self.on_unsubscribe = None
214214

215+
# Shared buffer
216+
self._rx_length = 0
217+
self._rx_buffer = bytearray(32)
218+
215219
# Socket helpers
216220
def _free_socket(self, socket):
217221
"""Frees a socket for re-use."""
@@ -405,6 +409,7 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
405409
with the broker, in seconds
406410
407411
"""
412+
buf = self._rx_buffer
408413
if host:
409414
self.broker = host
410415
if port:
@@ -481,14 +486,14 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
481486
while True:
482487
op = self._wait_for_msg()
483488
if op == 32:
484-
rc = self._sock.recv(3)
485-
assert rc[0] == 0x02
486-
if rc[2] != 0x00:
487-
raise MMQTTException(CONNACK_ERRORS[rc[2]])
489+
self._recv_into(buf, 3)
490+
assert buf[0] == 0x02
491+
if buf[2] != 0x00:
492+
raise MMQTTException(CONNACK_ERRORS[buf[2]])
488493
self._is_connected = True
489-
result = rc[0] & 1
494+
result = buf[0] & 1
490495
if self.on_connect is not None:
491-
self.on_connect(self, self._user_data, result, rc[2])
496+
self.on_connect(self, self._user_data, result, buf[2])
492497
return result
493498

494499
def disconnect(self):

0 commit comments

Comments
 (0)