Pipes in modules

Manlio Perillo manlio_perillo at libero.it
Wed Mar 4 19:38:39 MSK 2009


Marcus Clyne ha scritto:

Hi Marcus, I'm including the nginx mailing list, since this may be of 
interest for others

> [...]
> As well as your module code, I've been looking through the Nginx source 
> code, and I couldn't work out how to just create a pipe and tie it into 
> the event loop.  There didn't appear to be anything for file descriptors 
> on ngx_event_t.  I was thinking you were suggesting something like the 
> pseudo-code:
> 
> In handler
> ----------------
> - create pipe file descriptors                                     -   
> yes (I was thinking you were talking about using pipe() here)

yes, POSIX pipe

> - add the read file descriptor to an event structure   -   no


You first need to allocate an Nginx connection, with:
   c = ngx_get_connection(s, self->log);

Then you need to register the event handlers:

   /* Store this instance in the connection data */
   c->data = self;

   /* Set the event handler functions */
   c->read->handler = ngx_http_wsgi_poll_event_handler;
   c->write->handler = ngx_http_wsgi_poll_event_handler;

and, finally, register the connection with the event module:

   ngx_add_event(c->read, NGX_READ_EVENT, 0)

Note that I'm not sure that just calling ngx_add_event suffice.


Your handler will be called when there is data in the pipe.
Here you can retrieve page data (stored somewhere, maybe in the in the 
pipe you write the memory address, but this may be unsafe), and then 
call finalize_request.




Regards  Manlio





More information about the nginx mailing list