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

Function wait_connection_ready

src/ui/httpd.c:166–187  ·  view source on GitHub ↗

Wait against the caller's absolute deadline. Windows uses short select() * slices because shutdown() from the stop thread does not reliably wake a * Winsock select(); POSIX keeps its one-shot poll wait and shutdown fast path. * 1 = ready, 0 = original deadline expired, -1 = interrupted/error. */

Source from the content-addressed store, hash-verified

164 * Winsock select(); POSIX keeps its one-shot poll wait and shutdown fast path.
165 * 1 = ready, 0 = original deadline expired, -1 = interrupted/error. */
166static int wait_connection_ready(cbm_http_conn_t *connection, bool writing, int64_t deadline) {
167 for (;;) {
168 if (connection_interrupted(connection))
169 return -1;
170
171 int64_t remaining = deadline - now_ms();
172 if (remaining <= 0)
173 return 0;
174 int timeout_ms = remaining > INT_MAX ? INT_MAX : (int)remaining;
175#ifdef _WIN32
176 if (timeout_ms > CBM_HTTP_WAIT_SLICE_MS)
177 timeout_ms = CBM_HTTP_WAIT_SLICE_MS;
178#endif
179
180 int ready = wait_ready(connection->fd, writing, timeout_ms);
181 if (connection_interrupted(connection))
182 return -1;
183 if (ready != 0)
184 return ready;
185 /* A Windows slice or POSIX EINTR is not the caller's timeout. */
186 }
187}
188
189static int send_all(cbm_http_conn_t *connection, const void *data, size_t len, int64_t deadline) {
190 const char *p = data;

Callers 2

send_allFunction · 0.85
cbm_httpd_read_requestFunction · 0.85

Calls 3

connection_interruptedFunction · 0.85
wait_readyFunction · 0.85
now_msFunction · 0.70

Tested by

no test coverage detected