From 6e61c501ac7b92e569e57ca5db7a63fd0a820b17 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 7 May 2014 01:57:38 +0300 Subject: [PATCH] asyncio_micro: Support readall semantics and handle non-blocking read() well. Non-blocking read()/write() may return None if there's no data, and that's not EOF. --- asyncio_micro/asyncio_micro.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/asyncio_micro/asyncio_micro.py b/asyncio_micro/asyncio_micro.py index de182b22..e8dcf629 100644 --- a/asyncio_micro/asyncio_micro.py +++ b/asyncio_micro/asyncio_micro.py @@ -191,9 +191,13 @@ class StreamReader: def __init__(self, s): self.s = s - def read(self, n): + def read(self, n=-1): s = yield IORead(self.s) - res = self.s.read(n) + while True: + res = self.s.read(n) + if res is not None: + break + log.warn("Empty read") if not res: yield IODone(IO_READ, self.s) return res @@ -202,7 +206,11 @@ class StreamReader: log.debug("StreamReader.readline()") s = yield IORead(self.s) log.debug("StreamReader.readline(): after IORead: %s", s) - res = self.s.readline() + while True: + res = self.s.readline() + if res is not None: + break + log.warn("Empty read") if not res: yield IODone(IO_READ, self.s) log.debug("StreamReader.readline(): res: %s", res)