Commit 8ddaf8a4 authored by maybites's avatar maybites
Browse files

updated all udp scripts to reusable sockets

parent ed15bd03
......@@ -24,6 +24,7 @@ class Many2ManyBiProxy(multiprocessing.Process):
raise ValueError('Specified port "%s" is invalid.' % listen_port)
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.settimeout(0.1)
self.sock.bind((listen_address, listen_port))
except socket.error as msg:
......@@ -54,6 +55,10 @@ class Many2ManyBiProxy(multiprocessing.Process):
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
self.source.close()
self.sink.close()
def stop(self):
self.kill_signal.value = True
self.join()
......
......@@ -23,6 +23,7 @@ class MirrorProxy(multiprocessing.Process):
raise ValueError('Specified port "%s" is invalid.' % listen_port)
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.settimeout(0.1)
self.sock.bind((listen_address, listen_port))
except socket.error as msg:
......@@ -41,6 +42,8 @@ class MirrorProxy(multiprocessing.Process):
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
self.sock.close()
def stop(self):
self.kill_signal.value = True
self.join()
......
......@@ -26,11 +26,13 @@ class One2ManyBiProxy(multiprocessing.Process):
raise ValueError('Specified port "%s" is invalid.' % port)
try:
self.source = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.source.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.source.bind((listen_address, one_port))
except socket.error as msg:
raise
try:
self.sink = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sink.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sink.bind((listen_address, many_port))
except socket.error as msg:
raise
......@@ -82,6 +84,10 @@ class One2ManyBiProxy(multiprocessing.Process):
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
self.source.close()
self.sink.close()
def stop(self):
self.kill_signal.value = True
self.join()
......
......@@ -24,6 +24,7 @@ class One2OneBiProxy(multiprocessing.Process):
raise ValueError('Specified port "%s" is invalid.' % listen_port)
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.settimeout(0.1)
self.sock.bind((listen_address, listen_port))
except socket.error as msg:
......@@ -55,6 +56,8 @@ class One2OneBiProxy(multiprocessing.Process):
except:
self.logger.exception('Oops, something went wrong!', extra={'stack': True})
self.sock.close()
def stop(self):
self.kill_signal.value = True
self.join()
......
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