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

Function cbm_daemon_ipc_accept

src/daemon/ipc.c:2836–2872  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2834}
2835
2836int cbm_daemon_ipc_accept(cbm_daemon_ipc_listener_t *listener, uint32_t timeout_ms,
2837 cbm_daemon_ipc_connection_t **connection_out) {
2838 if (connection_out) {
2839 *connection_out = NULL;
2840 }
2841 if (!listener || listener->fd < 0 || listener->owner_pid != getpid() || !connection_out) {
2842 return -1;
2843 }
2844 uint64_t deadline_ms = ipc_deadline_after(timeout_ms);
2845 for (;;) {
2846 int ready = poll_until(listener->fd, POLLIN, deadline_ms);
2847 if (ready != 1) {
2848 return ready;
2849 }
2850 int fd = accept(listener->fd, NULL, NULL);
2851 if (fd < 0) {
2852 if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
2853 continue;
2854 }
2855 return -1;
2856 }
2857 if (!fd_set_cloexec(fd) || !fd_set_nonblocking(fd) || !socket_disable_sigpipe(fd) ||
2858 !socket_peer_is_current_user(fd)) {
2859 (void)close(fd);
2860 return -1;
2861 }
2862 cbm_daemon_ipc_connection_t *connection = malloc(sizeof(*connection));
2863 if (!connection) {
2864 (void)close(fd);
2865 return -1;
2866 }
2867 connection->fd = fd;
2868 atomic_init(&connection->poisoned, false);
2869 *connection_out = connection;
2870 return 1;
2871 }
2872}
2873
2874int cbm_daemon_ipc_endpoint_probe(const cbm_daemon_ipc_endpoint_t *endpoint, uint32_t timeout_ms) {
2875 if (!endpoint_runtime_still_valid(endpoint)) {

Callers 4

runtime_accept_loopFunction · 0.85
ipc_roundtrip_serverFunction · 0.85
test_daemon_ipc.cFile · 0.85
ipc_forever_wait_serverFunction · 0.85

Calls 8

ipc_deadline_afterFunction · 0.85
poll_untilFunction · 0.85
fd_set_cloexecFunction · 0.85
fd_set_nonblockingFunction · 0.85
socket_disable_sigpipeFunction · 0.85
win_pipe_instance_newFunction · 0.85

Tested by 2

ipc_roundtrip_serverFunction · 0.68
ipc_forever_wait_serverFunction · 0.68