How can a content handler block on certain events before sending a response?
lists at ruby-forum.com
Tue Nov 23 02:34:31 MSK 2010
I'm writing an Nginx module and I'd like to better understand how Nginx
content handlers work and how the Nginx main loop works.
As far as I know, Nginx content handler functions are supposed to create
a chain link of buffers containing the response data, and then call
ngx_http_output_filter(r, &the_chain_link) which will then take care of
passing this data to the next output filter and eventually sending the
data to the HTTP client.
How does one deal with situations in which the content handler function
cannot immediately generate a response? For example, suppose my content
handler must first fetch some data from MySQL. Since Nginx is an evented
server, I imagine that I need to do something like this:
1. Connect to MySQL and send a request to it.
2. Register the MySQL client file descriptor on the Nginx main loop.
3. The Nginx main loop notifies me when the MySQL fd becomes readable.
4. I read the MySQL response, generate HTTP response data, and call
But how do I do step 2? Which function do I need to call? What should I
return in my content handler function after having executed step 2?
Posted via http://www.ruby-forum.com/.
More information about the nginx