Exemplo n.º 1
0
def get_socket(dname, protocol, host, dno):
    assert protocol in SUPPORTED_PROTOCOLS
    try:
        # Darwin funky socket.
        if protocol == 'darwin':
            s = _get_unix_socket(dname)

        # TCP socket, note the special case: `unix:0.0` is equivalent to `:0.0`.
        elif (protocol is None or protocol != 'unix') and host and host != 'unix':
            s = _get_tcp_socket(host, dno)

        # Unix socket.
        else:
            address = '/tmp/.X11-unix/X%d' % dno
            if not os.path.exists(address):
                # Use abstract address.
                address = '\0' + address
            try:
                s = _get_unix_socket(address)
            except socket.error:
                if not protocol and not host:
                    # If no protocol/host was specified, fallback to TCP.
                    s = _get_tcp_socket(host, dno)
                else:
                    raise
    except socket.error as val:
        raise error.DisplayConnectionError(dname, str(val))

    # Make sure that the connection isn't inherited in child processes.
    fcntl.fcntl(s.fileno(), F_SETFD, FD_CLOEXEC)

    return s
Exemplo n.º 2
0
def get_socket(dname, host, dno):
    try:
        # Darwin funky socket
        if (uname[0] == 'Darwin') and host and host.startswith('/private/tmp/'):
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect(dname)

        # If hostname (or IP) is provided, use TCP socket
        elif host:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((host, 6000 + dno))

        # Else use Unix socket
        else:
            address = '/tmp/.X11-unix/X%d' % dno
            if not os.path.exists(address):
                # Use abstract address.
                address = '\0' + address
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect(address)
    except socket.error as val:
        raise error.DisplayConnectionError(dname, str(val))

    # Make sure that the connection isn't inherited in child processes
    fcntl.fcntl(s.fileno(), F_SETFD, FD_CLOEXEC)

    return s
Exemplo n.º 3
0
def get_socket(dname, host, dno):
    try:
        # Always use TCP/IP sockets.  Later it would be nice to
        # be able to use DECNET och LOCAL connections.

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((host, 6000 + dno))

    except socket.error, val:
        raise error.DisplayConnectionError(dname, str(val))
Exemplo n.º 4
0
def get_socket(dname, host, dno):
    try:
        # If hostname (or IP) is provided, use TCP socket
        if host:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((host, 6000 + dno))

        # Else use Unix socket
        else:
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect('/tmp/.X11-unix/X%d' % dno)
    except socket.error, val:
        raise error.DisplayConnectionError(dname, str(val))
Exemplo n.º 5
0
def get_socket(dname, host, dno):
    try:
        # Darwin funky socket
        if (uname[0] == 'Darwin') and host and host.startswith('/tmp/'):
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect(dname)

        # If hostname (or IP) is provided, use TCP socket
        elif host:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((host, 6000 + dno))

        # Else use Unix socket
        else:
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect('/tmp/.X11-unix/X%d' % dno)
    except socket.error, val:
        raise error.DisplayConnectionError(dname, str(val))
Exemplo n.º 6
0
    def __init__(self, display=None):
        name, host, displayno, screenno = connect.get_display(display)

        self.display_name = name
        self.default_screen = screenno

        self.socket = connect.get_socket(name, host, displayno)

        auth_name, auth_data = connect.get_auth(self.socket, name, host,
                                                displayno)

        # Internal structures for communication, grouped
        # by their function and locks

        # Socket error indicator, set when the socket is closed
        # in one way or another
        self.socket_error_lock = lock.allocate_lock()
        self.socket_error = None

        # Event queue
        self.event_queue_read_lock = lock.allocate_lock()
        self.event_queue_write_lock = lock.allocate_lock()
        self.event_queue = []

        # Unsent request queue and sequence number counter
        self.request_queue_lock = lock.allocate_lock()
        self.request_serial = 1
        self.request_queue = []

        # Send-and-recieve loop, see function send_and_recive
        # for a detailed explanation
        self.send_recv_lock = lock.allocate_lock()
        self.send_active = 0
        self.recv_active = 0

        self.event_waiting = 0
        self.event_wait_lock = lock.allocate_lock()
        self.request_waiting = 0
        self.request_wait_lock = lock.allocate_lock()

        # Data used by the send-and-recieve loop
        self.sent_requests = []
        self.request_length = 0
        self.data_send = ''
        self.data_recv = ''
        self.data_sent_bytes = 0

        # Resource ID structures
        self.resource_id_lock = lock.allocate_lock()
        self.resource_ids = {}
        self.last_resource_id = 0

        # Use an default error handler, one which just prints the error
        self.error_handler = None

        # Right, now we're all set up for the connection setup
        # request with the server.

        # Figure out which endianess the hardware uses
        self.big_endian = struct.unpack('BB', struct.pack('H', 0x0100))[0]

        if self.big_endian:
            order = 0x42
        else:
            order = 0x6c

        # Send connection setup
        r = ConnectionSetupRequest(self,
                                   byte_order=order,
                                   protocol_major=11,
                                   protocol_minor=0,
                                   auth_prot_name=auth_name,
                                   auth_prot_data=auth_data)

        # Did connection fail?
        if r.status != 1:
            raise error.DisplayConnectionError(self.display_name, r.reason)

        # Set up remaining info
        self.info = r
        self.default_screen = min(self.default_screen,
                                  len(self.info.roots) - 1)