Commit 351d0540 authored by Emmanuel Papillon's avatar Emmanuel Papillon
Browse files

comm/modbus.py: take timeout into account in connect(); raises RuntimeError

exception if connection cannot be established within 'timeout' seconds
parent 9dc5e5c7
......@@ -224,14 +224,15 @@ class ModbusTcp:
if self._connected:
return True
self._fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._fd.connect((local_host,local_port))
self._fd.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self._fd.setsockopt(socket.SOL_IP, socket.IP_TOS, 0x10)
self._host = local_host
self._port = local_port
self._raw_read_task = gevent.spawn(self._raw_read,
weakref.proxy(self), self._fd)
with gevent.Timeout(self._timeout, RuntimeError("Cannot connect to %s" % self._host)):
self._fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._fd.connect((local_host,local_port))
self._fd.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self._fd.setsockopt(socket.SOL_IP, socket.IP_TOS, 0x10)
self._host = local_host
self._port = local_port
self._raw_read_task = gevent.spawn(self._raw_read,
weakref.proxy(self), self._fd)
self._connected = True
return True
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment