aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/libpq/fe-connect.c38
-rw-r--r--src/interfaces/libpq/fe-exec.c39
2 files changed, 36 insertions, 41 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 6cfe06e3d19..48f4117acea 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.114 2000/01/23 01:27:39 petere Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.115 2000/01/24 02:12:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -391,7 +391,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
PGconn *conn;
char *tmp; /* An error message from some service we call. */
bool error = FALSE; /* We encountered an error. */
- int i;
conn = makeEmptyPGconn();
if (conn == NULL)
@@ -586,6 +585,30 @@ update_db_info(PGconn *conn)
}
/* ----------
+ * connectMakeNonblocking -
+ * Make a connection non-blocking.
+ * Returns 1 if successful, 0 if not.
+ * ----------
+ */
+static int
+connectMakeNonblocking(PGconn *conn)
+{
+#ifndef WIN32
+ if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
+#else
+ if (ioctlsocket(conn->sock, FIONBIO, &on) != 0)
+#endif
+ {
+ printfPQExpBuffer(&conn->errorMessage,
+ "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
+ errno, strerror(errno));
+ return 0;
+ }
+
+ return 1;
+}
+
+/* ----------
* connectNoDelay -
* Sets the TCP_NODELAY socket option.
* Returns 1 if successful, 0 if not.
@@ -755,7 +778,7 @@ connectDBStart(PGconn *conn)
* Ewan Mellor <eem21@cam.ac.uk>.
* ---------- */
#if (!defined(WIN32) || defined(WIN32_NON_BLOCKING_CONNECTIONS)) && !defined(USE_SSL)
- if (PQsetnonblocking(conn, TRUE) != 0)
+ if (connectMakeNonblocking(conn) == 0)
goto connect_errReturn;
#endif
@@ -868,7 +891,7 @@ connectDBStart(PGconn *conn)
/* This makes the connection non-blocking, for all those cases which forced us
not to do it above. */
#if (defined(WIN32) && !defined(WIN32_NON_BLOCKING_CONNECTIONS)) || defined(USE_SSL)
- if (PQsetnonblocking(conn, TRUE) != 0)
+ if (connectMakeNonblocking(conn) == 0)
goto connect_errReturn;
#endif
@@ -1786,6 +1809,13 @@ closePGconn(PGconn *conn)
(void) pqFlush(conn);
}
+ /*
+ * must reset the blocking status so a possible reconnect will work
+ * don't call PQsetnonblocking() because it will fail if it's unable
+ * to flush the connection.
+ */
+ conn->nonblocking = FALSE;
+
/*
* Close the connection, reset all transient state, flush I/O buffers.
*/
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 9840cc3b9c6..0b4a5077fd9 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.87 2000/01/18 06:09:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.88 2000/01/24 02:12:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2116,7 +2116,6 @@ PQgetisnull(const PGresult *res, int tup_num, int field_num)
int
PQsetnonblocking(PGconn *conn, int arg)
{
- int fcntlarg;
arg = (arg == TRUE) ? 1 : 0;
/* early out if the socket is already in the state requested */
@@ -2131,45 +2130,11 @@ PQsetnonblocking(PGconn *conn, int arg)
* _from_ or _to_ blocking mode, either way we can block them.
*/
/* if we are going from blocking to non-blocking flush here */
- if (!pqIsnonblocking(conn) && pqFlush(conn))
- return (-1);
-
-
-#ifdef USE_SSL
- if (conn->ssl)
- {
- printfPQExpBuffer(&conn->errorMessage,
- "PQsetnonblocking() -- not supported when using SSL\n");
- return (-1);
- }
-#endif /* USE_SSL */
-
-#ifndef WIN32
- fcntlarg = fcntl(conn->sock, F_GETFL, 0);
- if (fcntlarg == -1)
- return (-1);
-
- if ((arg == TRUE &&
- fcntl(conn->sock, F_SETFL, fcntlarg | O_NONBLOCK) == -1) ||
- (arg == FALSE &&
- fcntl(conn->sock, F_SETFL, fcntlarg & ~O_NONBLOCK) == -1))
-#else
- fcntlarg = arg;
- if (ioctlsocket(conn->sock, FIONBIO, &fcntlarg) != 0)
-#endif
- {
- printfPQExpBuffer(&conn->errorMessage,
- "PQsetblocking() -- unable to set nonblocking status to %s\n",
- arg == TRUE ? "TRUE" : "FALSE");
+ if (pqFlush(conn))
return (-1);
- }
conn->nonblocking = arg;
- /* if we are going from non-blocking to blocking flush here */
- if (pqIsnonblocking(conn) && pqFlush(conn))
- return (-1);
-
return (0);
}