| 131 | } |
| 132 | |
| 133 | int RoutinePeekWithTimeout(int source_fd, char * buf, int buf_size, int timeout_ms) { |
| 134 | assert(IsNonBlock(source_fd)); |
| 135 | struct pollfd pf[1]; |
| 136 | int nfds = 0; |
| 137 | memset(pf, 0, sizeof(pf)); |
| 138 | pf[0].fd = source_fd; |
| 139 | pf[0].events = (POLLIN | POLLERR | POLLHUP); |
| 140 | nfds++; |
| 141 | |
| 142 | int return_fd_count = co_poll(co_get_epoll_ct(), pf, nfds, timeout_ms); |
| 143 | if (return_fd_count < 0) { |
| 144 | return return_fd_count; |
| 145 | } |
| 146 | |
| 147 | if (pf[0].revents & POLLIN) { |
| 148 | return recv(source_fd, buf, buf_size, MSG_PEEK); |
| 149 | } else if (pf[0].revents & POLLHUP) { |
| 150 | return return_fd_count; |
| 151 | } else if (pf[0].revents & POLLERR) { |
| 152 | return return_fd_count; |
| 153 | } |
| 154 | return return_fd_count; |
| 155 | } |
| 156 | |
| 157 | } |
no test coverage detected