Skip to content

Commit

Permalink
Merge pull request #54 from masgari/main
Browse files Browse the repository at this point in the history
send large data in 2kb chunks
  • Loading branch information
brentru authored Mar 14, 2022
2 parents 7fd3be6 + a713177 commit cde1415
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@ def finish_response(self, result, client):
response += "\r\n"
client.send(response.encode("utf-8"))
for data in result:
if isinstance(data, bytes):
if not isinstance(data, bytes):
data = data.encode("utf-8")
if len(data) < 0x800:
client.send(data)
else:
client.send(data.encode("utf-8"))
# split to chunks of 2 kb
data_chunks = [
data[i : i + 0x800] for i in range(0, len(data), 0x800)
]
for data_chunk in data_chunks:
client.send(data_chunk)
gc.collect()
finally:
client.disconnect()
Expand Down

0 comments on commit cde1415

Please sign in to comment.