psql close

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

psql close

Anthony LaTorre
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 ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces