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

Function wait_readable

src/ui/httpd.c:74–94  ·  view source on GitHub ↗

Wait until the socket is readable. 1 = readable, 0 = timeout, -1 = error. * Windows uses select() deliberately (WSAPoll has a Won't-Fix bug where * certain socket errors are never reported, which can stall an event loop). */

Source from the content-addressed store, hash-verified

72 * Windows uses select() deliberately (WSAPoll has a Won't-Fix bug where
73 * certain socket errors are never reported, which can stall an event loop). */
74static int wait_readable(cbm_sock_t fd, int timeout_ms) {
75#ifdef _WIN32
76 fd_set rfds;
77 FD_ZERO(&rfds);
78 FD_SET(fd, &rfds);
79 struct timeval tv;
80 tv.tv_sec = timeout_ms / 1000;
81 tv.tv_usec = (timeout_ms % 1000) * 1000;
82 int rc = select(0, &rfds, NULL, NULL, &tv);
83 return rc < 0 ? -1 : (rc > 0 ? 1 : 0);
84#else
85 struct pollfd pfd;
86 pfd.fd = fd;
87 pfd.events = POLLIN;
88 pfd.revents = 0;
89 int rc = poll(&pfd, 1, timeout_ms);
90 if (rc < 0)
91 return errno == EINTR ? 0 : -1;
92 return rc > 0 ? 1 : 0;
93#endif
94}
95
96static int send_all(cbm_sock_t fd, const void *data, size_t len) {
97 const char *p = data;

Callers 2

cbm_httpd_acceptFunction · 0.85
cbm_httpd_read_requestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected