Commit 89037a10 authored by maybites's avatar maybites
Browse files

fixed logger

added try-exceptions
parent 8ddaf8a4
......@@ -51,7 +51,10 @@ class Many2ManyBiProxy(multiprocessing.Process):
if (self.active_endpoints[addr] + self.timeout) < time.time():
del self.active_endpoints[addr]
else:
self.sock.sendto(my_data, addr)
try:
self.sock.sendto(my_data, addr)
except BlockingIOError:
continue
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
......
......@@ -66,7 +66,10 @@ class One2ManyBiProxy(multiprocessing.Process):
if (self.active_endpoints[one_addr] + self.timeout) < time.time():
del self.active_endpoints[one_addr]
else:
self.source.sendto(many_data, one_addr)
try:
self.sink.sendto(many_data, one_addr)
except BlockingIOError:
continue
elif sock.getsockname()[1] == self.one_port:
# one sends to many
one_data, one_addr = sock.recvfrom(65536)
......@@ -78,7 +81,10 @@ class One2ManyBiProxy(multiprocessing.Process):
if (self.active_endpoints[many_addr] + self.timeout) < time.time():
del self.active_endpoints[many_addr]
else:
self.sink.sendto(one_data, many_addr)
try:
self.sink.sendto(one_data, many_addr)
except BlockingIOError:
continue
else:
print('We should not ever reach that point')
except:
......
......@@ -68,7 +68,10 @@ class One2ManyMoProxy(multiprocessing.Process):
# send data to remaining sink_clients
for client in self.sink_clients.keys():
self.sink.sendto(data, client)
try:
self.sink.sendto(data, client)
except BlockingIOError:
continue
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
......
......@@ -49,10 +49,13 @@ class One2OneBiProxy(multiprocessing.Process):
# transmit data
if client1 and client2:
if addr == client1:
self.sock.sendto(data, client2)
elif addr == client2:
self.sock.sendto(data, client1)
try:
if addr == client1:
self.sock.sendto(data, client2)
elif addr == client2:
self.sock.sendto(data, client1)
except BlockingIOError:
continue
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
......
......@@ -104,13 +104,13 @@ def start_proxy():
if proxydef['type'] == 'one2oneBi':
obj = proxies.One2OneBiProxy(listen_port=proxydef['port'], logger=app.logger)
elif proxydef['type'] == 'one2manyMo':
obj = proxies.One2ManyMoProxy(listen_port=proxydef['port'], send_port=proxydef['port']+1)
obj = proxies.One2ManyMoProxy(listen_port=proxydef['port'], send_port=proxydef['port']+1, logger=app.logger)
elif proxydef['type'] == 'mirror':
obj = proxies.MirrorProxy(listen_port=proxydef['port'])
obj = proxies.MirrorProxy(listen_port=proxydef['port'], logger=app.logger)
elif proxydef['type'] == 'one2manyBi':
obj = proxies.One2ManyBiProxy(one_port=proxydef['port'], many_port=proxydef['port']+1)
obj = proxies.One2ManyBiProxy(one_port=proxydef['port'], many_port=proxydef['port']+1, logger=app.logger)
elif proxydef['type'] == 'many2manyBi':
obj = proxies.Many2ManyBiProxy(listen_port=proxydef['port'])
obj = proxies.Many2ManyBiProxy(listen_port=proxydef['port'], logger=app.logger)
else:
response = {'status': 'Error', 'msg': 'An unknown error occurred'}
return r(json.dumps(response), 422)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment