Skip to content

Commit 47675dc

Browse files
committed
server: include OSError in debug message
1 parent 809cf98 commit 47675dc

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Revision history for pyModbusTCP
22

3+
0.3.1.dev0 xxxx-xx-xx
4+
5+
- fix ModbusServer: debug messages now include OSError exceptions produced by getpeername (thanks to Pär Åhlund).
6+
37
0.3.0 2024-09-04
48

59
- pyModbusTCP.client: now use the standard logging method as in the server part.

pyModbusTCP/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" pyModbusTCP package constants definition """
22

33
# Package version
4-
VERSION = '0.3.0'
4+
VERSION = '0.3.1.dev0'
55
# Modbus/TCP
66
MODBUS_PORT = 502
77
# Modbus function code

pyModbusTCP/server.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,14 +824,14 @@ def setup(self):
824824
self.request.settimeout(1.0)
825825

826826
def handle(self):
827-
# try/except end current thread on ModbusServer._InternalError or socket.error
827+
# try/except: end current thread on ModbusServer._InternalError, OSError or socket.error
828828
# this also close the current TCP session associated with it
829-
# init and update server info structure
830-
session_data = ModbusServer.SessionData()
831-
(session_data.client.address, session_data.client.port) = self.request.getpeername()
832-
# debug message
833-
logger.debug('accept new connection from %r', session_data.client)
834829
try:
830+
# init and update server info structure
831+
session_data = ModbusServer.SessionData()
832+
(session_data.client.address, session_data.client.port) = self.request.getpeername()
833+
# debug message
834+
logger.debug('accept new connection from %r', session_data.client)
835835
# main processing loop
836836
while True:
837837
# init session data for new request
@@ -846,7 +846,7 @@ def handle(self):
846846
self.server.engine(session_data)
847847
# send the tx pdu with the last rx mbap (only length field change)
848848
self._send_all(session_data.response.raw)
849-
except (ModbusServer.Error, socket.error) as e:
849+
except (ModbusServer.Error, OSError, socket.error) as e:
850850
# debug message
851851
logger.debug('Exception during request handling: %r', e)
852852
# on main loop except: exit from it and cleanly close the current socket

0 commit comments

Comments
 (0)