Skip to content

Commit 92afd3a

Browse files
cbbm142John Pastore
authored andcommitted
Preserve write buffer when raw.write() returns None on blocked socket
Add a check in cheroot.makefile.BufferedWriter._flush_unlocked to prevent clearing of the write buffer when raw.write() returns None due to a blocked stream. Also limits each write call to SOCK_WRITE_BLOCKSIZE bytes, which was defined but not previously used in this method.
1 parent 8888aa3 commit 92afd3a

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

cheroot/makefile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def _flush_unlocked(self):
3030
try:
3131
# ssl sockets only except 'bytes', not bytearrays
3232
# so perhaps we should conditionally wrap this for perf?
33-
n = self.raw.write(bytes(self._write_buf[:SOCK_WRITE_BLOCKSIZE]))
33+
n = self.raw.write(
34+
bytes(self._write_buf[:SOCK_WRITE_BLOCKSIZE]),
35+
)
3436
except io.BlockingIOError as e:
3537
n = e.characters_written
3638
if n:

cheroot/test/test_makefile.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def mock_raw_write(b):
7474
nonlocal call_count
7575
call_count += 1
7676
if call_count == 1:
77-
return None # simulates socket returning None on first blocked write
77+
return (
78+
None # simulates socket returning None on first blocked write
79+
)
7880
written.extend(b)
7981
return len(b)
8082

0 commit comments

Comments
 (0)