Skip to content

Commit

Permalink
[fix v3] poprawa sprawdzania timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekLew authored and dhoomakethu committed Jan 16, 2019
1 parent 6e72e44 commit 18fe036
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pymodbus/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,22 @@ def _recv(self, size):
recv_size = size

data = b''
begin = time.time()
time_ = time.time()
end = time_ + timeout
while recv_size > 0:
ready = select.select([self.socket], [], [], timeout)
ready = select.select([self.socket], [], [], end - time_)
if ready[0]:
data += self.socket.recv(recv_size)
time_ = time.time()

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

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

return data
Expand Down

0 comments on commit 18fe036

Please sign in to comment.