From 68b638e3a5c58ea122f3dfad706cdbc13f8ead01 Mon Sep 17 00:00:00 2001 From: rubin Date: Sun, 24 May 2026 14:03:13 +0200 Subject: implement fdwatcher remove operation Signed-off-by: rubin --- fdwatcher.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'fdwatcher.c') diff --git a/fdwatcher.c b/fdwatcher.c index a25d83d..25342ae 100644 --- a/fdwatcher.c +++ b/fdwatcher.c @@ -120,9 +120,31 @@ fdwatcher_watch(struct FDWatchHandle *handle, int (*meow)(struct FDWatchHandle * return 0; } -/* TODO */ +/* + * this isn't an atomic operation + */ int fdwatcher_remove(struct FDWatchHandle *handle, int fd) { - abort(); + struct pollfd *currPollie = NULL; + struct pollfd *lastPollie = NULL; + size_t i = 0; + + while (1) { + if (i == handle->maxWatchedFds) return -EINVAL; + if (handle->watchedFds->fd != fd) continue; + break; + + i++; + } + + lastPollie = &handle->watchedFds[handle->watchedFdCount - 1]; + currPollie = &handle->watchedFds[i]; + + memcpy(currPollie, lastPollie, sizeof(struct pollfd)); + memset(lastPollie, 0, sizeof(struct pollfd)); + + return 0; } + + -- cgit 1.4.1