mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
Add an "events" system to libpq, whereby applications can get callbacks that
enable them to manage private data associated with PGconns and PGresults. Andrew Chernow and Merlin Moncure
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.359 2008/05/29 22:02:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.360 2008/09/17 04:31:08 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1974,6 +1974,21 @@ makeEmptyPGconn(void)
|
||||
static void
|
||||
freePGconn(PGconn *conn)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* let any event procs clean up their state data */
|
||||
for (i = 0; i < conn->nEvents; i++)
|
||||
{
|
||||
PGEventConnDestroy evt;
|
||||
|
||||
evt.conn = conn;
|
||||
(void) conn->events[i].proc(PGEVT_CONNDESTROY, &evt,
|
||||
conn->events[i].passThrough);
|
||||
free(conn->events[i].name);
|
||||
}
|
||||
|
||||
if (conn->events)
|
||||
free(conn->events);
|
||||
if (conn->pghost)
|
||||
free(conn->pghost);
|
||||
if (conn->pghostaddr)
|
||||
@ -2155,8 +2170,30 @@ PQreset(PGconn *conn)
|
||||
{
|
||||
closePGconn(conn);
|
||||
|
||||
if (connectDBStart(conn))
|
||||
(void) connectDBComplete(conn);
|
||||
if (connectDBStart(conn) && connectDBComplete(conn))
|
||||
{
|
||||
/*
|
||||
* Notify event procs of successful reset. We treat an event
|
||||
* proc failure as disabling the connection ... good idea?
|
||||
*/
|
||||
int i;
|
||||
|
||||
for (i = 0; i < conn->nEvents; i++)
|
||||
{
|
||||
PGEventConnReset evt;
|
||||
|
||||
evt.conn = conn;
|
||||
if (!conn->events[i].proc(PGEVT_CONNRESET, &evt,
|
||||
conn->events[i].passThrough))
|
||||
{
|
||||
conn->status = CONNECTION_BAD;
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("PGEventProc \"%s\" failed during PGEVT_CONNRESET event\n"),
|
||||
conn->events[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2190,7 +2227,36 @@ PostgresPollingStatusType
|
||||
PQresetPoll(PGconn *conn)
|
||||
{
|
||||
if (conn)
|
||||
return PQconnectPoll(conn);
|
||||
{
|
||||
PostgresPollingStatusType status = PQconnectPoll(conn);
|
||||
|
||||
if (status == PGRES_POLLING_OK)
|
||||
{
|
||||
/*
|
||||
* Notify event procs of successful reset. We treat an event
|
||||
* proc failure as disabling the connection ... good idea?
|
||||
*/
|
||||
int i;
|
||||
|
||||
for (i = 0; i < conn->nEvents; i++)
|
||||
{
|
||||
PGEventConnReset evt;
|
||||
|
||||
evt.conn = conn;
|
||||
if (!conn->events[i].proc(PGEVT_CONNRESET, &evt,
|
||||
conn->events[i].passThrough))
|
||||
{
|
||||
conn->status = CONNECTION_BAD;
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("PGEventProc \"%s\" failed during PGEVT_CONNRESET event\n"),
|
||||
conn->events[i].name);
|
||||
return PGRES_POLLING_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
return PGRES_POLLING_FAILED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user