forked from Krautspace/doorstatus
secure socket wieder in try-except; finally-klauses wieder raus
This commit is contained in:
parent
991eeea9f8
commit
6bd34360a6
1 changed files with 35 additions and 32 deletions
|
@ -379,9 +379,9 @@ def main():
|
|||
ClientSocket, ClientAddress = MySocket.accept()
|
||||
logging.info('Client connected: {}:{}'.format(ClientAddress[0], ClientAddress[1]))
|
||||
# die verbindung in den ssl-context verpacken => Connection
|
||||
with context.wrap_socket(ClientSocket, server_side=True) as Connection:
|
||||
logging.info('SSL Connection established')
|
||||
try:
|
||||
Connection = context.wrap_socket(ClientSocket, server_side=True)
|
||||
logging.info('SSL Connection established')
|
||||
Connection.settimeout(float(config['general']['timeout']))
|
||||
logging.debug('Connection timeout set to {}'.format(config['general']['timeout']))
|
||||
cert = Connection.getpeercert(binary_form=False)
|
||||
|
@ -410,13 +410,16 @@ def main():
|
|||
Connection.close()
|
||||
except KeyboardInterrupt:
|
||||
logging.info('Keyboard interrupt received')
|
||||
sys.exit(255)
|
||||
except Exception as e:
|
||||
logging.error('{}'.format(e))
|
||||
finally:
|
||||
if MySocket:
|
||||
MySocket.close()
|
||||
logging.debug('TCP socket closed')
|
||||
sys.exit(255)
|
||||
except Exception as e:
|
||||
logging.error('{}'.format(e))
|
||||
if MySocket:
|
||||
MySocket.close()
|
||||
logging.debug('TCP socket closed')
|
||||
sys.exit(254)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue