| 75 | } |
| 76 | |
| 77 | static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) { |
| 78 | aeApiState *state = eventLoop->apidata; |
| 79 | int retval, j, numevents = 0; |
| 80 | |
| 81 | memcpy(&state->_rfds,&state->rfds,sizeof(fd_set)); |
| 82 | memcpy(&state->_wfds,&state->wfds,sizeof(fd_set)); |
| 83 | |
| 84 | retval = select(eventLoop->maxfd+1, |
| 85 | &state->_rfds,&state->_wfds,NULL,tvp); |
| 86 | if (retval > 0) { |
| 87 | for (j = 0; j <= eventLoop->maxfd; j++) { |
| 88 | int mask = 0; |
| 89 | aeFileEvent *fe = &eventLoop->events[j]; |
| 90 | |
| 91 | if (fe->mask == AE_NONE) continue; |
| 92 | if (fe->mask & AE_READABLE && FD_ISSET(j,&state->_rfds)) |
| 93 | mask |= AE_READABLE; |
| 94 | if (fe->mask & AE_WRITABLE && FD_ISSET(j,&state->_wfds)) |
| 95 | mask |= AE_WRITABLE; |
| 96 | eventLoop->fired[numevents].fd = j; |
| 97 | eventLoop->fired[numevents].mask = mask; |
| 98 | numevents++; |
| 99 | } |
| 100 | } |
| 101 | return numevents; |
| 102 | } |
| 103 | |
| 104 | static char *aeApiName(void) { |
| 105 | return "select"; |