event模块底层各种事件机制

来源:互联网 发布:电视盒子软件 编辑:程序博客网 时间:2024/05/22 03:21

1.aio机制

nginx_aio_module.c

static ngx_str_t      aio_name = ngx_string("aio");ngx_event_module_t  ngx_aio_module_ctx = {    &aio_name,    NULL,                                  /* create configuration */    NULL,                                  /* init configuration */    {        ngx_aio_add_event,                 /* add an event */        ngx_aio_del_event,                 /* delete an event */        NULL,                              /* enable an event */        NULL,                              /* disable an event */        NULL,                              /* add an connection */        ngx_aio_del_connection,            /* delete an connection */        NULL,                              /* process the changes */        ngx_aio_process_events,            /* process the events */        ngx_aio_init,                      /* init the events */        ngx_aio_done                       /* done the events */    }};ngx_module_t  ngx_aio_module = {    NGX_MODULE_V1,    &ngx_aio_module_ctx,                   /* module context */    NULL,                                  /* module directives */    NGX_EVENT_MODULE,                      /* module type */    NULL,                                  /* init master */    NULL,                                  /* init module */    NULL,                                  /* init process */    NULL,                                  /* init thread */    NULL,                                  /* exit thread */    NULL,                                  /* exit process */    NULL,                                  /* exit master */    NGX_MODULE_V1_PADDING};
两个数据结构:模块ngx_aio_module和模块上下文ngx_aio_module_ctx

2.devpoll机制

static struct pollfd   *change_list, *event_list;static ngx_uint_t       nchanges, max_changes, nevents;static ngx_event_t    **change_index;static ngx_str_t      devpoll_name = ngx_string("/dev/poll");static ngx_command_t  ngx_devpoll_commands[] = {    { ngx_string("devpoll_changes"),      NGX_EVENT_CONF|NGX_CONF_TAKE1,      ngx_conf_set_num_slot,      0,      offsetof(ngx_devpoll_conf_t, changes),      NULL },    { ngx_string("devpoll_events"),      NGX_EVENT_CONF|NGX_CONF_TAKE1,      ngx_conf_set_num_slot,      0,      offsetof(ngx_devpoll_conf_t, events),      NULL },      ngx_null_command};ngx_event_module_t  ngx_devpoll_module_ctx = {    &devpoll_name,    ngx_devpoll_create_conf,               /* create configuration */    ngx_devpoll_init_conf,                 /* init configuration */    {        ngx_devpoll_add_event,             /* add an event */        ngx_devpoll_del_event,             /* delete an event */        ngx_devpoll_add_event,             /* enable an event */        ngx_devpoll_del_event,             /* disable an event */        NULL,                              /* add an connection */        NULL,                              /* delete an connection */        NULL,                              /* process the changes */        ngx_devpoll_process_events,        /* process the events */        ngx_devpoll_init,                  /* init the events */        ngx_devpoll_done,                  /* done the events */    }};ngx_module_t  ngx_devpoll_module = {    NGX_MODULE_V1,    &ngx_devpoll_module_ctx,               /* module context */    ngx_devpoll_commands,                  /* module directives */    NGX_EVENT_MODULE,                      /* module type */    NULL,                                  /* init master */    NULL,                                  /* init module */    NULL,                                  /* init process */    NULL,                                  /* init thread */    NULL,                                  /* exit thread */    NULL,                                  /* exit process */    NULL,                                  /* exit master */    NGX_MODULE_V1_PADDING};

三个数据结构,ngx_devpoll_commands读取配置文件使用;

3.epoll机制

static ngx_str_t      epoll_name = ngx_string("epoll");static ngx_command_t  ngx_epoll_commands[] = {    { ngx_string("epoll_events"),      NGX_EVENT_CONF|NGX_CONF_TAKE1,      ngx_conf_set_num_slot,      0,      offsetof(ngx_epoll_conf_t, events),      NULL },    { ngx_string("worker_aio_requests"),      NGX_EVENT_CONF|NGX_CONF_TAKE1,      ngx_conf_set_num_slot,      0,      offsetof(ngx_epoll_conf_t, aio_requests),      NULL },      ngx_null_command};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 */        NULL,                            /* process the changes */        ngx_epoll_process_events,        /* process the events */        ngx_epoll_init,                  /* init the events */        ngx_epoll_done,                  /* done the events */    }};ngx_module_t  ngx_epoll_module = {    NGX_MODULE_V1,    &ngx_epoll_module_ctx,               /* module context */    ngx_epoll_commands,                  /* module directives */    NGX_EVENT_MODULE,                    /* module type */    NULL,                                /* init master */    NULL,                                /* init module */    NULL,                                /* init process */    NULL,                                /* init thread */    NULL,                                /* exit thread */    NULL,                                /* exit process */    NULL,                                /* exit master */    NGX_MODULE_V1_PADDING};


0 0
原创粉丝点击