PQconsumeinput() may close the fd

2022-10-21 Thread Vasily Kulikov
Hello, There is an event loop in my program (libev) and I do PQconsumeInput() if there is something ready in the PG socket fd. The problem is that sometimes PQconsumeInput() may close the connection and I learn it by checking for PQsocket() afterwards only. AFAICS, there is no way to learn it beforehand. The core issue is that I have to deregister socket fd in the event loop, but the fd is already closed. It is already not good because we're still working with already invalid fd, but worse, in multithreaded env other thread might open a socket with the same fd number and mess all the things. So, what to do in this case? Should I use other API that may not close fd? Or only select/poll API may be used with every time fd registration, but not epoll? Or maybe I'm wrong in some other way? Thanks in advance.




Re: PQconsumeinput() may close the fd

2022-11-01 Thread Vasily Kulikov
21.10.2022, 17:40, "Tom Lane" :Laurenz Albe <laurenz.a...@cybertec.at> writes: On Fri, 2022-10-21 at 07:27 +0300, Vasily Kulikov wrote: The problem is that sometimes PQconsumeInput() may close the connectionWhat I'd suggest doing is checking for PQstatus(conn) == CONNECTION_BAD,or else directly rechecking PQsocket() each time, rather than assumingthe socket is still there.I've chosen this one. Thanks for the help!