From fc875d18f8cde8ebfce9f123df6f21f313a58160 Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Tue, 5 Mar 2024 10:35:10 -0600 Subject: [PATCH 1/3] Remove dead code --- pymodbus/server/async_io.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index a2a48b87f..f073e94b3 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -146,7 +146,6 @@ async def handle(self): As a result, multiple clients can be interleaved without any interference between them. """ - reset_frame = False while self.running: try: await self.inner_handle() @@ -158,22 +157,13 @@ async def handle(self): except Exception as exc: # pylint: disable=broad-except # force TCP socket termination as processIncomingPacket # should handle application layer errors - # for UDP sockets, simply reset the frame - if isinstance(self, ModbusServerRequestHandler): - Log.error( - 'Unknown exception "{}" on stream {} forcing disconnect', - exc, - self.comm_params.comm_name, - ) - self.close() - self.callback_disconnected(exc) - else: - Log.error("Unknown error occurred {}", exc) - reset_frame = True # graceful recovery - finally: - if reset_frame: - self.framer.resetFrame() - reset_frame = False + Log.error( + 'Unknown exception "{}" on stream {} forcing disconnect', + exc, + self.comm_params.comm_name, + ) + self.close() + self.callback_disconnected(exc) def execute(self, request, *addr): """Call with the resulting message. From 1f36d64516fdaf61d880a34079aa467503c3693c Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Tue, 5 Mar 2024 10:35:30 -0600 Subject: [PATCH 2/3] Restore mangled docstring --- pymodbus/server/async_io.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index f073e94b3..ff15486b4 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -131,15 +131,14 @@ async def inner_handle(self): ) async def handle(self): - """Return Asyncio coroutine which represents a single conversation. - - between the modbus slave and master + """Coroutine which represents a single master <=> slave conversation. Once the client connection is established, the data chunks will be fed to this coroutine via the asyncio.Queue object which is fed by the ModbusServerRequestHandler class's callback Future. - This callback future gets data from either + This callback future gets data from either asyncio.BaseProtocol.data_received + or asyncio.DatagramProtocol.datagram_received. This function will execute without blocking in the while-loop and yield to the asyncio event loop when the frame is exhausted. From 576d68274bc81a411a35326dd5045a6a7c5f4d00 Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Tue, 5 Mar 2024 10:37:03 -0600 Subject: [PATCH 3/3] type hints --- pymodbus/server/async_io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index ff15486b4..e5a6d9d65 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -46,7 +46,7 @@ def __init__(self, owner): super().__init__(params, False) self.server = owner self.running = False - self.receive_queue = asyncio.Queue() + self.receive_queue: asyncio.Queue = asyncio.Queue() self.handler_task = None # coroutine to be run on asyncio loop self.framer: ModbusFramer @@ -130,7 +130,7 @@ async def inner_handle(self): single=single, ) - async def handle(self): + async def handle(self) -> None: """Coroutine which represents a single master <=> slave conversation. Once the client connection is established, the data chunks will be