mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-06 01:41:07 -05:00
Merge branch 'external-event-loop' into 'main'
Draft: server: make wl_event_loop optional See merge request wayland/wayland!299
This commit is contained in:
commit
71a54a235f
2 changed files with 97 additions and 63 deletions
|
|
@ -190,6 +190,9 @@ wl_event_loop_get_destroy_listener(struct wl_event_loop *loop,
|
|||
struct wl_display *
|
||||
wl_display_create(void);
|
||||
|
||||
struct wl_display *
|
||||
wl_display_create2(void);
|
||||
|
||||
void
|
||||
wl_display_destroy(struct wl_display *display);
|
||||
|
||||
|
|
@ -319,6 +322,9 @@ wl_client_destroy(struct wl_client *client);
|
|||
void
|
||||
wl_client_flush(struct wl_client *client);
|
||||
|
||||
int
|
||||
wl_client_dispatch(struct wl_client *client);
|
||||
|
||||
void
|
||||
wl_client_get_credentials(struct wl_client *client,
|
||||
pid_t *pid, uid_t *uid, gid_t *gid);
|
||||
|
|
|
|||
|
|
@ -329,10 +329,9 @@ destroy_client_with_error(struct wl_client *client, const char *reason)
|
|||
wl_client_destroy(client);
|
||||
}
|
||||
|
||||
static int
|
||||
wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||
WL_EXPORT int
|
||||
wl_client_dispatch(struct wl_client *client)
|
||||
{
|
||||
struct wl_client *client = data;
|
||||
struct wl_connection *connection = client->connection;
|
||||
struct wl_resource *resource;
|
||||
struct wl_object *object;
|
||||
|
|
@ -343,36 +342,11 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
|||
int opcode, size, since;
|
||||
int len;
|
||||
|
||||
if (mask & WL_EVENT_HANGUP) {
|
||||
wl_client_destroy(client);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mask & WL_EVENT_ERROR) {
|
||||
destroy_client_with_error(client, "socket error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mask & WL_EVENT_WRITABLE) {
|
||||
len = wl_connection_flush(connection);
|
||||
if (len < 0 && errno != EAGAIN) {
|
||||
destroy_client_with_error(
|
||||
client, "failed to flush client connection");
|
||||
return 1;
|
||||
} else if (len >= 0) {
|
||||
wl_event_source_fd_update(client->source,
|
||||
WL_EVENT_READABLE);
|
||||
}
|
||||
}
|
||||
|
||||
len = 0;
|
||||
if (mask & WL_EVENT_READABLE) {
|
||||
len = wl_connection_read(connection);
|
||||
if (len == 0 || (len < 0 && errno != EAGAIN)) {
|
||||
destroy_client_with_error(
|
||||
client, "failed to read client connection");
|
||||
return 1;
|
||||
}
|
||||
len = wl_connection_read(connection);
|
||||
if (len == 0 || (len < 0 && errno != EAGAIN)) {
|
||||
destroy_client_with_error(
|
||||
client, "failed to read client connection");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (len >= 0 && (size_t) len >= sizeof p) {
|
||||
|
|
@ -459,6 +433,42 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
|||
"error in client communication");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||
{
|
||||
struct wl_client *client = data;
|
||||
struct wl_connection *connection = client->connection;
|
||||
int len;
|
||||
|
||||
if (mask & WL_EVENT_HANGUP) {
|
||||
wl_client_destroy(client);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mask & WL_EVENT_ERROR) {
|
||||
destroy_client_with_error(client, "socket error");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mask & WL_EVENT_WRITABLE) {
|
||||
len = wl_connection_flush(connection);
|
||||
if (len < 0 && errno != EAGAIN) {
|
||||
destroy_client_with_error(
|
||||
client, "failed to flush client connection");
|
||||
return 1;
|
||||
} else if (len >= 0) {
|
||||
wl_event_source_fd_update(client->source,
|
||||
WL_EVENT_READABLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (mask & WL_EVENT_READABLE) {
|
||||
wl_client_dispatch(client);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -531,12 +541,15 @@ wl_client_create(struct wl_display *display, int fd)
|
|||
|
||||
wl_priv_signal_init(&client->resource_created_signal);
|
||||
client->display = display;
|
||||
client->source = wl_event_loop_add_fd(display->loop, fd,
|
||||
WL_EVENT_READABLE,
|
||||
wl_client_connection_data, client);
|
||||
|
||||
if (!client->source)
|
||||
goto err_client;
|
||||
if (display->loop) {
|
||||
client->source = wl_event_loop_add_fd(display->loop, fd,
|
||||
WL_EVENT_READABLE,
|
||||
wl_client_connection_data,
|
||||
client);
|
||||
if (!client->source)
|
||||
goto err_client;
|
||||
}
|
||||
|
||||
if (wl_os_socket_peercred(fd, &client->uid, &client->gid,
|
||||
&client->pid) != 0)
|
||||
|
|
@ -566,7 +579,8 @@ err_map:
|
|||
wl_map_release(&client->objects);
|
||||
wl_connection_destroy(client->connection);
|
||||
err_source:
|
||||
wl_event_source_remove(client->source);
|
||||
if (client->source)
|
||||
wl_event_source_remove(client->source);
|
||||
err_client:
|
||||
free(client);
|
||||
return NULL;
|
||||
|
|
@ -952,7 +966,8 @@ wl_client_destroy(struct wl_client *client)
|
|||
wl_client_flush(client);
|
||||
wl_map_for_each(&client->objects, remove_and_destroy_resource, NULL);
|
||||
wl_map_release(&client->objects);
|
||||
wl_event_source_remove(client->source);
|
||||
if (client->source)
|
||||
wl_event_source_remove(client->source);
|
||||
close(wl_connection_destroy(client->connection));
|
||||
|
||||
wl_priv_signal_final_emit(&client->destroy_late_signal, client);
|
||||
|
|
@ -1117,6 +1132,41 @@ handle_display_terminate(int fd, uint32_t mask, void *data) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
WL_EXPORT struct wl_display *
|
||||
wl_display_create2(void)
|
||||
{
|
||||
struct wl_display *display;
|
||||
const char *debug;
|
||||
|
||||
debug = getenv("WAYLAND_DEBUG");
|
||||
if (debug && (strstr(debug, "server") || strstr(debug, "1")))
|
||||
debug_server = 1;
|
||||
|
||||
display = zalloc(sizeof *display);
|
||||
if (display == NULL)
|
||||
return NULL;
|
||||
|
||||
wl_list_init(&display->global_list);
|
||||
wl_list_init(&display->socket_list);
|
||||
wl_list_init(&display->client_list);
|
||||
wl_list_init(&display->registry_resource_list);
|
||||
wl_list_init(&display->protocol_loggers);
|
||||
|
||||
wl_priv_signal_init(&display->destroy_signal);
|
||||
wl_priv_signal_init(&display->create_client_signal);
|
||||
|
||||
display->terminate_efd = -1;
|
||||
display->next_global_name = 1;
|
||||
display->serial = 0;
|
||||
|
||||
display->global_filter = NULL;
|
||||
display->global_filter_data = NULL;
|
||||
|
||||
wl_array_init(&display->additional_shm_formats);
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
/** Create Wayland display object.
|
||||
*
|
||||
* \return The Wayland display object. Null if failed to create
|
||||
|
|
@ -1129,13 +1179,8 @@ WL_EXPORT struct wl_display *
|
|||
wl_display_create(void)
|
||||
{
|
||||
struct wl_display *display;
|
||||
const char *debug;
|
||||
|
||||
debug = getenv("WAYLAND_DEBUG");
|
||||
if (debug && (strstr(debug, "server") || strstr(debug, "1")))
|
||||
debug_server = 1;
|
||||
|
||||
display = zalloc(sizeof *display);
|
||||
display = wl_display_create2();
|
||||
if (display == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -1158,23 +1203,6 @@ wl_display_create(void)
|
|||
if (display->term_source == NULL)
|
||||
goto err_term_source;
|
||||
|
||||
wl_list_init(&display->global_list);
|
||||
wl_list_init(&display->socket_list);
|
||||
wl_list_init(&display->client_list);
|
||||
wl_list_init(&display->registry_resource_list);
|
||||
wl_list_init(&display->protocol_loggers);
|
||||
|
||||
wl_priv_signal_init(&display->destroy_signal);
|
||||
wl_priv_signal_init(&display->create_client_signal);
|
||||
|
||||
display->next_global_name = 1;
|
||||
display->serial = 0;
|
||||
|
||||
display->global_filter = NULL;
|
||||
display->global_filter_data = NULL;
|
||||
|
||||
wl_array_init(&display->additional_shm_formats);
|
||||
|
||||
return display;
|
||||
|
||||
err_term_source:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue