[dev] synchronous write

Manlio Perillo manlio_perillo at libero.it
Wed Oct 17 00:16:56 MSD 2007


Igor Sysoev ha scritto:
> [...]
>>>> 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;
>>>    }
>>>
>> But if control does not return to Nginx, how can my handler be called?
> 
> "return" should return control to nginx.
> 
> 

The problem is that "return" returns control to the WSGI application and 
not to Nginx.

In the current implementation of mod_wsgi I'm raising an exception when 
Nginx returns a NGX_AGAIN.

A solution for this problem is to buffer all the data that the WSGI 
application want to send using the write callable, but I would like to 
know if there are other solutions, since buffering in this way is not 
allowed by the WSGI spec.


Thanks  Manlio Perillo





More information about the nginx mailing list