Welcome! Log In Create A New Profile

Advanced

How can a content handler block on certain events before sending a response?

Hongli Lai
November 22, 2010 06:38PM
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
ngx_http_output_filter().

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?
NGX_AGAIN?

--
Posted via http://www.ruby-forum.com/.

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

How can a content handler block on certain events before sending a response?

Hongli Lai November 22, 2010 06:38PM

Re: How can a content handler block on certain events before sending a response?

Maxim Dounin November 22, 2010 07:52PM

Re: How can a content handler block on certain events before sending a response?

Hongli Lai November 23, 2010 06:48PM

Re: How can a content handler block on certain events before sending a response?

Maxim Dounin November 23, 2010 08:18PM

Re: How can a content handler block on certain events before sending aresponse?

Piotr Sikora November 22, 2010 10:32PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 169
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready