From 8741fdf2ac624331d06f3f7a15eeffde102a4dae Mon Sep 17 00:00:00 2001 From: MiquelIR Date: Mon, 22 Oct 2018 11:27:34 +0200 Subject: [PATCH] MOD code to avoid timeouts --- iec870ree/ip.py | 12 ++++-------- iec870ree/protocol.py | 4 +++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/iec870ree/ip.py b/iec870ree/ip.py index 22bab27..a342179 100644 --- a/iec870ree/ip.py +++ b/iec870ree/ip.py @@ -36,7 +36,6 @@ def connect(self): """ self.connection = socket.create_connection(self.addr) self.connection.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - self.connection.settimeout(1) self.connected = True self.alive.set() self.thread.start() @@ -45,23 +44,20 @@ def connect(self): def disconnect(self): """Disconnects """ - self.connected = False self.alive.clear() - logger.debug("Disconnected from %s", self.addr) - self.thread.join() + self.thread.join(5) logger.debug("Thread joined..") if self.connection: self.connection.close() + self.connected = False + logger.debug("Disconnected from %s", self.addr) def read_port(self): """Read bytes from socket """ logger.debug("Start reading port for %s", self.addr) while self.alive.is_set(): - try: - response = bytearray(self.connection.recv(16)) - except socket.timeout: - continue + response = self.connection.recv(16) if not response: continue logger.debug( diff --git a/iec870ree/protocol.py b/iec870ree/protocol.py index b33128b..539ea0c 100644 --- a/iec870ree/protocol.py +++ b/iec870ree/protocol.py @@ -3,7 +3,6 @@ from .base_asdu import ( AsduParser, FixedAsdu, VariableAsdu ) -import traceback from .app_asdu import * import math @@ -46,12 +45,15 @@ def parse_asdu(trama): class ProtocolException(Exception): pass + class IntegrationPeriodNotAvailable(Exception): pass + class RequestedASDUTypeNotAvailable(Exception): pass + class AppLayer(with_metaclass(ABCMeta)): def initialize(self, link_layer):