"Hacking" the event model of Nginx

François Battail fb at francois.battail.name
Sat Apr 12 14:16:36 MSD 2008


Hi All!

I'm new on this nice discussion list but I'm a long time lurker.

I'm working on a very specific module for Nginx: a complete CMS. It may
sounds strange since upstream servers and scripting languages are the
norm for the CMS, but I want (and need) speed.

So far I've done many things without too much trouble, but I'm a little
bit stuck with the processing of events in Nginx. I would like to
process a specific event which is not connection related but created by
one of my worker threads.

I hope this short example will be clear:

// My specific Nginx http handler
int my_http_handler (ngx_request_t * r)
{
  if (r->my_state == 0) // first step: initiate the work to do
  {
    r->my_state ++ ;
    my_sendmsg (myqueue,r) ; // send a message to worker

    return NGX_AGAIN ; // please call me back when done
  }
  else // second step: results are ready
  {
    // produce xhtml output from results
    return NGX_OK ; // finished
  }
}

// The worker running on a specific thread
void my_http_worker (void * arg)
{
  ngx_http_request_t * r ;
  ngx_event_t * ev ;

  while (1)
  {
    my_recvmsg (myqueue,r) ;
    // processing the request
    // ...
    // wake up my_http_handler
    ngx_post_event (ev, (ngx_event_t * *) & ngx_posted_events) ;
  }
}

But I don't know how to fill the ngx_event_t (in particular the
handlers) in order to call again my_http_handler on Nginx's context.
I believe it's possible to do so from what I've seen, but Nginx's code
is not so easy to enter on (it's not a critic).

Sorry for this (first) long message but I think it would be nice to be
able to develop clean and non blocking modules for Nginx.

BTW forgive my English, I'm French ;-)






More information about the nginx mailing list