nginx 학습 10 ngxcycle_t 、ngx_connection_t 와 ngxlistening_t

8756 단어 nginx웹 서버
최근 nginx 의 이벤트 모듈 을 보기 시 작 했 습 니 다. ngx 를 자주 봅 니 다.cycle_t、ngx_connection_t 와 ngxlistening_t. 이 세 개의 구조 체 는 처음에 신경 쓰 지 않 고 보 자마자 다시 인터넷 변 수 를 한 다 는 뜻 이다. 나중에 이 세 개의 구조 체 를 이해 하지 못 하거나 그 중의 변수의 의 미 를 잘 모 르 는 것 은 정말 볼 수 없다 고 생각 했다. 왜냐하면 많은 함수 가 이 세 개의 구조 체 와 관련 되 기 때문이다.왜냐하면 ngxlistening_t 감청 관련 정보 저장, ngxconnection_t. 연결 에 관 한 정보 와 읽 기와 쓰기 이 벤트 를 저장 하고 ngxcycle_t. 이 구조 체 는 거의 핵심 구조 체 입 니 다. nginx 가 초기 화 될 때 이 구조 체 는 많은 것 을 저장 하고 초기 화 된 함수 가 있 습 니 다: ngxinit_cycle, 이 함수 의 코드 는 700 여 줄 입 니 다.이 구조 체 는 여러 가지 요점 이 있 음 을 알 수 있다.그래서 반나절 동안 이 몇 개의 구조 체 안의 구성원 들 의 뜻 을 찾 아 보기 편 하 게 했다. 이런 자 료 는 교과서 와 인터넷 에서 온 것 이기 때문에 오류 가 있 을 수 밖 에 없 기 때문에 앞으로 다른 자주 사용 하 는 구조 체 를 수정 하고 계속 추가 할 것 이다.
http://blog.csdn.net/xiaoliangsky/article/details/398310351ngx_listening_t
코어 / ngxconnection. h 중
struct ngx_listening_s {
    ngx_socket_t        fd;//     

    struct sockaddr    *sockaddr;//  sockaddr  
    socklen_t           socklen;    /*sockaddr     size of sockaddr */
    size_t              addr_text_max_len;//  ip      addr_text    
    ngx_str_t           addr_text;//        ip  
	//     。types SOCK_STREAM ,   tcp
    int                 type;
	//TCP      backlog  ,               tcp                     
    int                 backlog;
    int                 rcvbuf;//          
    int                 sndbuf;//          

    /* handler of accepted connection */
    ngx_connection_handler_pt   handler;//   tcp            
	//      HTTP  mail   ,                   
    void               *servers;  /* array of ngx_http_in_addr_t, for example */

    ngx_log_t           log;//  
    ngx_log_t          *logp;//    

    size_t              pool_size;//     tcp       ,            pool_size。
    /* should be here because of the AcceptEx() preread */
    size_t              post_accept_buffer_size;
    /* should be here because of the deferred accept */
    ngx_msec_t          post_accept_timeout;//~             ,      
	//   ngx_listening_t  ,       
    ngx_listening_t    *previous;
    ngx_connection_t   *connection;//         ngx_connection_t   

    unsigned            open:1;// 1        , 0      
    unsigned            remain:1;// 1              , 0             
    unsigned            ignore:1;// 1        ngx_listening_t        , 0         

    unsigned            bound:1;       /* already bound */
    unsigned            inherited:1;   /* inherited from previous process */
    unsigned            nonblocking_accept:1;
    unsigned            listen:1;// 1                 
    unsigned            nonblocking:1;
    unsigned            shared:1;    /* shared between threads or processes */
    unsigned            addr_ntop:1;// 1                  

#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
    unsigned            ipv6only:2;
#endif

#if (NGX_HAVE_DEFERRED_ACCEPT)
    unsigned            deferred_accept:1;
    unsigned            delete_deferred:1;
    unsigned            add_deferred:1;
#ifdef SO_ACCEPTFILTER
    char               *accept_filter;
#endif
#endif
#if (NGX_HAVE_SETFIB)
    int                 setfib;
#endif

};

2ngx_connction_t
코어 / ngxconnection. h 중
struct ngx_connection_s {
	//      ,data              next  。          ,HTTP ,data  ngx_http_request_t
    void               *data;
    ngx_event_t        *read;//        
    ngx_event_t        *write;//        

    ngx_socket_t        fd;//        

    ngx_recv_pt         recv;//            
    ngx_send_pt         send;//            
    ngx_recv_chain_pt   recv_chain;//              
    ngx_send_chain_pt   send_chain;//              
	//       ngx_listening_t    ,    listening         
    ngx_listening_t    *listening;

    off_t               sent;//            

    ngx_log_t          *log;//    
       /*   。   accept       ,        ,               。         listening   pool_size   */
    ngx_pool_t         *pool;

