mirror of
https://github.com/optim-enterprises-bv/nDPId.git
synced 2025-10-29 17:32:23 +00:00
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:
1
dependencies/nDPIsrvd.h
vendored
1
dependencies/nDPIsrvd.h
vendored
@@ -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>
|
||||
|
||||
|
||||
11
dependencies/nDPIsrvd.py
vendored
11
dependencies/nDPIsrvd.py
vendored
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user