xpra icon
Bug tracker and wiki

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


Ticket #1022: client-listen.patch

File client-listen.patch, 7.1 KB (added by Antoine Martin, 19 months ago)

add listen mode for client

  • xpra/client/client_base.py

     
    535535        import_glib()
    536536
    537537    def run(self):
    538         self._protocol.start()
     538        if self._protocol:
     539            self._protocol.start()
    539540
    540541    def quit(self, exit_code=0):
    541542        raise Exception("override me!")
  • xpra/client/mixins/network_state.py

     
    260260        self.send_deflate_level()
    261261
    262262    def send_deflate_level(self):
    263         self._protocol.set_compression_level(self.compression_level)
    264         self.send("set_deflate", self.compression_level)
     263        if self._protocol:
     264            self._protocol.set_compression_level(self.compression_level)
     265            self.send("set_deflate", self.compression_level)
    265266
    266267
    267268    def send_bandwidth_limit(self):
  • xpra/scripts/main.py

     
    147147
    148148def configure_logging(options, mode):
    149149    if mode in (
    150         "showconfig", "info", "id", "attach", "launcher", "stop", "print",
     150        "showconfig", "info", "id", "attach", "listen", "launcher", "stop", "print",
    151151        "control", "list", "list-mdns", "sessions", "mdns-gui", "bug-report",
    152152        "opengl", "opengl-probe", "test-connect",
    153153        ):
     
    171171    setloghandler(logging.StreamHandler(to))
    172172    if mode in (
    173173        "start", "start-desktop", "upgrade", "upgrade-desktop",
    174         "attach", "shadow", "proxy",
     174        "attach", "listen", "shadow", "proxy",
    175175        "_sound_record", "_sound_play",
    176176        "stop", "print", "showconfig",
    177177        "request-start", "request-start-desktop", "request-shadow",
     
    178178        "_dialog", "_pass",
    179179        ):
    180180        if "help" in options.speaker_codec or "help" in options.microphone_codec:
    181             codec_help = show_sound_codec_help(mode!="attach", options.speaker_codec, options.microphone_codec)
     181            server_mode = mode not in ("attach", "listen")
     182            codec_help = show_sound_codec_help(server_mode, options.speaker_codec, options.microphone_codec)
    182183            raise InitInfo("\n".join(codec_help))
    183184        fmt = LOG_FORMAT
    184185        if mode in ("stop", "showconfig"):
     
    329330        #sound commands don't want to set the name
    330331        #(they do it later to prevent glib import conflicts)
    331332        #"attach" does it when it received the session name from the server
    332         if mode not in ("attach", "start", "start-desktop", "upgrade", "upgrade-desktop", "proxy", "shadow"):
     333        if mode not in ("attach", "listen", "start", "start-desktop", "upgrade", "upgrade-desktop", "proxy", "shadow"):
    333334            from xpra.platform import set_name
    334335            set_name("Xpra", "Xpra %s" % mode.strip("_"))
    335336
    336337    if mode in (
    337338        "start", "start-desktop",
    338         "shadow", "attach",
     339        "shadow", "attach", "listen",
    339340        "request-start", "request-start-desktop", "request-shadow",
    340341        ):
    341342        options.encodings = validated_encodings(options.encodings)
     
    444445                add_when_ready(attach_client)
    445446            return run_server(error_cb, options, mode, script_file, args, current_display)
    446447        elif mode in (
    447             "attach", "detach",
     448            "attach", "listen", "detach",
    448449            "screenshot", "version", "info", "id",
    449450            "control", "_monitor", "top", "print",
    450451            "connect-test", "request-start", "request-start-desktop", "request-shadow",
     
    15751576            app.start_child_new_commands = []
    15761577            app.start_new_commands = []
    15771578        try:
    1578             conn, display_desc = connect()
     1579            if mode=="listen":
     1580                if extra_args:
     1581                    raise InitException("cannot specify extra arguments with 'listen' mode")
     1582                display_desc = {}
     1583                from xpra.platform import get_username
     1584                from xpra.net.socket_util import (
     1585                    get_network_logger, setup_local_sockets,
     1586                    create_sockets, add_listen_socket, accept_connection,
     1587                    )
     1588                netlog = get_network_logger()
     1589                sockets = create_sockets(opts, error_cb)
     1590                #we don't have a display,
     1591                #so we can't automatically create sockets:
     1592                if "auto" in opts.bind:
     1593                    opts.bind.remove("auto")
     1594                local_sockets = setup_local_sockets(opts.bind,
     1595                                                    opts.socket_dir, opts.socket_dirs,
     1596                                                    None, False,
     1597                                                    opts.mmap_group, opts.socket_permissions,
     1598                                                    get_username(), getuid, getgid)
     1599                sockets += local_sockets
     1600                saved_send_hello = app.send_hello
     1601                def new_connection(socktype, sock, *args):
     1602                    app.send_hello = saved_send_hello
     1603                    netlog.warn("new_connection%s", (socktype, sock, args))
     1604                    conn = accept_connection(socktype, sock)
     1605                    netlog.warn("accept_connection(%s, %s)=%s", socktype, sock, conn)
     1606                    app.setup_connection(conn)
     1607                    netlog.warn("saved_send_hello=%s", saved_send_hello)
     1608                    protocol = app._protocol
     1609                    protocol.start()
     1610                    app.send_hello()
     1611                saved_server_connection_established = app.server_connection_established
     1612                def server_connection_established():
     1613                    #TODO: close the other sockets and stop listening for new connections
     1614                    app.send_deflate_level()
     1615                    netlog.error("server_connection_established")
     1616                    saved_server_connection_established()
     1617                app.server_connection_established = server_connection_established
     1618                for socktype, sock, info, cleanup_socket in sockets:
     1619                    add_listen_socket(socktype, sock, info, new_connection)
     1620                def noop(*_args):
     1621                    pass
     1622                app.send_hello = noop
     1623                conn = None
     1624            else:
     1625                conn, display_desc = connect()
    15791626            #UGLY warning: connect will parse the display string,
    15801627            #which may change the username and password..
    15811628            app.username = opts.username
     
    15821629            app.password = opts.password
    15831630            app.display = opts.display
    15841631            app.display_desc = display_desc
    1585             app.setup_connection(conn)
     1632            if conn:
     1633                app.setup_connection(conn)
    15861634        except Exception as e:
    15871635            may_notify = getattr(app, "may_notify", None)
    15881636            if may_notify: