put socket timeout and deadline around mumble queries
This commit is contained in:
parent
3c7b276188
commit
c80aab88f3
1 changed files with 13 additions and 5 deletions
|
@ -20,13 +20,21 @@ class Module(ModuleManager.BaseModule):
|
||||||
timestamp = datetime.datetime.utcnow().microsecond
|
timestamp = datetime.datetime.utcnow().microsecond
|
||||||
ping_packet = struct.pack(">iQ", 0, timestamp)
|
ping_packet = struct.pack(">iQ", 0, timestamp)
|
||||||
s = socket.socket(type=socket.SOCK_DGRAM)
|
s = socket.socket(type=socket.SOCK_DGRAM)
|
||||||
|
s.settimeout(5)
|
||||||
|
|
||||||
try:
|
with utils.deadline():
|
||||||
s.sendto(ping_packet, (server, port))
|
try:
|
||||||
except socket.gaierror as e:
|
s.sendto(ping_packet, (server, port))
|
||||||
raise utils.EventError(str(e))
|
except socket.gaierror as e:
|
||||||
|
raise utils.EventError(str(e))
|
||||||
|
|
||||||
|
try:
|
||||||
|
pong_packet = s.recv(24)
|
||||||
|
except socket.timeout:
|
||||||
|
raise utils.EventError(
|
||||||
|
"Timed out waiting for response from %s:%d"
|
||||||
|
% (server, port))
|
||||||
|
|
||||||
pong_packet = s.recv(24)
|
|
||||||
pong = struct.unpack(">bbbbQiii", pong_packet)
|
pong = struct.unpack(">bbbbQiii", pong_packet)
|
||||||
|
|
||||||
version = ".".join(str(v) for v in pong[1:4])
|
version = ".".join(str(v) for v in pong[1:4])
|
||||||
|
|
Loading…
Reference in a new issue