Mercurial > hg > nginx
comparison src/event/modules/ngx_eventport_module.c @ 6021:117c77b22db1
Events: implemented eventport notification mechanism.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Sat, 14 Mar 2015 17:37:21 +0300 |
parents | 466bd63b63d1 |
children | 4652f8f26b12 |
comparison
equal
deleted
inserted
replaced
6020:e5f1d83360ef | 6021:117c77b22db1 |
---|---|
91 struct timespec *timeout) | 91 struct timespec *timeout) |
92 { | 92 { |
93 return -1; | 93 return -1; |
94 } | 94 } |
95 | 95 |
96 int port_send(int port, int events, void *user); | |
97 | |
98 int port_send(int port, int events, void *user) | |
99 { | |
100 return -1; | |
101 } | |
102 | |
96 | 103 |
97 int timer_create(clockid_t clock_id, struct sigevent *evp, timer_t *timerid); | 104 int timer_create(clockid_t clock_id, struct sigevent *evp, timer_t *timerid); |
98 | 105 |
99 int timer_create(clockid_t clock_id, struct sigevent *evp, timer_t *timerid) | 106 int timer_create(clockid_t clock_id, struct sigevent *evp, timer_t *timerid) |
100 { | 107 { |
131 static void ngx_eventport_done(ngx_cycle_t *cycle); | 138 static void ngx_eventport_done(ngx_cycle_t *cycle); |
132 static ngx_int_t ngx_eventport_add_event(ngx_event_t *ev, ngx_int_t event, | 139 static ngx_int_t ngx_eventport_add_event(ngx_event_t *ev, ngx_int_t event, |
133 ngx_uint_t flags); | 140 ngx_uint_t flags); |
134 static ngx_int_t ngx_eventport_del_event(ngx_event_t *ev, ngx_int_t event, | 141 static ngx_int_t ngx_eventport_del_event(ngx_event_t *ev, ngx_int_t event, |
135 ngx_uint_t flags); | 142 ngx_uint_t flags); |
143 static ngx_int_t ngx_eventport_notify(ngx_event_handler_pt handler); | |
136 static ngx_int_t ngx_eventport_process_events(ngx_cycle_t *cycle, | 144 static ngx_int_t ngx_eventport_process_events(ngx_cycle_t *cycle, |
137 ngx_msec_t timer, ngx_uint_t flags); | 145 ngx_msec_t timer, ngx_uint_t flags); |
138 | 146 |
139 static void *ngx_eventport_create_conf(ngx_cycle_t *cycle); | 147 static void *ngx_eventport_create_conf(ngx_cycle_t *cycle); |
140 static char *ngx_eventport_init_conf(ngx_cycle_t *cycle, void *conf); | 148 static char *ngx_eventport_init_conf(ngx_cycle_t *cycle, void *conf); |
141 | 149 |
142 static int ep = -1; | 150 static int ep = -1; |
143 static port_event_t *event_list; | 151 static port_event_t *event_list; |
144 static ngx_uint_t nevents; | 152 static ngx_uint_t nevents; |
145 static timer_t event_timer = (timer_t) -1; | 153 static timer_t event_timer = (timer_t) -1; |
154 static ngx_event_t notify_event; | |
146 | 155 |
147 static ngx_str_t eventport_name = ngx_string("eventport"); | 156 static ngx_str_t eventport_name = ngx_string("eventport"); |
148 | 157 |
149 | 158 |
150 static ngx_command_t ngx_eventport_commands[] = { | 159 static ngx_command_t ngx_eventport_commands[] = { |
170 ngx_eventport_del_event, /* delete an event */ | 179 ngx_eventport_del_event, /* delete an event */ |
171 ngx_eventport_add_event, /* enable an event */ | 180 ngx_eventport_add_event, /* enable an event */ |
172 ngx_eventport_del_event, /* disable an event */ | 181 ngx_eventport_del_event, /* disable an event */ |
173 NULL, /* add an connection */ | 182 NULL, /* add an connection */ |
174 NULL, /* delete an connection */ | 183 NULL, /* delete an connection */ |
175 NULL, /* trigger a notify */ | 184 ngx_eventport_notify, /* trigger a notify */ |
176 NULL, /* process the changes */ | 185 NULL, /* process the changes */ |
177 ngx_eventport_process_events, /* process the events */ | 186 ngx_eventport_process_events, /* process the events */ |
178 ngx_eventport_init, /* init the events */ | 187 ngx_eventport_init, /* init the events */ |
179 ngx_eventport_done, /* done the events */ | 188 ngx_eventport_done, /* done the events */ |
180 } | 189 } |
213 if (ep == -1) { | 222 if (ep == -1) { |
214 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, | 223 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
215 "port_create() failed"); | 224 "port_create() failed"); |
216 return NGX_ERROR; | 225 return NGX_ERROR; |
217 } | 226 } |
227 | |
228 notify_event.active = 1; | |
229 notify_event.log = cycle->log; | |
218 } | 230 } |
219 | 231 |
220 if (nevents < epcf->events) { | 232 if (nevents < epcf->events) { |
221 if (event_list) { | 233 if (event_list) { |
222 ngx_free(event_list); | 234 ngx_free(event_list); |
399 } | 411 } |
400 } | 412 } |
401 | 413 |
402 ev->active = 0; | 414 ev->active = 0; |
403 ev->oneshot = 0; | 415 ev->oneshot = 0; |
416 | |
417 return NGX_OK; | |
418 } | |
419 | |
420 | |
421 static ngx_int_t | |
422 ngx_eventport_notify(ngx_event_handler_pt handler) | |
423 { | |
424 notify_event.handler = handler; | |
425 | |
426 if (port_send(ep, 0, ¬ify_event) != 0) { | |
427 ngx_log_error(NGX_LOG_ALERT, notify_event.log, ngx_errno, | |
428 "port_send() failed"); | |
429 return NGX_ERROR; | |
430 } | |
404 | 431 |
405 return NGX_OK; | 432 return NGX_OK; |
406 } | 433 } |
407 | 434 |
408 | 435 |
578 } | 605 } |
579 } | 606 } |
580 | 607 |
581 continue; | 608 continue; |
582 | 609 |
610 case PORT_SOURCE_USER: | |
611 | |
612 ev->handler(ev); | |
613 | |
614 continue; | |
615 | |
583 default: | 616 default: |
584 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | 617 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
585 "unexpected eventport object %d", | 618 "unexpected eventport object %d", |
586 event_list[i].portev_object); | 619 event_list[i].portev_object); |
587 continue; | 620 continue; |