xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #2448: connect-after-mainloop-v2.patch

File connect-after-mainloop-v2.patch, 13.9 KB (added by Antoine Martin, 2 years ago)

updated patch

  • xpra/client/gobject_client_base.py

     
    106106    """
    107107    COMMAND_TIMEOUT = EXTRA_TIMEOUT
    108108
    109     def __init__(self, conn, opts):
    110         GObjectXpraClient.__init__(self)
    111         GObjectXpraClient.init(self, opts)
    112         connection, display_desc = conn
    113         self.display_desc = display_desc
    114         self.connect_with_timeout(connection)
    115         self._protocol._log_stats  = False
     109    def __init__(self, opts):
     110        super().__init__(self)
     111        super().init(self, opts)
     112        self.display_desc = {}
    116113        #not used by command line clients,
    117114        #so don't try probing for printers, etc
    118115        self.file_transfer = False
     
    122119                  "wants_versions", "wants_features", "wants_sound", "windows"):
    123120            self.hello_extra[x] = False
    124121
    125     def connect_with_timeout(self, conn):
    126         self.setup_connection(conn)
     122    def setup_connection(self, conn):
     123        super().setup_connection(conn)
     124        self._protocol._log_stats  = False
    127125        if conn.timeout>0:
    128126            GLib.timeout_add((conn.timeout + self.COMMAND_TIMEOUT) * 1000, self.timeout)
    129127        GLib.idle_add(self.send_hello)
     
    160158    def server_connection_established(self):
    161159        assert self.parse_encryption_capabilities(), "encryption failure"
    162160        assert self.parse_network_capabilities(), "network capabilities failure"
    163         return CommandConnectClient.server_connection_established(self)
     161        return super().server_connection_established(self)
    164162
    165163
    166164class HelloRequestClient(SendCommandConnectClient):
     
    170168    """
    171169
    172170    def make_hello_base(self):
    173         caps = CommandConnectClient.make_hello_base(self)
     171        caps = super().make_hello_base(self)
    174172        caps.update(self.hello_request())
    175173        return caps
    176174
     
    203201        and exits when the resulting image is received (or timedout)
    204202    """
    205203
    206     def __init__(self, conn, opts, screenshot_filename):
     204    def __init__(self, opts, screenshot_filename):
    207205        self.screenshot_filename = screenshot_filename
    208         CommandConnectClient.__init__(self, conn, opts)
     206        super().__init__(self, opts)
    209207        self.hello_extra["screenshot_request"] = True
    210208        self.hello_extra["request"] = "screenshot"
    211209
     
    224222        self.warn_and_quit(EXIT_OK, "screenshot %sx%s saved to: %s" % (w, h, self.screenshot_filename))
    225223
    226224    def init_packet_handlers(self):
    227         GObjectXpraClient.init_packet_handlers(self)
     225        super().init_packet_handlers(self)
    228226        self._ui_packet_handlers["screenshot"] = self._process_screenshot
    229227
    230228
     
    233231        it queries the server with an 'info' request
    234232    """
    235233
    236     def __init__(self, *args):
    237         CommandConnectClient.__init__(self, *args)
     234    def __init__(self, opts):
     235        super().__init__(self, opts)
    238236        self.hello_extra["info_request"] = True
    239237        self.hello_extra["request"] = "info"
    240238        if FLATTEN_INFO>=1:
     
    274272class IDXpraClient(InfoXpraClient):
    275273
    276274    def __init__(self, *args):
    277         InfoXpraClient.__init__(self, *args)
     275        super().__init__(self, *args)
    278276        self.hello_extra["request"] = "id"
    279277
    280278
     
    283281        it queries the server with an 'info' request
    284282    """
    285283
    286     def __init__(self, *args, **kwargs):
    287         CommandConnectClient.__init__(self, *args)
     284    def __init__(self, opts, **kwargs):
     285        super().__init__(self, opts)
    288286        self.value = get_hex_uuid()
    289287        self.hello_extra.update({
    290288            "connect_test_request"      : self.value,
     
    324322        If the server does not support this feature it exits with an error.
    325323    """
    326324
    327     def __init__(self, *args):
    328         SendCommandConnectClient.__init__(self, *args)
     325    def __init__(self, opts):
     326        super().__init__(self, opts)
    329327        for x in ("wants_features", "wants_events", "event_request"):
    330328            self.hello_extra[x] = True
    331329        self.hello_extra["request"] = "event"
     
    342340        log.info(": ".join(bytestostr(x) for x in packet[1:]))
    343341
    344342    def init_packet_handlers(self):
    345         SendCommandConnectClient.init_packet_handlers(self)
     343        super().init_packet_handlers(self)
    346344        self._packet_handlers["server-event"] = self._process_server_event
    347345        self._packet_handlers["ping"] = self._process_ping
    348346
     
    399397        self.warn_and_quit(EXIT_OK, text)
    400398
    401399    def make_hello(self):
    402         capabilities = GObjectXpraClient.make_hello(self)
     400        capabilities = super().make_hello(self)
    403401        log("make_hello() adding command request '%s' to %s", self.command, capabilities)
    404402        capabilities["command_request"] = self.command
    405403        capabilities["request"] = "command"
     
    460458        self.idle_add(self.send, "disconnect", DONE, "detaching")
    461459
    462460    def make_hello(self):
    463         capabilities = SendCommandConnectClient.make_hello(self)
     461        capabilities = super().make_hello(self)
    464462        capabilities["wants_features"] = True   #so we know if printing is supported or not
    465463        capabilities["print_request"] = True    #marker to skip full setup
    466464        capabilities["request"] = "print"
     
    538536
    539537    def _process_connection_lost(self, packet):
    540538        errwrite("\n")
    541         HelloRequestClient._process_connection_lost(self, packet)
     539        super()._process_connection_lost(self, packet)
    542540
    543541    def hello_request(self):
    544542        if first_time("hello-request"):
     
    575573            self.quit(0)
    576574        return True
    577575
    578     def __init__(self, conn, opts):
    579         HelloRequestClient.__init__(self, conn, opts)
     576    def __init__(self, opts):
     577        super().__init__(self, opts)
    580578        try:
    581579            self.displayfd = int(opts.displayfd)
    582580        except (ValueError, TypeError):
  • xpra/scripts/main.py

     
    1919
    2020from xpra.platform.dotxpra import DotXpra
    2121from xpra.util import csv, envbool, envint, nonl, pver, DEFAULT_PORT, DEFAULT_PORTS
    22 from xpra.exit_codes import EXIT_STR, EXIT_UNSUPPORTED
     22from xpra.exit_codes import EXIT_STR, EXIT_UNSUPPORTED, EXIT_CONNECTION_FAILED
    2323from xpra.os_util import (
    2424    get_util_logger, getuid, getgid,
    2525    monotonic_time, setsid, bytestostr, use_tty,
     
    13541354    if opts.quality!=-1 and (opts.quality < 0 or opts.quality > 100):
    13551355        error_cb("Quality must be between 0 and 100 inclusive. (or -1 to disable)")
    13561356
    1357     def connect():
    1358         desc = pick_display(error_cb, opts, extra_args)
    1359         return connect_or_fail(desc, opts), desc
     1357    app = None
     1358    def connect_to_server():
     1359        #on win32, we must run the main loop
     1360        #before we can call connect()
     1361        #because connect() may run a subprocess,
     1362        #and Gdk locks up the system if the main loop is not running by then!
     1363        from gi.repository import GLib
     1364        log = Logger("network")
     1365        def do_setup_connection():
     1366            try:
     1367                display_desc = pick_display(error_cb, opts, extra_args)
     1368                log("do_setup_connection() display_desc=%s", display_desc)
     1369                conn = connect_or_fail(display_desc, opts)
     1370                log("do_setup_connection() conn=%s", conn)
     1371                #UGLY warning: connect_or_fail() will parse the display string,
     1372                #which may change the username and password..
     1373                app.username = opts.username
     1374                app.password = opts.password
     1375                app.display = opts.display
     1376                app.display_desc = display_desc
     1377                app.setup_connection(conn)
     1378                app._protocol.start()
     1379                GLib.idle_add(app.send_hello)
     1380            except Exception as e:
     1381                log.error("Error: failed to connect")
     1382                log.error(" %s", e)
     1383                app.quit(EXIT_CONNECTION_FAILED)
     1384        def setup_connection():
     1385            log("setup_connection() starting setup-connection thread")
     1386            from xpra.make_thread import start_thread
     1387            start_thread(do_setup_connection, "setup-connection", True)
     1388        GLib.idle_add(setup_connection)
    13601389
    13611390    if mode=="screenshot":
    13621391        from xpra.client.gobject_client_base import ScreenshotXpraClient
    1363         app = ScreenshotXpraClient(connect(), opts, screenshot_filename)
     1392        app = ScreenshotXpraClient(opts, screenshot_filename)
    13641393    elif mode=="info":
    13651394        from xpra.client.gobject_client_base import InfoXpraClient
    1366         app = InfoXpraClient(connect(), opts)
     1395        app = InfoXpraClient(opts)
    13671396    elif mode=="id":
    13681397        from xpra.client.gobject_client_base import IDXpraClient
    1369         app = IDXpraClient(connect(), opts)
     1398        app = IDXpraClient(opts)
    13701399    elif mode=="connect-test":
    13711400        from xpra.client.gobject_client_base import ConnectTestXpraClient
    1372         app = ConnectTestXpraClient(connect(), opts)
     1401        app = ConnectTestXpraClient(opts)
    13731402    elif mode=="_monitor":
    13741403        from xpra.client.gobject_client_base import MonitorXpraClient
    1375         app = MonitorXpraClient(connect(), opts)
     1404        app = MonitorXpraClient(opts)
    13761405    elif mode == "top":
    13771406        from xpra.client.top_client import TopClient
    1378         app = TopClient(connect(), opts)
     1407        app = TopClient(opts)
    13791408    elif mode=="control":
    13801409        from xpra.client.gobject_client_base import ControlXpraClient
    13811410        if len(extra_args)<=1:
     
    13821411            error_cb("not enough arguments for 'control' mode")
    13831412        args = extra_args[1:]
    13841413        extra_args = extra_args[:1]
    1385         app = ControlXpraClient(connect(), opts)
     1414        app = ControlXpraClient(opts)
    13861415        app.set_command_args(args)
    13871416    elif mode=="print":
    13881417        from xpra.client.gobject_client_base import PrintClient
     
    13901419            error_cb("not enough arguments for 'print' mode")
    13911420        args = extra_args[1:]
    13921421        extra_args = extra_args[:1]
    1393         app = PrintClient(connect(), opts)
     1422        app = PrintClient(opts)
    13941423        app.set_command_args(args)
    13951424    elif mode=="version":
    13961425        from xpra.client.gobject_client_base import VersionXpraClient
    1397         app = VersionXpraClient(connect(), opts)
     1426        app = VersionXpraClient(opts)
    13981427    elif mode=="detach":
    13991428        from xpra.client.gobject_client_base import DetachXpraClient
    1400         app = DetachXpraClient(connect(), opts)
     1429        app = DetachXpraClient(opts)
    14011430    elif request_mode and opts.attach is not True:
    14021431        from xpra.client.gobject_client_base import RequestStartClient
    14031432        sns = get_start_new_session_dict(opts, request_mode, extra_args)
    14041433        extra_args = ["socket:%s" % opts.system_proxy_socket]
    1405         app = RequestStartClient(connect(), opts)
     1434        app = RequestStartClient(opts)
    14061435        app.hello_extra = {"connect" : False}
    14071436        app.start_new_session = sns
    14081437    else:
     
    14561485            app.start_child_new_commands = []
    14571486            app.start_new_commands = []
    14581487
    1459         def connect_to_server():
    1460             conn, display_desc = connect()
    1461             app.display_desc = display_desc
    1462             #UGLY warning: connect will parse the display string,
    1463             #which may change the username and password..
    1464             app.username = opts.username
    1465             app.password = opts.password
    1466             app.display = opts.display
    1467             app.setup_connection(conn)
    1468             return conn
    1469 
    14701488        try:
    14711489            if mode=="listen":
    14721490                if extra_args:
     
    15101528                                run_socket_cleanups()
    15111529                                netlog.info("connecting to %s", uri)
    15121530                                extra_args[:] = [uri, ]
    1513                                 conn = connect_to_server()
    1514                                 app._protocol.start()
    1515                                 app.idle_add(app.send_hello)
     1531                                connect_to_server()
     1532                                #app._protocol.start()
     1533                                #app.idle_add(app.send_hello)
    15161534                                return
    15171535                    app.idle_add(do_handle_connection, conn)
    15181536                def do_handle_connection(conn):
     
    15351553                    cleanup = add_listen_socket(socktype, sock, sinfo, new_connection)
    15361554                    if cleanup:
    15371555                        listen_cleanup.append(cleanup)
    1538             else:
    1539                 connect_to_server()
     1556                #listen mode is special,
     1557                #don't fall through to connect_to_server!
     1558                return app
    15401559        except Exception as e:
    15411560            may_notify = getattr(app, "may_notify", None)
    15421561            if may_notify:
     
    15481567                    body = "\n".join(lines[1:])
    15491568                else:
    15501569                    summary = "Xpra client failed to connect"
    1551                 may_notify(XPRA_FAILURE_NOTIFICATION_ID, summary, body, icon_name="disconnected")
     1570                may_notify(XPRA_FAILURE_NOTIFICATION_ID, summary, body, icon_name="disconnected")  #pylint: disable=not-callable
    15521571            app.cleanup()
    15531572            raise
     1573    connect_to_server()
    15541574    return app
    15551575
    15561576def run_opengl_probe():
     
    17171737        if isdisplaytype(args, "ssh"):
    17181738            #ssh will start the instance we requested,
    17191739            #then we just detach and we're done
    1720             app = WaitForDisconnectXpraClient((connect(), params), opts)
     1740            app = WaitForDisconnectXpraClient(opts)
    17211741        else:
    1722             app = RequestStartClient((connect(), params), opts)
     1742            app = RequestStartClient(opts)
    17231743            app.start_new_session = sns
    17241744        app.hello_extra = {"connect" : False}
    17251745    else:
     
    17271747        app.init(opts)
    17281748        app.init_ui(opts)
    17291749        app.hello_extra = hello_extra
    1730         app.setup_connection(connect())
     1750    app.connect(*connect())
    17311751    return do_run_client(app)
    17321752
    17331753