<div dir="ltr">Well, I get it.<div><br></div><div>By the way, If I want to add a timer, it can do something like crontab in worker process.</div><div>For example, we collect data in worker process and dump the data every 5 minutes.</div><div><br></div><div>event->cancelable = 1;</div><div><br></div><div>In event handler, the codes like the following:</div><div><br></div><div>static void</div><div>ngx_http_test_timer_handler(ngx_event_t *ev)</div><div>{</div><div><br></div><div> if (event->timedout) {</div><div> /* todo timedout */</div><div> return;</div><div> }</div><div><br></div><div> if (ngx_terminate || ngx_exiting) {</div><div> /* I'm not sure whether we need to determine the condition */</div><div> }</div><div><br></div><div> <span style="font-size:14px">/* I think we needn't to </span><span style="font-size:14px">explicitly remove the event timer */</span><span style="font-size:14px"> </span></div><div><span style="font-size:14px"> #if 0</span></div><div> <span style="font-size:14px">if (ev->timer_set) {</span></div><div style="font-size:14px"> ngx_del_timer(ev); </div><div style="font-size:14px"> }</div><div style="font-size:14px"> #endif</div><div>}</div><div><br></div><div>Thanks again.</div><div><br></div><div>B.R.~</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-09-17 8:25 GMT+08:00 洪志道 <span dir="ltr"><<a href="mailto:hongzhidao@gmail.com" target="_blank">hongzhidao@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<div><br></div><div>As the following codes.</div><div><br></div><div><div><br></div><div>buffer->event->handler = ngx_http_log_flush_handler;</div><div><br></div></div><div><br></div><div><div>static void</div><div>ngx_http_log_flush_handler(<wbr>ngx_event_t *ev)</div><div>{</div><div> ...</div><div> if (ev->timedout) {</div><div> ngx_http_log_flush(ev->data, ev->log);</div><div> return;</div><div> }</div><div> ...</div><div>}</div></div><div><br></div><div><br></div><div><div>static void</div><div>ngx_http_log_flush(ngx_open_<wbr>file_t *file, ngx_log_t *log)</div><div>{</div><div> ...</div></div><div><div> if (buffer->event && buffer->event->timer_set) {</div><div> ngx_del_timer(buffer->event); </div><div> }</div><div>}</div></div><div><br></div><div><br></div><div>I find there are two functions explicitly call event handler.</div><div>1. ngx_event_cancel_timers happened as long as worker process quits.</div><div>2. ngx_event_expire_timers in ngx_process_events_and_<wbr>timers.</div><div><br></div><div>And they remove timer from timer rbtree, then set timer_set zero.</div><div>After that they call event->handler.</div><div><br></div><div>So why we call ngx_del_timer in ngx_http_log_flush again?</div><div><br></div><div>Thanks.</div><div><br></div><div>B.R~</div>
</div>
</blockquote></div><br></div>