> duplicating the open fd is not a recommendable option Calling `dup` is an easy way to allow libuv to have an extra copy of the handle. There's some odd behavior with `epoll` if there is a new fd opened in place of the old one gets deleted from the epoll or the file gets closed entirely, but libuv tries to handle that. And it sounds like you won't run into that case anyways.
On Thu, Mar 29, 2018 at 8:10 AM Anders Hallström < [email protected]> wrote: > > However, the only tool I can find to do this is uv_close(handle) and I >>> guess it will close handle as well as its associated fd. So both eventlib >>> and libuv want to close the same fd, perhaps harmless but not nice. >>> >> >> not harmless -- this fd will be reused and you'll end up with surprises. >> > > I believe fd numbers are process-specific. "My" fd will not be reused by > other processes, I believe. My program is single-threaded and I will not > open another file in the time slot between the two close operations. So I > believe it will work in my case. The close system call must of course mark > the fd as no longer in use. It is then crucial that when calling close on a > closed fd, it should do nothing more, not for example decrease the link > count for the inode once more -- such code would too easily make the file > system unstable. > > > >> Should I instead duplicate the fd opened by eventlib and give the >>> duplicate to libuv? Then eventlib and uv will each have its own fd >>> describing the same socket, and it avoids the risk of closing the same fd >>> twice. This solution however assumes that uv_close will indeed close the >>> fd. So again, the clarification please. >>> >> >> Duplication may work, but as far as I remember epoll was doing some very >> magical things with fd -- as in "using file description instead file >> descriptor", so you end up with very weird behaviour if you try to watch >> two different fds referring to the same kernel object. I would proceed with >> caution. >> > > So in the general case, respecting the rule that an fd should be closed > only once: If uv_close will close the fd, and if duplicating the open fd is > not a recommendable option, then I am left with no safe solution. (Here I > am assuming that rewriting aforementioned "eventlib" is also not an option.) > > Then I would need libuv to provide a new method uv_tcp_close() that does > exactly the opposite of uv_tcp_open(), i.e. close the TCP handle but not > the fd. > > > -- > You received this message because you are subscribed to the Google Groups > "libuv" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/libuv. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
