Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4e723e6

Browse files
committed
Cleanup of libpq connection timeout code.
1 parent 78a693c commit 4e723e6

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.194 2002/08/18 01:35:39 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.195 2002/08/27 14:49:52 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1063,34 +1063,33 @@ connectDBComplete(PGconn *conn)
10631063
if (conn == NULL || conn->status == CONNECTION_BAD)
10641064
return 0;
10651065

1066-
/*
1067-
* Prepare to time calculations, if connect_timeout isn't zero.
1068-
*/
1069-
if (conn->connect_timeout != NULL)
1066+
/*
1067+
* Prepare to time calculations, if connect_timeout isn't zero.
1068+
*/
1069+
if (conn->connect_timeout != NULL)
10701070
{
1071-
remains.tv_sec = atoi(conn->connect_timeout);
1072-
if (!remains.tv_sec)
1073-
{
1074-
conn->status = CONNECTION_BAD;
1075-
return 0;
1076-
}
1077-
remains.tv_usec = 0;
1078-
rp = &remains;
1079-
}
1071+
remains.tv_sec = atoi(conn->connect_timeout);
1072+
if (!remains.tv_sec)
1073+
{
1074+
conn->status = CONNECTION_BAD;
1075+
return 0;
1076+
}
1077+
remains.tv_usec = 0;
1078+
rp = &remains;
1079+
}
10801080

1081+
while (rp == NULL || remains.tv_sec > 0 || (remains.tv_sec == 0 && remains.tv_usec > 0))
1082+
{
1083+
/*
1084+
* If connecting timeout is set, get current time.
1085+
*/
1086+
if (rp != NULL && gettimeofday(&start_time, NULL) == -1)
1087+
{
1088+
conn->status = CONNECTION_BAD;
1089+
return 0;
1090+
}
10811091

1082-
while (rp == NULL || remains.tv_sec > 0 || (remains.tv_sec == 0 && remains.tv_usec > 0))
1083-
{
10841092
/*
1085-
* If connecting timeout is set, get current time.
1086-
*/
1087-
if (rp != NULL && gettimeofday(&start_time, NULL) == -1)
1088-
{
1089-
conn->status = CONNECTION_BAD;
1090-
return 0;
1091-
}
1092-
1093-
/*
10941093
* Wait, if necessary. Note that the initial state (just after
10951094
* PQconnectStart) is to wait for the socket to select for
10961095
* writing.
@@ -1104,7 +1103,7 @@ connectDBComplete(PGconn *conn)
11041103
return 1; /* success! */
11051104

11061105
case PGRES_POLLING_READING:
1107-
if (pqWaitTimed(1, 0, conn, rp))
1106+
if (pqWaitTimed(1, 0, conn, rp))
11081107
{
11091108
conn->status = CONNECTION_BAD;
11101109
return 0;
@@ -1130,27 +1129,28 @@ connectDBComplete(PGconn *conn)
11301129
*/
11311130
flag = PQconnectPoll(conn);
11321131

1133-
/*
1134-
* If connecting timeout is set, calculate remain time.
1135-
*/
1136-
if (NULL != rp) {
1137-
if (-1 == gettimeofday(&finish_time, NULL))
1138-
{
1139-
conn->status = CONNECTION_BAD;
1140-
return 0;
1141-
}
1142-
if (0 > (finish_time.tv_usec -= start_time.tv_usec))
1143-
{
1144-
remains.tv_sec++;
1145-
finish_time.tv_usec += 1000000;
1146-
}
1147-
if (0 > (remains.tv_usec -= finish_time.tv_usec))
1148-
{
1149-
remains.tv_sec--;
1150-
remains.tv_usec += 1000000;
1151-
}
1152-
remains.tv_sec -= finish_time.tv_sec - start_time.tv_sec;
1153-
}
1132+
/*
1133+
* If connecting timeout is set, calculate remain time.
1134+
*/
1135+
if (NULL != rp)
1136+
{
1137+
if (gettimeofday(&finish_time, NULL) == -1)
1138+
{
1139+
conn->status = CONNECTION_BAD;
1140+
return 0;
1141+
}
1142+
if ((finish_time.tv_usec -= start_time.tv_usec) < 0 )
1143+
{
1144+
remains.tv_sec++;
1145+
finish_time.tv_usec += 1000000;
1146+
}
1147+
if ((remains.tv_usec -= finish_time.tv_usec) < 0 )
1148+
{
1149+
remains.tv_sec--;
1150+
remains.tv_usec += 1000000;
1151+
}
1152+
remains.tv_sec -= finish_time.tv_sec - start_time.tv_sec;
1153+
}
11541154
}
11551155
conn->status = CONNECTION_BAD;
11561156
return 0;

0 commit comments

Comments
 (0)