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
|
||||
ping_packet = struct.pack(">iQ", 0, timestamp)
|
||||
s = socket.socket(type=socket.SOCK_DGRAM)
|
||||
s.settimeout(5)
|
||||
|
||||
try:
|
||||
s.sendto(ping_packet, (server, port))
|
||||
except socket.gaierror as e:
|
||||
raise utils.EventError(str(e))
|
||||
with utils.deadline():
|
||||
try:
|
||||
s.sendto(ping_packet, (server, port))
|
||||
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)
|
||||
|
||||
version = ".".join(str(v) for v in pong[1:4])
|
||||
|
|
Loading…
Reference in a new issue