Skip to content

Commit 76b34be

Browse files
committed
Fix BufferedProtocol.get_buffer to accept *sizehint* argument
1 parent 124e981 commit 76b34be

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tests/test_tcp.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ class Test_UV_TCP(_TestTCP, tb.UVTestCase):
631631

632632
def test_create_server_buffered_1(self):
633633
SIZE = 123123
634+
eof = False
635+
done = False
634636

635637
class Proto(asyncio.BaseProtocol):
636638
def connection_made(self, tr):
@@ -639,7 +641,7 @@ def connection_made(self, tr):
639641
self.data = bytearray(50)
640642
self.buf = memoryview(self.data)
641643

642-
def get_buffer(self):
644+
def get_buffer(self, sizehint):
643645
return self.buf
644646

645647
def buffer_updated(self, nbytes):
@@ -648,7 +650,12 @@ def buffer_updated(self, nbytes):
648650
self.tr.write(b'hello')
649651

650652
def eof_received(self):
651-
pass
653+
nonlocal eof
654+
eof = True
655+
656+
def connection_lost(self, exc):
657+
nonlocal done
658+
done = exc
652659

653660
async def test():
654661
port = tb.find_free_port()
@@ -666,13 +673,15 @@ async def test():
666673
await srv.wait_closed()
667674

668675
self.loop.run_until_complete(test())
676+
self.assertTrue(eof)
677+
self.assertIsNone(done)
669678

670679
def test_create_server_buffered_2(self):
671680
class ProtoExc(asyncio.BaseProtocol):
672681
def __init__(self):
673682
self._lost_exc = None
674683

675-
def get_buffer(self):
684+
def get_buffer(self, sizehint):
676685
1 / 0
677686

678687
def buffer_updated(self, nbytes):
@@ -688,7 +697,7 @@ class ProtoZeroBuf1(asyncio.BaseProtocol):
688697
def __init__(self):
689698
self._lost_exc = None
690699

691-
def get_buffer(self):
700+
def get_buffer(self, sizehint):
692701
return bytearray(0)
693702

694703
def buffer_updated(self, nbytes):
@@ -704,7 +713,7 @@ class ProtoZeroBuf2(asyncio.BaseProtocol):
704713
def __init__(self):
705714
self._lost_exc = None
706715

707-
def get_buffer(self):
716+
def get_buffer(self, sizehint):
708717
return memoryview(bytearray(0))
709718

710719
def buffer_updated(self, nbytes):
@@ -720,7 +729,7 @@ class ProtoUpdatedError(asyncio.BaseProtocol):
720729
def __init__(self):
721730
self._lost_exc = None
722731

723-
def get_buffer(self):
732+
def get_buffer(self, sizehint):
724733
return memoryview(bytearray(100))
725734

726735
def buffer_updated(self, nbytes):

uvloop/handles/stream.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ cdef void __uv_stream_buffered_alloc(uv.uv_handle_t* stream,
909909

910910
sc._read_pybuf_acquired = 0
911911
try:
912-
buf = sc._protocol_get_buffer()
912+
buf = sc._protocol_get_buffer(suggested_size)
913913
PyObject_GetBuffer(buf, pybuf, PyBUF_WRITABLE)
914914
got_buf = 1
915915
except BaseException as exc:

0 commit comments

Comments
 (0)