void ipc_register(IpcPtr ipc, DispatchPtr dispatch) { if (ipc) { if (ipc->dispatch) { dispatch_remove_fd(ipc->dispatch, ipc_read_socket(ipc)); } ipc->dispatch = dispatch; dispatch_add(ipc->dispatch, ipc_read_socket(ipc), POLLIN, ipc_read_zero, NULL, NULL, ipc); } }
static void ipc_read_zero(void *arg) { IpcPtr ipc = (IpcPtr) arg; if (ipc) { uint8_t dummy = 0; ssize_t rdbytes = read(ipc_read_socket(ipc), &dummy, sizeof(dummy)); if (rdbytes < 0) { log_error("Error reading IPC pipe signal"); } } }
void ipc_free(IpcPtr ipc) { if (ipc) { if (ipc->dispatch) { dispatch_remove_fd(ipc->dispatch, ipc_read_socket(ipc)); } close(ipc->sockets[0]); close(ipc->sockets[1]); free(ipc); } }
static void ipc_read_handler(ngx_event_t *ev) { DBG("IPC channel handler"); //copypasta from os/unix/ngx_process_cycle.c (ngx_channel_handler) ngx_int_t n; ipc_alert_t alert; ngx_connection_t *c; if (ev->timedout) { ev->timedout = 0; return; } c = ev->data; while(1) { n = ipc_read_socket(c->fd, &alert, ev->log); if (n == NGX_ERROR) { ERR("IPC_READ_SOCKET failed: bad connection. This should never have happened, yet here we are..."); assert(0); return; } if (n == NGX_AGAIN) { return; } //ngx_log_debug1(NGX_LOG_DEBUG_CORE, ev->log, 0, "nchan: channel command: %d", ch.command); assert(n == sizeof(alert)); if(alert.worker_generation < memstore_worker_generation) { ERR("Got IPC alert for previous generation's worker. discarding."); } else { #if DEBUG_DELAY_IPC_RECEIVE_ALERT_MSEC delayed_alert_glob_t *glob = ngx_alloc(sizeof(*glob), ngx_cycle->log); if (NULL == glob) { ERR("Couldn't allocate memory for alert glob data."); return; } ngx_memzero(&glob->timer, sizeof(glob->timer)); nchan_init_timer(&glob->timer, fake_ipc_alert_delay_handler, glob); glob->alert = alert; glob->ipc = (ipc_t *)c->data; ngx_add_timer(&glob->timer, DEBUG_DELAY_IPC_RECEIVE_ALERT_MSEC); #else if(ngx_time() - alert.time_sent >= 2) { ipc_record_alert_receive_delay(ngx_time() - alert.time_sent); } nchan_update_stub_status(ipc_total_alerts_received, 1); ((ipc_t *)c->data)->handler(alert.src_slot, alert.code, alert.data); #endif } } }