[dev] synchronous write

Igor Sysoev is at rambler-co.ru
Tue Oct 16 23:49:32 MSD 2007


On Tue, Oct 16, 2007 at 09:33:00PM +0200, Manlio Perillo wrote:

> Igor Sysoev ha scritto:
> >On Tue, Oct 16, 2007 at 12:32:53PM +0200, Manlio Perillo wrote:
> >
> >>The mod_wsgi implementation is almost complete.
> >>The only feature that I have to implement is the write callable:
> >>http://www.python.org/dev/peps/pep-0333/#the-write-callable
> >>
> >>
> >>The problem is that the WSGI spec *requires* the passed-in string to be 
> >>completely sent to the client when the write function returns.
> >>
> >>Is this possible with Nginx?
> >>It does not matter that the entire process is blocked.
> >>
> >>Fortunately not so many WSGI applications use the write callable, and it 
> >>is going to be removed from the next revision of WSGI.
> >
> >In general socket API does not allow to say exactly whether data was
> >sent completely to a client. The single way is close() with SO_LINGER.
> >
> 
> No, the problem is not really whether data was sent completely to a peer 
> (it is sufficient that the data is in OS buffer)
> 
> My problem is how to handle NGX_AGAIN in the write callable, since I 
> can't return control to Nginx (and setting the event handlers).
> 
> As an example (pseudo code):
>   while ((rc = ngx_http_output_filter(r, &out) == NGX_AGAIN) {
>       sleep(...)
> 
> 
> But this does not works.

This code should be as:

my_handler(ngx_event_t *wev)
{
    ...

    rc = ngx_http_output_filter(...);

    if (rc == NGX_AGAIN) {
        r->write_handler = my_handler;
        ngx_handle_write_event(wev)
        add_timer(wev, XXX)
        return;
    }


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





More information about the nginx mailing list