From 2b0c96c5ea1694ac1d89a1ce18185d0a85fc15fe Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sun, 17 Oct 2021 04:35:38 +0200 Subject: [PATCH] xcb_in: Allow file descriptors to arrive early The xserver sends file descriptors independently of replies. If the server sends many events to the client, it is possible for the reply to arrive several messages after the file descriptor. The code already supported this but only if the intermediate messages ended in partial packets. With this patch, file descriptors will be buffered indefinitely until they are consumed by a reply. There is still a limit of 16 file descriptors imposed by the XCB_MAX_PASS_FD constant. If this limit is exceeded, we call _xcb_conn_shutdown. --- src/xcb_in.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/xcb_in.c b/src/xcb_in.c index c9a264d..47c708b 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -913,6 +913,7 @@ int _xcb_in_init(_xcb_in *in) void _xcb_in_destroy(_xcb_in *in) { + int i; pthread_cond_destroy(&in->event_cond); free_reply_list(in->current_reply); _xcb_map_delete(in->replies, (void (*)(void *)) free_reply_list); @@ -929,6 +930,9 @@ void _xcb_in_destroy(_xcb_in *in) in->pending_replies = pend->next; free(pend); } + for(i = 0; i < in->in_fd.nfd; i++) + close(in->in_fd.fd[i]); + in->in_fd.nfd = 0; } void _xcb_in_wake_up_next_reader(xcb_connection_t *c) @@ -1048,18 +1052,6 @@ int _xcb_in_read(xcb_connection_t *c) &c->in.in_fd.fd[c->in.in_fd.ifd], c->in.in_fd.nfd * sizeof (int)); c->in.in_fd.ifd = 0; - - /* If we have any left-over file descriptors after emptying - * the input buffer, then the server sent some that we weren't - * expecting. Close them and mark the connection as broken; - */ - if (c->in.queue_len == 0 && c->in.in_fd.nfd != 0) { - int i; - for (i = 0; i < c->in.in_fd.nfd; i++) - close(c->in.in_fd.fd[i]); - _xcb_conn_shutdown(c, XCB_CONN_CLOSED_FDPASSING_FAILED); - return 0; - } } #endif #ifndef _WIN32