socket.d 2.5.2__tar.gz → 2.5.4__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. {socket.d-2.5.2 → socket.d-2.5.4}/PKG-INFO +1 -1
  2. {socket.d-2.5.2 → socket.d-2.5.4}/setup.py +1 -1
  3. {socket.d-2.5.2 → socket.d-2.5.4}/socket.d.egg-info/PKG-INFO +1 -1
  4. {socket.d-2.5.2 → socket.d-2.5.4}/socket.d.egg-info/SOURCES.txt +1 -0
  5. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/SocketD.py +1 -1
  6. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/exception/SocketDExecption.py +5 -1
  7. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientChannel.py +3 -3
  8. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Asserts.py +2 -2
  9. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Channel.py +7 -4
  10. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/ChannelInternal.py +3 -0
  11. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Costants.py +3 -0
  12. socket.d-2.5.4/socketd/transport/core/FrameIoHandler.py +21 -0
  13. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Frames.py +34 -8
  14. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Listener.py +12 -0
  15. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Processor.py +14 -3
  16. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Session.py +5 -1
  17. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/ChannelBase.py +5 -1
  18. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/ChannelDefault.py +20 -27
  19. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/ProcessorDefault.py +56 -11
  20. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/SessionDefault.py +9 -2
  21. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/EventListener.py +19 -0
  22. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/PathListener.py +8 -0
  23. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/PipelineListener.py +8 -0
  24. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/SimpleListener.py +6 -0
  25. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/server/ServerBase.py +6 -0
  26. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/impl/RequestStreamImpl.py +1 -1
  27. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/impl/StreamBase.py +4 -1
  28. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/TCPAIOServer.py +1 -1
  29. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/TcpAioClientConnector.py +1 -1
  30. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/impl/AIOWebSocketClientImpl.py +1 -1
  31. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/impl/AIOWebSocketServerImpl.py +1 -1
  32. {socket.d-2.5.2 → socket.d-2.5.4}/README.md +0 -0
  33. {socket.d-2.5.2 → socket.d-2.5.4}/setup.cfg +0 -0
  34. {socket.d-2.5.2 → socket.d-2.5.4}/socket.d.egg-info/dependency_links.txt +0 -0
  35. {socket.d-2.5.2 → socket.d-2.5.4}/socket.d.egg-info/requires.txt +0 -0
  36. {socket.d-2.5.2 → socket.d-2.5.4}/socket.d.egg-info/top_level.txt +0 -0
  37. {socket.d-2.5.2 → socket.d-2.5.4}/socket.d.egg-info/zip-safe +0 -0
  38. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/__init__.py +0 -0
  39. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/broker/BroadcastBroker.py +0 -0
  40. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/broker/BrokerFragmentHandler.py +0 -0
  41. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/broker/BrokerListener.py +0 -0
  42. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/broker/BrokerListenerBase.py +0 -0
  43. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/broker/__init__.py +0 -0
  44. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/cluster/ClusterClient.py +0 -0
  45. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/cluster/ClusterClientSession.py +0 -0
  46. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/cluster/LoadBalancer.py +0 -0
  47. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/cluster/__init__.py +0 -0
  48. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/exception/__init__.py +0 -0
  49. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/__init__.py +0 -0
  50. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/Client.py +0 -0
  51. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientBase.py +0 -0
  52. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientConfig.py +0 -0
  53. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientConfigHandler.py +0 -0
  54. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientConnectHandler.py +0 -0
  55. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientConnector.py +0 -0
  56. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientConnectorBase.py +0 -0
  57. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientHandshakeResult.py +0 -0
  58. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientHeartbeatHandler.py +0 -0
  59. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientProvider.py +0 -0
  60. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/ClientSession.py +0 -0
  61. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/client/__init__.py +0 -0
  62. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/ChannelAssistant.py +0 -0
  63. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/ChannelSupporter.py +0 -0
  64. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Codec.py +0 -0
  65. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Config.py +0 -0
  66. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Entity.py +0 -0
  67. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/EntityMetas.py +0 -0
  68. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Flags.py +0 -0
  69. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/FragmentAggregator.py +0 -0
  70. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/FragmentHandler.py +0 -0
  71. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Frame.py +0 -0
  72. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/HandshakeDefault.py +0 -0
  73. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/IdGenerator.py +0 -0
  74. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/Message.py +0 -0
  75. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/__init__.py +0 -0
  76. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/codec/Buffer.py +0 -0
  77. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/codec/ByteBufferCodecReader.py +0 -0
  78. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/codec/ByteBufferCodecWriter.py +0 -0
  79. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/codec/CodecDefault.py +0 -0
  80. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/codec/__init__.py +0 -0
  81. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/entity/EntityDefault.py +0 -0
  82. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/entity/FileEntity.py +0 -0
  83. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/entity/MessageBuilder.py +0 -0
  84. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/entity/MessageDefault.py +0 -0
  85. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/entity/StringEntity.py +0 -0
  86. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/entity/__init__.py +0 -0
  87. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/fragment/FragmentAggregatorDefault.py +0 -0
  88. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/fragment/FragmentHandlerBase.py +0 -0
  89. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/fragment/FragmentHandlerDefault.py +0 -0
  90. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/fragment/FragmentHolder.py +0 -0
  91. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/fragment/__init__.py +0 -0
  92. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/ConfigBase.py +0 -0
  93. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/SessionBase.py +0 -0
  94. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/impl/__init__.py +0 -0
  95. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/RouteSelector.py +0 -0
  96. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/RouteSelectorDefault.py +0 -0
  97. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/core/listener/__init__.py +0 -0
  98. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/server/Server.py +0 -0
  99. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/server/ServerConfig.py +0 -0
  100. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/server/ServerProvider.py +0 -0
  101. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/server/__init__.py +0 -0
  102. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/RequestStream.py +0 -0
  103. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/SendStream.py +0 -0
  104. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/Stream.py +0 -0
  105. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/StreamManger.py +0 -0
  106. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/StreamMangerDefault.py +0 -0
  107. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/SubscribeStream.py +0 -0
  108. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/__init__.py +0 -0
  109. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/impl/SendStreamImpl.py +0 -0
  110. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/impl/SubscribeStreamImpl.py +0 -0
  111. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/transport/stream/impl/__init__.py +0 -0
  112. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/AsyncUtils.py +0 -0
  113. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/CompletableFuture.py +0 -0
  114. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/LogConfig.py +0 -0
  115. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/MapUtils.py +0 -0
  116. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/RunUtils.py +0 -0
  117. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/SessionUtils.py +0 -0
  118. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/StrUtils.py +0 -0
  119. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/__init__.py +0 -0
  120. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/async_api/AtomicRefer.py +0 -0
  121. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/async_api/__init__.py +0 -0
  122. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/sync_api/AtomicRefer.py +0 -0
  123. {socket.d-2.5.2 → socket.d-2.5.4}/socketd/utils/sync_api/__init__.py +0 -0
  124. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/TCPStreamIO.py +0 -0
  125. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/TcpAIOChannelAssistant.py +0 -0
  126. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/TcpAioClient.py +0 -0
  127. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/TcpAioProvider.py +0 -0
  128. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_aio_tcp/__init__.py +0 -0
  129. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/WsAioChannelAssistant.py +0 -0
  130. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/WsAioClient.py +0 -0
  131. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/WsAioClientConnector.py +0 -0
  132. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/WsAioProvider.py +0 -0
  133. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/WsAioServer.py +0 -0
  134. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/__init__.py +0 -0
  135. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/impl/AIOConnect.py +0 -0
  136. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/impl/AIOServe.py +0 -0
  137. {socket.d-2.5.2 → socket.d-2.5.4}/socketd_websocket/impl/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: socket.d
