Skip to content

Commit

Permalink
switch from recv to read
Browse files Browse the repository at this point in the history
  • Loading branch information
brentru committed Aug 29, 2019
1 parent 57b5d57 commit 7c3dd05
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def connect(self, clean_session=True):
while True:
op = self._wait_for_msg()
if op == 32:
rc = self._sock.read(3)
rc = self._sock.recv(3)
assert rc[0] == 0x02
if rc[2] != 0x00:
raise MMQTTException(CONNACK_ERRORS[rc[2]])
Expand Down Expand Up @@ -313,7 +313,7 @@ def ping(self):
while True:
op = self._wait_for_msg(0.5)
if op == 208:
ping_resp = self._sock.read(2)
ping_resp = self._sock.recv(2)
if ping_resp[0] != 0x00:
raise MMQTTException('PINGRESP not returned from broker.')
return
Expand Down Expand Up @@ -394,9 +394,9 @@ def publish(self, topic, msg, retain=False, qos=0):
while True:
op = self._wait_for_msg()
if op == 0x40:
sz = self._sock.read(1)
sz = self._sock.recv(1)
assert sz == b"\x02"
rcv_pid = self._sock.read(2)
rcv_pid = self._sock.recv(2)
rcv_pid = rcv_pid[0] << 0x08 | rcv_pid[1]
if pid == rcv_pid:
if self.on_publish is not None:
Expand Down Expand Up @@ -472,7 +472,7 @@ def subscribe(self, topic, qos=0):
while True:
op = self._wait_for_msg()
if op == 0x90:
rc = self._sock.read(4)
rc = self._sock.recv(4)
assert rc[1] == packet[2] and rc[2] == packet[3]
if rc[3] == 0x80:
raise MMQTTException('SUBACK Failure!')
Expand Down Expand Up @@ -529,7 +529,7 @@ def unsubscribe(self, topic):
while True:
op = self._wait_for_msg()
if op == 176:
return_code = self._sock.read(3)
return_code = self._sock.recv(3)
assert return_code[0] == 0x02
# [MQTT-3.32]
assert return_code[1] == packet_id_bytes[0] and return_code[2] == packet_id_bytes[1]
Expand Down Expand Up @@ -640,27 +640,27 @@ def _wait_for_msg(self, timeout=30):
"""Reads and processes network events.
Returns response code if successful.
"""
res = self._sock.read(1)
res = self._sock.recv(1)
self._sock.settimeout(timeout)
if res in [None, b""]:
return None
if res == MQTT_PINGRESP:
sz = self._sock.read(1)[0]
sz = self._sock.recv(1)[0]
assert sz == 0
return None
if res[0] & 0xf0 != 0x30:
return res[0]
sz = self._recv_len()
topic_len = self._sock.read(2)
topic_len = self._sock.recv(2)
topic_len = (topic_len[0] << 8) | topic_len[1]
topic = self._sock.read(topic_len)
topic = self._sock.recv(topic_len)
topic = str(topic, 'utf-8')
sz -= topic_len + 2
if res[0] & 0x06:
pid = self._sock.read(2)
pid = self._sock.recv(2)
pid = pid[0] << 0x08 | pid[1]
sz -= 0x02
msg = self._sock.read(sz)
msg = self._sock.recv(sz)
if self.on_message is not None:
self.on_message(self, topic, str(msg, 'utf-8'))
if res[0] & 0x06 == 0x02:
Expand All @@ -675,7 +675,7 @@ def _recv_len(self):
n = 0
sh = 0
while True:
b = self._sock.read(1)[0]
b = self._sock.recv(1)[0]
n |= (b & 0x7f) << sh
if not b & 0x80:
return n
Expand Down

0 comments on commit 7c3dd05

Please sign in to comment.