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

Function frontend_eof_writer

tests/test_daemon_frontend.c:258–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258static void *frontend_eof_writer(void *opaque) {
259 frontend_eof_writer_t *writer = opaque;
260 static const char first[] =
261 "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"test/block\",\"params\":{}}\n";
262 bool ok = frontend_eof_write_all(writer->fd, first, sizeof(first) - 1);
263 uint64_t deadline = cbm_now_ms() + FRONTEND_EOF_TEST_REQUEST_TIMEOUT_MS;
264 while (
265 ok &&
266 !atomic_load_explicit(&writer->application->first_request_started, memory_order_acquire) &&
267 cbm_now_ms() < deadline) {
268 cbm_usleep(1000);
269 }
270 ok = ok &&
271 atomic_load_explicit(&writer->application->first_request_started, memory_order_acquire);
272 for (int index = 0; ok && writer->overflow && index < FRONTEND_EOF_TEST_OVERFLOW_MESSAGES;
273 index++) {
274 char message[160];
275 int written =
276 snprintf(message, sizeof(message),
277 "{\"jsonrpc\":\"2.0\",\"id\":%d,\"method\":\"test/queued\",\"params\":{}}\n",
278 index + 2);
279 ok = written > 0 && written < (int)sizeof(message) &&
280 frontend_eof_write_all(writer->fd, message, (size_t)written);
281 }
282 ok = close(writer->fd) == 0 && ok;
283 writer->fd = -1;
284 if (writer->overflow) {
285 /* Everything — 32 over-capacity frames AND the EOF behind them — is now
286 * committed to the pipe. Only now release the held first request: the
287 * queue was provably full while it blocked, so the drain that follows
288 * exercises enqueue-wait, not a conveniently fast worker. */
289 atomic_store_explicit(&writer->application->release_first_request, true,
290 memory_order_release);
291 }
292 atomic_store_explicit(&writer->succeeded, ok, memory_order_release);
293 atomic_store_explicit(&writer->finished, true, memory_order_release);
294 return NULL;
295}
296
297static bool frontend_eof_fixture_start(frontend_eof_fixture_t *fixture, const char *parent) {
298 memset(fixture, 0, sizeof(*fixture));

Callers

nothing calls this directly

Calls 2

frontend_eof_write_allFunction · 0.85
cbm_now_msFunction · 0.85

Tested by

no test coverage detected