def _start_server_connect_nonblocking(self):
        """Setup the server socket and start a nonblocking connect"""
        try:
            # Start the blame request

            addr, port = self._get_client_remote_name()
            self._blame_in_progress = self.app_blame.get_applications_async(self.client_addr,
                    self.client_port, addr, port, self._on_get_applications_result)

            self.server_socket = socket.socket(self.client_socket.family,
                    self.client_socket.type,
                    self.client_socket.proto)
            self.server_socket.setblocking(False)
            self.server_bridge_fn = self._server_connect_bridge_fn
            # We don't want to handle any data from the client until the
            # connection to the server is established, only listen to the server
            # socket for now.
            self.set_select_fds(wlist=[self.server_socket])
            # Try and connect, this will probably raise an EINPROGRESS
            self.server_socket.connect((self.server_addr, self.server_port))
            # If we finished instantly call _on_server_connected()
            self._on_server_connected()
        except socket.error as e:
            # We expect an EINPROGRESS from the connect call.
            if e.errno != errno.EINPROGRESS:
                raise e
Setup the server socket and start a nonblocking connect
nogotofail/mitm/connection/connection.py