| 25 | #define WAITFD_W POLLOUT |
| 26 | #define WAITFD_C (POLLIN|POLLOUT) |
| 27 | int socket_waitfd(p_socket ps, int sw, p_timeout tm) { |
| 28 | int ret; |
| 29 | struct pollfd pfd; |
| 30 | pfd.fd = *ps; |
| 31 | pfd.events = sw; |
| 32 | pfd.revents = 0; |
| 33 | if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */ |
| 34 | do { |
| 35 | int t = (int)(timeout_getretry(tm)*1e3); |
| 36 | ret = poll(&pfd, 1, t >= 0? t: -1); |
| 37 | } while (ret == -1 && errno == EINTR); |
| 38 | if (ret == -1) return errno; |
| 39 | if (ret == 0) return IO_TIMEOUT; |
| 40 | if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED; |
| 41 | return IO_DONE; |
| 42 | } |
| 43 | #else |
| 44 | |
| 45 | #define WAITFD_R 1 |
no test coverage detected