backend/wayland: continue reading on hangup

If we stop immediately, we won't see any wl_display.error events.
Make sure we've read everything before handling hangup.
This commit is contained in:
Simon Ser 2023-06-26 19:54:08 +02:00 committed by Simon Zeni
parent 3f0d338643
commit d039ad8da3

View file

@ -55,16 +55,6 @@ struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *wlr_backe
static int dispatch_events(int fd, uint32_t mask, void *data) { static int dispatch_events(int fd, uint32_t mask, void *data) {
struct wlr_wl_backend *wl = data; struct wlr_wl_backend *wl = data;
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
if (mask & WL_EVENT_ERROR) {
wlr_log(WLR_ERROR, "Failed to read from remote Wayland display");
} else {
wlr_log(WLR_DEBUG, "Disconnected from remote Wayland display");
}
wlr_backend_destroy(&wl->backend);
return 0;
}
int count = 0; int count = 0;
if (mask & WL_EVENT_READABLE) { if (mask & WL_EVENT_READABLE) {
count = wl_display_dispatch(wl->remote_display); count = wl_display_dispatch(wl->remote_display);
@ -77,6 +67,18 @@ static int dispatch_events(int fd, uint32_t mask, void *data) {
wl_display_flush(wl->remote_display); wl_display_flush(wl->remote_display);
} }
// Make sure we've consumed all data before disconnecting due to hangup,
// so that we process any wl_display.error events
if (!(mask & WL_EVENT_READABLE) && (mask & (WL_EVENT_HANGUP | WL_EVENT_ERROR))) {
if (mask & WL_EVENT_ERROR) {
wlr_log(WLR_ERROR, "Failed to read from remote Wayland display");
} else {
wlr_log(WLR_DEBUG, "Disconnected from remote Wayland display");
}
wlr_backend_destroy(&wl->backend);
return 0;
}
if (count < 0) { if (count < 0) {
wlr_log(WLR_ERROR, "Failed to dispatch remote Wayland display"); wlr_log(WLR_ERROR, "Failed to dispatch remote Wayland display");
wlr_backend_destroy(&wl->backend); wlr_backend_destroy(&wl->backend);