static void receive_channel_auth_check(ngx_int_t sender, channel_authcheck_data_t *d) { memstore_channel_head_t *head; DBG("received channel_auth_check request for channel %V privdata %p", d->shm_chid, d->privdata); assert(memstore_slot() == memstore_channel_owner(d->shm_chid)); if(!d->cf->redis.enabled) { head = nchan_memstore_find_chanhead(d->shm_chid); if(head == NULL) { d->auth_ok = !d->channel_must_exist; } else if (d->max_subscribers == 0) { d->auth_ok = 1; } else { assert(head->shared); d->auth_ok = head->shared->sub_count < (ngx_uint_t )d->max_subscribers; } ipc_cmd(channel_auth_check_reply, sender, d); } else { channel_authcheck_data_callback_t *dd = ngx_alloc(sizeof(*dd), ngx_cycle->log); dd->d = *d; dd->sender = sender; nchan_store_redis.find_channel(d->shm_chid, d->cf, redis_receive_channel_auth_check_callback, dd); } }
static void receive_unsubscribed(ngx_int_t sender, unsubscribed_data_t *d) { DBG("received unsubscribed request for channel %V privdata %p", d->shm_chid, d->privdata); if(memstore_channel_owner(d->shm_chid) != memstore_slot()) { memstore_channel_head_t *head; //find channel head = nchan_memstore_find_chanhead(d->shm_chid); if(head == NULL) { //already deleted maybe? DBG("already unsubscribed..."); return; } //gc if no subscribers if(head->total_sub_count == 0) { DBG("add %p to GC", head); head->foreign_owner_ipc_sub = NULL; chanhead_gc_add(head, "received UNSUBSCRIVED over ipc, sub_count == 0"); } else { //subscribe again?... DBG("maybe subscribe again?..."); } } else { ERR("makes no sense..."); } str_shm_free(d->shm_chid); }
static void receive_get_channel_info_continued(ngx_int_t sender, channel_info_data_t *d, memstore_channel_head_t *head) { assert(memstore_slot() == memstore_channel_owner(d->shm_chid)); if(head == NULL) { //already deleted maybe? DBG("channel not for for get_channel_info"); d->channel_info = NULL; } else { d->channel_info = head->shared; assert(head->latest_msgid.tagcount <= 1); d->last_msgid = head->latest_msgid; } ipc_cmd(get_channel_info_reply, sender, d); }
static void receive_get_channel_info(ngx_int_t sender, channel_info_data_t *d) { memstore_channel_head_t *head; DBG("received get_channel_info request for channel %V privdata %p", d->shm_chid, d->privdata); head = nchan_memstore_find_chanhead(d->shm_chid); assert(memstore_slot() == memstore_channel_owner(d->shm_chid)); if(head == NULL) { //already deleted maybe? DBG("channel not for for get_channel_info"); d->channel_info = NULL; } else { d->channel_info = head->shared; assert(head->latest_msgid.tagcount <= 1); d->last_msgid = head->latest_msgid; } ipc_alert(nchan_memstore_get_ipc(), sender, IPC_GET_CHANNEL_INFO_REPLY, d, sizeof(*d)); }
static void receive_publish_message(ngx_int_t sender, publish_data_t *d) { publish_callback_data cd_data; publish_callback_data *cd; memstore_channel_head_t *head; assert(d->shm_chid->data != NULL); DBG("IPC: received publish request for channel %V msg %p", d->shm_chid, d->shm_msg); if(memstore_channel_owner(d->shm_chid) == memstore_slot()) { if(d->cf->redis.enabled) { cd = ngx_alloc(sizeof(*cd) + sizeof(*d), ngx_cycle->log); cd->allocd=1; cd->d = (publish_data_t *)&cd[1]; *cd->d = *d; } else { cd = &cd_data; cd->allocd=0; cd->d = d; } cd->sender = sender; nchan_store_publish_message_generic(d->shm_chid, d->shm_msg, 1, d->cf, publish_message_generic_callback, cd); //string will be freed on publish response } else { if((head = nchan_memstore_get_chanhead(d->shm_chid, d->cf))) { nchan_memstore_publish_generic(head, d->shm_msg, 0, NULL); } else { ERR("Unable to get chanhead for publishing"); } //don't deallocate shm_msg } msg_release(d->shm_msg, "publish_message"); str_shm_free(d->shm_chid); d->shm_chid=NULL; }