Reusing event connections

Hi,

Is it possible to re-use connections/events created using
ngx_get_connection and ngx_add_event()?

I’ve tried using them, using write() to trigger an event (outside the
event loop in a different thread) and read() to read the data (in the
event loop). This works as expected for the first use, but subsequent
uses cause Nginx to go into an infinite loop (I’m guessing it’s causing
the main event loop to trigger, but I’ve not checked).

It does work properly if I delete the event and connection on each
request, but I’d like to reused the same connection / event to trigger
events multiple times without creating a connection / event each time.
Is this possible? What do I need to do to get it to work?

Below is roughly the code I’m using:

// to setup the connection / event

int fd[2];

if (pipe (fd)) {
return NGX_ERROR;
}

c = ngx_get_connection (fd[0], log);

if (c == NULL) {

close (fd[0]);
close (fd[1]);
return  NGX_ERROR;

}

c->data = data; // some relevant data - read my_handler_func
c->read->handler = my_handler_func;

ngx_add_event (c->read, NGX_READ_EVENT, 0);

// to trigger the event

write (fd[1], " ", 1);

// inside my_handler_func

char buf[1];

read (fd[0], buf, 1); // this prevents re-triggering the event in the
event loop

Any suggestions would be gratefully received.

Thanks,

Marcus.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs