2018-11-01 05:31:00 +08:00
|
|
|
from abc import ABC, abstractmethod
|
2018-11-12 07:03:04 +08:00
|
|
|
|
2018-11-01 05:31:00 +08:00
|
|
|
|
|
|
|
class IMuxedStream(ABC):
|
|
|
|
|
2018-11-12 07:03:04 +08:00
|
|
|
@abstractmethod
|
|
|
|
def read(self):
|
|
|
|
"""
|
|
|
|
read from stream
|
|
|
|
:return: bytes of input
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def write(self, _bytes):
|
|
|
|
"""
|
|
|
|
write to stream
|
|
|
|
:return: number of bytes written
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def close(self):
|
|
|
|
"""
|
|
|
|
close stream
|
|
|
|
:return: true if successful
|
|
|
|
"""
|
|
|
|
pass
|
2018-11-01 05:31:00 +08:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def reset(self):
|
|
|
|
"""
|
|
|
|
closes both ends of the stream
|
|
|
|
tells this remote side to hang up
|
|
|
|
:return: error/exception
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_deadline(self, ttl):
|
|
|
|
"""
|
|
|
|
set deadline for muxed stream
|
|
|
|
:return: a new stream
|
|
|
|
"""
|
|
|
|
pass
|