예제 #1
0
static void
setup_marshal_data(struct marshal_data *data)
{
	assert(socketpair(AF_UNIX,
			  SOCK_STREAM | SOCK_CLOEXEC, 0, data->s) == 0);
	data->read_connection = wl_connection_create(data->s[0]);
	assert(data->read_connection);
	data->write_connection = wl_connection_create(data->s[1]);
	assert(data->write_connection);
}
예제 #2
0
파일: sockets.c 프로젝트: jinzhangf/wldbg
int
connect_to_wayland_server(struct wldbg_connection *conn, const char *display)
{
	conn->server.fd = connect_to_wayland_socket(display);
	if (conn->server.fd == -1) {
		perror("Failed opening wayland socket");
		return -1;
	}

	conn->server.connection = wl_connection_create(conn->server.fd);
	if (!conn->server.connection) {
		perror("Failed creating wl_connection");
		goto err;
	}

	/* XXX this is shared between clients and can be in
	 * wldbg struct */
	conn->server.pid = get_pid_for_socket(conn->server.fd);

	return conn->server.fd;

err:
	close(conn->server.fd);
	return -1;
}
예제 #3
0
static void
setup_marshal_data(struct marshal_data *data)
{
	assert(socketpair(AF_UNIX,
			  SOCK_STREAM | SOCK_CLOEXEC, 0, data->s) == 0);

	data->read_connection =
		wl_connection_create(data->s[0],
				     update_func, &data->read_mask);
	assert(data->read_connection);
	assert(data->read_mask == WL_CONNECTION_READABLE);

	data->write_connection =
		wl_connection_create(data->s[1],
				     update_func, &data->write_mask);
	assert(data->write_connection);
	assert(data->write_mask == WL_CONNECTION_READABLE);
}
예제 #4
0
/** Connect to Wayland display on an already open fd
 *
 * \param fd The fd to use for the connection
 * \return A \ref wl_display object or \c NULL on failure
 *
 * The wl_display takes ownership of the fd and will close it when the
 * display is destroyed.  The fd will also be closed in case of
 * failure.
 *
 * \memberof wl_display
 */
WL_EXPORT struct wl_display *
wl_display_connect_to_fd(int fd)
{
	struct wl_display *display;
	const char *debug;

	debug = getenv("WAYLAND_DEBUG");
	if (debug && (strstr(debug, "client") || strstr(debug, "1")))
		debug_client = 1;

	display = malloc(sizeof *display);
	if (display == NULL) {
		close(fd);
		return NULL;
	}

	memset(display, 0, sizeof *display);

	display->fd = fd;
	wl_map_init(&display->objects, WL_MAP_CLIENT_SIDE);
	wl_event_queue_init(&display->default_queue, display);
	wl_event_queue_init(&display->display_queue, display);
	wl_list_init(&display->event_queue_list);
	pthread_mutex_init(&display->mutex, NULL);
	pthread_cond_init(&display->reader_cond, NULL);
	display->reader_count = 0;

	wl_map_insert_new(&display->objects, 0, NULL);

	display->proxy.object.interface = &wl_display_interface;
	display->proxy.object.id = wl_map_insert_new(&display->objects, 0, display);
	display->proxy.display = display;
	display->proxy.object.implementation = (void(**)(void)) &display_listener;
	display->proxy.user_data = display;
	display->proxy.queue = &display->default_queue;
	display->proxy.flags = 0;
	display->proxy.refcount = 1;

	display->connection = wl_connection_create(display->fd);
	if (display->connection == NULL)
		goto err_connection;

	printf("<< %s:%u\n", __func__, __LINE__);
	return display;

 err_connection:
	pthread_mutex_destroy(&display->mutex);
	pthread_cond_destroy(&display->reader_cond);
	wl_map_release(&display->objects);
	close(display->fd);
	free(display);

	return NULL;
}
예제 #5
0
static struct wl_connection *
setup(int *s)
{
	struct wl_connection *connection;

	assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);

	connection = wl_connection_create(s[0]);
	assert(connection);

	return connection;
}
예제 #6
0
static struct wl_connection *
setup(int *s, uint32_t *mask)
{
	struct wl_connection *connection;

	assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);

	connection = wl_connection_create(s[0], update_func, mask);
	assert(connection);
	assert(*mask == WL_CONNECTION_READABLE);

	return connection;
}
예제 #7
0
WL_EXPORT struct wl_display *
wl_display_create(const char *address)
{
    struct wl_display *display;
    struct wl_proxy *backend_adv;
    struct sockaddr_un name;
    socklen_t size;
    size_t n;

    display = malloc(sizeof *display);
    if (display == NULL)
        return NULL;

    memset(display, 0, sizeof *display);
    display->fd = socket(PF_LOCAL, SOCK_STREAM, 0);
    if (display->fd < 0)
        goto fail;

    name.sun_family = AF_LOCAL;
    memcpy(name.sun_path, address, strlen(address + 1) + 2);

    size = offsetof (struct sockaddr_un, sun_path) + sizeof socket_name;

    if (connect(display->fd, (struct sockaddr *) &name, size) < 0)
        goto fail;

    /* FIXME: We'll need a protocol for getting a new range, I
     * guess... */
    read(display->fd, &display->id, sizeof display->id);

    display->connection = wl_connection_create(display->fd,
                          connection_update,
                          display);

    read(display->fd, &n, sizeof n);
    wl_display_read_proxy (display, &display->proxy);
    while (n--)
        wl_display_read_proxy (display, NULL);

    for (backend_adv = NULL; ; ) {
        backend_adv = wl_display_get_interface (display,
                                                "backend_advertisement",
                                                backend_adv);
        if (backend_adv == NULL)
            break;

        display->backend = wl_display_create_backend (display, backend_adv);
        if (display->backend != NULL)
            break;
    }

    if (display->backend == NULL)
        goto fail;

    return display;

fail:
    if (display && display->backend)
        wl_backend_destroy(display->backend);
    if (display && display->fd != -1)
        close(display->fd);
    free(display);
    return NULL;
}