From 604546d6fa83f16b8abbdc953da9bec4a1a6df3a Mon Sep 17 00:00:00 2001 From: jan iversen Date: Sun, 24 Nov 2024 13:31:08 +0100 Subject: [PATCH] Add special ssl socket handling of "no data". (#2466) --- pymodbus/client/tcp.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 1e1e3cb25..a8cb51815 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -5,6 +5,7 @@ import socket import time from collections.abc import Callable +from ssl import SSLWantReadError from pymodbus.client.base import ModbusBaseClient, ModbusBaseSyncClient from pymodbus.exceptions import ConnectionException @@ -235,10 +236,13 @@ def recv(self, size: int | None) -> bytes: except ValueError: return self._handle_abrupt_socket_close(size, data, time.time() - time_) if ready[0]: - if (recv_data := self.socket.recv(recv_size)) == b"": - return self._handle_abrupt_socket_close( - size, data, time.time() - time_ - ) + try: + if (recv_data := self.socket.recv(recv_size)) == b"": + return self._handle_abrupt_socket_close( + size, data, time.time() - time_ + ) + except SSLWantReadError: + continue data.append(recv_data) data_length += len(recv_data) time_ = time.time()