mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-18 13:09:08 +02:00
Peer server handle accept connection in new thread (#1339)
This commit is contained in:
parent
29c58d9231
commit
aecde57fc7
2 changed files with 16 additions and 5 deletions
|
|
@ -53,7 +53,6 @@ class PeerClient(object):
|
|||
self.handle_connection(
|
||||
peer_socket,
|
||||
address,
|
||||
outgoing=True,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception('Failed to make connection to {}'.format(address))
|
||||
|
|
@ -63,13 +62,12 @@ class PeerClient(object):
|
|||
self,
|
||||
peer_socket: socket.socket,
|
||||
peer_address: PeerAddress,
|
||||
outgoing: bool,
|
||||
):
|
||||
"""Handle a newly connected peer socket."""
|
||||
self.peer_handler.handle_connection(
|
||||
peer_socket,
|
||||
peer_address,
|
||||
outgoing,
|
||||
outgoing=True,
|
||||
)
|
||||
|
||||
def get_socket(self):
|
||||
|
|
|
|||
|
|
@ -70,7 +70,20 @@ class PeerServer(object):
|
|||
port=port,
|
||||
)
|
||||
peer_socket.setblocking(True)
|
||||
self.peer_handler.handle_connection(
|
||||
peer_socket, peer_address, outgoing=False)
|
||||
self.handle_connection(
|
||||
peer_socket,
|
||||
peer_address,
|
||||
)
|
||||
except Exception:
|
||||
logger.info("Stopped accepting incoming connections.")
|
||||
|
||||
def handle_connection(
|
||||
self,
|
||||
peer_socket: socket.socket,
|
||||
peer_address: PeerAddress,
|
||||
):
|
||||
"""Handle a newly connected peer socket."""
|
||||
threading.Thread(
|
||||
target=self.peer_handler.handle_connection,
|
||||
args=(peer_socket, peer_address, False),
|
||||
).start()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue