Sorry to spam, but here is an improved version: for (i = 0; i < num; i++) { apr_os_sock_t fd; aprset[i].rtnevents = 0; /* Always clear events */ if (aprset[i].desc_type == APR_POLL_SOCKET) { fd = aprset[i].desc.s->socketdes; } else if (aprset[i].desc_type == APR_NO_DESC) { continue; /* No-op socket OK */ } #if APR_FILES_AS_SOCKETS if (aprset[i].desc_type == APR_POLL_FILE) { fd = aprset[i].desc.f->filedes; } #endif else { return APR_EBADF; /* Unknown fd type */ } if (FD_ISSET(fd, &readset)) { aprset[i].rtnevents |= APR_POLLIN; } if (FD_ISSET(fd, &writeset)) { aprset[i].rtnevents |= APR_POLLOUT; } if (FD_ISSET(fd, &exceptset)) { aprset[i].rtnevents |= APR_POLLERR; } } return APR_SUCCESS; }