Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/mcp/mcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2389,16 +2389,21 @@ int cbm_mcp_server_run(cbm_mcp_server_t *srv, FILE *in, FILE *out) {
continue;
}
#else
struct pollfd pfd = {.fd = fd, .events = POLLIN};
int pr = poll(&pfd, 1, STORE_IDLE_TIMEOUT_S * 1000);

if (pr < 0) {
break; /* error or signal */
}
if (pr == 0) {
/* Timeout — evict idle store to free resources */
cbm_mcp_server_evict_idle(srv, STORE_IDLE_TIMEOUT_S);
continue;
#ifdef __GLIBC__
int has_buffered = (in->_IO_read_ptr < in->_IO_read_end);
#else
/* macOS / BSD: use __srget-style check.
* fp->_r is the count of unread bytes in the buffer. */
int has_buffered = (in->_r > 0);
#endif
if (!has_buffered) {
struct pollfd pfd = {.fd = fd, .events = POLLIN};
int pr = poll(&pfd, 1, STORE_IDLE_TIMEOUT_S * 1000);
if (pr < 0) break;
if (pr == 0) {
cbm_mcp_server_evict_idle(srv, STORE_IDLE_TIMEOUT_S);
continue;
}
}
#endif

Expand Down