Skip to content

Commit cb16a27

Browse files
author
brentru
committed
switch to _exact_recv on publish(), assert self._pid instead of unbound pid
1 parent cd8d954 commit cb16a27

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,13 @@ def publish(self, topic, msg, retain=False, qos=0):
642642
while True:
643643
op = self._wait_for_msg()
644644
if op == 0x40:
645-
self._recv_into(buf, 1)
646-
assert buf == b"\x02"
647-
# rcv_pid = self._sock.recv(2)
648-
self._recv_into(buf, 2)
649-
buf = buf[0] << 0x08 | buf[1]
650-
if pid == buf:
645+
sz = self._sock_exact_recv(1)
646+
assert sz == b"\x02"
647+
rcv_pid = self._sock_exact_recv(2)
648+
rcv_pid = rcv_pid[0] << 0x08 | rcv_pid[1]
649+
if self._pid == rcv_pid:
651650
if self.on_publish is not None:
652-
self.on_publish(self, self._user_data, topic, buf)
651+
self.on_publish(self, self._user_data, topic, rcv_pid)
653652
return
654653

655654
def subscribe(self, topic, qos=0):

0 commit comments

Comments
 (0)