Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,13 @@ def items(self):
A generator that yields (token_hex, fail_time) pairs retrieved from
the APNs feedback server
"""
buff = b''
buff = bytearray()
for chunk in self._chunks():
buff += chunk

# Quit if there's no more data to read
if not buff:
break

# Sanity check: after a socket read we should always have at least
# 6 bytes in the buffer
if len(buff) < 6:
if not chunk:
break
buff.extend(chunk)

while len(buff) > 6:
while len(buff) >= 6:
token_length = APNs.unpacked_ushort_big_endian(buff[4:6])
bytes_to_read = 6 + token_length
if len(buff) >= bytes_to_read:
Expand All @@ -458,7 +451,7 @@ def items(self):
yield (token, fail_time)

# Remove data for current token from buffer
buff = buff[bytes_to_read:]
del buff[:bytes_to_read]
else:
# break out of inner while loop - i.e. go and fetch
# some more data and append to buffer
Expand Down