Skip to content

Commit

Permalink
Add special ssl socket handling of "no data". (#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Nov 24, 2024
1 parent e0d40d9 commit 604546d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 604546d

Please sign in to comment.