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

Function cbm_daemon_ipc_send_frame

src/daemon/ipc.c:6096–6118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6094#endif /* _WIN32 */
6095
6096bool cbm_daemon_ipc_send_frame(cbm_daemon_ipc_connection_t *connection,
6097 cbm_daemon_frame_type_t type, uint16_t flags, const void *payload,
6098 uint32_t length) {
6099 if (!connection || atomic_load_explicit(&connection->poisoned, memory_order_acquire) ||
6100 (length > 0 && !payload)) {
6101 return false;
6102 }
6103 uint8_t header[CBM_DAEMON_FRAME_HEADER_SIZE];
6104 if (!cbm_daemon_frame_header_encode(header, type, flags, length)) {
6105 return false;
6106 }
6107 uint64_t deadline_ms = ipc_deadline_after(CBM_DAEMON_IPC_SEND_TIMEOUT_MS);
6108 if (connection_write_full(connection, header, sizeof(header), deadline_ms) != 1) {
6109 return false;
6110 }
6111 if (length > 0 && connection_write_full(connection, payload, length, deadline_ms) != 1) {
6112 /* The peer has already received a complete header and will interpret
6113 * subsequent bytes as this payload, so this stream cannot be reused. */
6114 atomic_store_explicit(&connection->poisoned, true, memory_order_release);
6115 return false;
6116 }
6117 return true;
6118}
6119
6120int cbm_daemon_ipc_receive_frame_bounded(cbm_daemon_ipc_connection_t *connection,
6121 uint32_t timeout_ms, uint32_t max_payload_length,

Calls 3

ipc_deadline_afterFunction · 0.85
connection_write_fullFunction · 0.85