From 1ac44cc286f6ce5cf1c129c1dcd9dcabdfb54e4c Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:22:35 +0100 Subject: [PATCH] modify poll return values --- R/later.R | 4 ++-- man/later_fd.Rd | 4 ++-- src/fd.cpp | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/R/later.R b/R/later.R index 5dc4c222..5b34fe9b 100644 --- a/R/later.R +++ b/R/later.R @@ -274,8 +274,8 @@ later <- function(func, delay = 0, loop = current_loop()) { #' @param func A function that takes a single argument, a logical vector that #' indicates which file descriptors are ready (a concatenation of `readfds`, #' `writefds` and `exceptfds`). This may be all `FALSE` if the -#' `timeout` argument is non-`Inf`. Invalid file descriptors or those with -#' exceptions will be returned as `NA`. +#' `timeout` argument is non-`Inf`. Invalid file descriptors and those with +#' activity other than the monitored type will be returned as `NA`. #' @param readfds Integer vector of file descriptors, or Windows `SOCKET`s to #' monitor for read activity. #' @param writefds Integer vector of file descriptors, or Windows `SOCKET`s to diff --git a/man/later_fd.Rd b/man/later_fd.Rd index 23d04dc6..fc2887c6 100644 --- a/man/later_fd.Rd +++ b/man/later_fd.Rd @@ -17,8 +17,8 @@ later_fd( \item{func}{A function that takes a single argument, a logical vector that indicates which file descriptors are ready (a concatenation of \code{readfds}, \code{writefds} and \code{exceptfds}). This may be all \code{FALSE} if the -\code{timeout} argument is non-\code{Inf}. Invalid file descriptors or those with -exceptions will be returned as \code{NA}.} +\code{timeout} argument is non-\code{Inf}. Invalid file descriptors and those with +activity other than the monitored type will be returned as \code{NA}.} \item{readfds}{Integer vector of file descriptors, or Windows \code{SOCKET}s to monitor for read activity.} diff --git a/src/fd.cpp b/src/fd.cpp index 4f8d3bab..7a6ebf17 100644 --- a/src/fd.cpp +++ b/src/fd.cpp @@ -139,8 +139,14 @@ static int wait_thread(void *arg) { values = (int *) DATAPTR_RO(CADR(args->callback)); if (result > 0) { - for (int i = 0; i < args->num_fds; i++) { - values[i] = pollfds[i].revents & (POLLIN | POLLOUT) ? 1 : pollfds[i].revents & (POLLNVAL | POLLHUP | POLLERR) ? R_NaInt : 0; + for (int i = 0; i < args->rfds; i++) { + values[i] = pollfds[i].revents & POLLIN ? 1 : pollfds[i].revents & (POLLNVAL | POLLHUP | POLLERR) ? R_NaInt : 0; + } + for (int i = args->rfds; i < (args->rfds + args->wfds); i++) { + values[i] = pollfds[i].revents & POLLOUT ? 1 : pollfds[i].revents & (POLLNVAL | POLLHUP | POLLERR) ? R_NaInt : 0; + } + for (int i = args->rfds + args->wfds; i < args->num_fds; i++) { + values[i] = pollfds[i].revents != 0; } } else if (result == 0) { std::memset(values, 0, args->num_fds * sizeof(int));