Welcome! Log In Create A New Profile

Advanced

Reusing event connections

Marcus Clyne
October 27, 2009 08:30PM
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.
Subject Author Posted

Reusing event connections

Marcus Clyne October 27, 2009 08:30PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 112
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