diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-08-17 12:33:18 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-08-17 12:33:18 +0000 |
commit | f0ed4311b6f44dac079ae720b370413e948f30d5 (patch) | |
tree | 21c74a2c5ba8ce6ada390d021537e014f00af9a3 /src/interfaces/libpq/fe-misc.c | |
parent | b7214a877cc1d0fc181f207ec332ca1b9dd90dcd (diff) | |
download | postgresql-f0ed4311b6f44dac079ae720b370413e948f30d5.tar.gz postgresql-f0ed4311b6f44dac079ae720b370413e948f30d5.zip |
Add libpq connection timeout parameter.
Denis A Ustimenko
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r-- | src/interfaces/libpq/fe-misc.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 1799b3c02d8..be91d796c08 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -25,7 +25,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.76 2002/06/20 20:29:54 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.77 2002/08/17 12:33:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -776,10 +776,19 @@ pqFlush(PGconn *conn) int pqWait(int forRead, int forWrite, PGconn *conn) { + return pqWaitTimed( forRead, forWrite, conn, (const struct timeval *) NULL); +} + +int +pqWaitTimed(int forRead, int forWrite, PGconn *conn, const struct timeval *timeout) +{ fd_set input_mask; fd_set output_mask; fd_set except_mask; + struct timeval tmp_timeout; + struct timeval *ptmp_timeout = NULL; + if (conn->sock < 0) { printfPQExpBuffer(&conn->errorMessage, @@ -807,9 +816,18 @@ retry5: if (forWrite) FD_SET(conn->sock, &output_mask); FD_SET(conn->sock, &except_mask); - if (select(conn->sock + 1, &input_mask, &output_mask, &except_mask, - (struct timeval *) NULL) < 0) + + if (NULL != timeout) { + /* + * select may modify timeout argument on some platforms use copy + */ + tmp_timeout = *timeout; + ptmp_timeout = &tmp_timeout; + } + if (select(conn->sock + 1, &input_mask, &output_mask, + &except_mask, ptmp_timeout) < 0) + { if (SOCK_ERRNO == EINTR) goto retry5; printfPQExpBuffer(&conn->errorMessage, |