diff options
| author | rubin <rubinowyblask@meow.li> | 2026-05-24 14:03:13 +0200 |
|---|---|---|
| committer | rubin <rubinowyblask@meow.li> | 2026-05-24 14:03:13 +0200 |
| commit | 68b638e3a5c58ea122f3dfad706cdbc13f8ead01 (patch) | |
| tree | 45dd574bf3dcb7c7724f4a3c98457e5a6de7a95c | |
| parent | 30d15a7d087a1bcb2f48537a5e0cca5ac5b406d1 (diff) | |
implement fdwatcher remove operation nyan
Signed-off-by: rubin <rubinowyblask@meow.li>
| -rw-r--r-- | fdwatcher.c | 26 |
1 files changed, 24 insertions, 2 deletions
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; } + + |
