| 244 | } |
| 245 | |
| 246 | static int aeApiPoll(aeEventLoop *eventLoop, struct timeval *tvp) { |
| 247 | aeApiState *state = eventLoop->apidata; |
| 248 | struct timespec timeout, *tsp; |
| 249 | uint_t mask, i; |
| 250 | uint_t nevents; |
| 251 | port_event_t event[MAX_EVENT_BATCHSZ]; |
| 252 | |
| 253 | /* |
| 254 | * If we've returned fd events before, we must re-associate them with the |
| 255 | * port now, before calling port_get(). See the block comment at the top of |
| 256 | * this file for an explanation of why. |
| 257 | */ |
| 258 | for (i = 0; i < state->npending; i++) { |
| 259 | if (state->pending_fds[i] == -1) |
| 260 | /* This fd has since been deleted. */ |
| 261 | continue; |
| 262 | |
| 263 | if (aeApiAssociate("aeApiPoll", state->portfd, |
| 264 | state->pending_fds[i], state->pending_masks[i]) != 0) { |
| 265 | /* See aeApiDelEvent for why this case is fatal. */ |
| 266 | abort(); |
| 267 | } |
| 268 | |
| 269 | state->pending_masks[i] = AE_NONE; |
| 270 | state->pending_fds[i] = -1; |
| 271 | } |
| 272 | |
| 273 | state->npending = 0; |
| 274 | |
| 275 | if (tvp != NULL) { |
| 276 | timeout.tv_sec = tvp->tv_sec; |
| 277 | timeout.tv_nsec = tvp->tv_usec * 1000; |
| 278 | tsp = &timeout; |
| 279 | } else { |
| 280 | tsp = NULL; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * port_getn can return with errno == ETIME having returned some events (!). |
| 285 | * So if we get ETIME, we check nevents, too. |
| 286 | */ |
| 287 | nevents = 1; |
| 288 | if (port_getn(state->portfd, event, MAX_EVENT_BATCHSZ, &nevents, |
| 289 | tsp) == -1 && (errno != ETIME || nevents == 0)) { |
| 290 | if (errno == ETIME || errno == EINTR) |
| 291 | return 0; |
| 292 | |
| 293 | /* Any other error indicates a bug. */ |
| 294 | perror("aeApiPoll: port_get"); |
| 295 | abort(); |
| 296 | } |
| 297 | |
| 298 | state->npending = nevents; |
| 299 | |
| 300 | for (i = 0; i < nevents; i++) { |
| 301 | mask = 0; |
| 302 | if (event[i].portev_events & POLLIN) |
| 303 | mask |= AE_READABLE; |
nothing calls this directly
no test coverage detected