diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-17 04:31:08 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-17 04:31:08 +0000 |
commit | 32f159cc55bacad6a4737d3584cb69698c33fc86 (patch) | |
tree | 94799aea36c869020b389fdf53362140dc17eca5 /src/interfaces/libpq/fe-connect.c | |
parent | b73c0c2a51500d52fcf0eb69100a701cc2273c2e (diff) | |
download | postgresql-32f159cc55bacad6a4737d3584cb69698c33fc86.tar.gz postgresql-32f159cc55bacad6a4737d3584cb69698c33fc86.zip |
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
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 5e687c15585..7e77c9a5c7a 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -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; } |