Connection pool cleanup
- minor code quality improvement
This commit is contained in:
parent
0dc0b22974
commit
916b85c862
|
@ -69,7 +69,7 @@ class BMConnectionPool(object):
|
||||||
def removeConnection(self, connection):
|
def removeConnection(self, connection):
|
||||||
if isinstance(connection, network.udp.UDPSocket):
|
if isinstance(connection, network.udp.UDPSocket):
|
||||||
del self.udpSockets[connection.listening.host]
|
del self.udpSockets[connection.listening.host]
|
||||||
if isinstance(connection, network.tcp.TCPServer):
|
elif isinstance(connection, network.tcp.TCPServer):
|
||||||
del self.listeningSockets[state.Peer(connection.destination.host, connection.destination.port)]
|
del self.listeningSockets[state.Peer(connection.destination.host, connection.destination.port)]
|
||||||
elif connection.isOutbound:
|
elif connection.isOutbound:
|
||||||
try:
|
try:
|
||||||
|
@ -163,21 +163,23 @@ class BMConnectionPool(object):
|
||||||
|
|
||||||
self.lastSpawned = time.time()
|
self.lastSpawned = time.time()
|
||||||
|
|
||||||
if acceptConnections and len(self.listeningSockets) == 0:
|
if acceptConnections:
|
||||||
|
if not self.listeningSockets:
|
||||||
self.startListening()
|
self.startListening()
|
||||||
logger.info('Listening for incoming connections.')
|
logger.info('Listening for incoming connections.')
|
||||||
if acceptConnections and len(self.udpSockets) == 0:
|
if not self.udpSockets:
|
||||||
if BMConfigParser().safeGet("network", "bind") is None:
|
if BMConfigParser().safeGet("network", "bind") is None:
|
||||||
self.startUDPSocket()
|
self.startUDPSocket()
|
||||||
else:
|
else:
|
||||||
for bind in re.sub("[^\w.]+", " ", BMConfigParser().safeGet("network", "bind")).split():
|
for bind in re.sub("[^\w.]+", " ", BMConfigParser().safeGet("network", "bind")).split():
|
||||||
self.startUDPSocket(bind)
|
self.startUDPSocket(bind)
|
||||||
logger.info('Starting UDP socket(s).')
|
logger.info('Starting UDP socket(s).')
|
||||||
if len(self.listeningSockets) > 0 and not acceptConnections:
|
else:
|
||||||
|
if self.listeningSockets:
|
||||||
for i in self.listeningSockets:
|
for i in self.listeningSockets:
|
||||||
i.handle_close()
|
i.handle_close()
|
||||||
logger.info('Stopped listening for incoming connections.')
|
logger.info('Stopped listening for incoming connections.')
|
||||||
if len(self.udpSockets) > 0 and not acceptConnections:
|
if self.udpSockets:
|
||||||
for i in self.udpSockets:
|
for i in self.udpSockets:
|
||||||
i.handle_close()
|
i.handle_close()
|
||||||
logger.info('Stopped udp sockets.')
|
logger.info('Stopped udp sockets.')
|
||||||
|
|
Reference in New Issue
Block a user