void s_service_dispatch (service_t *self) { // for each message, check regexp and dispatch if possible if (zlistx_size (self->offers)) { mlm_msg_t *message = (mlm_msg_t *) zlistx_first (self->queue); while (message) { offer_t *offer = (offer_t *) zlistx_first (self->offers); while (offer) { if (zrex_matches (offer->rex, mlm_msg_subject (message))) { client_t *target = offer->client; assert (target); assert (!target->msg); target->msg = (mlm_msg_t *) zlistx_detach ( self->queue, zlistx_cursor (self->queue)); engine_send_event (target, service_message_event); zlistx_move_end (self->offers, zlistx_cursor (self->offers)); break; } offer = (offer_t *) zlistx_next (self->offers); } message = (mlm_msg_t *) zlistx_next (self->queue); } } }
static bool s_service_dispatch_message (service_t *self, mlm_msg_t *message) { offer_t *offer = (offer_t *) zlistx_first (self->offers); while (offer) { if (zrex_matches (offer->rex, mlm_msg_subject (message))) { client_t *target = offer->client; assert (target); assert (!target->msg); target->msg = message; engine_send_event (target, service_message_event); zlistx_move_end (self->offers, zlistx_cursor (self->offers)); return true; } offer = (offer_t *) zlistx_next (self->offers); } return false; }
static int s_stream_engine_handle_message (stream_engine_t *self) { void *sender; mlm_msg_t *msg; zsock_brecv (self->msgpipe, "pp", &sender, &msg); selector_t *selector = (selector_t *) zlistx_first (self->selectors); while (selector) { if (zrex_matches (selector->rex, mlm_msg_subject (msg))) { void *client = zlistx_first (selector->clients); while (client) { if (client != sender) zsock_bsend (self->msgpipe, "pp", client, mlm_msg_link (msg)); client = zlistx_next (selector->clients); } } selector = (selector_t *) zlistx_next (self->selectors); } mlm_msg_unlink (&msg); return 0; }