Merge
This commit is contained in:
@@ -336,7 +336,7 @@ class GreenSocket(object):
|
|||||||
class GreenPipe(object):
|
class GreenPipe(object):
|
||||||
""" GreenPipe is a cooperatively-yielding wrapper around OS pipes.
|
""" GreenPipe is a cooperatively-yielding wrapper around OS pipes.
|
||||||
"""
|
"""
|
||||||
newlines = '\r\n'
|
newlines = '\n'
|
||||||
def __init__(self, fd):
|
def __init__(self, fd):
|
||||||
set_nonblocking(fd)
|
set_nonblocking(fd)
|
||||||
self.fd = fd
|
self.fd = fd
|
||||||
@@ -416,7 +416,7 @@ class GreenPipe(object):
|
|||||||
chunk, self.recvbuffer = buf[:found], buf[found:]
|
chunk, self.recvbuffer = buf[:found], buf[found:]
|
||||||
return chunk
|
return chunk
|
||||||
checked = max(0, len(buf) - (len(terminator) - 1))
|
checked = max(0, len(buf) - (len(terminator) - 1))
|
||||||
d = self.read(BUFFER_SIZE)
|
d = self._recv(BUFFER_SIZE)
|
||||||
if not d:
|
if not d:
|
||||||
break
|
break
|
||||||
buf += d
|
buf += d
|
||||||
@@ -428,7 +428,7 @@ class GreenPipe(object):
|
|||||||
chunk, self.recvbuffer = buf[:found], buf[found:]
|
chunk, self.recvbuffer = buf[:found], buf[found:]
|
||||||
return chunk
|
return chunk
|
||||||
checked = len(buf)
|
checked = len(buf)
|
||||||
d = self.read(BUFFER_SIZE)
|
d = self._recv(BUFFER_SIZE)
|
||||||
if not d:
|
if not d:
|
||||||
break
|
break
|
||||||
buf += d
|
buf += d
|
||||||
|
@@ -260,6 +260,38 @@ class TestGreenIo(LimitedTestCase):
|
|||||||
server.close()
|
server.close()
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
def test_pipe_read(self):
|
||||||
|
# ensure that 'readline' works properly on GreenPipes when data is not
|
||||||
|
# immediately available (fd is nonblocking, was raising EAGAIN)
|
||||||
|
# also ensures that readline() terminates on '\n' and '\r\n'
|
||||||
|
r, w = os.pipe()
|
||||||
|
|
||||||
|
r = os.fdopen(r)
|
||||||
|
w = os.fdopen(w, 'w')
|
||||||
|
|
||||||
|
r = greenio.GreenPipe(r)
|
||||||
|
w = greenio.GreenPipe(w)
|
||||||
|
|
||||||
|
def writer():
|
||||||
|
eventlet.sleep(.1)
|
||||||
|
|
||||||
|
w.write('line\n')
|
||||||
|
w.flush()
|
||||||
|
|
||||||
|
w.write('line\r\n')
|
||||||
|
w.flush()
|
||||||
|
|
||||||
|
gt = eventlet.spawn(writer)
|
||||||
|
|
||||||
|
eventlet.sleep(0)
|
||||||
|
|
||||||
|
line = r.readline()
|
||||||
|
self.assertEquals(line, 'line\n')
|
||||||
|
|
||||||
|
line = r.readline()
|
||||||
|
self.assertEquals(line, 'line\r\n')
|
||||||
|
|
||||||
|
gt.wait()
|
||||||
|
|
||||||
class TestGreenIoLong(LimitedTestCase):
|
class TestGreenIoLong(LimitedTestCase):
|
||||||
TEST_TIMEOUT=10 # the test here might take a while depending on the OS
|
TEST_TIMEOUT=10 # the test here might take a while depending on the OS
|
||||||
|
Reference in New Issue
Block a user