def serve(port_queue: "Queue[int]", shutdown_queue: "Queue[bool]") -> None: httpd = TCPServer(("", 0), handler_class) httpd.timeout = 0.1 if ssl_context: httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True) port_queue.put(httpd.server_address[1]) while shutdown_queue.empty(): httpd.handle_request()
def serve(port_queue, shutdown_queue): httpd = TCPServer(("", 0), handler_class) httpd.timeout = 0.1 port_queue.put(httpd.server_address[1]) while shutdown_queue.empty(): httpd.handle_request()
def serve(port_queue: "Queue[int]", shutdown_queue: "Queue[bool]") -> None: httpd = TCPServer(("", 0), handler_class) httpd.timeout = 0.1 port_queue.put(httpd.server_address[1]) while shutdown_queue.empty(): httpd.handle_request()
def run(self): """ This starts a rendezvous "server" that listens to a port for messages from a given client. It will handle the rendezvous protocol based on being the "contacted" party. The thread should be set to DONE if this node decides to be the "contacting" party instead. """ success = False tries = 0 server = None while not success and tries < 10: self.port = self.port + tries try: logger.debug("Opening 'server' port: {}".format(self.port)) server = TCPServer((socket.gethostname(), self.port), self._RendezvousHandler) success = True except: logger.debug("Problems opening port") tries = tries + 1 if not success: logger.error( "Could not open port for rendezvous server. Failure.") self.done = True self.result = (False, None) self.queue.put("FAIL") self.callback() return # Set up data needed by the handler server.timeout = self.timeout server.shared_secret = self.shared_secret server.own_rendezvous_info = self.own_rendezvous_info server.provider = self.provider server.timeout = 0.5 server.done = False server.result = (False, None) # Signal to parent that we are now up and running self.queue.put("RUNNING") start = time.time() while not server.done and not self.done: server.handle_request() now = time.time() if now - start > self.timeout: self.done = True # If the server is done, we are done as well. if server.done: server.socket.close() self.done = True self.result = server.result else: server.socket.close() self.done = True self.queue.put("STOPPED") self.callback()