| 38 | # endif |
| 39 | |
| 40 | int acl_readable(ACL_SOCKET fd) |
| 41 | { |
| 42 | struct pollfd fds; |
| 43 | int delay = 0; |
| 44 | |
| 45 | fds.fd = fd; |
| 46 | #ifdef ACL_WINDOWS |
| 47 | fds.events = POLLIN /* | POLLHUP | POLLERR */; |
| 48 | #else |
| 49 | fds.events = POLLIN | POLLHUP | POLLERR | POLLPRI; |
| 50 | #endif |
| 51 | fds.revents = 0; |
| 52 | |
| 53 | acl_set_error(0); |
| 54 | |
| 55 | for (;;) { |
| 56 | switch (__sys_poll(&fds, 1, delay)) { |
| 57 | #ifdef ACL_WINDOWS |
| 58 | case SOCKET_ERROR: |
| 59 | #else |
| 60 | case -1: |
| 61 | #endif |
| 62 | if (acl_last_error() == ACL_EINTR) { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | acl_msg_error("%s(%d), %s: poll error(%s), fd: %d", |
| 67 | __FILE__, __LINE__, __FUNCTION__, |
| 68 | acl_last_serror(), (int) fd); |
| 69 | return -1; |
| 70 | case 0: |
| 71 | return 0; |
| 72 | default: |
| 73 | if ((fds.revents & POLLIN)) { |
| 74 | return 1; |
| 75 | } else if (fds.revents & (POLLHUP | POLLERR)) { |
| 76 | return 1; |
| 77 | } else { |
| 78 | return 0; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | #else |
| 85 |
no test coverage detected
searching dependent graphs…