    struct sockaddr    *sockaddr;//      sockaddr
    socklen_t           socklen;//sockaddr      
    ngx_str_t           addr_text;//           IP  

#if (NGX_SSL)
    ngx_ssl_connection_t  *ssl;
#endif
	//         sockaddr   ,     listening     sockaddr  
    struct sockaddr    *local_sockaddr;

    ngx_buf_t          *buffer;//    、           ,buffer          ,      
	/*                    ngx_cycle_t      reuseable_connection_queue     ,         */
    ngx_queue_t         queue;
	/*      。ngx_connection_t                 ,               ,number   1*/
    ngx_atomic_uint_t   number;

    ngx_uint_t          requests;//       
	//        。
    unsigned            buffered:8;
	//        ,  3 ,     0~7,       5  , ngx_connection_log_error_e    。
    unsigned            log_error:3;     /* ngx_connection_log_error_e */

    unsigned            single_connection:1;// 1        , 0                     
    unsigned            unexpected_eof:1;// 1          
    unsigned            timedout:1;// 1        
    unsigned            error:1;// 1             
    unsigned            destroyed:1;// 1        

    unsigned            idle:1;// 1          , keepalive         
    unsigned            reusable:1;// 1       ,    queue      
    unsigned            close:1;// 1      

    unsigned            sendfile:1;// 1                   
	/* 1                               ,             。  ngx_handle_write_event    lowat      */
    unsigned            sndlowat:1;
    unsigned            tcp_nodelay:2;   /* ngx_connection_tcp_nodelay_e */
    unsigned            tcp_nopush:2;    /* ngx_connection_tcp_nopush_e */

#if (NGX_HAVE_IOCP)
    unsigned            accept_context_updated:1;
#endif

#if (NGX_HAVE_AIO_SENDFILE)
    unsigned            aio_sendfile:1;
    ngx_buf_t          *busy_sendfile;
#endif

#if (NGX_THREADS)
    ngx_atomic_t        lock;
#endif
};

3ngx_cycle_t
코어 / ngxcycle. h 중
struct ngx_cycle_s {
	/*                  ,        ,            ,                 */
    void                  ****conf_ctx;
    ngx_pool_t               *pool;//   
	/*            ngx_log_t       ,   log          ngx_init_cycle   ,          ,            ,      log  ,       。 ngx_init_cycle     ,    nginx.conf         ,          ,    log    */
    ngx_log_t                *log;
	/*  ngx_init_cycle   ,  new_log        log  */
    ngx_log_t                 new_log;
	//fiels    ngx_connection_t        ,files_n       ,           files    
    ngx_connection_t        **files;
	//     , free_connection_n    
    ngx_connection_t         *free_connections;
	//           
    ngx_uint_t                free_connection_n;
	//            ,     ngx_connection_t
    ngx_queue_t               reusable_connections_queue;
	//  ngx_listening_t  
    ngx_array_t               listening;
	//   Nginx        ,       ,      ,           Nginx    。
    ngx_array_t               pathes;
	//  Nginx         (ngx_open_file_t   )    。
    ngx_list_t                open_files;
	//     ngx_shm_zone_t,            。
    ngx_list_t                shared_memory;
	//                ,    connections      
    ngx_uint_t                connection_n;
	//  files   ngx_connection_t     
    ngx_uint_t                files_n;
	//              ,                   
    ngx_connection_t         *connections;
	//               ,connection_n            
    ngx_event_t              *read_events;
	//               ,connection_n            
    ngx_event_t              *write_events;
	/*  ngx_cycle_t         ngx_cycle_t      ,  ngx_init_cycle  ,     ,         ngx_cycle_t        ,   ngx_init_cycle   ,      ngx_cycle_t      ,   old_clcle           ngx_clcle_t  。*/
    ngx_cycle_t              *old_cycle;
	//                
    ngx_str_t                 conf_file;
	//Nginx                       ,   -g       
    ngx_str_t                 conf_param;
	//Nginx         
    ngx_str_t                 conf_prefix;
	//Nginx       
    ngx_str_t                 prefix;
	//             
    ngx_str_t                 lock_file;
	//  gethostname          
    ngx_str_t                 hostname;
};
4ngx_conf_t
코어 / ngxconf_file.h
struct ngx_conf_s {
    char                 *name;//          
    ngx_array_t          *args;//            

    ngx_cycle_t          *cycle;//         ,  ngx_cycle.h  
    ngx_pool_t           *pool;//   
    ngx_pool_t           *temp_pool;//                ,      
    ngx_conf_file_t      *conf_file;//ngx_conf_file_t      
    ngx_log_t            *log;//

    void                 *ctx;//        
    ngx_uint_t            module_type;//         
    ngx_uint_t            cmd_type;//     

    ngx_conf_handler_pt   handler;//          
    char                 *handler_conf;//              
};

좋은 웹페이지 즐겨찾기