<div dir="ltr">Hi, <div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 9, 2013 at 7:02 PM, Yichun Zhang (agentzh) <span dir="ltr"><<a href="mailto:agentzh@gmail.com" target="_blank">agentzh@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello!<br>
<div class="im"><br>
On Tue, Jul 9, 2013 at 5:12 PM, Julien Zefi wrote:<br>
> But if in some triggered callback by the timer the<br>
> ngx_http_output_filter(..) returns NGX_AGAIN *i assume* NginX will send that<br>
> chain as soon as the socket becomes available again.<br>
<br>
</div>This assumption is not correct. Nginx will only flush out the pending<br>
data for you when r->write_event_handler is set to ngx_http_writer.<br>
This only (automatically) happens in ngx_http_finalize_request (by<br>
calling the ngx_http_set_write_handler function to do the assignment<br>
to r->write_event_handler).<br>
<div class="im"><br>
> But after that happens,<br>
> how can i restore my timer cycle ?<br>
><br>
<br>
</div>My suggestion is to register your own r->write_event_handler handler<br>
to propagate the pending outputs by calling ngx_http_output_filter<br>
with a NULL chain link pointer yourself. And in that handler, you can<br>
also restore your timer cycle and etc when all the pending outputs<br>
have been flushed out (into the system socket send buffers).<br>
<br>
I've been doing something like this in our ngx_lua module. You can<br>
check out the ngx.flush() API function's implementation in particular:<br>
<br>
<a href="http://wiki.nginx.org/HttpLuaModule#ngx.flush" target="_blank">http://wiki.nginx.org/HttpLuaModule#ngx.flush</a></blockquote><div><br></div><div style>I have been trying many workarounds without luck, the last one that i have is that if in my timer-callback the flush returns NGX_AGAIN, invoke a new handler that sends out an empty chain, but it continue returning NGX_AGAIN, it never backs to NGX_OK, this is how it looks:</div>
<div style><br></div><div> 306 static void ngx_http_hls_flush(ngx_event_t *e) </div><div> 307 { </div>
<div> 308 printf("Trying to flush data\n"); </div><div> 309 int ret; </div><div> 310 ngx_buf_t *buf; </div>
<div> 311 ngx_chain_t chain; </div><div> 312 ngx_http_request_t *r; </div><div> 313 ngx_http_hls_event_t *hls_event; </div>
<div> 314 </div><div> 315 hls_event = e->data; </div><div> 316 r = hls_event->r; </div>
<div> 317 </div><div> 318 buf = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); </div><div> 319 buf->pos = NULL; </div>
<div> 320 buf->last = NULL; </div><div> 321 buf->memory = 0; </div><div> 322 buf->last_buf = 1; </div>
<div> 323 </div><div> 324 chain.buf = buf; </div><div> 325 chain.next = NULL; </div>
<div> 326 </div><div> 327 ret = ngx_http_output_filter(r, &chain); </div><div> 328 if (ret == NGX_OK) { </div>
<div> 329 e->handler = ngx_http_hls_timer; </div><div> 330 } </div><div> 331 else if (ret == NGX_AGAIN) { </div>
<div> 332 e->handler = ngx_http_hls_flush; </div><div> 333 } </div><div> 334 else { </div>
<div> 335 e->handler = ngx_http_hls_finalize; </div><div> 336 } </div><div> 337 </div>
<div> 338 ngx_add_timer(e, 50); </div><div style> 339 } </div><div style><br></div><div style>it always returns to hgx_http_hls_flush, what else i can do ?, i have spent bunch of hours on this, any extra help is welcome.</div>
</div></div></div>