Skip to content

Commit 18fe036

Browse files
MarekLewdhoomakethu
authored andcommitted
[fix v3] poprawa sprawdzania timeout
1 parent 6e72e44 commit 18fe036

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pymodbus/client/sync.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,22 @@ def _recv(self, size):
263263
recv_size = size
264264

265265
data = b''
266-
begin = time.time()
266+
time_ = time.time()
267+
end = time_ + timeout
267268
while recv_size > 0:
268-
ready = select.select([self.socket], [], [], timeout)
269+
ready = select.select([self.socket], [], [], end - time_)
269270
if ready[0]:
270271
data += self.socket.recv(recv_size)
272+
time_ = time.time()
271273

272274
# If size isn't specified continue to read until timeout expires.
273275
if size:
274276
recv_size = size - len(data)
275277

276278
# Timeout is reduced also if some data has been received in order
277-
# to avoid infinite loops when there isn't an expected response size
278-
# and the slave sends noisy data continuosly.
279-
timeout -= time.time() - begin
280-
if timeout <= 0:
279+
# to avoid infinite loops when there isn't an expected response
280+
# size and the slave sends noisy data continuosly.
281+
if time_ > end:
281282
break
282283

283284
return data

0 commit comments

Comments
 (0)