X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/0ff9ea389c749836c7c6f23f1e654bc9a5600ebf..1957695ce47dd93c30efc48ca1f272a34c732841:/unix/uxsel.c diff --git a/unix/uxsel.c b/unix/uxsel.c index aaedc022..0383faa6 100644 --- a/unix/uxsel.c +++ b/unix/uxsel.c @@ -19,6 +19,7 @@ struct fd { int fd; int rwx; /* 4=except 2=write 1=read */ uxsel_callback_fn callback; + int id; /* for uxsel_input_remove */ }; static tree234 *fds; @@ -70,17 +71,20 @@ void uxsel_set(int fd, int rwx, uxsel_callback_fn callback) oldfd = find234(fds, newfd, NULL); if (oldfd) { + uxsel_input_remove(oldfd->id); del234(fds, oldfd); sfree(oldfd); } add234(fds, newfd); + newfd->id = uxsel_input_add(fd, rwx); } void uxsel_del(int fd) { struct fd *oldfd = find234(fds, &fd, uxsel_fd_findcmp); if (oldfd) { + uxsel_input_remove(oldfd->id); del234(fds, oldfd); sfree(oldfd); } @@ -111,6 +115,13 @@ int first_fd(int *state, int *rwx) int select_result(int fd, int event) { struct fd *fdstruct = find234(fds, &fd, uxsel_fd_findcmp); - assert(fdstruct != NULL); - return fdstruct->callback(fd, event); + /* + * Apparently this can sometimes be NULL. Can't see how, but I + * assume it means I need to ignore the event since it's on an + * fd I've stopped being interested in. Sigh. + */ + if (fdstruct) + return fdstruct->callback(fd, event); + else + return 1; }