| 260 | } |
| 261 | |
| 262 | duk_size_t duk_trans_socket_peek_cb(void *udata) { |
| 263 | #if defined(USE_SELECT) |
| 264 | struct timeval tm; |
| 265 | fd_set rfds; |
| 266 | int select_rc; |
| 267 | #else |
| 268 | struct pollfd fds[1]; |
| 269 | int poll_rc; |
| 270 | #endif |
| 271 | |
| 272 | (void) udata; /* not needed by the example */ |
| 273 | |
| 274 | #if defined(DEBUG_PRINTS) |
| 275 | fprintf(stderr, "%s: udata=%p\n", __func__, (void *) udata); |
| 276 | fflush(stderr); |
| 277 | #endif |
| 278 | |
| 279 | if (client_sock < 0) { |
| 280 | return 0; |
| 281 | } |
| 282 | #if defined(USE_SELECT) |
| 283 | FD_ZERO(&rfds); |
| 284 | FD_SET(client_sock, &rfds); |
| 285 | tm.tv_sec = tm.tv_usec = 0; |
| 286 | select_rc = select(client_sock + 1, &rfds, NULL, NULL, &tm); |
| 287 | if (select_rc == 0) { |
| 288 | return 0; |
| 289 | } else if (select_rc == 1) { |
| 290 | return 1; |
| 291 | } |
| 292 | goto fail; |
| 293 | #else /* USE_SELECT */ |
| 294 | fds[0].fd = client_sock; |
| 295 | fds[0].events = POLLIN; |
| 296 | fds[0].revents = 0; |
| 297 | |
| 298 | poll_rc = poll(fds, 1, 0); |
| 299 | if (poll_rc < 0) { |
| 300 | fprintf(stderr, "%s: poll returned < 0, closing connection: %s\n", |
| 301 | __FILE__, strerror(errno)); |
| 302 | fflush(stderr); |
| 303 | goto fail; /* also returns 0, which is correct */ |
| 304 | } else if (poll_rc > 1) { |
| 305 | fprintf(stderr, "%s: poll returned > 1, treating like 1\n", |
| 306 | __FILE__); |
| 307 | fflush(stderr); |
| 308 | return 1; /* should never happen */ |
| 309 | } else if (poll_rc == 0) { |
| 310 | return 0; /* nothing to read */ |
| 311 | } else { |
| 312 | return 1; /* something to read */ |
| 313 | } |
| 314 | #endif /* USE_SELECT */ |
| 315 | fail: |
| 316 | if (client_sock >= 0) { |
| 317 | (void) close(client_sock); |
| 318 | client_sock = -1; |
| 319 | } |
nothing calls this directly
no outgoing calls
no test coverage detected