本文整理汇总了Python中stream.Stream.set_tcp_no_delay方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.set_tcp_no_delay方法的具体用法?Python Stream.set_tcp_no_delay怎么用?Python Stream.set_tcp_no_delay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Stream
的用法示例。
在下文中一共展示了Stream.set_tcp_no_delay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tunnel
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import set_tcp_no_delay [as 别名]
class Tunnel(object):
_TCP_INITIAL_DATA = 0
_TCP_FIN_DATA = 1
_TCP_CLOSED_DATA = 2
_UDP_INITIAL_DATA = 3
_UDP_CLOSED_DATA = 4
_TUN_INITIAL_DATA = 5
_PAYLOAD = 10
_HEARTBEAT = 100
_static_handlers = {
_HEARTBEAT: (lambda _, __, ___: None)
}
@staticmethod
def set_tcp_initial_handler(handler):
Tunnel._static_handlers[Tunnel._TCP_INITIAL_DATA] = handler
@staticmethod
def set_tcp_fin_received_handler(handler):
Tunnel._static_handlers[Tunnel._TCP_FIN_DATA] = handler
@staticmethod
def set_tcp_closed_handler(handler):
Tunnel._static_handlers[Tunnel._TCP_CLOSED_DATA] = handler
@staticmethod
def set_udp_initial_handler(handler):
Tunnel._static_handlers[Tunnel._UDP_INITIAL_DATA] = handler
@staticmethod
def set_udp_closed_handler(handler):
Tunnel._static_handlers[Tunnel._UDP_CLOSED_DATA] = handler
@staticmethod
def set_tun_initial_handler(handler):
Tunnel._static_handlers[Tunnel._TUN_INITIAL_DATA] = handler
def __init__(self, connection=None, connect_to=None):
self._stream = connection
self._connect_to = connect_to
self._on_initial_data = None
self._on_payload = None
self._on_stream_closed = None
self._handlers = self._static_handlers.copy()
self._handlers.update({
Tunnel._PAYLOAD: lambda _, id_, data: self._on_payload(self, id_, data)
})
self._on_ready_to_send = None
self._on_send_buffer_full = None
self._hb_event = None
self.connections = {}
def __hash__(self):
return hash(self._stream)
def __eq__(self, other):
if not isinstance(other, Tunnel):
return False
return self._stream == other._stream
def __str__(self):
return str(self._stream)
def _send_heartbeat(self):
self._send_content(Tunnel._HEARTBEAT, None, None)
self._enable_heartbeat()
def _enable_heartbeat(self):
self._hb_event = Event.add_timer(HEARTBEAT_INTERVAL)
self._hb_event.set_handler(lambda ev: self._send_heartbeat())
def _disable_heartbeat(self):
if self._hb_event is not None:
self._hb_event.del_timer()
self._hb_event = None
def _on_fin_received(self):
self._disable_heartbeat()
self._stream.close()
def initialize(self):
if self._stream is None:
self._stream = Stream(prefix='TUNNEL')
# self._stream.set_buffer_size(BUFF_SIZE)
self._stream.set_tcp_no_delay()
self._stream.append_send_handler(obscure.pack_data)
self._stream.append_send_handler(obscure.random_padding)
# self._stream.append_send_handler(obscure.gen_aes_encrypt())
self._stream.append_send_handler(obscure.gen_xor_encrypt())
# self._stream.append_send_handler(obscure.base64_encode)
self._stream.append_send_handler(obscure.gen_http_encode(self._connect_to is not None))
self._stream.append_receive_handler(obscure.gen_http_decode(self._connect_to is not None))
# self._stream.append_receive_handler(obscure.base64_decode)
self._stream.append_receive_handler(obscure.gen_xor_decrypt())
# self._stream.append_receive_handler(obscure.gen_aes_decrypt())
self._stream.append_receive_handler(obscure.unpad_random)
self._stream.append_receive_handler(obscure.unpack_data)
#.........这里部分代码省略.........