1 = requested readiness, 0 = timeout/interruption, -1 = socket error. */
| 2155 | |
| 2156 | /* 1 = requested readiness, 0 = timeout/interruption, -1 = socket error. */ |
| 2157 | static int main_daemon_ctl_socket_wait(main_daemon_ctl_socket_t socket_handle, bool writing, |
| 2158 | int timeout_ms) { |
| 2159 | #ifdef _WIN32 |
| 2160 | fd_set ready; |
| 2161 | fd_set errors; |
| 2162 | FD_ZERO(&ready); |
| 2163 | FD_ZERO(&errors); |
| 2164 | FD_SET(socket_handle, &ready); |
| 2165 | FD_SET(socket_handle, &errors); |
| 2166 | struct timeval timeout = { |
| 2167 | .tv_sec = timeout_ms / 1000, |
| 2168 | .tv_usec = (timeout_ms % 1000) * 1000, |
| 2169 | }; |
| 2170 | int result = select(0, writing ? NULL : &ready, writing ? &ready : NULL, &errors, &timeout); |
| 2171 | if (result <= 0) { |
| 2172 | return result < 0 ? -1 : 0; |
| 2173 | } |
| 2174 | return FD_ISSET(socket_handle, &errors) ? -1 : 1; |
| 2175 | #else |
| 2176 | struct pollfd descriptor = { |
| 2177 | .fd = socket_handle, |
| 2178 | .events = writing ? POLLOUT : POLLIN, |
| 2179 | .revents = 0, |
| 2180 | }; |
| 2181 | int result = poll(&descriptor, 1, timeout_ms); |
| 2182 | if (result < 0) { |
| 2183 | return errno == EINTR ? 0 : -1; |
| 2184 | } |
| 2185 | if (result == 0) { |
| 2186 | return 0; |
| 2187 | } |
| 2188 | return (descriptor.revents & descriptor.events) != 0 ? 1 : -1; |
| 2189 | #endif |
| 2190 | } |
| 2191 | |
| 2192 | static int main_daemon_ctl_socket_remaining_ms(uint64_t deadline_ms) { |
| 2193 | uint64_t now_ms = cbm_now_ms(); |
no test coverage detected