13 #include "../../include/ecl/io/poll.hpp" 26 #if defined(ECL_IS_WIN32) 27 fd_set readfds, writefds, exceptfds;
28 struct timeval tv, *ptv;
46 for (rc = -1, max_fd = 0, i = 0; i < nfds; i++) {
47 if (fds[i].fd == INVALID_SOCKET) {
50 if (fds[i].events & (POLLIN | POLLRDNORM)) {
51 FD_SET (fds[i].fd, &readfds);
53 if (fds[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND)) {
54 FD_SET (fds[i].fd, &writefds);
56 if (fds[i].events & (POLLPRI | POLLRDBAND)) {
57 FD_SET (fds[i].fd, &exceptfds);
59 if (fds[i].fd > max_fd &&
60 (fds[i].events & (POLLIN | POLLOUT | POLLPRI |
61 POLLRDNORM | POLLRDBAND |
62 POLLWRNORM | POLLWRBAND))) {
83 tv.tv_sec = timeout / 1000;
84 tv.tv_usec = (timeout % 1000) * 1000;
88 rc = select (max_fd + 1, &readfds, &writefds, &exceptfds, ptv);
91 }
else if ( rc == 0 ) {
95 for (rc = 0, i = 0; i < nfds; i++) {
96 if (fds[i].fd != INVALID_SOCKET) {
99 if (FD_ISSET(fds[i].fd, &readfds)) {
100 int save_errno = errno;
106 ret = recv(fds[i].fd, data, 64, MSG_PEEK);
109 (errno == WSAESHUTDOWN || errno == WSAECONNRESET ||
110 (errno == WSAECONNABORTED) || errno == WSAENETRESET))
113 (errno == ESHUTDOWN || errno == ECONNRESET ||
114 (errno == ECONNABORTED) || errno == ENETRESET))
117 fds[i].revents |= POLLHUP;
119 fds[i].revents |= fds[i].events & (POLLIN | POLLRDNORM);
123 if (FD_ISSET(fds[i].fd, &writefds)) {
124 fds[i].revents |= fds[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND);
127 if (FD_ISSET(fds[i].fd, &exceptfds)) {
128 fds[i].revents |= fds[i].events & (POLLPRI | POLLRDBAND);
131 if (fds[i].revents & ~POLLHUP) {
135 fds[i].revents = POLLNVAL;
144 int result = poll(fds, nfds, timeout);
152 #endif // poll_sockets functions
int socket_descriptor
Cross-platform typedef for a socket file descriptor.
struct pollfd socket_pollfd
ecl_io_PUBLIC int poll_sockets(socket_pollfd *fds, nfds_t nfds, int timeout)