ngx_http_upstream_conpaas_module.c
/**
 * Peer initialization function, called once for each HTTP request.
 * Sets up the ngx_http_upstream_conpaas_peer_data_t structure associated with the request.
 */
Peer initialization function, called once for each HTTP request.
Sets up the ngx_http_upstream_conpaas_peer_data_t structure associated with the request.
Peer initialization function called once for each HTTP request . Sets up the ngx_http_upstream_conpaas_peer_data_t structure associated with the request .
ngx_int_t
ngx_http_upstream_init_conpaas_peer(ngx_http_request_t *r,
    ngx_http_upstream_srv_conf_t *us)
{
    ngx_uint_t                         n;
    ngx_http_upstream_conpaas_peer_data_t  *rrp;
    struct sigaction sa;
    int ret;
    if (!signal_initialized) {
    	memset(&sa, 0, sizeof(sa));
    	sa.sa_handler = sigusr2_handler;
    	ret = sigaction(SIGUSR2, &sa, NULL);
    	ngx_log_error(NGX_LOG_NOTICE, r -> connection -> log, 0, "signal handler set: %d", ret);
    	signal_initialized = 1;
    }
    ngx_log_error(NGX_LOG_NOTICE, r -> connection ->log, 0, "init_conpaas_peer");
    rrp = r->upstream->peer.data;
    if (rrp == NULL) {
        rrp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_conpaas_peer_data_t));
        if (rrp == NULL) {
            return NGX_ERROR;
        }
        r->upstream->peer.data = rrp;
    }
    rrp->peers = us->peer.data;
    rrp->current = 0;
    if (rrp->peers->number <= 8 * sizeof(uintptr_t)) {
        rrp->tried = &rrp->data;
        rrp->data = 0;
    } else {
        n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1))
                / (8 * sizeof(uintptr_t));
        rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t));
        if (rrp->tried == NULL) {
            return NGX_ERROR;
        }
    }
    rrp -> module_conf =  ngx_http_get_module_loc_conf(r, ngx_http_upstream_conpaas_module);
    r->upstream->peer.get = ngx_http_upstream_get_conpaas_peer;
    r->upstream->peer.free = ngx_http_upstream_free_conpaas_peer;
    r->upstream->peer.tries = rrp->peers->number;
    return NGX_OK;
}
ngx_int_t ngx_http_upstream_init_conpaas_peer ( ngx_http_request_t * r , ngx_http_upstream_srv_conf_t * us ) { ngx_uint_t n ; ngx_http_upstream_conpaas_peer_data_t * rrp ; struct sigaction sa ; int ret ; if ( ! signal_initialized ) { memset ( & sa , 0 , sizeof ( sa ) ) ; sa . sa_handler = sigusr2_handler ; ret = sigaction ( SIGUSR2 , & sa , NULL ) ; ngx_log_error ( NGX_LOG_NOTICE , r -> connection -> log , 0 , " " , ret ) ; signal_initialized = 1 ; } ngx_log_error ( NGX_LOG_NOTICE , r -> connection -> log , 0 , " " ) ; rrp = r -> upstream -> peer . data ; if ( rrp == NULL ) { rrp = ngx_palloc ( r -> pool , sizeof ( ngx_http_upstream_conpaas_peer_data_t ) ) ; if ( rrp == NULL ) { return NGX_ERROR ; } r -> upstream -> peer . data = rrp ; } rrp -> peers = us -> peer . data ; rrp -> current = 0 ; if ( rrp -> peers -> number <= 8 * sizeof ( uintptr_t ) ) { rrp -> tried = & rrp -> data ; rrp -> data = 0 ; } else { n = ( rrp -> peers -> number + ( 8 * sizeof ( uintptr_t ) - 1 ) ) / ( 8 * sizeof ( uintptr_t ) ) ; rrp -> tried = ngx_pcalloc ( r -> pool , n * sizeof ( uintptr_t ) ) ; if ( rrp -> tried == NULL ) { return NGX_ERROR ; } } rrp -> module_conf = ngx_http_get_module_loc_conf ( r , ngx_http_upstream_conpaas_module ) ; r -> upstream -> peer . get = ngx_http_upstream_get_conpaas_peer ; r -> upstream -> peer . free = ngx_http_upstream_free_conpaas_peer ; r -> upstream -> peer . tries = rrp -> peers -> number ; return NGX_OK ; }
Peer initialization function, called once for each HTTP request.
Peer initialization function called once for each HTTP request .
/* set signal handler */ /* act.sa_flags = SA_SIGINFO; */ /* ngx_log_debug0(NGX_LOG_NOTICE, r -> connection ->log, 0, "In ngx_http_upstream_init_conpaas_peer()..."); */ /* store the module configuration parameters */