diff options
author | MaZderMind <git@mazdermind.de> | 2016-09-26 20:42:07 +0200 |
---|---|---|
committer | MaZderMind <git@mazdermind.de> | 2016-09-26 20:42:07 +0200 |
commit | 6e846c7081e242213cd70ceacfcff319e221942c (patch) | |
tree | 9d037e9272e65aea06c74775b2af1eae2f50a46e /voctocore/lib/tcpmulticonnection.py | |
parent | fbcbc3743e9179738244a96be54aa588e44314cb (diff) | |
parent | 1972da7f6aa60d3cb3b68808d0381e37898665f3 (diff) |
Merge branch 'pep8'
Diffstat (limited to 'voctocore/lib/tcpmulticonnection.py')
-rw-r--r-- | voctocore/lib/tcpmulticonnection.py | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/voctocore/lib/tcpmulticonnection.py b/voctocore/lib/tcpmulticonnection.py index 66fc33f..ac228a3 100644 --- a/voctocore/lib/tcpmulticonnection.py +++ b/voctocore/lib/tcpmulticonnection.py @@ -1,41 +1,48 @@ -import logging, socket +import logging +import socket from queue import Queue from gi.repository import GObject from lib.config import Config + class TCPMultiConnection(object): - def __init__(self, port): - if not hasattr(self, 'log'): - self.log = logging.getLogger('TCPMultiConnection') - self.boundSocket = None - self.currentConnections = dict() + def __init__(self, port): + if not hasattr(self, 'log'): + self.log = logging.getLogger('TCPMultiConnection') + + self.boundSocket = None + self.currentConnections = dict() - self.log.debug('Binding to Source-Socket on [::]:%u', port) - self.boundSocket = socket.socket(socket.AF_INET6) - self.boundSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.boundSocket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False) - self.boundSocket.bind(('::', port)) - self.boundSocket.listen(1) + self.log.debug('Binding to Source-Socket on [::]:%u', port) + self.boundSocket = socket.socket(socket.AF_INET6) + self.boundSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.boundSocket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, + False) + self.boundSocket.bind(('::', port)) + self.boundSocket.listen(1) - self.log.debug('Setting GObject io-watch on Socket') - GObject.io_add_watch(self.boundSocket, GObject.IO_IN, self.on_connect) + self.log.debug('Setting GObject io-watch on Socket') + GObject.io_add_watch(self.boundSocket, GObject.IO_IN, self.on_connect) - def on_connect(self, sock, *args): - conn, addr = sock.accept() - conn.setblocking(False) + def on_connect(self, sock, *args): + conn, addr = sock.accept() + conn.setblocking(False) - self.log.info("Incomming Connection from [%s]:%u (fd=%u)", addr[0], addr[1], conn.fileno()) + self.log.info("Incomming Connection from [%s]:%u (fd=%u)", + addr[0], addr[1], conn.fileno()) - self.currentConnections[conn] = Queue() - self.log.info('Now %u Receiver connected', len(self.currentConnections)) + self.currentConnections[conn] = Queue() + self.log.info('Now %u Receiver connected', + len(self.currentConnections)) - self.on_accepted(conn, addr) + self.on_accepted(conn, addr) - return True + return True - def close_connection(self, conn): - if conn in self.currentConnections: - del(self.currentConnections[conn]) - self.log.info('Now %u Receiver connected', len(self.currentConnections)) + def close_connection(self, conn): + if conn in self.currentConnections: + del(self.currentConnections[conn]) + self.log.info('Now %u Receiver connected', + len(self.currentConnections)) |