mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-29 06:46:35 -04:00
fdm: use poll(3) instead of epoll_wait(2)
poll() is more portable, and since foot doesn’t use _that_ many FDs, there should be no noticeable performance difference between the two.
This commit is contained in:
parent
e19db15104
commit
4fa4d54d2b
9 changed files with 204 additions and 165 deletions
|
|
@ -49,6 +49,7 @@
|
|||
|
||||
### Changed
|
||||
|
||||
* Use `poll()` instead of `epoll_wait()`.
|
||||
* The fcft and tllist library subprojects are now handled via Meson
|
||||
[wrap files](https://mesonbuild.com/Wrap-dependency-system-manual.html)
|
||||
instead of needing to be manually cloned.
|
||||
|
|
|
|||
258
fdm.c
258
fdm.c
|
|
@ -3,11 +3,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/epoll.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <tllist.h>
|
||||
|
||||
|
|
@ -15,13 +15,16 @@
|
|||
#define LOG_ENABLE_DBG 0
|
||||
#include "log.h"
|
||||
#include "debug.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
struct handler {
|
||||
int fd;
|
||||
int events;
|
||||
enum {
|
||||
HANDLER_ACTIVE,
|
||||
HANDLER_DEFERRED_DELETE,
|
||||
HANDLER_DEFERRED_DELETE_AND_CLOSE
|
||||
} status;
|
||||
fdm_handler_t callback;
|
||||
void *callback_data;
|
||||
bool deleted;
|
||||
};
|
||||
|
||||
struct hook {
|
||||
|
|
@ -32,35 +35,54 @@ struct hook {
|
|||
typedef tll(struct hook) hooks_t;
|
||||
|
||||
struct fdm {
|
||||
int epoll_fd;
|
||||
bool is_polling;
|
||||
tll(struct handler *) fds;
|
||||
tll(struct handler *) deferred_delete;
|
||||
/*
|
||||
* Paired arrays of poll() data and the associated callbacks.
|
||||
*
|
||||
* Both arrays have <size> number of elements. The first <count>
|
||||
* elements are valid/in use.
|
||||
*
|
||||
* <max_count> is for debugging/statistics, and tracks the maximum
|
||||
* number of simultaniously active FDs.
|
||||
*/
|
||||
struct pollfd *fds;
|
||||
struct handler *handlers;
|
||||
size_t count;
|
||||
size_t size;
|
||||
size_t max_count;
|
||||
|
||||
hooks_t hooks_low;
|
||||
hooks_t hooks_normal;
|
||||
hooks_t hooks_high;
|
||||
bool is_polling;
|
||||
};
|
||||
|
||||
static const size_t min_slot_count = 32;
|
||||
|
||||
struct fdm *
|
||||
fdm_init(void)
|
||||
{
|
||||
int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (epoll_fd == -1) {
|
||||
LOG_ERRNO("failed to create epoll FD");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fdm *fdm = malloc(sizeof(*fdm));
|
||||
if (unlikely(fdm == NULL)) {
|
||||
LOG_ERRNO("malloc() failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct pollfd *fds = malloc(min_slot_count * sizeof(fds[0]));
|
||||
struct handler *handlers = malloc(min_slot_count * sizeof(handlers[0]));
|
||||
|
||||
if (fds == NULL || handlers == NULL) {
|
||||
LOG_ERRNO("failed to allocate initial array of FD handlers");
|
||||
free(handlers);
|
||||
free(fds);
|
||||
free(fdm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*fdm = (struct fdm){
|
||||
.epoll_fd = epoll_fd,
|
||||
.is_polling = false,
|
||||
.fds = tll_init(),
|
||||
.deferred_delete = tll_init(),
|
||||
.fds = fds,
|
||||
.handlers = handlers,
|
||||
.size = min_slot_count,
|
||||
.hooks_low = tll_init(),
|
||||
.hooks_normal = tll_init(),
|
||||
.hooks_high = tll_init(),
|
||||
|
|
@ -74,7 +96,9 @@ fdm_destroy(struct fdm *fdm)
|
|||
if (fdm == NULL)
|
||||
return;
|
||||
|
||||
if (tll_length(fdm->fds) > 0)
|
||||
LOG_DBG("max FDs registered: %zu", fdm->max_count);
|
||||
|
||||
if (fdm->count > 0)
|
||||
LOG_WARN("FD list not empty");
|
||||
|
||||
if (tll_length(fdm->hooks_low) > 0 ||
|
||||
|
|
@ -84,34 +108,25 @@ fdm_destroy(struct fdm *fdm)
|
|||
LOG_WARN("hook list not empty");
|
||||
}
|
||||
|
||||
xassert(tll_length(fdm->fds) == 0);
|
||||
xassert(tll_length(fdm->deferred_delete) == 0);
|
||||
xassert(fdm->count == 0);
|
||||
xassert(tll_length(fdm->hooks_low) == 0);
|
||||
xassert(tll_length(fdm->hooks_normal) == 0);
|
||||
xassert(tll_length(fdm->hooks_high) == 0);
|
||||
|
||||
tll_free(fdm->fds);
|
||||
tll_free(fdm->deferred_delete);
|
||||
free(fdm->fds);
|
||||
free(fdm->handlers);
|
||||
tll_free(fdm->hooks_low);
|
||||
tll_free(fdm->hooks_normal);
|
||||
tll_free(fdm->hooks_high);
|
||||
close(fdm->epoll_fd);
|
||||
free(fdm);
|
||||
}
|
||||
|
||||
bool
|
||||
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
|
||||
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t cb, void *data)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
int flags = fcntl(fd, F_GETFL);
|
||||
if (!(flags & O_NONBLOCK)) {
|
||||
LOG_ERR("FD=%d is in blocking mode", fd);
|
||||
xassert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
tll_foreach(fdm->fds, it) {
|
||||
if (it->item->fd == fd) {
|
||||
for (size_t i = 0; i < fdm->count; i++) {
|
||||
if (fdm->fds[i].fd == fd) {
|
||||
LOG_ERR("FD=%d already registered", fd);
|
||||
xassert(false);
|
||||
return false;
|
||||
|
|
@ -119,65 +134,86 @@ fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
|
|||
}
|
||||
#endif
|
||||
|
||||
struct handler *fd_data = malloc(sizeof(*fd_data));
|
||||
if (unlikely(fd_data == NULL)) {
|
||||
LOG_ERRNO("malloc() failed");
|
||||
return false;
|
||||
if (fdm->count >= fdm->size) {
|
||||
/* No free slot - increase number of pollfds + handlers */
|
||||
|
||||
size_t old_size = fdm->size;
|
||||
size_t new_size = old_size * 2;
|
||||
|
||||
fdm->fds = xrealloc(fdm->fds, new_size * sizeof(fdm->fds[0]));
|
||||
fdm->handlers = xrealloc(fdm->handlers, new_size * sizeof(fdm->handlers[0]));
|
||||
fdm->size = new_size;
|
||||
}
|
||||
|
||||
*fd_data = (struct handler) {
|
||||
.fd = fd,
|
||||
.events = events,
|
||||
.callback = handler,
|
||||
.callback_data = data,
|
||||
.deleted = false,
|
||||
};
|
||||
xassert(fdm->count < fdm->size);
|
||||
|
||||
tll_push_back(fdm->fds, fd_data);
|
||||
struct pollfd *pfd = &fdm->fds[fdm->count];
|
||||
struct handler *handler = &fdm->handlers[fdm->count];
|
||||
|
||||
struct epoll_event ev = {
|
||||
.events = events,
|
||||
.data = {.ptr = fd_data},
|
||||
};
|
||||
pfd->fd = fd;
|
||||
pfd->events = events;
|
||||
|
||||
if (epoll_ctl(fdm->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
|
||||
LOG_ERRNO("failed to register FD=%d with epoll", fd);
|
||||
free(fd_data);
|
||||
tll_pop_back(fdm->fds);
|
||||
return false;
|
||||
}
|
||||
handler->callback = cb;
|
||||
handler->callback_data = data;
|
||||
handler->status = HANDLER_ACTIVE;
|
||||
|
||||
if (++fdm->count > fdm->max_count)
|
||||
fdm->max_count = fdm->count;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
deferred_delete(struct fdm *fdm, size_t idx)
|
||||
{
|
||||
xassert(!fdm->is_polling);
|
||||
xassert(idx < fdm->count);
|
||||
|
||||
struct handler *handler = &fdm->handlers[idx];
|
||||
xassert(fdm->handlers[idx].status != HANDLER_ACTIVE);
|
||||
|
||||
if (handler->status == HANDLER_DEFERRED_DELETE_AND_CLOSE) {
|
||||
xassert(fdm->fds[idx].fd >= 0);
|
||||
close(fdm->fds[idx].fd);
|
||||
}
|
||||
|
||||
const size_t remaining = fdm->count - (idx + 1);
|
||||
|
||||
memmove(&fdm->fds[idx], &fdm->fds[idx + 1],
|
||||
remaining * sizeof(fdm->fds[0]));
|
||||
|
||||
memmove(&fdm->handlers[idx], &fdm->handlers[idx + 1],
|
||||
remaining * sizeof(fdm->handlers[0]));
|
||||
|
||||
fdm->count--;
|
||||
}
|
||||
|
||||
static bool
|
||||
fdm_del_internal(struct fdm *fdm, int fd, bool close_fd)
|
||||
{
|
||||
if (fd == -1)
|
||||
return true;
|
||||
|
||||
tll_foreach(fdm->fds, it) {
|
||||
if (it->item->fd != fd)
|
||||
for (size_t i = 0; i < fdm->count; i++) {
|
||||
struct pollfd *pfd = &fdm->fds[i];
|
||||
struct handler *handler = &fdm->handlers[i];
|
||||
|
||||
if (pfd->fd != fd)
|
||||
continue;
|
||||
|
||||
if (epoll_ctl(fdm->epoll_fd, EPOLL_CTL_DEL, fd, NULL) < 0)
|
||||
LOG_ERRNO("failed to unregister FD=%d from epoll", fd);
|
||||
handler->status = close_fd
|
||||
? HANDLER_DEFERRED_DELETE_AND_CLOSE
|
||||
: HANDLER_DEFERRED_DELETE;
|
||||
|
||||
if (close_fd)
|
||||
close(it->item->fd);
|
||||
if (!fdm->is_polling)
|
||||
deferred_delete(fdm, i);
|
||||
|
||||
it->item->deleted = true;
|
||||
if (fdm->is_polling)
|
||||
tll_push_back(fdm->deferred_delete, it->item);
|
||||
else
|
||||
free(it->item);
|
||||
|
||||
tll_remove(fdm->fds, it);
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERR("no such FD: %d", fd);
|
||||
close(fd);
|
||||
if (close_fd)
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -193,35 +229,17 @@ fdm_del_no_close(struct fdm *fdm, int fd)
|
|||
return fdm_del_internal(fdm, fd, false);
|
||||
}
|
||||
|
||||
static bool
|
||||
event_modify(struct fdm *fdm, struct handler *fd, int new_events)
|
||||
{
|
||||
if (new_events == fd->events)
|
||||
return true;
|
||||
|
||||
struct epoll_event ev = {
|
||||
.events = new_events,
|
||||
.data = {.ptr = fd},
|
||||
};
|
||||
|
||||
if (epoll_ctl(fdm->epoll_fd, EPOLL_CTL_MOD, fd->fd, &ev) < 0) {
|
||||
LOG_ERRNO("failed to modify FD=%d with epoll (events 0x%08x -> 0x%08x)",
|
||||
fd->fd, fd->events, new_events);
|
||||
return false;
|
||||
}
|
||||
|
||||
fd->events = new_events;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
fdm_event_add(struct fdm *fdm, int fd, int events)
|
||||
{
|
||||
tll_foreach(fdm->fds, it) {
|
||||
if (it->item->fd != fd)
|
||||
for (size_t i = 0; i < fdm->count; i++) {
|
||||
struct pollfd *pfd = &fdm->fds[i];
|
||||
|
||||
if (pfd->fd != fd)
|
||||
continue;
|
||||
|
||||
return event_modify(fdm, it->item, it->item->events | events);
|
||||
pfd->events |= events;
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERR("FD=%d not registered with the FDM", fd);
|
||||
|
|
@ -231,11 +249,14 @@ fdm_event_add(struct fdm *fdm, int fd, int events)
|
|||
bool
|
||||
fdm_event_del(struct fdm *fdm, int fd, int events)
|
||||
{
|
||||
tll_foreach(fdm->fds, it) {
|
||||
if (it->item->fd != fd)
|
||||
for (size_t i = 0; i < fdm->count; i++) {
|
||||
struct pollfd *pfd = &fdm->fds[i];
|
||||
|
||||
if (pfd->fd != fd)
|
||||
continue;
|
||||
|
||||
return event_modify(fdm, it->item, it->item->events & ~events);
|
||||
pfd->events &= ~events;
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERR("FD=%d not registered with the FDM", fd);
|
||||
|
|
@ -322,35 +343,52 @@ fdm_poll(struct fdm *fdm)
|
|||
it->item.callback(fdm, it->item.callback_data);
|
||||
}
|
||||
|
||||
struct epoll_event events[tll_length(fdm->fds)];
|
||||
|
||||
int r = epoll_wait(fdm->epoll_fd, events, tll_length(fdm->fds), -1);
|
||||
int r = poll(fdm->fds, fdm->count, -1);
|
||||
if (unlikely(r < 0)) {
|
||||
if (errno == EINTR)
|
||||
return true;
|
||||
|
||||
LOG_ERRNO("failed to epoll");
|
||||
LOG_ERRNO("failed to poll");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
|
||||
fdm->is_polling = true;
|
||||
for (int i = 0; i < r; i++) {
|
||||
struct handler *fd = events[i].data.ptr;
|
||||
if (fd->deleted)
|
||||
for (int i = 0, matched = 0; matched < r; i++) {
|
||||
xassert(i < fdm->count);
|
||||
|
||||
struct pollfd *pfd = &fdm->fds[i];
|
||||
if (pfd->revents == 0)
|
||||
continue;
|
||||
|
||||
if (!fd->callback(fdm, fd->fd, events[i].events, fd->callback_data)) {
|
||||
ret = false;
|
||||
break;
|
||||
matched++;
|
||||
|
||||
struct handler *handler = &fdm->handlers[i];
|
||||
if (handler->status == HANDLER_ACTIVE) {
|
||||
if (!handler->callback(
|
||||
fdm, pfd->fd, pfd->revents, handler->callback_data))
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fdm->is_polling = false;
|
||||
|
||||
tll_foreach(fdm->deferred_delete, it) {
|
||||
free(it->item);
|
||||
tll_remove(fdm->deferred_delete, it);
|
||||
size_t count = fdm->count;
|
||||
size_t i = 0;
|
||||
|
||||
while (i < count) {
|
||||
struct handler *handler = &fdm->handlers[i];
|
||||
if (handler->status == HANDLER_ACTIVE) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
deferred_delete(fdm, i);
|
||||
count--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
10
input.c
10
input.c
|
|
@ -6,10 +6,10 @@
|
|||
#include <threads.h>
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <linux/input-event-codes.h>
|
||||
|
|
@ -51,10 +51,10 @@ fdm_write_pipe(struct fdm *fdm, int fd, int events, void *data)
|
|||
{
|
||||
struct pipe_context *ctx = data;
|
||||
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
goto pipe_closed;
|
||||
|
||||
xassert(events & EPOLLOUT);
|
||||
xassert(events & POLLOUT);
|
||||
ssize_t written = write(fd, &ctx->text[ctx->idx], ctx->left);
|
||||
|
||||
if (written < 0) {
|
||||
|
|
@ -253,7 +253,7 @@ execute_binding(struct seat *seat, struct terminal *term,
|
|||
};
|
||||
|
||||
/* Asynchronously write the output to the pipe */
|
||||
if (!fdm_add(term->fdm, pipe_fd[1], EPOLLOUT, &fdm_write_pipe, ctx))
|
||||
if (!fdm_add(term->fdm, pipe_fd[1], POLLOUT, &fdm_write_pipe, ctx))
|
||||
goto pipe_err;
|
||||
|
||||
return true;
|
||||
|
|
@ -1611,7 +1611,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
|
|||
int fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
||||
if (fd >= 0 &&
|
||||
timerfd_settime(fd, 0, &timeout, NULL) == 0 &&
|
||||
fdm_add(wayl->fdm, fd, EPOLLIN, &fdm_csd_move, seat))
|
||||
fdm_add(wayl->fdm, fd, POLLIN, &fdm_csd_move, seat))
|
||||
{
|
||||
win->csd.move_timeout_fd = fd;
|
||||
win->csd.serial = serial;
|
||||
|
|
|
|||
8
reaper.c
8
reaper.c
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <poll.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <tllist.h>
|
||||
|
|
@ -60,7 +60,7 @@ reaper_init(struct fdm *fdm)
|
|||
.children = tll_init(),
|
||||
};
|
||||
|
||||
if (!fdm_add(fdm, fd, EPOLLIN, &fdm_reap, reaper)){
|
||||
if (!fdm_add(fdm, fd, POLLIN, &fdm_reap, reaper)){
|
||||
LOG_ERR("failed to register with the FDM");
|
||||
goto err;
|
||||
}
|
||||
|
|
@ -115,8 +115,8 @@ fdm_reap(struct fdm *fdm, int fd, int events, void *data)
|
|||
{
|
||||
struct reaper *reaper = data;
|
||||
|
||||
bool pollin = events & EPOLLIN;
|
||||
bool hup = events & EPOLLHUP;
|
||||
bool pollin = events & POLLIN;
|
||||
bool hup = events & POLLHUP;
|
||||
|
||||
if (hup && !pollin)
|
||||
return false;
|
||||
|
|
|
|||
6
render.c
6
render.c
|
|
@ -3,11 +3,11 @@
|
|||
#include <string.h>
|
||||
#include <wctype.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "macros.h"
|
||||
|
|
@ -2727,7 +2727,7 @@ fdm_tiocswinsz(struct fdm *fdm, int fd, int events, void *data)
|
|||
{
|
||||
struct terminal *term = data;
|
||||
|
||||
if (events & EPOLLIN)
|
||||
if (events & POLLIN)
|
||||
tiocswinsz(term);
|
||||
|
||||
fdm_del(fdm, fd);
|
||||
|
|
@ -2762,7 +2762,7 @@ send_dimensions_to_client(struct terminal *term)
|
|||
fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
||||
if (fd < 0)
|
||||
LOG_ERRNO("failed to create TIOCSWINSZ timer");
|
||||
else if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_tiocswinsz, term)) {
|
||||
else if (!fdm_add(term->fdm, fd, POLLIN, &fdm_tiocswinsz, term)) {
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
|
|
|
|||
22
selection.c
22
selection.c
|
|
@ -6,8 +6,8 @@
|
|||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <wctype.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#define LOG_MODULE "selection"
|
||||
|
|
@ -1106,7 +1106,7 @@ selection_primary_unset(struct seat *seat)
|
|||
static bool
|
||||
fdm_scroll_timer(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct terminal *term = data;
|
||||
|
|
@ -1159,7 +1159,7 @@ selection_start_scroll_timer(struct terminal *term, int interval_ns,
|
|||
goto err;
|
||||
}
|
||||
|
||||
if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_scroll_timer, term)) {
|
||||
if (!fdm_add(term->fdm, fd, POLLIN, &fdm_scroll_timer, term)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1223,7 +1223,7 @@ fdm_send(struct fdm *fdm, int fd, int events, void *data)
|
|||
{
|
||||
struct clipboard_send *ctx = data;
|
||||
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
goto done;
|
||||
|
||||
switch (async_write(fd, ctx->data, ctx->len, &ctx->idx)) {
|
||||
|
|
@ -1273,7 +1273,7 @@ send_clipboard_or_primary(struct seat *seat, int fd, const char *selection,
|
|||
.idx = 0,
|
||||
};
|
||||
|
||||
if (fdm_add(seat->wayl->fdm, fd, EPOLLOUT, &fdm_send, ctx))
|
||||
if (fdm_add(seat->wayl->fdm, fd, POLLOUT, &fdm_send, ctx))
|
||||
return;
|
||||
|
||||
free(ctx->data);
|
||||
|
|
@ -1471,10 +1471,10 @@ static bool
|
|||
fdm_receive_timeout(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
struct clipboard_receive *ctx = data;
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
xassert(events & EPOLLIN);
|
||||
xassert(events & POLLIN);
|
||||
|
||||
uint64_t expire_count;
|
||||
ssize_t ret = read(fd, &expire_count, sizeof(expire_count));
|
||||
|
|
@ -1582,7 +1582,7 @@ fdm_receive(struct fdm *fdm, int fd, int events, void *data)
|
|||
{
|
||||
struct clipboard_receive *ctx = data;
|
||||
|
||||
if ((events & EPOLLHUP) && !(events & EPOLLIN))
|
||||
if ((events & POLLHUP) && !(events & POLLIN))
|
||||
goto done;
|
||||
|
||||
/* Reset timeout timer */
|
||||
|
|
@ -1716,8 +1716,8 @@ begin_receive_clipboard(struct terminal *term, int read_fd,
|
|||
.user = user,
|
||||
};
|
||||
|
||||
if (!fdm_add(term->fdm, read_fd, EPOLLIN, &fdm_receive, ctx) ||
|
||||
!fdm_add(term->fdm, timeout_fd, EPOLLIN, &fdm_receive_timeout, ctx))
|
||||
if (!fdm_add(term->fdm, read_fd, POLLIN, &fdm_receive, ctx) ||
|
||||
!fdm_add(term->fdm, timeout_fd, POLLIN, &fdm_receive_timeout, ctx))
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
|
@ -1787,7 +1787,7 @@ receive_offer_done(void *user)
|
|||
|
||||
/* Make sure we send any queued up non-paste data */
|
||||
if (tll_length(term->ptmx_buffers) > 0)
|
||||
fdm_event_add(term->fdm, term->ptmx, EPOLLOUT);
|
||||
fdm_event_add(term->fdm, term->ptmx, POLLOUT);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
12
server.c
12
server.c
|
|
@ -3,10 +3,10 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#include <sys/un.h>
|
||||
|
||||
|
|
@ -120,10 +120,10 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
|
|||
|
||||
char **argv = NULL;
|
||||
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
goto shutdown;
|
||||
|
||||
xassert(events & EPOLLIN);
|
||||
xassert(events & POLLIN);
|
||||
|
||||
if (client->term != NULL) {
|
||||
uint8_t dummy[128];
|
||||
|
|
@ -299,7 +299,7 @@ shutdown:
|
|||
static bool
|
||||
fdm_server(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct server *server = data;
|
||||
|
|
@ -320,7 +320,7 @@ fdm_server(struct fdm *fdm, int fd, int events, void *data)
|
|||
.fd = client_fd,
|
||||
};
|
||||
|
||||
if (!fdm_add(server->fdm, client_fd, EPOLLIN, &fdm_client, client)) {
|
||||
if (!fdm_add(server->fdm, client_fd, POLLIN, &fdm_client, client)) {
|
||||
close(client_fd);
|
||||
free(client);
|
||||
return false;
|
||||
|
|
@ -422,7 +422,7 @@ server_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
.clients = tll_init(),
|
||||
};
|
||||
|
||||
if (!fdm_add(fdm, fd, EPOLLIN, &fdm_server, server))
|
||||
if (!fdm_add(fdm, fd, POLLIN, &fdm_server, server))
|
||||
goto err;
|
||||
|
||||
LOG_INFO("accepting connections on %s", sock_path);
|
||||
|
|
|
|||
38
terminal.c
38
terminal.c
|
|
@ -7,11 +7,11 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -84,7 +84,7 @@ data_to_slave(struct terminal *term, const void *data, size_t len,
|
|||
switch (async_write(term->ptmx, data, len, &async_idx)) {
|
||||
case ASYNC_WRITE_REMAIN:
|
||||
/* Switch to asynchronous mode; let FDM write the remaining data */
|
||||
if (!fdm_event_add(term->fdm, term->ptmx, EPOLLOUT))
|
||||
if (!fdm_event_add(term->fdm, term->ptmx, POLLOUT))
|
||||
return false;
|
||||
enqueue_data_for_slave(data, len, async_idx, buffer_list);
|
||||
return true;
|
||||
|
|
@ -196,7 +196,7 @@ fdm_ptmx_out(struct fdm *fdm, int fd, int events, void *data)
|
|||
* otherwise we'd just be called right away again, with nothing to
|
||||
* write.
|
||||
*/
|
||||
fdm_event_del(term->fdm, term->ptmx, EPOLLOUT);
|
||||
fdm_event_del(term->fdm, term->ptmx, POLLOUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -213,9 +213,9 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
|
|||
{
|
||||
struct terminal *term = data;
|
||||
|
||||
const bool pollin = events & EPOLLIN;
|
||||
const bool pollout = events & EPOLLOUT;
|
||||
const bool hup = events & EPOLLHUP;
|
||||
const bool pollin = events & POLLIN;
|
||||
const bool pollout = events & POLLOUT;
|
||||
const bool hup = events & POLLHUP;
|
||||
|
||||
if (pollout) {
|
||||
if (!fdm_ptmx_out(fdm, fd, events, data))
|
||||
|
|
@ -330,7 +330,7 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
|
|||
static bool
|
||||
fdm_flash(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct terminal *term = data;
|
||||
|
|
@ -358,7 +358,7 @@ fdm_flash(struct fdm *fdm, int fd, int events, void *data)
|
|||
static bool
|
||||
fdm_blink(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct terminal *term = data;
|
||||
|
|
@ -421,7 +421,7 @@ term_arm_blink_timer(struct terminal *term)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_blink, term)) {
|
||||
if (!fdm_add(term->fdm, fd, POLLIN, &fdm_blink, term)) {
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
|
@ -450,7 +450,7 @@ cursor_refresh(struct terminal *term)
|
|||
static bool
|
||||
fdm_cursor_blink(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct terminal *term = data;
|
||||
|
|
@ -480,7 +480,7 @@ fdm_cursor_blink(struct fdm *fdm, int fd, int events, void *data)
|
|||
static bool
|
||||
fdm_delayed_render(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct terminal *term = data;
|
||||
|
|
@ -528,7 +528,7 @@ static bool
|
|||
fdm_app_sync_updates_timeout(
|
||||
struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct terminal *term = data;
|
||||
|
|
@ -1063,10 +1063,10 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
* size (and thus no grid) before then.
|
||||
*/
|
||||
|
||||
if (!fdm_add(fdm, flash_fd, EPOLLIN, &fdm_flash, term) ||
|
||||
!fdm_add(fdm, delay_lower_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
||||
!fdm_add(fdm, delay_upper_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
||||
!fdm_add(fdm, app_sync_updates_fd, EPOLLIN, &fdm_app_sync_updates_timeout, term))
|
||||
if (!fdm_add(fdm, flash_fd, POLLIN, &fdm_flash, term) ||
|
||||
!fdm_add(fdm, delay_lower_fd, POLLIN, &fdm_delayed_render, term) ||
|
||||
!fdm_add(fdm, delay_upper_fd, POLLIN, &fdm_delayed_render, term) ||
|
||||
!fdm_add(fdm, app_sync_updates_fd, POLLIN, &fdm_app_sync_updates_timeout, term))
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
|
@ -1274,7 +1274,7 @@ term_window_configured(struct terminal *term)
|
|||
/* Enable ptmx FDM callback */
|
||||
if (!term->is_shutting_down) {
|
||||
xassert(term->window->is_configured);
|
||||
fdm_add(term->fdm, term->ptmx, EPOLLIN, &fdm_ptmx, term);
|
||||
fdm_add(term->fdm, term->ptmx, POLLIN, &fdm_ptmx, term);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1362,7 +1362,7 @@ term_shutdown(struct terminal *term)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!fdm_add(term->fdm, event_fd, EPOLLIN, &fdm_shutdown, term)) {
|
||||
if (!fdm_add(term->fdm, event_fd, POLLIN, &fdm_shutdown, term)) {
|
||||
close(event_fd);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -2038,7 +2038,7 @@ cursor_blink_rearm_timer(struct terminal *term)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!fdm_add(term->fdm, fd, EPOLLIN, &fdm_cursor_blink, term)) {
|
||||
if (!fdm_add(term->fdm, fd, POLLIN, &fdm_cursor_blink, term)) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
12
wayland.c
12
wayland.c
|
|
@ -6,9 +6,9 @@
|
|||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-cursor.h>
|
||||
|
|
@ -770,7 +770,7 @@ static const struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration
|
|||
static bool
|
||||
fdm_repeat(struct fdm *fdm, int fd, int events, void *data)
|
||||
{
|
||||
if (events & EPOLLHUP)
|
||||
if (events & POLLHUP)
|
||||
return false;
|
||||
|
||||
struct seat *seat = data;
|
||||
|
|
@ -879,7 +879,7 @@ handle_global(void *data, struct wl_registry *registry,
|
|||
|
||||
struct seat *seat = &tll_back(wayl->seats);
|
||||
|
||||
if (!fdm_add(wayl->fdm, repeat_fd, EPOLLIN, &fdm_repeat, seat)) {
|
||||
if (!fdm_add(wayl->fdm, repeat_fd, POLLIN, &fdm_repeat, seat)) {
|
||||
close(repeat_fd);
|
||||
seat->kbd.repeat.fd = -1;
|
||||
seat_destroy(seat);
|
||||
|
|
@ -1092,7 +1092,7 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data)
|
|||
struct wayland *wayl = data;
|
||||
int event_count = 0;
|
||||
|
||||
if (events & EPOLLIN) {
|
||||
if (events & POLLIN) {
|
||||
if (wl_display_read_events(wayl->display) < 0) {
|
||||
LOG_ERRNO("failed to read events from the Wayland socket");
|
||||
return false;
|
||||
|
|
@ -1102,7 +1102,7 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data)
|
|||
wl_display_dispatch_pending(wayl->display);
|
||||
}
|
||||
|
||||
if (events & EPOLLHUP) {
|
||||
if (events & POLLHUP) {
|
||||
LOG_WARN("disconnected from Wayland");
|
||||
wl_display_cancel_read(wayl->display);
|
||||
return false;
|
||||
|
|
@ -1206,7 +1206,7 @@ wayl_init(const struct config *conf, struct fdm *fdm)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (!fdm_add(fdm, wayl->fd, EPOLLIN, &fdm_wayl, wayl))
|
||||
if (!fdm_add(fdm, wayl->fd, POLLIN, &fdm_wayl, wayl))
|
||||
goto out;
|
||||
|
||||
if (wl_display_prepare_read(wayl->display) != 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue