static ngx_int_t ngx_http_upstream_get_available_capacity_peer(ngx_peer_connection_t *pc, void *data)
{
    ngx_http_upstream_available_capacity_data_t *cap_data = data;
    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, "get available capacity peer, try: %ui", pc->tries);
    pc->cached = 0;
    pc->connection = NULL;

    ngx_http_upstream_available_capacity_srv_conf_t *conf = ngx_http_conf_upstream_srv_conf(cap_data->conf, ngx_http_upstream_available_capacity_module);
    ngx_http_upstream_available_capacity_server_t *found_server = NULL;
    ngx_http_upstream_available_capacity_server_t *server = conf->search_start_peer;
    size_t i = 0;
    for (; i < conf->server_num; ++i) {
        if (i != 0) {
            server = NEXT_SERVER(conf, server);
        }
        if (server->capacity > 0) {
            found_server = server;
            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, "server_capacity = [%d]\n", server->capacity);
            --server->capacity;
            break;
        }
    }
    conf->search_start_peer = (server == conf->search_start_peer) ? NEXT_SERVER(conf, server) : server;

    if (found_server) {
        pc->sockaddr = found_server->addr.sockaddr;
        pc->socklen  = found_server->addr.socklen;
        pc->name     = &found_server->server->name;
    } else {
        ngx_log_error_core(NGX_LOG_ERR, pc->log, 0, "cannot load balance");
        return NGX_ERROR;
    }

    return NGX_OK;
}
ngx_http_xsltproc_xslt_keys_t *
ngx_http_xsltproc_xslt_keys_new(char *stylesheet_uri, time_t stylesheet_mtime,
    char *document_uri, time_t document_mtime, xsltDocumentPtr xslt_document)
{
    ngx_http_xsltproc_xslt_keys_t *xslt_keys;

    if ((xslt_keys = ngx_http_xsltproc_malloc(sizeof(ngx_http_xsltproc_xslt_keys_t))) == NULL) {
        return NULL;
    }

    memset(xslt_keys, 0, sizeof(ngx_http_xsltproc_xslt_keys_t));

    xslt_keys->stylesheet_uri   = strdup(stylesheet_uri);
    xslt_keys->stylesheet_mtime = stylesheet_mtime;
    xslt_keys->document_uri     = strdup(document_uri);
    xslt_keys->document_mtime   = document_mtime;
    xslt_keys->xslt_document    = xslt_document;

#ifdef NGX_DEBUG
    ngx_log_error_core(NGX_LOG_DEBUG, xslt_keys_log, 0,
                       "ngx_http_xsltproc_xslt_keys_new: stylesheet %s %d, document %s %d",
                       stylesheet_uri, (int) stylesheet_mtime,
                       document_uri, (int) document_mtime);
#endif

    return xslt_keys;
}
ngx_http_xsltproc_xslt_document_t *ngx_http_xsltproc_xslt_document_cache_lookup(char *uri) {
    ngx_http_xsltproc_xslt_document_t           *xslt_document = NULL;
    ngx_http_xsltproc_list_t                    *el;
    ngx_http_xsltproc_xml_document_extra_info_t *doc_extra_info;
    xmlDocPtr                                    doc;
    int                                          found = 0;

    for (
        el = ngx_http_xsltproc_list_first(&xslt_document_cache);
        el != ngx_http_xsltproc_list_end(&xslt_document_cache);
        el = ngx_http_xsltproc_list_next(el)
    ) {
        xslt_document = (ngx_http_xsltproc_xslt_document_t *) el;

        if (strcmp(xslt_document->uri, uri) == 0) {
#ifdef NGX_DEBUG
    ngx_log_error_core(NGX_LOG_DEBUG, xslt_document_cache_log, 0,
                       "ngx_http_xsltproc_xslt_document_cache_lookup: document %s is found in cache",
                       uri);
#endif
            found = 1;

            break;
        }
    }

    if (found && ngx_http_xsltproc_xslt_document_is_updated(xslt_document)) {
#ifdef NGX_DEBUG
    ngx_log_error_core(NGX_LOG_DEBUG, xslt_document_cache_log, 0,
                       "ngx_http_xsltproc_xslt_document_cache_looku: document %s is expired",
                       xslt_document->uri);
#endif
        doc               = xslt_document->doc;
        doc_extra_info    = doc->_private;

        ngx_http_xsltproc_xslt_keys_cache_expire(NULL, 0, xslt_document->uri, doc_extra_info->mtime);

        ngx_http_xsltproc_xslt_document_clear(xslt_document);
    }

    if (!found) {
        xslt_document = ngx_http_xsltproc_xslt_document_new(uri);
        ngx_http_xsltproc_list_insert_tail(&xslt_document_cache, (ngx_http_xsltproc_list_t *) xslt_document);
    }

    return xslt_document;
}
Ejemplo n.º 4
0
void ngx_cdecl
ngx_log_debug_core(ngx_log_t *log, ngx_err_t err, const char *fmt, ...)
{
    va_list  args;
    va_start(args, fmt);
    ngx_log_error_core(NGX_LOG_DEBUG, log, err, fmt, args);
    va_end(args);
}
void ngx_cdecl ngx_log_error(ngx_uint_t level,ngx_log_t *log,ngx_err_t err,const char * fmt,...){
    va_list args;

    if  (log->log_level >= level){
        va_start (args,fmt);
        ngx_log_error_core(level,log,err,fmt,args);
        va_end (args);
    }
}
Ejemplo n.º 6
0
void ngx_cdecl
ngx_log_errorall(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
    const char *fmt, ...)
{
    va_list  args;

    va_start(args, fmt);
    ngx_log_error_core(level, log,__FUNCTION__, __LINE__, err, fmt, args);
    va_end(args);
}
static void 
ngx_rtmp_hls_av_log_callback(void* avcl, int level, const char* fmt, 
        va_list args) 
{
    char           *p;
    static char     buf[1024];
    int             n;


    n = vsnprintf(buf, sizeof(buf), fmt, args);
    buf[n] = 0;

    for (p = buf; *p; ++p) {
        if (*p == (u_char)'\n' || *p == (u_char)'\r') {
            *p = ' ';
        }
    }

    ngx_log_error_core(NGX_LOG_ERR, ngx_rtmp_hls_log, 0, "hls: av: %s", buf);
}
void 
radius_logger( void* log, const char* fmt ) {
    ngx_uint_t level = 0;
    ngx_err_t err = 0;
    ngx_log_error_core( level, log, err, fmt, NULL );
}
/*
 *  Called once per process to initialize the rrd lib.
 */
