diff options
author | MaZderMind <git@mazdermind.de> | 2015-09-02 15:19:30 +0200 |
---|---|---|
committer | MaZderMind <git@mazdermind.de> | 2015-09-02 15:19:30 +0200 |
commit | 20d75f6c7f5cad2f5c1b4da71ad5405848230201 (patch) | |
tree | 93894d7bc79a0b018275efbc0db524ac6f686570 /voctocore/lib/tcpmulticonnection.py | |
parent | a004948051e182edb3a7e40f1f7f2e14bebb0e0e (diff) | |
parent | 8646386d09ab6cdabf0b8421cece5c1ddd69633f (diff) |
Merge branch 'control-server-resilience'
Based on the work made by zuntrax & mithro at cccamp15
Diffstat (limited to 'voctocore/lib/tcpmulticonnection.py')
-rw-r--r-- | voctocore/lib/tcpmulticonnection.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/voctocore/lib/tcpmulticonnection.py b/voctocore/lib/tcpmulticonnection.py index 927ac06..e9caf2c 100644 --- a/voctocore/lib/tcpmulticonnection.py +++ b/voctocore/lib/tcpmulticonnection.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 import logging, socket +from queue import Queue from gi.repository import GObject from lib.config import Config @@ -10,7 +11,7 @@ class TCPMultiConnection(object): self.log = logging.getLogger('TCPMultiConnection') self.boundSocket = None - self.currentConnections = [] + self.currentConnections = dict() self.log.debug('Binding to Source-Socket on [::]:%u', port) self.boundSocket = socket.socket(socket.AF_INET6) @@ -24,9 +25,11 @@ class TCPMultiConnection(object): def on_connect(self, sock, *args): conn, addr = sock.accept() + conn.setblocking(False) + self.log.info("Incomming Connection from %s", addr) - self.currentConnections.append(conn) + self.currentConnections[conn] = Queue() self.log.info('Now %u Receiver connected', len(self.currentConnections)) self.on_accepted(conn, addr) @@ -34,5 +37,6 @@ class TCPMultiConnection(object): return True def close_connection(self, conn): - self.currentConnections.remove(conn) + if conn in self.currentConnections: + del(self.currentConnections[conn]) self.log.info('Now %u Receiver connected', len(self.currentConnections)) |