static int s_self_handle_pipe (self_t *self) { // Get just the command off the pipe char *command = zstr_recv (self->pipe); if (!command) return -1; // Interrupted if (self->verbose) zsys_info ("zbeacon: API command=%s", command); if (streq (command, "VERBOSE")) self->verbose = true; else if (streq (command, "CONFIGURE")) { int port; int rc = zsock_recv (self->pipe, "i", &port); assert (rc == 0); s_self_configure (self, port); } else if (streq (command, "PUBLISH")) { zframe_destroy (&self->transmit); zsock_recv (self->pipe, "fi", &self->transmit, &self->interval); assert (zframe_size (self->transmit) <= UDP_FRAME_MAX); if (self->interval == 0) self->interval = INTERVAL_DFLT; // Start broadcasting immediately self->ping_at = zclock_mono (); } else if (streq (command, "SILENCE")) zframe_destroy (&self->transmit); else if (streq (command, "SUBSCRIBE")) { zframe_destroy (&self->filter); self->filter = zframe_recv (self->pipe); assert (zframe_size (self->filter) <= UDP_FRAME_MAX); } else if (streq (command, "UNSUBSCRIBE")) zframe_destroy (&self->filter); else if (streq (command, "$TERM")) self->terminated = true; else { zsys_error ("zbeacon: - invalid command: %s", command); assert (false); } zstr_free (&command); return 0; }
static int s_self_handle_pipe (self_t *self) { // Get the whole message off the pipe in one go zmsg_t *request = zmsg_recv (self->pipe); if (!request) return -1; // Interrupted char *command = zmsg_popstr (request); assert (command); if (self->verbose) zsys_info ("zproxy: API command=%s", command); if (streq (command, "FRONTEND")) { s_self_configure (self, &self->frontend, request, "frontend"); zsock_signal (self->pipe, 0); } else if (streq (command, "BACKEND")) { s_self_configure (self, &self->backend, request, "backend"); zsock_signal (self->pipe, 0); } else if (streq (command, "CAPTURE")) { self->capture = zsock_new (ZMQ_PUSH); assert (self->capture); char *endpoint = zmsg_popstr (request); assert (endpoint); int rc = zsock_connect (self->capture, "%s", endpoint); assert (rc == 0); zstr_free (&endpoint); zsock_signal (self->pipe, 0); } else if (streq (command, "PAUSE")) { zpoller_destroy (&self->poller); self->poller = zpoller_new (self->pipe, NULL); assert (self->poller); zsock_signal (self->pipe, 0); } else if (streq (command, "RESUME")) { zpoller_destroy (&self->poller); self->poller = zpoller_new (self->pipe, self->frontend, self->backend, NULL); assert (self->poller); zsock_signal (self->pipe, 0); } else if (streq (command, "VERBOSE")) { self->verbose = true; zsock_signal (self->pipe, 0); } else if (streq (command, "$TERM")) self->terminated = true; else { zsys_error ("zproxy: - invalid command: %s", command); assert (false); } zstr_free (&command); zmsg_destroy (&request); return 0; }
static int s_self_handle_pipe (self_t *self) { // Get the whole message off the pipe in one go zmsg_t *request = zmsg_recv (self->pipe); if (!request) return -1; // Interrupted char *command = zmsg_popstr (request); assert (command); if (self->verbose) zsys_info ("zproxy: API command=%s", command); if (streq (command, "FRONTEND")) { s_self_configure (self, &self->frontend, request, FRONTEND); zsock_signal (self->pipe, 0); } else if (streq (command, "BACKEND")) { s_self_configure (self, &self->backend, request, BACKEND); zsock_signal (self->pipe, 0); } else if (streq (command, "CAPTURE")) { self->capture = zsock_new (ZMQ_PUSH); assert (self->capture); char *endpoint = zmsg_popstr (request); assert (endpoint); int rc = zsock_connect (self->capture, "%s", endpoint); assert (rc == 0); zstr_free (&endpoint); zsock_signal (self->pipe, 0); } else if (streq (command, "PAUSE")) { zpoller_destroy (&self->poller); self->poller = zpoller_new (self->pipe, NULL); assert (self->poller); zsock_signal (self->pipe, 0); } else if (streq (command, "RESUME")) { zpoller_destroy (&self->poller); self->poller = zpoller_new (self->pipe, self->frontend, self->backend, NULL); assert (self->poller); zsock_signal (self->pipe, 0); } else if (streq (command, "VERBOSE")) { self->verbose = true; zsock_signal (self->pipe, 0); } else if (streq (command, "DOMAIN")) { proxy_socket selected_socket = s_self_selected_socket (request); char *domain = zmsg_popstr (request); assert (domain); zstr_free (&self->domain [selected_socket]); self->domain [selected_socket] = domain; zsock_signal (self->pipe, 0); } else if (streq (command, "PLAIN")) { proxy_socket selected_socket = s_self_selected_socket (request); self->auth_type [selected_socket] = AUTH_PLAIN; zsock_signal (self->pipe, 0); } else if (streq (command, "CURVE")) { proxy_socket selected_socket = s_self_selected_socket (request); self->auth_type [selected_socket] = AUTH_CURVE; char *public_key = zmsg_popstr (request); assert (public_key); char *secret_key = zmsg_popstr (request); assert (secret_key); zstr_free (&self->public_key [selected_socket]); zstr_free (&self->secret_key [selected_socket]); self->public_key [selected_socket] = public_key; self->secret_key [selected_socket] = secret_key; zsock_signal (self->pipe, 0); } else if (streq (command, "$TERM")) self->terminated = true; else { zsys_error ("zproxy: - invalid command: %s", command); assert (false); } zstr_free (&command); zmsg_destroy (&request); return 0; }