Annotation of embedaddon/nginx/src/event/modules/ngx_aio_module.c, revision 1.1
1.1 ! misho 1:
! 2: /*
! 3: * Copyright (C) Igor Sysoev
! 4: * Copyright (C) Nginx, Inc.
! 5: */
! 6:
! 7:
! 8: #include <ngx_config.h>
! 9: #include <ngx_core.h>
! 10: #include <ngx_event.h>
! 11:
! 12:
! 13: extern ngx_event_module_t ngx_kqueue_module_ctx;
! 14:
! 15:
! 16: static ngx_int_t ngx_aio_init(ngx_cycle_t *cycle, ngx_msec_t timer);
! 17: static void ngx_aio_done(ngx_cycle_t *cycle);
! 18: static ngx_int_t ngx_aio_add_event(ngx_event_t *ev, ngx_int_t event,
! 19: ngx_uint_t flags);
! 20: static ngx_int_t ngx_aio_del_event(ngx_event_t *ev, ngx_int_t event,
! 21: ngx_uint_t flags);
! 22: static ngx_int_t ngx_aio_del_connection(ngx_connection_t *c, ngx_uint_t flags);
! 23: static ngx_int_t ngx_aio_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
! 24: ngx_uint_t flags);
! 25:
! 26:
! 27: ngx_os_io_t ngx_os_aio = {
! 28: ngx_aio_read,
! 29: ngx_aio_read_chain,
! 30: NULL,
! 31: ngx_aio_write,
! 32: ngx_aio_write_chain,
! 33: 0
! 34: };
! 35:
! 36:
! 37: static ngx_str_t aio_name = ngx_string("aio");
! 38:
! 39: ngx_event_module_t ngx_aio_module_ctx = {
! 40: &aio_name,
! 41: NULL, /* create configuration */
! 42: NULL, /* init configuration */
! 43:
! 44: {
! 45: ngx_aio_add_event, /* add an event */
! 46: ngx_aio_del_event, /* delete an event */
! 47: NULL, /* enable an event */
! 48: NULL, /* disable an event */
! 49: NULL, /* add an connection */
! 50: ngx_aio_del_connection, /* delete an connection */
! 51: NULL, /* process the changes */
! 52: ngx_aio_process_events, /* process the events */
! 53: ngx_aio_init, /* init the events */
! 54: ngx_aio_done /* done the events */
! 55: }
! 56:
! 57: };
! 58:
! 59: ngx_module_t ngx_aio_module = {
! 60: NGX_MODULE_V1,
! 61: &ngx_aio_module_ctx, /* module context */
! 62: NULL, /* module directives */
! 63: NGX_EVENT_MODULE, /* module type */
! 64: NULL, /* init master */
! 65: NULL, /* init module */
! 66: NULL, /* init process */
! 67: NULL, /* init thread */
! 68: NULL, /* exit thread */
! 69: NULL, /* exit process */
! 70: NULL, /* exit master */
! 71: NGX_MODULE_V1_PADDING
! 72: };
! 73:
! 74:
! 75: #if (NGX_HAVE_KQUEUE)
! 76:
! 77: static ngx_int_t
! 78: ngx_aio_init(ngx_cycle_t *cycle, ngx_msec_t timer)
! 79: {
! 80: if (ngx_kqueue_module_ctx.actions.init(cycle, timer) == NGX_ERROR) {
! 81: return NGX_ERROR;
! 82: }
! 83:
! 84: ngx_io = ngx_os_aio;
! 85:
! 86: ngx_event_flags = NGX_USE_AIO_EVENT;
! 87: ngx_event_actions = ngx_aio_module_ctx.actions;
! 88:
! 89:
! 90: return NGX_OK;
! 91: }
! 92:
! 93:
! 94: static void
! 95: ngx_aio_done(ngx_cycle_t *cycle)
! 96: {
! 97: ngx_kqueue_module_ctx.actions.done(cycle);
! 98: }
! 99:
! 100:
! 101: /* the event adding and deleting are needed for the listening sockets */
! 102:
! 103: static ngx_int_t
! 104: ngx_aio_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
! 105: {
! 106: return ngx_kqueue_module_ctx.actions.add(ev, event, flags);
! 107: }
! 108:
! 109:
! 110: static ngx_int_t
! 111: ngx_aio_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
! 112: {
! 113: return ngx_kqueue_module_ctx.actions.del(ev, event, flags);
! 114: }
! 115:
! 116:
! 117: static ngx_int_t
! 118: ngx_aio_del_connection(ngx_connection_t *c, ngx_uint_t flags)
! 119: {
! 120: int rc;
! 121:
! 122: if (c->read->active == 0 && c->write->active == 0) {
! 123: return NGX_OK;
! 124: }
! 125:
! 126: if (flags & NGX_CLOSE_EVENT) {
! 127: return NGX_OK;
! 128: }
! 129:
! 130: rc = aio_cancel(c->fd, NULL);
! 131:
! 132: ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_cancel: %d", rc);
! 133:
! 134: if (rc == AIO_CANCELED) {
! 135: c->read->active = 0;
! 136: c->write->active = 0;
! 137: return NGX_OK;
! 138: }
! 139:
! 140: if (rc == AIO_ALLDONE) {
! 141: c->read->active = 0;
! 142: c->write->active = 0;
! 143: ngx_log_error(NGX_LOG_ALERT, c->log, 0,
! 144: "aio_cancel() returned AIO_ALLDONE");
! 145: return NGX_OK;
! 146: }
! 147:
! 148: if (rc == -1) {
! 149: ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
! 150: "aio_cancel() failed");
! 151: return NGX_ERROR;
! 152: }
! 153:
! 154: if (rc == AIO_NOTCANCELED) {
! 155: ngx_log_error(NGX_LOG_ALERT, c->log, 0,
! 156: "aio_cancel() returned AIO_NOTCANCELED");
! 157:
! 158: return NGX_ERROR;
! 159: }
! 160:
! 161: return NGX_OK;
! 162: }
! 163:
! 164:
! 165: static ngx_int_t
! 166: ngx_aio_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, ngx_uint_t flags)
! 167: {
! 168: return ngx_kqueue_module_ctx.actions.process_events(cycle, timer, flags);
! 169: }
! 170:
! 171: #endif /* NGX_HAVE_KQUEUE */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>