static ngx_int_t sub_respond_message(ngx_int_t status, void *ptr, sub_data_t* d) { nchan_msg_t *msg = (nchan_msg_t *) ptr; nchan_loc_conf_t cf; nchan_msg_id_t *lastid; DBG("%p memstore-redis subscriber respond with message", d->sub); cf.max_messages = d->chanhead->max_messages; cf.redis.enabled = 0; cf.message_timeout = msg->expires - ngx_time(); cf.complex_max_messages = NULL; cf.complex_message_timeout = NULL; lastid = &d->chanhead->latest_msgid; respond_msgexpected_callbacks(d, MSG_NORESPONSE); assert(lastid->tagcount == 1 && msg->id.tagcount == 1); if(lastid->time < msg->id.time || (lastid->time == msg->id.time && lastid->tag.fixed[0] < msg->id.tag.fixed[0])) { memstore_ensure_chanhead_is_ready(d->chanhead, 1); nchan_store_chanhead_publish_message_generic(d->chanhead, msg, 0, &cf, NULL, NULL); } else { //meh, this message has already been delivered probably hopefully } return NGX_OK; }
static ngx_int_t sub_respond_message(ngx_int_t status, nchan_msg_t *msg, sub_data_t* d) { nchan_msg_copy_t remsg; //nchan_msg_id_t *last_msgid; ngx_int_t mcount; int16_t tags[NCHAN_MULTITAG_MAX], prevtags[NCHAN_MULTITAG_MAX]; //remsg = ngx_alloc(sizeof(*remsg), ngx_cycle->log); //assert(remsg); assert( msg->id.tagcount == 1 ); assert( msg->prev_id.tagcount == 1 ); remsg.original = msg; remsg.copy = *msg; remsg.copy.shared = 0; remsg.copy.temp_allocd = 0; mcount = d->multi_chanhead->multi_count; remsg.copy.prev_id.tagcount = mcount; remsg.copy.prev_id.tagactive = d->n; remsg.copy.id.tagcount = mcount; remsg.copy.id.tagactive = d->n; if(mcount > NCHAN_FIXED_MULTITAG_MAX) { remsg.copy.id.tag.allocd = tags; tags[0]=msg->id.tag.fixed[0]; remsg.copy.prev_id.tag.allocd = prevtags; prevtags[0]=msg->prev_id.tag.fixed[0]; } nchan_expand_msg_id_multi_tag(&remsg.copy.prev_id, 0, d->n, -1); nchan_expand_msg_id_multi_tag(&remsg.copy.id, 0, d->n, -1); memstore_ensure_chanhead_is_ready(d->multi_chanhead, 1); DBG("%p respond with transformed message %p %V (%p %V %i) %V", d->multi->sub, &remsg.copy, msgid_to_str(&remsg.copy.id), d->multi_chanhead, &d->multi_chanhead->id, d->n, &d->multi->id); nchan_memstore_publish_generic(d->multi_chanhead, &remsg.copy, 0, NULL); return NGX_OK; }