MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / main_daemon_ctl_socket_wait

Function main_daemon_ctl_socket_wait

src/main.c:2157–2190  ·  view source on GitHub ↗

1 = requested readiness, 0 = timeout/interruption, -1 = socket error. */

Source from the content-addressed store, hash-verified

2155
2156/* 1 = requested readiness, 0 = timeout/interruption, -1 = socket error. */
2157static 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
2192static int main_daemon_ctl_socket_remaining_ms(uint64_t deadline_ms) {
2193 uint64_t now_ms = cbm_now_ms();

Calls 2

selectFunction · 0.50
pollFunction · 0.50

Tested by

no test coverage detected