From 77a87254b65f8f58ae58051f7422160ca33e648c Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 7 Jun 2022 17:59:47 +0200 Subject: nDPIsrvd.py: Throw SocketTimeout Exception to catch both timeout exceptions different Python versions can throw. Signed-off-by: Toni Uhlig --- dependencies/nDPIsrvd.h | 1 + dependencies/nDPIsrvd.py | 11 +++++++++++ examples/py-flow-info/flow-info.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dependencies/nDPIsrvd.h b/dependencies/nDPIsrvd.h index 8132c0f19..cafe25395 100644 --- a/dependencies/nDPIsrvd.h +++ b/dependencies/nDPIsrvd.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/dependencies/nDPIsrvd.py b/dependencies/nDPIsrvd.py index 38e181bfc..29b9458d5 100644 --- a/dependencies/nDPIsrvd.py +++ b/dependencies/nDPIsrvd.py @@ -278,6 +278,7 @@ class nDPIsrvdException(Exception): SOCKET_CONNECTION_BROKEN = 3 INVALID_LINE_RECEIVED = 4 CALLBACK_RETURNED_FALSE = 5 + SOCKET_TIMEOUT = 6 def __init__(self, etype): self.etype = etype @@ -318,6 +319,12 @@ class CallbackReturnedFalse(nDPIsrvdException): def __str__(self): return 'Callback returned False, abort.' +class SocketTimeout(nDPIsrvdException): + def __init__(self): + super().__init__(nDPIsrvdException.SOCKET_TIMEOUT) + def __str__(self): + return 'Socket timeout.' + class nDPIsrvdSocket: def __init__(self): self.sock_family = None @@ -352,6 +359,10 @@ class nDPIsrvdSocket: except ConnectionResetError: connection_finished = True recvd = bytes() + except TimeoutError: + raise SocketTimeout() + except socket.timeout: + raise SocketTimeout() if len(recvd) == 0: connection_finished = True diff --git a/examples/py-flow-info/flow-info.py b/examples/py-flow-info/flow-info.py index 541a8c16d..7384d687a 100755 --- a/examples/py-flow-info/flow-info.py +++ b/examples/py-flow-info/flow-info.py @@ -439,7 +439,7 @@ if __name__ == '__main__': except KeyboardInterrupt: print('\n\nKeyboard Interrupt: cleaned up {} flows.'.format(len(nsock.shutdown()))) break - except TimeoutError: + except nDPIsrvd.SocketTimeout: stats.updateSpinner() stats.resetStatus() stats.printStatus() -- cgit v1.2.3