3
- Version: 2.5.2
3
+ Version: 2.5.4
4
4
  Summary: @noear/socket.d python project
5
5
  Home-page: https://socketd.noear.org/
6
6
  Author: noear,bai
@@ -4,7 +4,7 @@ from setuptools import setup,find_packages
4
4
 
5
5
  setup(
6
6
  name='socket.d',
7
- version='2.5.2',
7
+ version='2.5.4',
8
8
  description='@noear/socket.d python project',
9
9
  author='noear,bai',
10
10
  url='https://socketd.noear.org/',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: socket.d
3
- Version: 2.5.2
3
+ Version: 2.5.4
4
4
  Summary: @noear/socket.d python project
5
5
  Home-page: https://socketd.noear.org/
6
6
  Author: noear,bai
@@ -47,6 +47,7 @@ socketd/transport/core/Flags.py
47
47
  socketd/transport/core/FragmentAggregator.py
48
48
  socketd/transport/core/FragmentHandler.py
49
49
  socketd/transport/core/Frame.py
50
+ socketd/transport/core/FrameIoHandler.py
50
51
  socketd/transport/core/Frames.py
51
52
  socketd/transport/core/HandshakeDefault.py
52
53
  socketd/transport/core/IdGenerator.py
@@ -14,7 +14,7 @@ from socketd_aio_tcp.TcpAioProvider import TcpAioProvider
14
14
 
15
15
 
16
16
  def version() -> str:
17
- return "2.5.2"
17
+ return "2.5.4"
18
18
 
19
19
  def protocol_name() -> str:
20
20
  return "Socket.D"
@@ -16,9 +16,13 @@ class SocketDAlarmException(SocketDException):
16
16
  def __init__(self, alarm:Message):
17
17
  super().__init__(alarm.data_as_string())
18
18
  self.__alarm = alarm
19
- def get_alarm(self):
19
+ self.__alarmCode = alarm.meta_as_int("code");
20
+ def get_alarm(self) -> Message:
20
21
  return self.__alarm
21
22
 
23
+ def get_alarm_code(self) -> int:
24
+ return self.__alarmCode;
25
+
22
26
 
23
27
  class SocketDChannelException(SocketDException):
24
28
  """ 通道"""
@@ -63,7 +63,7 @@ class ClientChannel(ChannelBase):
63
63
 
64
64
  if Asserts.is_closed_and_end(self.__real):
65
65
  log.debug("Client channel is closed (pause heartbeat), sessionId=" + self.get_session().session_id())
66
- await self.close(self.__real.is_closed())
66
+ await self.close(self.__real.close_code())
67
67
  return
68
68
 
69
69
  if self.__real.is_closing():
@@ -86,11 +86,11 @@ class ClientChannel(ChannelBase):
86
86
  else:
87
87
  return self.__real.is_valid()
88
88
 
89
- def is_closed(self):
89
+ def close_code(self):
90
90
  if self.__real is None:
91
91
  return False
92
92
  else:
93
- return self.__real.is_closed()
93
+ return self.__real.close_code()
94
94
 
95
95
  def get_remote_address(self):
96
96
  if self.__real is None:
@@ -12,12 +12,12 @@ class Asserts:
12
12
 
13
13
  @staticmethod
14
14
  def assert_closed(channel: Channel):
15
- if channel and channel.is_closed() > 0:
15
+ if channel and channel.close_code() > 0:
16
16
  raise SocketDChannelException("This channel is closed, sessionId=" + channel.get_session().session_id())
17
17
 
18
18
  @staticmethod
19
19
  def is_closed_and_end(channel: Channel):
20
- return channel.is_closed() == Constants.CLOSE2009_USER or channel.is_closed() == Constants.CLOSE2008_OPEN_FAIL
20
+ return channel.close_code() == Constants.CLOSE2009_USER or channel.close_code() == Constants.CLOSE2008_OPEN_FAIL
21
21
 
22
22
  @staticmethod
23
23
  def assert_closed_and_end(channel: Channel):
@@ -2,6 +2,7 @@ import asyncio
2
2
  from typing import Any, Optional
3
3
  from asyncio import Future
4
4
 
5
+ from socketd.transport.core import Entity
5
6
  from socketd.transport.core.HandshakeDefault import HandshakeDefault
6
7
  from socketd.transport.core.Session import Session
7
8
  from socketd.transport.core.Config import Config
@@ -30,7 +31,7 @@ class Channel(ABC):
30
31
  ...
31
32
 
32
33
  @abstractmethod
33
- def is_closed(self) -> int:
34
+ def close_code(self) -> int:
34
35
  ...
35
36
 
36
37
  @abstractmethod
@@ -79,17 +80,19 @@ class Channel(ABC):
79
80
  ...
80
81
 
81
82
  @abstractmethod
82
- async def send_alarm(self, _from: Message, alarm:str) -> None:
83
+ async def send_alarm(self, _from: Message, alarm:Entity) -> None:
83
84
  ...
84
85
 
85
86
  @abstractmethod
86
- async def send(self, frame: 'Frame', stream: Optional[StreamInternal]) -> None:
87
+ async def send_pressure(self, _from: Message, pressure: Entity) -> None:
87
88
  ...
88
89
 
90
+
89
91
  @abstractmethod
90
- async def retrieve(self, frame: Frame, stream: StreamInternal) -> None:
92
+ async def send(self, frame: 'Frame', stream: Optional[StreamInternal]) -> None:
91
93
  ...
92
94
 
95
+
93
96
  @abstractmethod
94
97
  def get_session(self) -> Session:
95
98
  ...
@@ -13,6 +13,9 @@ class ChannelInternal(Channel, ABC):
13
13
  @abstractmethod
14
14
  def set_live_time_as_now(self):...
15
15
 
16
+ @abstractmethod
17
+ def set_alarm_code(self, alarm_code:int):...
18
+
16
19
  @abstractmethod
17
20
  def get_stream(self, sid: str): ...
18
21
 
@@ -50,3 +50,6 @@ class Constants:
50
50
  CLOSE2008_OPEN_FAIL = 2008
51
51
  # 因用户主动关闭(不可再重连)
52
52
  CLOSE2009_USER = 2009
53
+
54
+ # 因压力告警
55
+ ALARM3001_PRESSURE = 3001
@@ -0,0 +1,21 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import TypeVar, Callable
3
+
4
+ from socketd.transport.core.ChannelAssistant import ChannelAssistant
5
+ from socketd.transport.core.ChannelInternal import ChannelInternal
6
+ from socketd.transport.core.Frame import Frame
7
+
8
+ S = TypeVar("S")
9
+
10
+ # 帧输入输出处理器 # 为 TrafficLimiter 提供支持
11
+ class FrameIoHandler(ABC):
12
+ # 发送帧处理
13
+ @abstractmethod
14
+ async def send_frame_handle(self, channel: ChannelInternal, frame: Frame, channelAssistant: ChannelAssistant[S],
15
+ target: S, completionHandler:Callable[[bool, Exception], None]):
16
+ ...
17
+
18
+ # 接收帧处理
19
+ @abstractmethod
20
+ async def reve_frame_handle(self, channel: ChannelInternal, frame: Frame):
21
+ ...
@@ -1,4 +1,5 @@
1
1
  from socketd import SocketD
2
+ from socketd.transport.core.Entity import Entity
2
3
  from socketd.transport.core.Flags import Flags
3
4
  from socketd.transport.core.EntityMetas import EntityMetas
4
5
  from socketd.transport.core.HandshakeDefault import HandshakeInternal
@@ -23,7 +24,7 @@ class Frames:
23
24
  return Frame(Flags.Connect, message)
24
25
 
25
26
  @staticmethod
26
- def connack_frame(handshake: HandshakeInternal):
27
+ def connack_frame(handshake: HandshakeInternal) -> Frame:
27
28
  entity = EntityDefault()
28
29
  # 添加框架版本号
29
30
  entity.meta_map_put(handshake.get_out_meta_map())
@@ -37,27 +38,52 @@ class Frames:
37
38
  return Frame(Flags.Connack, message)
38
39
 
39
40
  @staticmethod
40
- def ping_frame():
41
+ def ping_frame() -> Frame:
41
42
  return Frame(Flags.Ping, None)
42
43
 
43
44
  @staticmethod
44
- def pong_frame():
45
+ def pong_frame() -> Frame:
45
46
  return Frame(Flags.Pong, None)
46
47
 
47
48
  @staticmethod
48
- def close_frame(_code: int):
49
+ def close_frame(_code: int) -> Frame:
49
50
  messageBuilder = MessageBuilder()
50
51
  messageBuilder.entity(EntityDefault().meta_put("code", str(_code)))
51
52
 
52
53
  return Frame(Flags.Close, messageBuilder.build())
53
54
 
54
55
  @staticmethod
55
- def alarm_frame(_from: Message, alarm: str):
56
+ def alarm_frame(_from: Message, alarm: Entity) -> Frame:
56
57
  messageBuilder = MessageBuilder()
57
58
 
58
59
  if _from:
59
- messageBuilder.sid(_from.sid()).event(_from.event())
60
- messageBuilder.entity(StringEntity(alarm).meta_string_set(_from.data_as_string()))
60
+ entity = EntityDefault()
61
+ entity.meta_string_set(_from.meta_string())
62
+ entity.data_set(alarm.data());
63
+ entity.meta_map_put(alarm.meta_map())
64
+
65
+ messageBuilder.sid(_from.sid());
66
+ messageBuilder.event(_from.event());
67
+ messageBuilder.entity(entity)
61
68
  else:
62
- messageBuilder.entity(StringEntity(alarm))
69
+ messageBuilder.entity(alarm)
70
+
63
71
  return Frame(Flags.Alarm, messageBuilder.build())
72
+
73
+ @staticmethod
74
+ def pressure_frame(_from: Message, pressure: Entity) -> Frame:
75
+ messageBuilder = MessageBuilder()
76
+
77
+ if _from:
78
+ entity = EntityDefault()
79
+ entity.meta_string_set(_from.meta_string())
80
+ entity.data_set(pressure.data());
81
+ entity.meta_map_put(pressure.meta_map())
82
+
83
+ messageBuilder.sid(_from.sid());
84
+ messageBuilder.event(_from.event());
85
+ messageBuilder.entity(entity)
86
+ else:
87
+ messageBuilder.entity(pressure)
88
+
89
+ return Frame(Flags.Pressure, messageBuilder.build())
@@ -5,18 +5,30 @@ from socketd.transport.core.Session import Session
5
5
 
6
6
 
7
7
  class Listener(abc.ABC):
8
+ # 打开时
8
9
  @abc.abstractmethod
9
10
  async def on_open(self, session: Session):
10
11
  pass
11
12
 
13
+ # 收到消息时
12
14
  @abc.abstractmethod
13
15
  async def on_message(self, session: Session, message: Message):
14
16
  pass
15
17
 
18
+ # 收到答复时
19
+ async def on_reply(self, session: Session, message: Message):
20
+ pass
21
+
22
+ # 发送消息时
23
+ async def on_send(self, session: Session, message: Message):
24
+ pass
25
+
26
+ # 关闭时
16
27
  @abc.abstractmethod
17
28
  async def on_close(self, session: Session):
18
29
  pass
19
30
 
31
+ # 出错时
20
32
  @abc.abstractmethod
21
33
  async def on_error(self, session: Session, error):
22
34
  pass
@@ -1,11 +1,14 @@
1
1
  from abc import ABC, abstractmethod
2
+ from typing import TypeVar, Callable
2
3
 
3
4
  from socketd.transport.core import Listener
4
5
  from socketd.transport.core.Channel import Channel
6
+ from socketd.transport.core.ChannelAssistant import ChannelAssistant
5
7
  from socketd.transport.core.ChannelInternal import ChannelInternal
6
8
  from socketd.transport.core.Frame import Frame
7
- from socketd.transport.core.Message import Message
9
+ from socketd.transport.stream.Stream import StreamInternal
8
10
 
11
+ S = TypeVar("S")
9
12
 
10
13
  class Processor(ABC):
11
14
 
@@ -14,7 +17,11 @@ class Processor(ABC):
14
17
  pass
15
18
 
16
19
  @abstractmethod
17
- def on_receive(self, channel: Channel, frame:Frame):
20
+ def send_frame(self, channel: ChannelInternal, frame: Frame, channelAssistant: ChannelAssistant[S], target: S):
21
+ pass
22
+
23
+ @abstractmethod
24
+ def reve_frame(self, channel: Channel, frame: Frame):
18
25
  pass
19
26
 
20
27
  @abstractmethod
@@ -22,9 +29,13 @@ class Processor(ABC):
22
29
  pass
23
30
 
24
31
  @abstractmethod
25
- def on_message(self, channel: ChannelInternal, message:Message):
32
+ def on_message(self, channel: ChannelInternal, frame: Frame):
26
33
  pass
27
34
 
35
+ @abstractmethod
36
+ def on_reply(self, channel: ChannelInternal, frame: Frame, stream: StreamInternal) -> None:
37
+ ...
38
+
28
39
  @abstractmethod
29
40
  def on_close(self, channel: ChannelInternal):
30
41
  pass
@@ -69,7 +69,11 @@ class Session(ClientSession):
69
69
  ...
70
70
 
71
71
  @abc.abstractmethod
72
- async def send_alarm(self, _from: Message, alarm: str) -> None:
72
+ async def send_alarm(self, _from: Message, alarm: Entity) -> None:
73
+ ...
74
+
75
+ @abc.abstractmethod
76
+ async def send_pressure(self, _from: Message, pressure: Entity) -> None:
73
77
  ...
74
78
 
75
79
  @abc.abstractmethod
@@ -4,6 +4,7 @@ import threading
4
4
  from abc import ABC
5
5
  from typing import Optional
6
6
 
7
+ from socketd.transport.core import Entity
7
8
  from socketd.transport.core.Channel import Channel
8
9
  from socketd.transport.core.Costants import Constants
9
10
  from socketd.transport.core.Frames import Frames
@@ -72,9 +73,12 @@ class ChannelBase(Channel, ABC):
72
73
  async def send_close(self, code: int):
73
74
  await self.send(Frames.close_frame(code), None)
74
75
 
75
- async def send_alarm(self, _from: Message, alarm: str):
76
+ async def send_alarm(self, _from: Message, alarm: Entity):
76
77
  await self.send(Frames.alarm_frame(_from, alarm), None)
77
78
 
79
+ async def send_pressure(self, _from: Message, pressure: Entity):
80
+ await self.send(Frames.pressure_frame(_from, pressure), None)
81
+
78
82
  async def close(self, code: int):
79
83
  if code > Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING:
80
84
  self.__attachments.clear()
@@ -40,15 +40,16 @@ class ChannelDefault(ChannelBase, ChannelInternal):
40
40
  self._session: Optional[Session] = None
41
41
  self._liveTime: Optional[float] = None
42
42
  self._closeCode: int = 0
43
- self._isCloseNotified = False;
43
+ self._isCloseNotified = False
44
+ self._alarmCode: int = 0
44
45
 
45
46
  def is_valid(self) -> bool:
46
- return self.is_closed() == 0 and self._assistant.is_valid(self._source)
47
+ return self.close_code() == 0 and self._assistant.is_valid(self._source)
47
48
 
48
49
  def is_closing(self) -> bool:
49
50
  return self._closeCode == Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING
50
51
 
51
- def is_closed(self):
52
+ def close_code(self):
52
53
  if self._closeCode > Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING:
53
54
  return self._closeCode
54
55
  else:
@@ -60,6 +61,9 @@ class ChannelDefault(ChannelBase, ChannelInternal):
60
61
  def set_live_time_as_now(self):
61
62
  self._liveTime = time.time()
62
63
 
64
+ def set_alarm_code(self, alarm_code:int):
65
+ self._alarmCode = alarm_code
66
+
63
67
  def get_remote_address(self) -> str:
64
68
  return self._assistant.get_remote_address(self._source)
65
69
 
@@ -74,13 +78,20 @@ class ChannelDefault(ChannelBase, ChannelInternal):
74
78
  else:
75
79
  log.debug(f"S-SEN:{frame}")
76
80
 
77
- if self.get_config().is_nolock_send():
81
+ with self:
78
82
  await self.send_do(frame, stream)
79
- else:
80
- with self:
81
- await self.send_do(frame, stream)
82
83
 
83
84
  async def send_do(self, frame: Frame, stream: StreamInternal):
85
+ if self._alarmCode == Constants.ALARM3001_PRESSURE:
86
+ if frame.flag() >= Flags.Message and frame.flag() <= Flags.Subscribe:
87
+ if frame.message().meta(EntityMetas.META_X_UNLIMITED) is None:
88
+ try:
89
+ log.debug("Too much pressure, sleep=100ms")
90
+ self.set_alarm_code(0)
91
+ time.sleep(0.1)
92
+ except Exception as e:
93
+ ... #略过
94
+
84
95
  if frame.message() is not None:
85
96
  message: Message = frame.message()
86
97
  # 注册流接收器
@@ -100,33 +111,15 @@ class ChannelDefault(ChannelBase, ChannelInternal):
100
111
  messageNew = MessageBuilder().flag(frame.flag()).sid(message.sid()).event(
101
112
  message.event()).entity(fragmentEntity).build()
102
113
  fragmentFrame = Frame(frame.flag(), messageNew)
103
- await self._assistant.write(self._source, fragmentFrame)
114
+ await self._processor.send_frame(self, fragmentFrame, self._assistant, self._source)
104
115
 
105
116
  await self.get_config().get_fragment_handler().split_fragment(self, stream, message, __consumer)
106
117
  return
107
118
 
108
- await self._assistant.write(self._source, frame)
119
+ await self._processor.send_frame(self, frame, self._assistant, self._source)
109
120
  if stream is not None:
110
121
  stream.on_progress(True, 1, 1)
111
122
 
112
- async def retrieve(self, frame: Frame, stream: StreamInternal) -> None:
113
- """接收(接收答复帧)"""
114
- if stream is not None:
115
- if stream.demands() < Constants.DEMANDS_MULTIPLE or frame.flag() == Flags.ReplyEnd:
116
- # 如果是单收或者答复结束,则移除流接收器
117
- self._streamManger.remove_stream(frame.message().sid())
118
-
119
- if stream.demands() < Constants.DEMANDS_MULTIPLE:
120
- # 单收时,内部已经是异步机制
121
- await RunUtils.waitTry(stream.on_reply(frame.message()))
122
- else:
123
- # 改为异步处理,避免卡死Io线程
124
- asyncio.get_running_loop().run_in_executor(self.get_config().get_exchange_executor(),
125
- lambda _m: asyncio.run(stream.on_reply(_m)), frame.message())
126
- else:
127
- log.debug(
128
- f"{self.get_config().get_role_name()} stream not found, sid={frame.message().sid()}, sessionId={self.get_session().session_id()}")
129
-
130
123
  def reconnect(self):
131
124
  ...
132
125
 
@@ -1,9 +1,12 @@
1
+ import asyncio
1
2
  import traceback
2
3
  from abc import ABC
3
- from typing import Optional
4
+ from typing import Optional, Callable, TypeVar
4
5
 
5
6
  from socketd.exception.SocketDExecption import SocketDAlarmException, SocketDConnectionException
7
+ from socketd.transport.core.ChannelAssistant import ChannelAssistant
6
8
  from socketd.transport.core.ChannelInternal import ChannelInternal
9
+ from socketd.transport.core.FrameIoHandler import FrameIoHandler
7
10
  from socketd.transport.core.HandshakeDefault import HandshakeDefault
8
11
  from socketd.transport.core.Message import Message
9
12
  from socketd.transport.core.Processor import Processor
@@ -16,8 +19,10 @@ from socketd.transport.core.listener.SimpleListener import SimpleListener
16
19
  from socketd.transport.stream.Stream import StreamInternal
17
20
  from socketd.utils.RunUtils import RunUtils
18
21
 
22
+ S = TypeVar("S")
19
23
 
20
- class ProcessorDefault(Processor, ABC):
24
+ # 协议处理器默认实现(原则上,写不要在读的线程上执行)
25
+ class ProcessorDefault(Processor, FrameIoHandler, ABC):
21
26
 
22
27
  def __init__(self):
23
28
  self.listener = SimpleListener()
@@ -26,7 +31,23 @@ class ProcessorDefault(Processor, ABC):
26
31
  if listener is not None:
27
32
  self.listener = listener
28
33
 
29
- async def on_receive(self, channel: ChannelInternal, frame):
34
+ async def send_frame(self, channel: ChannelInternal, frame: Frame, channelAssistant: ChannelAssistant[S], target: S):
35
+ def completionHandler(result:bool, throwable:Exception):
36
+ ...
37
+
38
+ await self.send_frame_handle(channel, frame, channelAssistant, target, completionHandler)
39
+
40
+ async def send_frame_handle(self, channel: ChannelInternal, frame: Frame, channelAssistant: ChannelAssistant[S],
41
+ target: S, completionHandler:Callable[[bool, Exception], None]):
42
+ await channelAssistant.write(target, frame)
43
+
44
+ if frame.flag() >= Flags.Message:
45
+ await RunUtils.waitTry(self.listener.on_send(channel.get_session(), frame.message()))
46
+
47
+ async def reve_frame(self, channel: ChannelInternal, frame):
48
+ await self.reve_frame_handle(channel, frame)
49
+
50
+ async def reve_frame_handle(self, channel: ChannelInternal, frame: Frame):
30
51
  if channel.get_config().client_mode():
31
52
  log.debug(f"C-REV:{frame}")
32
53
  else:
@@ -72,7 +93,7 @@ class ProcessorDefault(Processor, ABC):
72
93
 
73
94
  try:
74
95
  if frame.flag() == Flags.Ping:
75
- await channel.send_pong()
96
+ RunUtils.taskTry(channel.send_pong())
76
97
  elif frame.flag() == Flags.Pong:
77
98
  pass
78
99
  elif frame.flag() == Flags.Close:
@@ -87,14 +108,18 @@ class ProcessorDefault(Processor, ABC):
87
108
  await self.on_close_internal(channel, code)
88
109
  elif frame.flag() == Flags.Alarm:
89
110
  e = SocketDAlarmException(frame.message())
111
+ channel.set_alarm_code(e.get_alarm_code())
112
+
90
113
  stream: StreamInternal = channel.get_config().get_stream_manger().get_stream(frame.message().sid())
91
114
 
92
115
  if stream is None:
93
116
  self.on_error(channel, e)
94
117
  else:
95
118
  channel.get_config().get_stream_manger().remove_stream(frame.message().sid())
96
- stream.on_error(e)
119
+ RunUtils.taskTry(stream.on_error(e))
97
120
  elif frame.flag() == Flags.Pressure:
121
+ code = frame.message().meta_as_int("code")
122
+ channel.set_alarm_code(code)
98
123
  pass
99
124
  elif frame.flag() in [Flags.Message, Flags.Request, Flags.Subscribe]:
100
125
  await self.on_receive_do(channel, frame, False)
@@ -138,9 +163,9 @@ class ProcessorDefault(Processor, ABC):
138
163
  if isReply:
139
164
  if stream:
140
165
  stream.on_progress(False, streamIndex, streamTotal)
141
- await channel.retrieve(frame, stream)
166
+ await self.on_reply(channel, frame, stream)
142
167
  else:
143
- self.on_message(channel, frame.message())
168
+ self.on_message(channel, frame)
144
169
 
145
170
  def on_open(self, channel: ChannelInternal):
146
171
  RunUtils.taskTry(self.on_open_do(channel))
@@ -154,19 +179,39 @@ class ProcessorDefault(Processor, ABC):
154
179
  log.warning(f"{channel.get_config().get_role_name()} channel listener onOpen error \n{e_msg}")
155
180
  channel.do_open_future(False, e)
156
181
 
157
- def on_message(self, channel: ChannelInternal, message: Message):
158
- RunUtils.taskTry(self.on_message_do(channel, message))
182
+ def on_message(self, channel: ChannelInternal, frame: Frame):
183
+ RunUtils.taskTry(self.on_message_do(channel, frame.message()))
159
184
 
160
185
  async def on_message_do(self, channel: ChannelInternal, message: Message):
161
186
  try:
162
- await self.listener.on_message(channel.get_session(), message)
187
+ await RunUtils.waitTry(self.listener.on_message(channel.get_session(), message))
163
188
  except Exception as e:
164
189
  e_msg = traceback.format_exc()
165
190
  log.warning(f"{channel.get_config().get_role_name()} channel listener onMessage error \n{e_msg}")
166
191
  self.on_error(channel, e)
167
192
 
193
+ async def on_reply(self, channel: ChannelInternal, frame: Frame, stream: StreamInternal) -> None:
194
+ """接收(接收答复帧)"""
195
+ if stream is not None:
196
+ if stream.demands() < Constants.DEMANDS_MULTIPLE or frame.flag() == Flags.ReplyEnd:
197
+ # 如果是单收或者答复结束,则移除流接收器
198
+ channel.get_config().get_stream_manger().remove_stream(frame.message().sid())
199
+
200
+ if stream.demands() < Constants.DEMANDS_MULTIPLE:
201
+ # 单收时,内部已经是异步机制
202
+ await RunUtils.waitTry(stream.on_reply(frame.message()))
203
+ await RunUtils.waitTry(self.listener.on_reply(channel.get_session(), frame.message()))
204
+ else:
205
+ # 改为异步处理,避免卡死Io线程
206
+ asyncio.get_running_loop().run_in_executor(self.get_config().get_exchange_executor(),
207
+ lambda _m: asyncio.run(stream.on_reply(_m)), frame.message())
208
+ else:
209
+ await RunUtils.waitTry(self.listener.on_reply(channel.get_session(), frame.message()))
210
+ log.debug(
211
+ f"{channel.get_config().get_role_name()} stream not found, sid={frame.message().sid()}, sessionId={channel.get_session().session_id()}")
212
+
168
213
  def on_close(self, channel: ChannelInternal):
169
- if channel.is_closed() <= Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING:
214
+ if channel.close_code() <= Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING:
170
215
  RunUtils.taskTry(self.on_close_internal(channel, Constants.CLOSE2003_DISCONNECTION))
171
216
 
172
217
  async def on_close_internal(self, channel: ChannelInternal, code: int):
@@ -2,6 +2,7 @@ import traceback
2
2
  from typing import Optional
3
3
 
4
4
  from socketd.transport.core.entity.MessageBuilder import MessageBuilder
5
+ from socketd.transport.core.entity.StringEntity import StringEntity
5
6
  from socketd.transport.core.impl.SessionBase import SessionBase
6
7
  from socketd.transport.core.Channel import Channel
7
8
  from socketd.transport.core.HandshakeDefault import HandshakeDefault
@@ -122,7 +123,13 @@ class SessionDefault(SessionBase):
122
123
  def param_or_default(self, name: str, defVal: str) -> str:
123
124
  return self.handshake().param_or_default(name, defVal)
124
125
 
125
- async def send_alarm(self, _from: Message, alarm: str) -> None:
126
- await self._channel.send_alarm(_from, alarm)
126
+ async def send_alarm(self, _from: Message, alarm: str|Entity) -> None:
127
+ if isinstance(alarm, str):
128
+ await self._channel.send_alarm(_from, StringEntity(alarm))
129
+ else:
130
+ await self._channel.send_alarm(_from, alarm)
131
+
132
+ async def send_pressure(self, _from: Message, pressure: Entity) -> None:
133
+ await self._channel.send_pressure(_from, pressure)
127
134
 
128
135
 
@@ -15,6 +15,9 @@ class EventListener(Listener):
15
15
  def __init__(self):
16
16
  self._doOnOpenHandler: Union[Callable[[Session], Coroutine], None] = None
17
17
  self._doOnMessageHandler: Union[Callable[[Session, Message], Coroutine], None] = None
18
+ self._doOnReplyHandler: Union[Callable[[Session, Message], Coroutine], None] = None
19
+ self._doOnSendHandler: Union[Callable[[Session, Message], Coroutine], None] = None
20
+
18
21
  self._doOnCloseHandler: Union[Callable[[Session], Coroutine], None] = None
19
22
  self._doOnErrorHandler: Union[Callable[[Session, Exception], Coroutine], None] = None
20
23
  self._eventRouteSelector: Dict[str, Callable[[Session, Message], Coroutine]] = {}
@@ -27,6 +30,14 @@ class EventListener(Listener):
27
30
  self._doOnMessageHandler = handler
28
31
  return self
29
32
 
33
+ def do_on_reply(self, handler: Callable[[Session, Message], None]) -> 'EventListener':
34
+ self._doOnReplyHandler = handler
35
+ return self
36
+
37
+ def do_on_send(self, handler: Callable[[Session, Message], None]) -> 'EventListener':
38
+ self._doOnSendHandler = handler
39
+ return self
40
+
30
41
  def do_on_close(self, handler: Callable[[Session], None]) -> 'EventListener':
31
42
  self._doOnCloseHandler = handler
32
43
  return self
@@ -50,6 +61,14 @@ class EventListener(Listener):
50
61
  if message_handler := self._eventRouteSelector.get(message.event()):
51
62
  await RunUtils.waitTry(message_handler(session, message))
52
63
 
64
+ async def on_reply(self, session: Session, message: Message):
65
+ if self._doOnReplyHandler:
66
+ await RunUtils.waitTry(self._doOnReplyHandler(session, message))
67
+
68
+ async def on_send(self, session: Session, message: Message):
69
+ if self._doOnSendHandler:
70
+ await RunUtils.waitTry(self._doOnSendHandler(session, message))
71
+
53
72
  async def on_close(self, session: Session):
54
73
  if self._doOnCloseHandler:
55
74
  await RunUtils.waitTry(self._doOnCloseHandler(session))