From: | Anthony LaTorre <tlatorre(at)uchicago(dot)edu> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | psql close |
Date: | 2016-05-20 19:50:21 |
Message-ID: | CAO49afJWaXVuz8un-w=o1REz+2t7Rhue4wAkkDKuVp92cj_Lyw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | Postg배트맨 토토SQL : |
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
From | Date | Subject | |
---|---|---|---|
Next Message | sangeetha | 2016-06-23 08:57:33 | insert records from a CSV file |
Previous Message | William B. Clay | 2016-04-26 14:13:56 | Re: Error: no connection to the server |