diff options
Diffstat (limited to 'fdwatcher.c')
| -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; } + + |
