本文整理汇总了Python中stream.Stream.is_closed方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.is_closed方法的具体用法?Python Stream.is_closed怎么用?Python Stream.is_closed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Stream
的用法示例。
在下文中一共展示了Stream.is_closed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tunnel
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import is_closed [as 别名]
#.........这里部分代码省略.........
def _on_tunnel_send_buffer_full(self):
if self._on_send_buffer_full is not None:
self._on_send_buffer_full(self)
def _on_received(self, data, _addr):
_logger.debug("tunnel %s received %d bytes" % (str(self), len(data)))
if len(data) < 6 + 16:
raise Exception('corrupted data')
type_, content_length = struct.unpack('!HI', data[: 6])
id_ = uuid.UUID(bytes=data[6: 6 + 16])
if type_ not in self._handlers or self._handlers[type_] is None:
_logger.warning("tunnel message type %d can not be handled", type_)
if len(data) - 6 - 16 != content_length:
raise Exception('corrupted data')
self._handlers[type_](self, id_, data[6 + 16:])
return True
def send_tcp_initial_data(self, id_, data):
self._send_content(Tunnel._TCP_INITIAL_DATA, id_, data)
def send_tcp_fin_data(self, id_, data=''):
self._send_content(Tunnel._TCP_FIN_DATA, id_, data)
def send_tcp_closed_data(self, id_, data=''):
self._send_content(Tunnel._TCP_CLOSED_DATA, id_, data)
def send_udp_initial_data(self, id_, data):
self._send_content(Tunnel._UDP_INITIAL_DATA, id_, data)
def send_udp_closed_data(self, id_, data=''):
self._send_content(Tunnel._UDP_CLOSED_DATA, id_, data)
def send_tun_initial_data(self, id_, data):
self._send_content(Tunnel._TUN_INITIAL_DATA, id_, data)
def send_payload(self, id_, payload):
self._send_content(Tunnel._PAYLOAD, id_, payload)
def set_on_payload(self, handler):
self._on_payload = handler
def set_on_ready_to_send(self, handler):
self._on_ready_to_send = handler
def set_on_send_buffer_full(self, handler):
self._on_send_buffer_full = handler
def _on_closed(self):
self._disable_heartbeat()
if self._on_stream_closed is not None:
self._on_stream_closed(self)
def set_on_closed(self, handler):
self._on_stream_closed = handler
def close(self):
self._stream.close()
def is_closed(self):
return self._stream.is_closed()
def _on_decode_error(self, received):
self._disable_heartbeat()
self._stream._encoders = []
backend = Stream(prefix="SIMPLE")
def tunnel_ready_to_send(_):
backend.start_receiving()
def tunnel_send_buffer_full(_):
backend.stop_receiving()
def tunnel_received(_, data, _addr):
backend.send(data)
return backend.is_ready_to_send()
def tunnel_closed(_):
backend.close()
def backend_received(_, data, _addr):
self._stream.send(data)
return self._stream.is_ready_to_send()
def backend_closed(_self):
self._stream.close()
self._stream.set_on_ready_to_send(tunnel_ready_to_send)
self._stream.set_on_send_buffer_full(tunnel_send_buffer_full)
self._stream.set_on_received(tunnel_received)
self._stream.set_on_closed(tunnel_closed)
backend.set_on_received(backend_received)
backend.set_on_closed(backend_closed)
if received is not None and len(received) > 0:
backend.send(received)
backend.connect(UNKNOWN_CONN_ADDR, UNKNOWN_CONN_PORT)