Use RawConnection.read

Instead of accessing its reader and writer directly.

TODO: considering add `ReaderWriterCloser` interface and let connection
and stream inherit from it.
This commit is contained in:
mhchia
2019-08-20 18:09:36 +08:00
parent 0b466ddc86
commit ef476e555b
9 changed files with 22 additions and 31 deletions

View File

@ -188,11 +188,9 @@ class Mplex(IMuxedConn):
# loop in handle_incoming
timeout = 0.1
try:
header = await decode_uvarint_from_stream(self.conn.reader, timeout)
length = await decode_uvarint_from_stream(self.conn.reader, timeout)
message = await asyncio.wait_for(
self.conn.reader.read(length), timeout=timeout
)
header = await decode_uvarint_from_stream(self.conn, timeout)
length = await decode_uvarint_from_stream(self.conn, timeout)
message = await asyncio.wait_for(self.conn.read(length), timeout=timeout)
except asyncio.TimeoutError:
return None, None, None