| 39 | } |
| 40 | |
| 41 | int acl_write_wait_ms(ACL_SOCKET fd, int timeout) |
| 42 | { |
| 43 | const char *myname = "acl_write_wait"; |
| 44 | struct pollfd fds; |
| 45 | int delay = timeout; |
| 46 | #if 0 |
| 47 | time_t begin, end; |
| 48 | #endif |
| 49 | |
| 50 | fds.events = POLLOUT; |
| 51 | fds.revents = 0; |
| 52 | fds.fd = fd; |
| 53 | |
| 54 | #if 0 |
| 55 | begin = time(NULL); |
| 56 | #endif |
| 57 | |
| 58 | for (;;) { |
| 59 | switch (__sys_poll(&fds, 1, delay)) { |
| 60 | #ifdef ACL_WINDOWS |
| 61 | case SOCKET_ERROR: |
| 62 | #else |
| 63 | case -1: |
| 64 | #endif |
| 65 | if (acl_last_error() == ACL_EINTR) { |
| 66 | continue; |
| 67 | } |
| 68 | #if 0 |
| 69 | acl_msg_error("%s(%d), %s: poll error(%s), fd: %d", |
| 70 | __FILE__, __LINE__, myname, |
| 71 | acl_last_serror(), (int) fd); |
| 72 | #endif |
| 73 | return -1; |
| 74 | case 0: |
| 75 | if (timeout == 0) { |
| 76 | acl_set_error(ACL_EAGAIN); |
| 77 | } else { |
| 78 | acl_set_error(ACL_ETIMEDOUT); |
| 79 | } |
| 80 | #if 0 |
| 81 | end = time(NULL); |
| 82 | acl_msg_error("%s(%d), %s: poll return 0, delay=%d, " |
| 83 | "fd=%d, cost=%ld", __FILE__, __LINE__, |
| 84 | myname, delay, fd, (long) ( end - begin)); |
| 85 | #endif |
| 86 | return -1; |
| 87 | default: |
| 88 | if (fds.revents & POLLNVAL) { |
| 89 | acl_msg_error("%s(%d), %s: %s, POLLNVAL, fd=%d", |
| 90 | __FILE__, __LINE__, myname, |
| 91 | acl_last_serror(), (int) fd); |
| 92 | acl_set_error(ACL_EINVAL); |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | if ((fds.revents & (POLLHUP | POLLERR))) { |
| 97 | /* |
| 98 | acl_msg_error("%s(%d), %s: %s, %s, %s, fd=%d", |
no test coverage detected
searching dependent graphs…