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

@ -1,5 +1,4 @@
from abc import ABC, abstractmethod
import asyncio
class IRawConnection(ABC):
@ -9,17 +8,12 @@ class IRawConnection(ABC):
initiator: bool
# TODO: reader and writer shouldn't be exposed.
# Need better API for the consumers
reader: asyncio.StreamReader
writer: asyncio.StreamWriter
@abstractmethod
async def write(self, data: bytes) -> None:
pass
@abstractmethod
async def read(self) -> bytes:
async def read(self, n: int = -1) -> bytes:
pass
@abstractmethod