diff options
-rw-r--r-- | dependencies/nDPIsrvd.h | 1 | ||||
-rw-r--r-- | dependencies/nDPIsrvd.py | 11 | ||||
-rwxr-xr-x | examples/py-flow-info/flow-info.py | 2 |
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() |