static ngx_int_t ngx_http_rrd_init_process(ngx_cycle_t *cycle) {
    ARG_START_KEY = ngx_hash_key(ARG_START.data, ARG_START.len);
    rrd_get_context();
    ngx_log_error_core(NGX_LOG_DEBUG, cycle->log, 0, "rrd: init");
    return NGX_OK;
}
Ejemplo n.º 10
0
int
main(int argc, char *const *argv)
{
	void   	*ret;
	void   	*freeptr;
	ngx_pool_t			*curptr;
	ngx_int_t rlt;
	printf("--------pool Test---------\n");
  ngx_pool_t          *pool;
    int i=0;
  unit_create_log();  
  
  /*The the value of the ngx_pool_s.max be wrong if missing this call.
   *Because the ngx_pagesize = getpagesize() should be call for getting real page size. 
   *In function  ngx_create_pool:
   *   #define NGX_MAX_ALLOC_FROM_POOL  (ngx_pagesize - 1)   
   *   size = size - sizeof(ngx_pool_t);
   *   p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL;
   *The max will be size - sizeof(ngx_pool_t)
   */
   
  ngx_os_init(mylog); 
  
  ngx_log_error_core(NGX_LOG_NOTICE, mylog, 0,"ngx_create_pool size:%d", NGX_CYCLE_POOL_SIZE);

	printf("--System memory setting---------\n");  
  printf("Value of NGX_DEFAULT_POOL_SIZE size = %d\n", NGX_CYCLE_POOL_SIZE);   
	printf("Value of ngx_pagesize:getpagesize() = %d\n", getpagesize());   
  printf("Value of NGX_MAX_ALLOC_FROM_POOL£ºngx_pagesize-1= %d\n", NGX_MAX_ALLOC_FROM_POOL);   
	printf("size of ngx_pool_data_t = %d\n", sizeof(ngx_pool_data_t)); 
	printf("size of ngx_pool_t      = %d\n", sizeof(ngx_pool_t));    
	printf("size of ngx_pool_large_t= %d\n", sizeof(ngx_pool_large_t));    	
	


		  
  
  printf("\n\n--------ngx_create_pool--------\n");  
  //#define NGX_DEFAULT_POOL_SIZE    (16 * 1024)  
  printf("ngx_create_pool using NGX_DEFAULT_POOL_SIZE size = %d\n", NGX_CYCLE_POOL_SIZE); 
	printf("--------------------------------------\n");  
  pool = ngx_create_pool(NGX_CYCLE_POOL_SIZE, mylog); 
  if (pool == NULL) {
      return NULL;
  }
	dump_pool(pool);
		
	printf("\n--------size of ngx_align_ptr(p, a):--------\n");  	
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		
	printf("NGX_ALIGNMENT = %d\n", NGX_ALIGNMENT);  	

	printf("\n--------alloc block 1024 from the pool:--------\n");   
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		
	ret = ngx_palloc(pool, 1024); 
	printf("--------return address:0x%p--------\n",ret);
	dump_pool(pool);	

		
	printf("--------alloc block 1000 from the pool:--------\n");   
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		
	ret = ngx_palloc(pool, 1000); 
	printf("--------return address:0x%p--------\n",ret);	
	dump_pool(pool);

#if (TEST_ngx_palloc_large)	
	printf("--------alloc large block 3 from the pool:--------\n"); 
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		  
	ret = ngx_palloc(pool,  3*1024); 
	printf("--------return address:0x%p--------\n",ret);	
	dump_pool(pool);
	
	printf("--------alloc large block  4 from the pool:--------\n");   
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		
	ret = ngx_palloc(pool, 4*1024); 
	freeptr =  ret;
	printf("--------return address:0x%p--------\n",ret);	
	dump_pool(pool);

	printf("--------alloc large block  5 from the pool:--------\n");  
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		 
	ret = ngx_palloc(pool, 5*1024); 
	printf("--------return address:0x%p--------\n",ret);	
	dump_pool(pool);

	printf("--------free large block  4 from the pool:--------\n");  
  printf("block 4 address = p\n", freeptr);   
	rlt = ngx_pfree(pool,freeptr);
	if (rlt == NGX_OK){
	    printf("block 4 address deleted\n");   
			dump_pool(pool);
	}
	else{
	    printf("ngx_pfree return error=%d\n",rlt);   
	}

	printf("--------alloc large block  6 from the pool:--------\n");  
	printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		 
	ret = ngx_palloc(pool, 6*1024); 
	printf("--------return address:0x%p--------\n",ret);	
	dump_pool(pool);		
#endif	


#if (TEST_ngx_palloc_block)
	for(i=0;i<30;i++){
			printf("--------Loop alloc block 1024 from the pool:[%d]--------\n",i);   	
			printf("pool->d.last=%p,size of ngx_align_ptr(p, a) = %p\n",pool->d.last,ngx_align_ptr(pool->d.last, NGX_ALIGNMENT));  		
			ret = ngx_palloc(pool, 4095); 
			printf("--------return address:0x%p--------\n",ret);	
			dump_pool(pool);
	}


			
#endif	


#if (TEST_ngx_pool_cleanup_add)
  	printf("\n--------test for ngx_pool_cleanup_add : --------\n");		
  	ngx_pool_cleanup_t        *cln;
  	void											*buf;

		buf = ngx_pcalloc(pool, 100);
    cln = ngx_pool_cleanup_add(pool, 0);
    if (cln == NULL) {
    		printf("\n--------ngx_pool_cleanup_add failure --------\n");		
        return NGX_ERROR;
    }
      
    cln->handler = ngx_cleanup_callback;
    cln->data = buf;
    
    
#endif	

	

	
	printf("\n--------call ngx_destroy_pool--------\n");		
	dump_pool(pool);	
	ngx_destroy_pool(pool);     
	
  
	return 0;
	
}