diff --git a/uasyncio/uasyncio/__init__.py b/uasyncio/uasyncio/__init__.py index d16fc509..b6b3e6d7 100644 --- a/uasyncio/uasyncio/__init__.py +++ b/uasyncio/uasyncio/__init__.py @@ -131,17 +131,18 @@ class StreamWriter: self.s = s self.extra = extra - def awrite(self, buf): + def awrite(self, buf, off=0, sz=-1): # This method is called awrite (async write) to not proliferate # incompatibility with original asyncio. Unlike original asyncio # whose .write() method is both not a coroutine and guaranteed # to return immediately (which means it has to buffer all the # data), this method is a coroutine. - sz = len(buf) + if sz == -1: + sz = len(buf) - off if DEBUG and __debug__: log.debug("StreamWriter.awrite(): spooling %d bytes", sz) while True: - res = self.s.write(buf) + res = self.s.write(buf, off, sz) # If we spooled everything, return immediately if res == sz: if DEBUG and __debug__: @@ -152,7 +153,7 @@ class StreamWriter: if DEBUG and __debug__: log.debug("StreamWriter.awrite(): spooled partial %d bytes", res) assert res < sz - buf = buf[res:] + off += res sz -= res yield IOWrite(self.s) #assert s2.fileno() == self.s.fileno()