Skip to content

Commit 8e65459

Browse files
committed
Chunk buffer sends into 64 byte chunks
Prevents errors with unsent data on large header values, long URL paths
1 parent 74eaea9 commit 8e65459

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,15 @@ def socket_write(self, socket_num, buffer):
527527
if self._debug:
528528
print("Writing:", buffer)
529529
self._socknum_ll[0][0] = socket_num
530-
resp = self._send_command_get_response(_SEND_DATA_TCP_CMD,
531-
(self._socknum_ll[0], buffer),
532-
sent_param_len_16=True)
530+
chunk_size = 64
531+
sent = 0
532+
for chunk in range((len(buffer) // chunk_size)+1):
533+
chunk_buffer = buffer[(chunk*chunk_size):((chunk+1)*chunk_size)]
534+
resp = self._send_command_get_response(_SEND_DATA_TCP_CMD,
535+
(self._socknum_ll[0], chunk_buffer),
536+
sent_param_len_16=True)
537+
sent += resp[0][0]
533538

534-
sent = resp[0][0]
535539
if sent != len(buffer):
536540
raise RuntimeError("Failed to send %d bytes (sent %d)" % (len(buffer), sent))
537541

0 commit comments

Comments
 (0)