nginx fork子进程代码和epoll_create, epoll_ctrl函数的实现关系

main(int argc, char *const *argv)
->
ngx_master_process_cycle(cycle);
->
ngx_start_worker_processes(cycle, ccf->worker_processes,
NGX_PROCESS_RESPAWN);
->
ngx_spawn_process(cycle, ngx_worker_process_cycle,
(void *) (intptr_t) i, “worker process”, type);
->
pid = fork();

main(int argc, char *const *argv)
->
ngx_master_process_cycle(cycle);
->
ngx_start_cache_manager_processes(cycle, 0);
->
ngx_spawn_process(cycle, ngx_cache_manager_process_cycle,
&ngx_cache_manager_ctx, “cache manager process”,
respawn ? NGX_PROCESS_JUST_RESPAWN : NGX_PROCESS_RESPAWN);
->
pid = fork();

static ngx_str_t epoll_name = ngx_string(“epoll”);
static ngx_command_t ngx_epoll_commands[]

ngx_epoll_module
->
ngx_epoll_module_ctx
->
ngx_epoll_init
->
ep = epoll_create(cycle->connection_n / 2);

static ngx_str_t event_core_name = ngx_string(“event_core”);
static ngx_command_t ngx_event_core_commands[]
ngx_event_core_module
->
ngx_event_core_module_ctx
->
ngx_event_core_init_conf(ngx_cycle_t *cycle, void *conf)
->
fd = epoll_create(100);

在ngx_event_core_init_conf(ngx_cycle_t *cycle, void *conf)函数中
会判断是否支持EPOLL,然后创建epoll树节点:
#if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)

fd = epoll_create(100);

if (fd != -1) {
    (void) close(fd);
    module = &ngx_epoll_module;

} else if (ngx_errno != NGX_ENOSYS) {
    module = &ngx_epoll_module;
}

#endif

ngx_event_module_t ngx_epoll_module_ctx
->
ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
->
epoll_ctl(ep, op, c->fd, &ee)

ngx_event_module_t ngx_epoll_module_ctx = {
&epoll_name,
ngx_epoll_create_conf, /* create configuration /
ngx_epoll_init_conf, /
init configuration */

{
    ngx_epoll_add_event,             /* add an event */
    ngx_epoll_del_event,             /* delete an event */
    ngx_epoll_add_event,             /* enable an event */
    ngx_epoll_del_event,             /* disable an event */
    ngx_epoll_add_connection,        /* add an connection */
    ngx_epoll_del_connection,        /* delete an connection */

#if (NGX_HAVE_EVENTFD)
ngx_epoll_notify, /* trigger a notify /
#else
NULL, /
trigger a notify /
#endif
ngx_epoll_process_events, /
process the events /
ngx_epoll_init, /
init the events /
ngx_epoll_done, /
done the events */
}
};
ngx_event_actions = ngx_epoll_module_ctx.actions;

在Ngx_event.c中,处理事件event的函数是从event_module中继承过来的:
#define ngx_process_events ngx_event_actions.process_events
#define ngx_done_events ngx_event_actions.done

#define ngx_add_event ngx_event_actions.add
#define ngx_del_event ngx_event_actions.del
#define ngx_add_conn ngx_event_actions.add_conn
#define ngx_del_conn ngx_event_actions.del_conn

#define ngx_notify ngx_event_actions.notify

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值