psql close
Anthony LaTorre <[email protected]> Fri, 20 May 2016 15:50:21 -0400
| Newsgroups | gmane.comp.db.postgresql.interfaces |
|---|---|
| Message-ID | <CAO49afJWaXVuz8un-w=o1REz+2t7Rhue4wAkkDKuVp92cj_Lyw@mail.gmail.com> |
Hi all,
I've been using the libpq asynchronous functions to hook up database
calls into my event loop, and I've noticed a problem and was hoping
someone might know the solution.
The problem is that I have to unregister the file descriptor from the
event loop whenever the postgres connection fails, but often by the
time I notice it has failed in the code, it has already closed its
socket and so I can't guarantee that if I close the previously opened
socket that it hasn't already been opened up by someone else.
Maybe an example will make it clearer:
void send_to_db(PGConn *conn, char *command)
{
PQsendQuery(conn, command);
if (PQstatus(conn) == CONNECTION_BAD) {
Log(WARNING, "database connection disconnected");
/* By this point PQsocket() returns -1. Even if I keep a
reference to the socket number
* it might have already been opened by another socket call. */
PQfinish(conn);
/* Call function to reconnect, but I should have already
deleted the file event callbacks for the postgres connection socket.
*/
}
}
Please let me know what the solution is, or if something isn't clear.
Thanks,
Tony
--
Sent via pgsql-interfaces mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces