Nginx函数ngx_single_process_cycle学习笔记

来源:互联网 发布:昆仑虚麒麟臂升阶数据 编辑:程序博客网 时间:2024/06/10 17:02
  • ngx_cycle_t=ngx_cycle_s
    ngx_cycle_s的定义如下,下面介绍的函数中有一个重要的ngx_cycle_t类型的参数cycle,所一写介绍下它的类型结构。
struct ngx_cycle_s {void                  ****conf_ctx;ngx_pool_t               *pool;ngx_log_t                *log;ngx_log_t                 new_log; ngx_uint_t                log_use_stderr;  /* unsigned  log_use_stderr:1; */ngx_connection_t        **files;ngx_connection_t         *free_connections;ngx_uint_t                free_connection_n;ngx_module_t            **modules;ngx_uint_t                modules_n;ngx_uint_t                modules_used;    /* unsigned  modules_used:1; */ngx_queue_t               reusable_connections_queue;ngx_array_t               listening;ngx_array_t               paths;ngx_array_t               config_dump;ngx_list_t                open_files;ngx_list_t                shared_memory;ngx_uint_t                connection_n;ngx_uint_t                files_n;ngx_connection_t         *connections;ngx_event_t              *read_events;ngx_event_t              *write_events;ngx_cycle_t              *old_cycle;ngx_str_t                 conf_file;ngx_str_t                 conf_param;ngx_str_t                 conf_prefix;ngx_str_t                 prefix;ngx_str_t                 lock_file;ngx_str_t                 hostname;};
  • ngx_module_t=ngx_module_s
    在ngx_cycle_s中modules成员类型如下
    说明:ngx_module_t表示Nginx模块的基本接口,针对每个不同类型的模块,都有一个结构提来描述这一类模块的通用接口,这个接口保存在ngx_module_t的ctx成员中。例如核心模块的通用接口是ngx_core_model_t结构体,而事件模块的通用接口则是ngx_event_module_t
struct ngx_module_s {ngx_uint_t            ctx_index;ngx_uint_t            index;char                 *name;ngx_uint_t            spare0;ngx_uint_t            spare1;ngx_uint_t            version;const char           *signature;void                 *ctx;ngx_command_t        *commands;ngx_uint_t            type;ngx_int_t           (*init_master)(ngx_log_t *log);ngx_int_t           (*init_module)(ngx_cycle_t *cycle);ngx_int_t           (*init_process)(ngx_cycle_t *cycle);ngx_int_t           (*init_thread)(ngx_cycle_t *cycle);void                (*exit_thread)(ngx_cycle_t *cycle);void                (*exit_process)(ngx_cycle_t *cycle);void                (*exit_master)(ngx_cycle_t *cycle);uintptr_t             spare_hook0;uintptr_t             spare_hook1;uintptr_t             spare_hook2;uintptr_t             spare_hook3;uintptr_t             spare_hook4;uintptr_t             spare_hook5;uintptr_t             spare_hook6;uintptr_t             spare_hook7;};//ctx指向以下的ngx_event_module_ttypedef struct {ngx_str_t              *name;void                 *(*create_conf)(ngx_cycle_t *cycle);char                 *(*init_conf)(ngx_cycle_t *cycle, void *conf);ngx_event_actions_t     actions;} ngx_event_module_t;//ngx_command_t的定义如下struct ngx_command_s {ngx_str_t             name;ngx_uint_t            type;char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);ngx_uint_t            conf;ngx_uint_t            offset;void                 *post;};
  • ngx_process_events
    在void ngx_process_events_and_timers(ngx_cycle_t *cycle)方法中,ngx_process_events的定义如下
    ngx_process_events实际对应的函数为:static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)

define ngx_process_events ngx_event_actions.process_events

ngx_event_actions_t   ngx_event_actions;typedef struct {ngx_int_t  (*add)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);ngx_int_t  (*del)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);ngx_int_t  (*enable)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);ngx_int_t  (*disable)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags);ngx_int_t  (*add_conn)(ngx_connection_t *c);ngx_int_t  (*del_conn)(ngx_connection_t *c, ngx_uint_t flags);ngx_int_t  (*notify)(ngx_event_handler_pt handler);ngx_int_t  (*process_events)(ngx_cycle_t *cycle, ngx_msec_t timer,ngx_uint_t flags);ngx_int_t  (*init)(ngx_cycle_t *cycle, ngx_msec_t timer);void       (*done)(ngx_cycle_t *cycle);} ngx_event_actions_t;
  • ngx_set_environment

  • init_process

  • ngx_log_debug0

  • ngx_process_events_and_timers

  • exit_process

  • ngx_master_process_exit

0 0
原创粉丝点击