Welcome! Log In Create A New Profile

Advanced

Re: Custom file descriptor handler

Marat Dakota
February 08, 2015 08:20PM
Here's what I've come up with:

// In upper scope.
ngx_connection_t myConn;
ngx_event_t myConnRev;


static ngx_int_t
my_module_init(ngx_cycle_t *cycle) {
int myFd;
... // Initialize myFd.

memset(&myConn, 0, sizeof(myConn));
memset(&myConnRev, 0, sizeof(myConnRev));

myConn.number = ngx_atomic_fetch_add(ngx_connection_counter, 1);
myConn.fd = myFd;
myConn.pool = cycle->pool;
myConn.log = cycle->log;
myConn.read = &myConnRev;

myConnRev.data = &myConn;
myConnRev.ready = 1;
myConnRev.active = 1;
myConnRev.instance = 1;
myConnRev.handler = myReadCallback;
myConnRev.log = cycle->log;

ngx_add_event(&myConnRev, NGX_READ_EVENT, 0);
}


It looks like working on OSX, I had no chance to test it on other
platforms, but there are a couple of questions.

Is it enough, should it be stable? And I also have no actual idea what
`ready`, `active` and `instance` flags actually mean. Do I need to
`ngx_atomic_fetch_add(ngx_connection_counter, 1);` my connection number? Is
it ok to leave write event field blank (I will only read from the
descriptor)? Do I need to fill some other fields?

The idea is that the file descriptor is initialized once the module is
initialized and lives for as long as worker process does.

Thanks!

--
Marat


On Sun, Feb 8, 2015 at 7:17 AM, Marat Dakota <dakota@brokenpipe.ru> wrote:

> Hi,
>
> I have a file descriptor (it is created by other software, not by nginx).
> How to add it to nginx event loop watcher properly? All I need is to have
> my callback called when my file descriptor has a new data to read (I'll
> read the data by myself).
>
> Browsing the code shows functions like ngx_add_conn and ngx_add_event, but
> it seems like a non-trivial thing to prepare the proper input arguments.
>
> Thanks!
>
> --
> Marat
>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Custom file descriptor handler

Marat Dakota 772 February 07, 2015 11:18PM

Re: Custom file descriptor handler

Marat Dakota 302 February 08, 2015 08:20PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

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