improve error handling on client connections

- send a heartbeat, if no events for 5 sec.
  an interrupted connection (not closed by the other end) may
  not be detected for a long time when nothing is sent
+ make the error reply on a non SECoPEror more verbose
  e.g. "KeyError('foo')" instead of just "foo"
+ allow cfg file without nodeinterface
+ shorter logger name in HasIodev

Change-Id: I6b1ff23f9bf8c96feb25af44935596437b7d726f
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/23098
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2020-05-15 14:21:34 +02:00
parent 5c33cbf7a5
commit 7953826fac
5 changed files with 23 additions and 8 deletions

View File

@ -30,10 +30,11 @@ from collections import defaultdict
from secop.lib import mkthread, formatExtendedTraceback, formatExtendedStack
from secop.lib.asynconn import AsynConn, ConnectionClosed
from secop.datatypes import get_datatype, EnumType
from secop.datatypes import get_datatype
from secop.protocol.interface import encode_msg_frame, decode_msg
from secop.protocol.messages import REQUEST2REPLY, ERRORPREFIX, EVENTREPLY, WRITEREQUEST, WRITEREPLY, \
READREQUEST, READREPLY, IDENTREQUEST, IDENTPREFIX, ENABLEEVENTSREQUEST, COMMANDREQUEST, DESCRIPTIONREQUEST
READREQUEST, READREPLY, IDENTREQUEST, IDENTPREFIX, ENABLEEVENTSREQUEST, COMMANDREQUEST, \
DESCRIPTIONREQUEST, HEARTBEATREQUEST
import secop.errors
import secop.params
@ -290,13 +291,19 @@ class SecopClient(ProxyClient):
self.disconnect(False)
def __rxthread(self):
noactivity = 0
while self._running:
try:
reply = self.io.readline()
if reply is None:
noactivity += 1
if noactivity % 5 == 0:
# send ping to check if the connection is still alive
self.queue_request(HEARTBEATREQUEST, str(noactivity))
continue
except ConnectionClosed:
break
noactivity = 0
action, ident, data = decode_msg(reply)
if ident == '.':
ident = None