static void zre_node_agent (void *args, zctx_t *ctx, void *pipe) { // Create agent instance to pass around agent_t *self = agent_new (ctx, pipe); if (!self) // Interrupted return; // Send first beacon immediately uint64_t ping_at = zclock_time (); zmq_pollitem_t pollitems [] = { { self->pipe, 0, ZMQ_POLLIN, 0 }, { self->inbox, 0, ZMQ_POLLIN, 0 }, { 0, zre_udp_handle (self->udp), ZMQ_POLLIN, 0 }, { fmq_client_handle (self->fmq_client), 0, ZMQ_POLLIN, 0 } }; while (!zctx_interrupted) { long timeout = (long) (ping_at - zclock_time ()); assert (timeout <= PING_INTERVAL); if (timeout < 0) timeout = 0; if (zmq_poll (pollitems, 4, timeout * ZMQ_POLL_MSEC) == -1) break; // Interrupted if (pollitems [0].revents & ZMQ_POLLIN) agent_recv_from_api (self); if (pollitems [1].revents & ZMQ_POLLIN) agent_recv_from_peer (self); if (pollitems [2].revents & ZMQ_POLLIN) agent_recv_udp_beacon (self); if (pollitems [3].revents & ZMQ_POLLIN) agent_recv_fmq_event (self); if (zclock_time () >= ping_at) { agent_beacon_send (self); ping_at = zclock_time () + PING_INTERVAL; // Ping all peers and reap any expired ones zhash_foreach (self->peers, agent_ping_peer, self); } } agent_destroy (&self); }
zmsg_t *msg = fmq_client_recv (fmq_client_handle (self->fmq_client)); zmsg_send (&msg, self->pipe);