static ngx_int_t ngx_http_push_stream_assing_subscription_to_channel_locked(ngx_slab_pool_t *shpool, ngx_str_t *channel_id, ngx_http_push_stream_subscription_t *subscription, ngx_http_push_stream_subscription_t *subscriptions_sentinel, ngx_log_t *log) { ngx_queue_t *cur_worker; ngx_http_push_stream_pid_queue_t *worker, *worker_subscribers_sentinel = NULL; ngx_http_push_stream_channel_t *channel; // check if channel still exists if ((channel = ngx_http_push_stream_find_channel(channel_id, log)) == NULL) { ngx_log_error(NGX_LOG_ERR, log, 0, "push stream module: something goes very wrong, arrived on ngx_http_push_stream_subscriber_assign_channel without created channel %s", channel_id->data); return NGX_ERROR; } cur_worker = &channel->workers_with_subscribers; while ((cur_worker = ngx_queue_next(cur_worker)) && (cur_worker != NULL) && (cur_worker != &channel->workers_with_subscribers)) { worker = ngx_queue_data(cur_worker, ngx_http_push_stream_pid_queue_t, queue); if (worker->pid == ngx_pid) { worker_subscribers_sentinel = worker; break; } } if (worker_subscribers_sentinel == NULL) { // found nothing worker_subscribers_sentinel = ngx_http_push_stream_create_worker_subscriber_channel_sentinel_locked(shpool, channel_id, log); if (worker_subscribers_sentinel == NULL) { return NGX_ERROR; } } channel->subscribers++; // do this only when we know everything went okay channel->last_activity_time = ngx_time(); ngx_queue_insert_tail(&subscriptions_sentinel->queue, &subscription->queue); ngx_queue_insert_tail(&worker_subscribers_sentinel->subscriptions_queue, &subscription->channel_worker_queue); return NGX_OK; }
static ngx_int_t ngx_http_push_stream_assing_subscription_to_channel_locked(ngx_slab_pool_t *shpool, ngx_str_t *channel_id, ngx_http_push_stream_subscription_t *subscription, ngx_http_push_stream_subscription_t *subscriptions_sentinel, ngx_log_t *log) { ngx_http_push_stream_pid_queue_t *cur, *worker_subscribers_sentinel = NULL; ngx_http_push_stream_channel_t *channel; ngx_http_push_stream_queue_elem_t *element_subscriber; // check if channel still exists if ((channel = ngx_http_push_stream_find_channel(channel_id, log)) == NULL) { ngx_log_error(NGX_LOG_ERR, log, 0, "push stream module: something goes very wrong, arrived on ngx_http_push_stream_subscriber_assign_channel without created channel %s", channel_id->data); return NGX_ERROR; } cur = &channel->workers_with_subscribers; while ((cur = (ngx_http_push_stream_pid_queue_t *) ngx_queue_next(&cur->queue)) != &channel->workers_with_subscribers) { if (cur->pid == ngx_pid) { worker_subscribers_sentinel = cur; break; } } if (worker_subscribers_sentinel == NULL) { // found nothing worker_subscribers_sentinel = ngx_http_push_stream_create_worker_subscriber_channel_sentinel_locked(shpool, channel_id, log); if (worker_subscribers_sentinel == NULL) { return NGX_ERROR; } } if ((element_subscriber = ngx_palloc(subscription->subscriber->request->pool, sizeof(ngx_http_push_stream_queue_elem_t))) == NULL) { // unable to allocate request queue element ngx_log_error(NGX_LOG_ERR, log, 0, "push stream module: unable to allocate subscriber reference"); return NGX_ERROR; } element_subscriber->value = subscription->subscriber; subscription->channel_subscriber_element_ref = element_subscriber; channel->subscribers++; // do this only when we know everything went okay channel->last_activity_time = ngx_time(); ngx_queue_insert_tail(&subscriptions_sentinel->queue, &subscription->queue); ngx_queue_insert_tail(&worker_subscribers_sentinel->subscribers_sentinel.queue, &element_subscriber->queue); return NGX_OK; }