Пример #1
0
apr_status_t procmgr_stop_procmgr(void *server)
{
    apr_status_t status;
    fcgid_server_conf *conf;

    /* Tell the world to die */
    g_must_exit = 1;
    if (g_msgqueue)
        apr_queue_push(g_msgqueue, NULL);

    /* Wait */
    if (g_thread && apr_thread_join(&status, g_thread) == APR_SUCCESS) {
        /* Free the memory left in queue */
        fcgid_command *peakcmd = NULL;

        while (apr_queue_trypop(g_msgqueue, (void **)&peakcmd) == APR_SUCCESS) {
            if (peakcmd)
                free(peakcmd);
        }
    }

    /* Clean up the Job object if present */
    conf = ap_get_module_config(((server_rec*)server)->module_config,
                                &fcgid_module);

    if (conf->hJobObjectForAutoCleanup != NULL) {
        CloseHandle(conf->hJobObjectForAutoCleanup);
    }

    if (g_wakeup_thread)
        return apr_thread_join(&status, g_wakeup_thread);

    return APR_SUCCESS;
}
Пример #2
0
int trypop_queue(struct seed_cmd *cmd) {
#ifdef USE_FORK
    int ret;
    struct msg_cmd mcmd;
    ret = msgrcv(msqid, &mcmd, sizeof(struct seed_cmd), 1, IPC_NOWAIT);
    if(errno == ENOMSG) return APR_EAGAIN;
    if(ret>0) {
    *cmd = mcmd.cmd;
    return APR_SUCCESS;
    } else {
      printf("failed to trypop tile\n");
      return APR_EGENERAL;
    }
#else
   int ret;
   struct seed_cmd *pcmd;
   ret = apr_queue_trypop(work_queue,(void**)&pcmd);
   if(ret == APR_SUCCESS) {
      *cmd = *pcmd;
      free(pcmd);
   }
   return ret;
#endif
}
Пример #3
0
SWITCH_DECLARE(switch_status_t) switch_queue_trypop(switch_queue_t *queue, void **data)
{
	return apr_queue_trypop(queue, data);
}
Пример #4
0
bool LLThreadSafeQueueImplementation::tryPopBack(void *& element)
{
	return apr_queue_trypop(mQueue, &element) == APR_SUCCESS;
}
Пример #5
0
static int manage_redis_context_queue(redisContext **ctx, int management_mode, request_rec *r)
{

    apr_status_t rv; 
    int redis_queue_enabled = 0;

    secuip_svr_config *svr_config = (secuip_svr_config *) ap_get_module_config(r->server->module_config, &secuip_module);

    // check the redis connection pool on/off setting
    redis_queue_enabled = svr_config->redis_queue_enabled;

    if (management_mode == TRYPOP_REDIS_CONTEXT) {
        // not using queue
        if (!redis_queue_enabled) {
            *ctx = init_redisclient(r->server, svr_config->redis_ip, svr_config->redis_port, svr_config->redis_password);
            if (*ctx == NULL) // redis error
            {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "trying to redis connection error.[%d]");
                return -1; // reponse: DECLINED
            }
            return 0;
        }

        // pop redis context
        rv = apr_queue_trypop(redis_context_queue, (void **)ctx); 
        if (rv != APR_SUCCESS) {
            // queue empty
            if (rv == APR_EAGAIN) {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "redis connection pool is empty. skipping to check request count.");

                *ctx = init_redisclient(r->server, svr_config->redis_ip, svr_config->redis_port, svr_config->redis_password);
                if (*ctx == NULL) { // redis error 
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "trying to redis connection error.[%d]");
                    return -1; // reponse: DECLINED
                }
            }
            else {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "queue error(trypop)");
                return -1; // reponse: DECLINED
            }
        }
    }
    else if (management_mode == TRYPUSH_REDIS_CONTEXT) {
        if (!redis_queue_enabled) {
            free_redis_ctx(*ctx, r->server);
            return 0; // success
        }

        // push redis context for reuse
        rv = apr_queue_trypush(redis_context_queue, *ctx);
        if (rv != APR_SUCCESS) {
            // anyway, free context
            free_redis_ctx(*ctx, r->server);

            if (rv == APR_EAGAIN) { // queue full 
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "redis connection pool is full.(if this occures, there is a error of queue management.");
            }
            ap_log_error(APLOG_MARK, APLOG_ERR, rv, r->server,"Failed to push queue in block module");
            return 0; //success
        }
        // log (current queue size)
        //ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "redis context pushed[%d].", apr_queue_size(redis_context_queue));
    }

    return 0;
}