*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.62 2002/06/20 20:29:53 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.63 2002/08/17 12:19:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#if TCL_MAJOR_VERSION >= 8
conn = PgGetConnectionId(interp, argv[1], &connid);
- if (connid->notifier_channel != NULL)
+ if (connid->notifier_channel != NULL) {
+ /* stop listening for NOTIFY events on that channel */
+ PgStopNotifyEventSource(connid,1);
Tcl_UnregisterChannel(interp, connid->notifier_channel);
+ }
#endif
return Tcl_UnregisterChannel(interp, conn_chan);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.30 2002/06/20 20:29:53 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.31 2002/08/17 12:19:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
* Turn off the Tcl event source for this connection, and delete any
* pending notify events.
*/
- PgStopNotifyEventSource(connid);
+ PgStopNotifyEventSource(connid,1);
/* Close the libpq connection too */
PQfinish(connid->conn);
*mark = '.';
if (conn_chan && Tcl_GetChannelType(conn_chan) == &Pg_ConnType)
{
- Tcl_SetResult(interp, Tcl_GetChannelName(conn_chan), TCL_VOLATILE);
+ Tcl_SetResult(interp, (char *)Tcl_GetChannelName(conn_chan), TCL_VOLATILE);
return TCL_OK;
}
* closed socket descriptor.
*/
if (PQsocket(connid->conn) < 0)
- PgStopNotifyEventSource(connid);
+ /* do not remove any pending events, so that the virtual notification
+ connection_closed will be processed */
+ PgStopNotifyEventSource(connid,0);
}
/*
* it internally to libpq; but it will clear the read-ready
* condition).
*/
- PQconsumeInput(connid->conn);
+ if (!PQconsumeInput(connid->conn)) {
+ NotifyEvent *event = (NotifyEvent *) ckalloc(sizeof(NotifyEvent));
+
+ PGnotify *closed = (PGnotify *) ckalloc(sizeof(PGnotify));
+ strcpy(closed->relname,"connection_closed");
+ event->header.proc = Pg_Notify_EventProc;
+ event->info= *closed;
+ event->connid = connid;
+ Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
+ ckfree((void *)closed);
+ }
/* Transfer notify events from libpq to Tcl event queue. */
PgNotifyTransferEvents(connid);
}
void
-PgStopNotifyEventSource(Pg_ConnectionId * connid)
+PgStopNotifyEventSource(Pg_ConnectionId * connid, int remove_pending)
{
/* Remove the event source */
if (connid->notifier_running)
}
/* Kill any queued Tcl events that reference this channel */
- Tcl_DeleteEvents(NotifyEventDeleteProc, (ClientData) connid);
+ if (remove_pending) Tcl_DeleteEvents(NotifyEventDeleteProc, (ClientData) connid);
}
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pgtclId.h,v 1.18 2002/06/20 20:29:53 momjian Exp $
+ * $Id: pgtclId.h,v 1.19 2002/08/17 12:19:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern void PgDelResultId(Tcl_Interp *interp, char *id);
extern int PgGetConnByResultId(Tcl_Interp *interp, char *resid);
extern void PgStartNotifyEventSource(Pg_ConnectionId * connid);
-extern void PgStopNotifyEventSource(Pg_ConnectionId * connid);
+extern void PgStopNotifyEventSource(Pg_ConnectionId * connid, int remove_pend);
extern void PgNotifyTransferEvents(Pg_ConnectionId * connid);
extern void PgNotifyInterpDelete(ClientData clientData, Tcl_Interp *interp);