Well, I get it.

By the way, If I want to add a timer, it can do something like crontab in
worker process.
For example, we collect data in worker process and dump the data every 5
minutes.

event->cancelable = 1;

In event handler, the codes like the following:

static void
ngx_http_test_timer_handler(ngx_event_t *ev)
{

     if (event->timedout) {
         /* todo timedout */
         return;
     }

     if (ngx_terminate || ngx_exiting) {
         /* I'm not sure whether we need to determine the condition */
     }

     /* I think we needn't to explicitly remove the event timer */
     #if 0
     if (ev->timer_set) {
        ngx_del_timer(ev);
    }
    #endif
}

Thanks again.

B.R.~

2016-09-17 8:25 GMT+08:00 洪志道 <hongzhi...@gmail.com>:

> Hi
>
> As the following codes.
>
>
> buffer->event->handler = ngx_http_log_flush_handler;
>
>
> static void
> ngx_http_log_flush_handler(ngx_event_t *ev)
> {
>     ...
>     if (ev->timedout) {
>         ngx_http_log_flush(ev->data, ev->log);
>         return;
>     }
>     ...
> }
>
>
> static void
> ngx_http_log_flush(ngx_open_file_t *file, ngx_log_t *log)
> {
>     ...
>     if (buffer->event && buffer->event->timer_set) {
>         ngx_del_timer(buffer->event);
>     }
> }
>
>
> I find there are two functions explicitly call event handler.
> 1. ngx_event_cancel_timers happened as long as worker process quits.
> 2. ngx_event_expire_timers in ngx_process_events_and_timers.
>
> And they remove timer from timer rbtree, then set timer_set zero.
> After that they call event->handler.
>
> So why we call ngx_del_timer in ngx_http_log_flush again?
>
> Thanks.
>
> B.R~
>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to