Skip to content

Commit

Permalink
modify poll return values
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Oct 25, 2024
1 parent cd8c5e0 commit 1ac44cc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions R/later.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions man/later_fd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/fd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1ac44cc

Please sign in to comment.