*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.164 2001/03/31 23:14:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.165 2001/07/06 17:58:53 petere Exp $
*
*-------------------------------------------------------------------------
*/
if (areq == AUTH_REQ_OK)
{
/* We are done with authentication exchange */
+ conn->startup_complete = TRUE;
conn->status = CONNECTION_AUTH_OK;
/*
freePGconn(conn);
conn = NULL;
}
+ conn->startup_complete = FALSE;
return conn;
}
static void
closePGconn(PGconn *conn)
{
- if (conn->sock >= 0)
+ /* Note that the protocol doesn't allow us to send Terminate
+ messages during the startup phase. */
+ if (conn->sock >= 0 && conn->startup_complete)
{
/*
* avoid getting SIGPIPE'd if the connection were already closed.
* Now we rely on pqFlush to avoid the signal.
*/
- (void) pqPuts("X", conn);
- (void) pqFlush(conn);
+ pqPutc('X', conn);
+ pqFlush(conn);
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.101 2001/02/10 02:31:30 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.102 2001/07/06 17:58:53 petere Exp $
*
*-------------------------------------------------------------------------
*/
return 0;
/* 'Q' == queries */
/* XXX: if we fail here we really ought to not block */
- if (pqPutnchar("Q", 1, conn) ||
- pqPuts(query, conn))
+ if (pqPutc('Q', conn) != 0 || pqPuts(query, conn) != 0)
{
handleSendFailure(conn);
return 0;
* give the data a push, ignore the return value as ConsumeInput()
* will do any aditional flushing if needed
*/
- (void) pqFlush(conn);
+ pqFlush(conn);
}
else
{
/*
* the frontend-backend protocol uses 'Q' to designate queries
*/
- if (pqPutnchar("Q", 1, conn) ||
- pqPuts(query, conn) ||
- pqFlush(conn))
+ if (pqPutc('Q', conn) != 0 || pqPuts(query, conn) != 0 ||
+ pqFlush(conn) != 0)
{
handleSendFailure(conn);
return 0;
return NULL;
}
- if (pqPuts("F ", conn) || /* function */
- pqPutInt(fnid, 4, conn) || /* function id */
- pqPutInt(nargs, 4, conn)) /* # of args */
+ if (pqPuts("F ", conn) != 0 || /* function */
+ pqPutInt(fnid, 4, conn) != 0 || /* function id */
+ pqPutInt(nargs, 4, conn) != 0) /* # of args */
{
handleSendFailure(conn);
return NULL;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.49 2001/05/28 15:29:51 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.50 2001/07/06 17:58:53 petere Exp $
*
*-------------------------------------------------------------------------
*/
#define DONOTICE(conn,message) \
((*(conn)->noticeHook) ((conn)->noticeArg, (message)))
+static int pqPutBytes(const char *s, size_t nbytes, PGconn *conn);
+
/* --------------------------------------------------------------------- */
/* pqGetc:
}
+/*
+ * write 1 char to the connection
+ */
+int
+pqPutc(char c, PGconn *conn)
+{
+ if (pqPutBytes(&c, 1, conn) == EOF)
+ return EOF;
+
+ if (conn->Pfdebug)
+ fprintf(conn->Pfdebug, "To backend> %c\n", c);
+
+ return 0;
+}
+
+
/* --------------------------------------------------------------------- */
/* pqPutBytes: local routine to write N bytes to the connection,
with buffering
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-int.h,v 1.33 2001/03/22 04:01:27 momjian Exp $
+ * $Id: libpq-int.h,v 1.34 2001/07/06 17:58:53 petere Exp $
*
*-------------------------------------------------------------------------
*/
PQExpBufferData workBuffer; /* expansible string */
int client_encoding;/* encoding id */
+ int startup_complete;
};
/* String descriptions of the ExecStatusTypes.
* necessarily any error.
*/
extern int pqGetc(char *result, PGconn *conn);
+extern int pqPutc(char c, PGconn *conn);
extern int pqGets(PQExpBuffer buf, PGconn *conn);
extern int pqPuts(const char *s, PGconn *conn);
extern int pqGetnchar(char *s, size_t len, PGconn *conn);