Skip to content
Myr

wayland: improve wayl_flush()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Handle errors * Try to read and dispatch on EPIPE, to print the protocol error that likely was the cause for the closed socket. * Handle EINTR+EAGAIN

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 6d38404 · Browse files · 1 file+50 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+50 added−1 removed

  • other:+50 added−1 removed

1 file+50 added−1 removed

modified:wayland.c+50 added-1 removed
8 unmodified lines
9#include <locale.h>1011#include <sys/mman.h>12#include <sys/epoll.h>13#include <sys/poll.h>14#include <sys/timerfd.h>1516#include <wayland-client.h>17#include <wayland-cursor.h>
2488 unmodified lines
25062507void2508wayl_flush(struct wayland *wayl)2509{2510 while (true) {2509 wl_display_flush(wayl->display);2511 int r = wl_display_flush(wayl->display);2512 if (r >= 0) {2513 /* Most likely code path - the flush succeed */2514 return;2515 }25162517 if (errno == EINTR) {2518 /* Unlikely */2519 continue;2520 }25212522 if (errno != EAGAIN) {2523 const int saved_errno = errno;25242525 if (errno == EPIPE) {2526 wl_display_read_events(wayl->display);2527 wl_display_dispatch_pending(wayl->display);2528 }25292530 LOG_ERRNO_P("failed to flush wayland socket", saved_errno);2531 return;2532 }25332534 /* Socket buffer is full - need to wait for it to become2535 writeable again */2536 assert(errno == EAGAIN);25372538 while (true) {2539 int wayl_fd = wl_display_get_fd(wayl->display);2540 struct pollfd fds[] = {{.fd = wayl_fd, .events = POLLOUT}};25412542 r = poll(fds, sizeof(fds) / sizeof(fds[0]), -1);25432544 if (r < 0) {2545 if (errno == EINTR)2546 continue;25472548 LOG_ERRNO("failed to poll");2549 return;2550 }25512552 if (fds[0].revents & POLLHUP)2553 return;25542555 assert(fds[0].revents & POLLOUT);2556 break;2557 }2558 }2559}25602561int2562wayl_exit_code(const struct wayland *wayl)
22 unmodified lines