Commit 54cd0503 authored by Jason Madden's avatar Jason Madden

Let GreenFileDescriptorIO inherit RawIOBase's read() method so that it handles...

Let GreenFileDescriptorIO inherit RawIOBase's read() method so that it handles negative/missing size reads appropriately. Fixes #675.
parent 86b23311
......@@ -13,6 +13,9 @@
- Python 3: The SSLSocket class should return an empty ``bytes``
object on an EOF instead of a ``str``. Fixed in :pr:`674` by Dahoon
Kim.
- Python 2: Workaround a buffering bug in the stdlib ``io`` module
that caused ``FileObjectPosix`` to be slower than necessary in some
cases. Reported in :issue:`675` by WGH-.
1.1b6 (Oct 17, 2015)
====================
......
......@@ -75,9 +75,16 @@ class GreenFileDescriptorIO(RawIOBase):
self._fileno = None
os.close(fileno)
def read(self, n=1):
# RawIOBase provides a 'read' method that will call readall() if
# the `size` was missing or -1 and otherwise call readinto(). We
# want to take advantage of this to avoid single byte reads when
# possible. This is highlighted by a bug in BufferedIOReader that
# calls read() in a loop when its readall() method is invoked;
# this was fixed in Python 3.3. See
# https://github.com/gevent/gevent/issues/675)
def __read(self, n):
if not self._readable:
raise UnsupportedOperation('readinto')
raise UnsupportedOperation('read')
while True:
try:
return _read(self._fileno, n)
......@@ -89,14 +96,14 @@ class GreenFileDescriptorIO(RawIOBase):
def readall(self):
ret = BytesIO()
while True:
data = self.read(DEFAULT_BUFFER_SIZE)
data = self.__read(DEFAULT_BUFFER_SIZE)
if not data:
break
ret.write(data)
return ret.getvalue()
def readinto(self, b):
data = self.read(len(b))
data = self.__read(len(b))
n = len(data)
try:
b[:n] = data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment