summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-10-03 17:09:42 +0000
committerBruce Momjian <bruce@momjian.us>2002-10-03 17:09:42 +0000
commita0bf2503ea0d9a1a2208dd3cf74727bcda7e69d2 (patch)
treeaa3d6727dc94d4a0c4741077184e7cfcf5cdf709 /src/interfaces/libpq/fe-connect.c
parentd4eae72513d919522c8711b55894511f4fb49443 (diff)
The attached patch fixes a number of issues related to compiling the
client utilities (libpq.dll and psql.exe) for win32 (missing defines, adjustments to includes, pedantic casting, non-existent functions) per: http://developer.postgresql.org/docs/postgres/install-win32.html. It compiles cleanly under Windows 2000 using Visual Studio .net. Also compiles clean and passes all regression tests (regular and contrib) under Linux. In addition to a review by the usual suspects, it would be very desirable for someone well versed in the peculiarities of win32 to take a look. Joe Conway
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r--src/interfaces/libpq/fe-connect.c43
1 files changed, 15 insertions, 28 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index a51ade9bd2a..cbb29fa4a54 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.205 2002/09/22 20:57:21 petere Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.206 2002/10/03 17:09:42 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -21,7 +21,6 @@
#include <errno.h>
#include <ctype.h>
#include <time.h>
-#include <unistd.h>
#include "libpq-fe.h"
#include "libpq-int.h"
@@ -1053,10 +1052,10 @@ connectDBComplete(PGconn *conn)
{
PostgresPollingStatusType flag = PGRES_POLLING_WRITING;
- struct timeval remains,
- *rp = NULL,
- finish_time,
- start_time;
+ time_t finish_time = 0,
+ current_time;
+ struct timeval remains,
+ *rp = NULL;
if (conn == NULL || conn->status == CONNECTION_BAD)
return 0;
@@ -1074,20 +1073,14 @@ connectDBComplete(PGconn *conn)
}
remains.tv_usec = 0;
rp = &remains;
+
+ /* calculate the finish time based on start + timeout */
+ finish_time = time((time_t *) NULL) + remains.tv_sec;
}
while (rp == NULL || remains.tv_sec > 0 || remains.tv_usec > 0)
{
/*
- * If connecting timeout is set, get current time.
- */
- if (rp != NULL && gettimeofday(&start_time, NULL) == -1)
- {
- conn->status = CONNECTION_BAD;
- return 0;
- }
-
- /*
* Wait, if necessary. Note that the initial state (just after
* PQconnectStart) is to wait for the socket to select for
* writing.
@@ -1128,26 +1121,18 @@ connectDBComplete(PGconn *conn)
flag = PQconnectPoll(conn);
/*
- * If connecting timeout is set, calculate remain time.
+ * If connecting timeout is set, calculate remaining time.
*/
if (rp != NULL)
{
- if (gettimeofday(&finish_time, NULL) == -1)
+ if (time(&current_time) == -1)
{
conn->status = CONNECTION_BAD;
return 0;
}
- if ((finish_time.tv_usec -= start_time.tv_usec) < 0)
- {
- remains.tv_sec++;
- finish_time.tv_usec += 1000000;
- }
- if ((remains.tv_usec -= finish_time.tv_usec) < 0)
- {
- remains.tv_sec--;
- remains.tv_usec += 1000000;
- }
- remains.tv_sec -= finish_time.tv_sec - start_time.tv_sec;
+
+ remains.tv_sec = finish_time - current_time;
+ remains.tv_usec = 0;
}
}
conn->status = CONNECTION_BAD;
@@ -2946,6 +2931,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
return NULL;
}
+#ifndef WIN32
/* If password file is insecure, alert the user and ignore it. */
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
{
@@ -2955,6 +2941,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
free(pgpassfile);
return NULL;
}
+#endif
fp = fopen(pgpassfile, "r");
free(pgpassfile);