summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2022-06-07 17:59:47 +0200
committerToni Uhlig <matzeton@googlemail.com>2022-06-07 17:59:47 +0200
commit77a87254b65f8f58ae58051f7422160ca33e648c (patch)
tree7bfb5ce84dbe1156528d0c6be8f510119fa0c009
parent4fde63b5c27f0e3b809545d9e877c2218148b475 (diff)
nDPIsrvd.py: Throw SocketTimeout Exception to catch both timeout exceptions different Python versions can throw.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--dependencies/nDPIsrvd.h1
-rw-r--r--dependencies/nDPIsrvd.py11
-rwxr-xr-xexamples/py-flow-info/flow-info.py2
3 files changed, 13 insertions, 1 deletions
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 <stdlib.h>
#include <string.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <sys/un.h>
#include <unistd.h>
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()