Skip to content
Snippets Groups Projects
Commit 16559725 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

failures on accept() resolved nicely

parent ecf6a7d1
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ class SelectLoop(BaseThread): ...@@ -19,6 +19,8 @@ class SelectLoop(BaseThread):
* select's on the sockets, closing and removing failed ones as necessary * select's on the sockets, closing and removing failed ones as necessary
* dispatches on_read and on_write, accepts connections. * dispatches on_read and on_write, accepts connections.
if those calls throw ConnectionFailedException, they will be closed if those calls throw ConnectionFailedException, they will be closed
if you are doing something THAT fancy that server socket accept() may fail (eg. SSL), you have
to throw ConnectionFailedException in your on_accept() if that happens
- when terminated, invokes on_cleanup() - when terminated, invokes on_cleanup()
- remaining client sockets are closed. Server socket is NOT CLOSED. - remaining client sockets are closed. Server socket is NOT CLOSED.
...@@ -45,7 +47,7 @@ class SelectLoop(BaseThread): ...@@ -45,7 +47,7 @@ class SelectLoop(BaseThread):
@type sock: L{satella.network.socket.BaseSocket} descendants""" @type sock: L{satella.network.socket.BaseSocket} descendants"""
self.external_accepts.put(sock) self.external_accepts.put(sock)
def on_accept(self, socket, addr): def on_accept(self, server_socket):
""" """
Override this. Override this.
@param socket: raw socket object @param socket: raw socket object
...@@ -54,7 +56,7 @@ class SelectLoop(BaseThread): ...@@ -54,7 +56,7 @@ class SelectLoop(BaseThread):
@return: new L{satella.network.socket.BaseSocket} or None, if socket is to be forgotten @return: new L{satella.network.socket.BaseSocket} or None, if socket is to be forgotten
(it can be returned later by send_socket) (it can be returned later by send_socket)
""" """
return BaseSocket(socket) return BaseSocket(server_socket.accept()[0])
def on_startup(self): def on_startup(self):
"""Override this. Called before the loop starts iterating, in new thread-context""" """Override this. Called before the loop starts iterating, in new thread-context"""
...@@ -122,9 +124,13 @@ class SelectLoop(BaseThread): ...@@ -122,9 +124,13 @@ class SelectLoop(BaseThread):
for sock in rs: # analyze sockets ready to be read for sock in rs: # analyze sockets ready to be read
if sock == self.server_socket: # accepting if sock == self.server_socket: # accepting
n_sock = self.on_accept(*sock.accept()) try:
if n_sock != None: # socket returned n_sock = self.on_accept(sock)
self.client_sockets.append(n_sock) except ConnectionFailedException:
pass
else:
if n_sock != None: # socket returned
self.client_sockets.append(n_sock)
else: # just a civilian socket else: # just a civilian socket
try: try:
sock.on_read() sock.on_read()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment