comparison src/event/modules/ngx_iocp_module.c @ 103:6dfda4cf5200

nginx-0.0.1-2003-06-11-19:28:34 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Jun 2003 15:28:34 +0000
parents 7e86d028d8f0
children ac69ab96328d
comparison
equal deleted inserted replaced
102:7e86d028d8f0 103:6dfda4cf5200
5 5
6 6
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 10 #include <ngx_iocp_module.h>
11
12 typedef struct {
13 int threads;
14 } ngx_iocp_conf_t;
15 11
16 12
17 static int ngx_iocp_init(ngx_log_t *log); 13 static int ngx_iocp_init(ngx_log_t *log);
18 static void ngx_iocp_done(ngx_log_t *log); 14 static void ngx_iocp_done(ngx_log_t *log);
19 static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key); 15 static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key);
16 static int ngx_iocp_del_connection(ngx_connection_t *c);
20 static int ngx_iocp_process_events(ngx_log_t *log); 17 static int ngx_iocp_process_events(ngx_log_t *log);
21 static void *ngx_iocp_create_conf(ngx_pool_t *pool); 18 static void *ngx_iocp_create_conf(ngx_pool_t *pool);
22 static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf); 19 static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf);
23 20
24 21
31 ngx_conf_set_num_slot, 28 ngx_conf_set_num_slot,
32 0, 29 0,
33 offsetof(ngx_iocp_conf_t, threads), 30 offsetof(ngx_iocp_conf_t, threads),
34 NULL}, 31 NULL},
35 32
33 {ngx_string("acceptex"),
34 NGX_EVENT_CONF|NGX_CONF_TAKE1,
35 ngx_conf_set_num_slot,
36 0,
37 offsetof(ngx_iocp_conf_t, acceptex),
38 NULL},
39
40 {ngx_string("acceptex_read"),
41 NGX_EVENT_CONF|NGX_CONF_TAKE1,
42 ngx_conf_set_flag_slot,
43 0,
44 offsetof(ngx_iocp_conf_t, acceptex_read),
45 NULL},
46
36 ngx_null_command 47 ngx_null_command
37 }; 48 };
38 49
39 50
40 ngx_event_module_t ngx_iocp_module_ctx = { 51 ngx_event_module_t ngx_iocp_module_ctx = {
46 ngx_iocp_add_event, /* add an event */ 57 ngx_iocp_add_event, /* add an event */
47 NULL, /* delete an event */ 58 NULL, /* delete an event */
48 NULL, /* enable an event */ 59 NULL, /* enable an event */
49 NULL, /* disable an event */ 60 NULL, /* disable an event */
50 NULL, /* add an connection */ 61 NULL, /* add an connection */
51 NULL, /* delete an connection */ 62 ngx_iocp_del_connection, /* delete an connection */
52 ngx_iocp_process_events, /* process the events */ 63 ngx_iocp_process_events, /* process the events */
53 ngx_iocp_init, /* init the events */ 64 ngx_iocp_init, /* init the events */
54 ngx_iocp_done /* done the events */ 65 ngx_iocp_done /* done the events */
55 } 66 }
56 67
109 { 120 {
110 ngx_connection_t *c; 121 ngx_connection_t *c;
111 122
112 c = (ngx_connection_t *) ev->data; 123 c = (ngx_connection_t *) ev->data;
113 124
114 ngx_log_debug(ev->log, "iocp add: %d, %08x:%08x" _ c->fd _ key _ &ev->ovlp); 125 c->read->active = 1;
126 c->write->active = 1;
127
128 ngx_log_debug(ev->log, "iocp add: %d, %d:%08x" _ c->fd _ key _ &ev->ovlp);
115 129
116 if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) { 130 if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) {
117 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, 131 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
118 "CreateIoCompletionPort() failed"); 132 "CreateIoCompletionPort() failed");
133 return NGX_ERROR;
134 }
135
136 return NGX_OK;
137 }
138
139
140 static int ngx_iocp_del_connection(ngx_connection_t *c)
141 {
142 if (CancelIo((HANDLE) c->fd) == 0) {
143 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CancelIo() failed");
119 return NGX_ERROR; 144 return NGX_ERROR;
120 } 145 }
121 146
122 return NGX_OK; 147 return NGX_OK;
123 } 148 }
146 ngx_log_debug(log, "iocp timer: %d" _ timer); 171 ngx_log_debug(log, "iocp timer: %d" _ timer);
147 172
148 rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key, 173 rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key,
149 (LPOVERLAPPED *) &ovlp, timer); 174 (LPOVERLAPPED *) &ovlp, timer);
150 175
151 ngx_log_debug(log, "iocp: %d, %d:%08x:%08x" _ rc _ bytes _ key _ ovlp); 176 ngx_log_debug(log, "iocp: %d, %d, %d:%08x" _ rc _ bytes _ key _ ovlp);
152 177
153 if (rc == 0) { 178 if (rc == 0) {
154 err = ngx_errno; 179 err = ngx_errno;
155 180
156 if (ovlp == NULL) { 181 if (ovlp == NULL) {
177 ngx_log_debug(log, "iocp ev: %08x" _ ev); 202 ngx_log_debug(log, "iocp ev: %08x" _ ev);
178 203
179 switch (key) { 204 switch (key) {
180 case NGX_IOCP_IO: 205 case NGX_IOCP_IO:
181 ev->ready = 1; 206 ev->ready = 1;
182 ev->available = bytes;
183 break; 207 break;
184 208
185 case NGX_IOCP_ACCEPT: 209 case NGX_IOCP_ACCEPT:
210 if (bytes) {
211 ev->ready = 1;
212 }
186 break; 213 break;
187 } 214 }
188 215
216 ev->available = bytes;
217
189 ngx_log_debug(log, "iocp ev handler: %08x" _ ev->event_handler); 218 ngx_log_debug(log, "iocp ev handler: %08x" _ ev->event_handler);
190 219
191 ev->event_handler(ev); 220 ev->event_handler(ev);
192 } 221 }
193 222
201 230
202 ngx_test_null(cf, ngx_palloc(pool, sizeof(ngx_iocp_conf_t)), 231 ngx_test_null(cf, ngx_palloc(pool, sizeof(ngx_iocp_conf_t)),
203 NGX_CONF_ERROR); 232 NGX_CONF_ERROR);
204 233
205 cf->threads = NGX_CONF_UNSET; 234 cf->threads = NGX_CONF_UNSET;
235 cf->acceptex = NGX_CONF_UNSET;
236 cf->acceptex_read = NGX_CONF_UNSET;
206 237
207 return cf; 238 return cf;
208 } 239 }
209 240
210 241
211 static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf) 242 static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf)
212 { 243 {
213 ngx_iocp_conf_t *cf = conf; 244 ngx_iocp_conf_t *cf = conf;
214 245
215 ngx_conf_init_value(cf->threads, 0); 246 ngx_conf_init_value(cf->threads, 0);
247 ngx_conf_init_value(cf->acceptex, 10);
248 ngx_conf_init_value(cf->acceptex_read, 1);
216 249
217 return NGX_CONF_OK; 250 return NGX_CONF_OK;
218 } 251 }