Esempio n. 1
0
SWITCH_DECLARE(switch_status_t) switch_queue_trypush(switch_queue_t *queue, void *data)
{
	apr_status_t s;

	do {
		s = apr_queue_trypush(queue, data);
	} while (s == APR_EINTR);

	return s;
}
Esempio n. 2
0
static void *APR_THREAD_FUNC wakeup_thread(apr_thread_t * thd, void *data)
{
    while (!g_must_exit) {
        /* Wake up every second to check g_must_exit flag */
        int i;

        for (i = 0; i < g_wakeup_timeout; i++) {
            if (g_must_exit)
                break;
            apr_sleep(apr_time_from_sec(1));
        }

        /* Send a wake up message to procmgr_fetch_cmd() */
        if (!g_must_exit && g_msgqueue)
            apr_queue_trypush(g_msgqueue, NULL);
    }
    return NULL;
}
Esempio n. 3
0
static void setup_redisclient_child_init(apr_pool_t *pchild, server_rec *s)
{
    apr_status_t rv; 
    redisContext *ctx;
    redisReply *reply;
    int i;

    ap_log_perror(APLOG_MARK, APLOG_ERR, 0, pchild, "redis client initializaion.(apache child. PID:[%d])", getpid());

    /*********************/
    secuip_svr_config *svr_config = (secuip_svr_config *)ap_get_module_config(s->module_config, &secuip_module);
    
    //TODO: per virtualServer(maybe next version)
    //secuip_svr_config *svr_config = (secuip_svr_config *)ap_get_module_config(s->next->module_config, &secuip_module);
    /*********************/

    rv = apr_pool_create(&svr_config->pool, pchild);
    if (rv != APR_SUCCESS) {
        ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, pchild, "Failed to create subpool for secuip");
        return;
    }

#if APR_HAS_THREADS
    rv = apr_thread_mutex_create(&svr_config->mutex, APR_THREAD_MUTEX_DEFAULT, svr_config->pool);
    if (rv != APR_SUCCESS) {
        ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, svr_config->pool,"[0]Failed to create mutex for sucuip");
        return; 
    }
#endif

//    rv = apr_queue_create(&svr_config->redis_context_queue, svr_config->redis_init_count, svr_config->pool);
    rv = apr_queue_create(&redis_context_queue, svr_config->redis_init_count, svr_config->pool);
    if (rv != APR_SUCCESS) {
        ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, svr_config->pool,"[1]Failed to create queue for secuip");
        return; 
    }

    // not using redis connection pool
    if (svr_config->redis_queue_enabled != 1) {
        ap_log_perror(APLOG_MARK, APLOG_ERR, 0, pchild, "svr_config->redis_queue_enabled value[%d].(apache child. PID:[%d], init count[%d])", svr_config->redis_queue_enabled, getpid(), svr_config->redis_init_count);
        return;
    }

    for (i = 0; i < svr_config->redis_init_count; i++) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,"init redis for secuip:[%d], PID:[%d]", i, getpid());
        ctx = init_redisclient(s, svr_config->redis_ip, svr_config->redis_port, svr_config->redis_password);
        if ( ctx == NULL) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "init redisclient error.");
            return;
        }

        // reg. cleanup
        //apr_pool_cleanup_register(svr_config->pool, ctx, redisFree, apr_pool_cleanup_null) ;

        // add ctx to queue.
        rv = apr_queue_trypush(redis_context_queue, ctx);
        if (rv != APR_SUCCESS) {
            // queue full
            //free
            free_redis_ctx(ctx, s);
            if (rv == APR_EAGAIN) {
            //redisCommand(ctx, "GET trypush_queue_full(%X)", ctx);
	            ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "redis connection pool is full.(if this occures, there is a error of queue management.");
            }
            //redisCommand(ctx, "GET trypush_error(%X)", ctx);
            ap_log_perror(APLOG_MARK, APLOG_ERR, rv, svr_config->pool, "[2]Failed to push queue for secuip.");
            return; 
        }
        // log (current queue size)
            //redisCommand(ctx, "GET trypush_success(%X)(pid%d)(size%d)", ctx, getpid(), apr_queue_size(redis_context_queue));
        //ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "redis context pushed[%d].", apr_queue_size(redis_context_queue));
    }

    //redisFree(ctx); // not necessary in here.
    return;
}
Esempio n. 4
0
bool LLThreadSafeQueueImplementation::tryPushFront(void * element){
	return apr_queue_trypush(mQueue, element) == APR_SUCCESS;
}
Esempio n. 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;
}