sending data in "chunks"

Igor Sysoev is at rambler-co.ru
Sun Sep 16 22:14:14 MSD 2007


On Sun, Sep 16, 2007 at 08:08:09PM +0200, Manlio Perillo wrote:

> Igor Sysoev ha scritto:
> >On Sun, Sep 16, 2007 at 07:36:49PM +0200, Manlio Perillo wrote:
> >
> >>I need to send to the client some data in chunks.
> >>The data is read from a Python file like object.
> >>
> >>Right now I'm using a static ngx_chain_t variable, and for each cycle I 
> >>read data from the "file" object in a buffer and do:
> >>
> >> // allocate buf and b
> >> out.buf = b;
> >> out.next = NULL;
> >>
> >> b->pos = buf;
> >> b->last = buf + n;
> >>
> >> b->memory = 1;
> >> b->last_buf = 0;
> >>
> >> rc = ngx_http_output_filter(r, &out);
> >> if (rc != NGX_OK) {
> >>   goto error;
> >>
> >>
> >>Then at the end of the cycle, then, I do a
> >>
> >> return ngx_http_output_filter(r, NULL);
> >>
> >>
> >>Unfortunately this does not works.
> >>What is the right method for sending data in chunks?
> >
> >You should set b->last_buf in last buf.
> >NULL is simply pump. It is used for exmple by default write handler
> >to pass all buffered data to client.
> 
> Ok, thanks.
> I have also found the real problem: one of the call to 
> ngx_http_output_filter fails with a return value -2.
> 
> Now I have to found the problem...

It's NGX_AGAIN.
If you have got all your data ready you may send them at once in one chain.
But if you are getting then gradually, then after NGX_AGAIN you should
set event handlers and timer and return control to nginx.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list