コード例 #1
0
ファイル: maintenance.py プロジェクト: wash34000/gateway
    def start(self, port, connection_timeout):
        """
        Run the maintenance service, accepts a connection. Starts a serial
        redirector when a connection is accepted.
        """
        LOGGER.info('Starting maintenance socket on port ' + str(port))
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.settimeout(connection_timeout)
        sock = System.get_ssl_socket(
            sock,
            private_key_filename=self._privatekey_filename,
            certificate_filename=self._certificate_filename)
        sock.bind(('', port))
        sock.listen(1)

        try:
            LOGGER.info('Waiting for maintenance connection.')
            connection, addr = sock.accept()
            self.handle_connection(connection, str(addr))
            LOGGER.info(
                'Maintenance session ended, closing maintenance socket')
            sock.close()
        except socket.timeout:
            LOGGER.info('Maintenance socket timed out, closing.')
            sock.close()
        except Exception:
            LOGGER.error('Error in maintenance service: %s\n',
                         traceback.format_exc())
            sock.close()
コード例 #2
0
    def _run_socket_server(self, port):
        connection_timeout = MaintenanceController.SOCKET_TIMEOUT
        logger.info('Starting maintenance socket on port %s', port)

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.settimeout(connection_timeout)
        sock = System.get_ssl_socket(
            sock,
            private_key_filename=self._privatekey_filename,
            certificate_filename=self._certificate_filename)
        sock.bind(('', port))
        sock.listen(1)

        try:
            logger.info('Waiting for maintenance connection.')
            self._connection, address = sock.accept()
            logger.info('Maintenance connection from %s', str(address))
            self._handle_connection()
            logger.info(
                'Maintenance session ended, closing maintenance socket')
            sock.close()
        except socket.timeout:
            logger.info('Maintenance socket timed out, closing.')
            sock.close()
        except Exception:
            logger.exception('Error in maintenance service')
            sock.close()
コード例 #3
0
ファイル: maintenance.py プロジェクト: openmotics/gateway
    def start(self, port, connection_timeout):
        """
        Run the maintenance service, accepts a connection. Starts a serial
        redirector when a connection is accepted.
        """
        LOGGER.info('Starting maintenance socket on port %s', port)
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.settimeout(connection_timeout)
        sock = System.get_ssl_socket(sock,
                                     private_key_filename=self._privatekey_filename,
                                     certificate_filename=self._certificate_filename)
        sock.bind(('', port))
        sock.listen(1)

        try:
            LOGGER.info('Waiting for maintenance connection.')
            connection, addr = sock.accept()
            self.handle_connection(connection, str(addr))
            LOGGER.info('Maintenance session ended, closing maintenance socket')
            sock.close()
        except socket.timeout:
            LOGGER.info('Maintenance socket timed out, closing.')
            sock.close()
        except Exception:
            LOGGER.error('Error in maintenance service: %s\n', traceback.format_exc())
            sock.close()