comparison src/event/modules/ngx_epoll_module.c @ 324:f7cd062ee035 NGINX_0_6_6

nginx 0.6.6 *) Feature: the --sysconfdir=PATH option in configure. *) Feature: named locations. *) Feature: the $args variable can be set with the "set" directive. *) Feature: the $is_args variable. *) Bugfix: fair big weight upstream balancer. *) Bugfix: if a client has closed connection to mail proxy then nginx might not close connection to backend. *) Bugfix: if the same host without specified port was used as backend for HTTP and HTTPS, then nginx used only one port - 80 or 443. *) Bugfix: fix building on Solaris/amd64 by Sun Studio 11 and early versions; bug appeared in 0.6.4.
author Igor Sysoev <http://sysoev.ru>
date Mon, 30 Jul 2007 00:00:00 +0400
parents 56688ed172c8
children 12defd37f578
comparison
equal deleted inserted replaced
323:7e977a664d91 324:f7cd062ee035
64 64
65 #endif 65 #endif
66 66
67 67
68 typedef struct { 68 typedef struct {
69 u_int events; 69 ngx_uint_t events;
70 } ngx_epoll_conf_t; 70 } ngx_epoll_conf_t;
71 71
72 72
73 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer); 73 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
74 static void ngx_epoll_done(ngx_cycle_t *cycle); 74 static void ngx_epoll_done(ngx_cycle_t *cycle);
75 static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags); 75 static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event,
76 static ngx_int_t ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags); 76 ngx_uint_t flags);
77 static ngx_int_t ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event,
78 ngx_uint_t flags);
77 static ngx_int_t ngx_epoll_add_connection(ngx_connection_t *c); 79 static ngx_int_t ngx_epoll_add_connection(ngx_connection_t *c);
78 static ngx_int_t ngx_epoll_del_connection(ngx_connection_t *c, u_int flags); 80 static ngx_int_t ngx_epoll_del_connection(ngx_connection_t *c,
81 ngx_uint_t flags);
79 static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, 82 static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
80 ngx_uint_t flags); 83 ngx_uint_t flags);
81 84
82 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle); 85 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle);
83 static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf); 86 static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf);
84 87
85 static int ep = -1; 88 static int ep = -1;
86 static struct epoll_event *event_list; 89 static struct epoll_event *event_list;
87 static u_int nevents; 90 static ngx_uint_t nevents;
88 91
89 92
90 static ngx_str_t epoll_name = ngx_string("epoll"); 93 static ngx_str_t epoll_name = ngx_string("epoll");
91 94
92 static ngx_command_t ngx_epoll_commands[] = { 95 static ngx_command_t ngx_epoll_commands[] = {
203 nevents = 0; 206 nevents = 0;
204 } 207 }
205 208
206 209
207 static ngx_int_t 210 static ngx_int_t
208 ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags) 211 ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
209 { 212 {
210 int op; 213 int op;
211 uint32_t events, prev; 214 uint32_t events, prev;
212 ngx_event_t *e; 215 ngx_event_t *e;
213 ngx_connection_t *c; 216 ngx_connection_t *c;
238 241
239 } else { 242 } else {
240 op = EPOLL_CTL_ADD; 243 op = EPOLL_CTL_ADD;
241 } 244 }
242 245
243 ee.events = events | flags; 246 ee.events = events | (uint32_t) flags;
244 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); 247 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
245 248
246 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, 249 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
247 "epoll add event: fd:%d op:%d ev:%08XD", 250 "epoll add event: fd:%d op:%d ev:%08XD",
248 c->fd, op, ee.events); 251 c->fd, op, ee.events);
261 return NGX_OK; 264 return NGX_OK;
262 } 265 }
263 266
264 267
265 static ngx_int_t 268 static ngx_int_t
266 ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags) 269 ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
267 { 270 {
268 int op; 271 int op;
269 uint32_t prev; 272 uint32_t prev;
270 ngx_event_t *e; 273 ngx_event_t *e;
271 ngx_connection_t *c; 274 ngx_connection_t *c;
293 prev = EPOLLIN; 296 prev = EPOLLIN;
294 } 297 }
295 298
296 if (e->active) { 299 if (e->active) {
297 op = EPOLL_CTL_MOD; 300 op = EPOLL_CTL_MOD;
298 ee.events = prev | flags; 301 ee.events = prev | (uint32_t) flags;
299 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); 302 ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
300 303
301 } else { 304 } else {
302 op = EPOLL_CTL_DEL; 305 op = EPOLL_CTL_DEL;
303 ee.events = 0; 306 ee.events = 0;
343 return NGX_OK; 346 return NGX_OK;
344 } 347 }
345 348
346 349
347 static ngx_int_t 350 static ngx_int_t
348 ngx_epoll_del_connection(ngx_connection_t *c, u_int flags) 351 ngx_epoll_del_connection(ngx_connection_t *c, ngx_uint_t flags)
349 { 352 {
350 int op; 353 int op;
351 struct epoll_event ee; 354 struct epoll_event ee;
352 355
353 /* 356 /*
354 * when the file descriptor is closed the epoll automatically deletes 357 * when the file descriptor is closed the epoll automatically deletes
355 * it from its queue so we do not need to delete explicity the event 358 * it from its queue so we do not need to delete explicity the event
356 * before the closing the file descriptor 359 * before the closing the file descriptor
397 /* NGX_TIMER_INFINITE == INFTIM */ 400 /* NGX_TIMER_INFINITE == INFTIM */
398 401
399 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 402 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
400 "epoll timer: %M", timer); 403 "epoll timer: %M", timer);
401 404
402 events = epoll_wait(ep, event_list, nevents, timer); 405 events = epoll_wait(ep, event_list, (int) nevents, timer);
403 406
404 if (events == -1) { 407 if (events == -1) {
405 err = ngx_errno; 408 err = ngx_errno;
406 } else { 409 } else {
407 err = 0; 410 err = 0;