|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.297 2005/01/06 18:29:10 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.298 2005/01/06 20:06:58 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -1452,30 +1452,36 @@ PQconnectPoll(PGconn *conn)
|
1452 | 1452 |
|
1453 | 1453 | /*
|
1454 | 1454 | * On first time through, get the postmaster's response to
|
1455 |
| - * our SSL negotiation packet. Be careful to read only |
1456 |
| - * one byte (if there's more, it could be SSL data). |
| 1455 | + * our SSL negotiation packet. |
1457 | 1456 | */
|
1458 | 1457 | if (conn->ssl == NULL)
|
1459 | 1458 | {
|
| 1459 | + /* |
| 1460 | + * We use pqReadData here since it has the logic to |
| 1461 | + * distinguish no-data-yet from connection closure. |
| 1462 | + * Since conn->ssl isn't set, a plain recv() will occur. |
| 1463 | + */ |
1460 | 1464 | char SSLok;
|
1461 |
| - int nread; |
| 1465 | + int rdresult; |
1462 | 1466 |
|
1463 |
| - retry_ssl_read: |
1464 |
| - nread = recv(conn->sock, &SSLok, 1, 0); |
1465 |
| - if (nread < 0) |
| 1467 | + rdresult = pqReadData(conn); |
| 1468 | + if (rdresult < 0) |
1466 | 1469 | {
|
1467 |
| - if (SOCK_ERRNO == EINTR) |
1468 |
| - /* Interrupted system call - just try again */ |
1469 |
| - goto retry_ssl_read; |
1470 |
| - |
1471 |
| - printfPQExpBuffer(&conn->errorMessage, |
1472 |
| - libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"), |
1473 |
| - SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); |
| 1470 | + /* errorMessage is already filled in */ |
1474 | 1471 | goto error_return;
|
1475 | 1472 | }
|
1476 |
| - if (nread == 0) |
| 1473 | + if (rdresult == 0) |
| 1474 | + { |
1477 | 1475 | /* caller failed to wait for data */
|
1478 | 1476 | return PGRES_POLLING_READING;
|
| 1477 | + } |
| 1478 | + if (pqGetc(&SSLok, conn) < 0) |
| 1479 | + { |
| 1480 | + /* should not happen really */ |
| 1481 | + return PGRES_POLLING_READING; |
| 1482 | + } |
| 1483 | + /* mark byte consumed */ |
| 1484 | + conn->inStart = conn->inCursor; |
1479 | 1485 | if (SSLok == 'S')
|
1480 | 1486 | {
|
1481 | 1487 | /* Do one-time setup; this creates conn->ssl */
|
|
0 commit comments