Commit e30cc46b authored by Antoine Millet's avatar Antoine Millet
Browse files

Fixed exception when the ssl handshake fail on a new client connection.

parent 9c0445bc
......@@ -5,6 +5,7 @@ import ssl
import time
import socket
import select
import logging
from sjrpc.core import RpcConnection, ConnectionManager
class SimpleRpcServer(ConnectionManager):
......@@ -47,11 +48,13 @@ class SimpleRpcServer(ConnectionManager):
if fd == self._listening_sock.fileno():
# Event concerns the listening socket:
if event & select.EPOLLIN:
sock, address = self._accept_connection()
sock.setblocking(False)
connection = RpcConnection(sock, self,
handler=self._default_handler)
self.register(connection)
accepted = self._accept_connection()
if accepted is not None:
sock, address = accepted
sock.setblocking(False)
connection = RpcConnection(sock, self,
handler=self._default_handler)
self.register(connection)
else:
# Event concerns a client socket:
connection = self._clients[fd]
......@@ -95,9 +98,13 @@ class SimpleSslRpcServer(SimpleRpcServer):
def _accept_connection(self):
sock, address = self._listening_sock.accept()
sslsock = ssl.wrap_socket(sock, server_side=True, keyfile=self._keyfile,
certfile=self._certfile,
ssl_version=ssl.PROTOCOL_TLSv1,
do_handshake_on_connect=True)
return sslsock, address
try:
sslsock = ssl.wrap_socket(sock, server_side=True,
keyfile=self._keyfile,
certfile=self._certfile,
ssl_version=ssl.PROTOCOL_TLSv1,
do_handshake_on_connect=True)
except ssl.SSLError as err:
logging.error('Error when accepting ssl connection: %s' % err)
else:
return sslsock, address
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment