Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Fix BufferedSocket capacity calculation #399

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion hyper/common/bufsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _remaining_capacity(self):
"""
The maximum number of bytes the buffer could still contain.
"""
return self._buffer_size - self._index
return self._buffer_size - self._index - self._bytes_in_buffer

@property
def _buffer_end(self):
Expand Down
14 changes: 14 additions & 0 deletions test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ def test_socket_fill_resizes_if_needed(self):
assert len(b.buffer) == 4
assert b._index == 0

def test_socket_fill_resizes_if_needed_with_bytes_in_buffer(self):
s = DummySocket()
b = BufferedSocket(s)

b._index = 982
b._buffer_view[982:1000] = b'This is incomplete'
b._bytes_in_buffer += 18
assert len(b.buffer) == 18

s.inbound_packets = [b' not anymore']
b.fill()
assert len(b.buffer) == 30
assert b._index == 0

def test_socket_fill_raises_connection_errors(self):
s = DummySocket()
b = BufferedSocket(s)
Expand Down