<div dir="ltr">Here's what I've come up with:<div><br></div><div>// In upper scope.</div><div>ngx_connection_t myConn;</div><div>ngx_event_t myConnRev;<br></div><div><br></div><div><br></div><div>static ngx_int_t</div><div>my_module_init(ngx_cycle_t *cycle) {</div><div> int myFd;</div><div> ... // Initialize myFd.</div><div> </div><div> memset(&myConn, 0, sizeof(myConn));</div><div> memset(&myConnRev, 0, sizeof(myConnRev));</div><div><br></div><div> myConn.number = ngx_atomic_fetch_add(ngx_connection_counter, 1);</div><div> myConn.fd = myFd;</div><div> myConn.pool = cycle->pool;</div><div> myConn.log = cycle->log;</div><div> myConn.read = &myConnRev;</div><div><br></div><div> myConnRev.data = &myConn;</div><div> myConnRev.ready = 1;</div><div> myConnRev.active = 1;</div><div> myConnRev.instance = 1;</div><div> myConnRev.handler = myReadCallback;</div><div> myConnRev.log = cycle->log;</div><div><br></div><div> ngx_add_event(&myConnRev, NGX_READ_EVENT, 0);<br></div><div>}</div><div><br></div><div><br></div><div>It looks like working on OSX, I had no chance to test it on other platforms, but there are a couple of questions.</div><div><br></div><div>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?</div><div><br></div><div>The idea is that the file descriptor is initialized once the module is initialized and lives for as long as worker process does.</div><div><br></div><div>Thanks!</div><div><br></div><div>--</div><div>Marat</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 8, 2015 at 7:17 AM, Marat Dakota <span dir="ltr"><<a href="mailto:dakota@brokenpipe.ru" target="_blank">dakota@brokenpipe.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I have a file descriptor (it is created by other software, not by nginx).</div><div>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).<br></div><div><br></div><div>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.</div><div><br></div><div>Thanks!</div><div><br></div><div>--</div><div>Marat</div></div>
</blockquote></div><br></div>