nDPIsrvd.py: Throw SocketTimeout Exception to catch both timeout exceptions different Python versions can throw.

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2022-06-07 17:59:47 +02:00
parent 4fde63b5c2
commit 77a87254b6
3 changed files with 13 additions and 1 deletions

View File

@@ -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>

View File

@@ -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

View File

@@ -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()