* Simple wrapper for reading from pqsecure_raw_read. * * This takes the same arguments as pqsecure_raw_read, plus an output parameter * to return the number of bytes read. This handles if blocking would occur and * if we detect EOF on the connection. */
| 440 | * if we detect EOF on the connection. |
| 441 | */ |
| 442 | static PostgresPollingStatusType |
| 443 | gss_read(PGconn *conn, void *recv_buffer, size_t length, ssize_t *ret) |
| 444 | { |
| 445 | *ret = pqsecure_raw_read(conn, recv_buffer, length); |
| 446 | if (*ret < 0) |
| 447 | { |
| 448 | if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) |
| 449 | return PGRES_POLLING_READING; |
| 450 | else |
| 451 | return PGRES_POLLING_FAILED; |
| 452 | } |
| 453 | |
| 454 | /* Check for EOF */ |
| 455 | if (*ret == 0) |
| 456 | { |
| 457 | int result = pqReadReady(conn); |
| 458 | |
| 459 | if (result < 0) |
| 460 | return PGRES_POLLING_FAILED; |
| 461 | |
| 462 | if (!result) |
| 463 | return PGRES_POLLING_READING; |
| 464 | |
| 465 | *ret = pqsecure_raw_read(conn, recv_buffer, length); |
| 466 | if (*ret < 0) |
| 467 | { |
| 468 | if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) |
| 469 | return PGRES_POLLING_READING; |
| 470 | else |
| 471 | return PGRES_POLLING_FAILED; |
| 472 | } |
| 473 | if (*ret == 0) |
| 474 | return PGRES_POLLING_FAILED; |
| 475 | } |
| 476 | |
| 477 | return PGRES_POLLING_OK; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * Negotiate GSSAPI transport for a connection. When complete, returns |
no test coverage detected