* pqDropConnection * * Close any physical connection to the server, and reset associated * state inside the connection object. We don't release state that * would be needed to reconnect, though, nor local state that might still * be useful later. * * We can always flush the output buffer, since there's no longer any hope * of sending that data. However, unprocessed input data might stil
| 510 | * valuable, so the caller must tell us whether to flush that or not. |
| 511 | */ |
| 512 | void |
| 513 | pqDropConnection(PGconn *conn, bool flushInput) |
| 514 | { |
| 515 | /* Drop any SSL state */ |
| 516 | pqsecure_close(conn); |
| 517 | |
| 518 | /* Close the socket itself */ |
| 519 | if (conn->sock != PGINVALID_SOCKET) |
| 520 | closesocket(conn->sock); |
| 521 | conn->sock = PGINVALID_SOCKET; |
| 522 | |
| 523 | /* Optionally discard any unread data */ |
| 524 | if (flushInput) |
| 525 | conn->inStart = conn->inCursor = conn->inEnd = 0; |
| 526 | |
| 527 | /* Always discard any unsent data */ |
| 528 | conn->outCount = 0; |
| 529 | |
| 530 | /* Free authentication/encryption state */ |
| 531 | #ifdef ENABLE_GSS |
| 532 | { |
| 533 | OM_uint32 min_s; |
| 534 | |
| 535 | if (conn->gcred != GSS_C_NO_CREDENTIAL) |
| 536 | { |
| 537 | gss_release_cred(&min_s, &conn->gcred); |
| 538 | conn->gcred = GSS_C_NO_CREDENTIAL; |
| 539 | } |
| 540 | if (conn->gctx) |
| 541 | gss_delete_sec_context(&min_s, &conn->gctx, GSS_C_NO_BUFFER); |
| 542 | if (conn->gtarg_nam) |
| 543 | gss_release_name(&min_s, &conn->gtarg_nam); |
| 544 | if (conn->gss_SendBuffer) |
| 545 | { |
| 546 | free(conn->gss_SendBuffer); |
| 547 | conn->gss_SendBuffer = NULL; |
| 548 | } |
| 549 | if (conn->gss_RecvBuffer) |
| 550 | { |
| 551 | free(conn->gss_RecvBuffer); |
| 552 | conn->gss_RecvBuffer = NULL; |
| 553 | } |
| 554 | if (conn->gss_ResultBuffer) |
| 555 | { |
| 556 | free(conn->gss_ResultBuffer); |
| 557 | conn->gss_ResultBuffer = NULL; |
| 558 | } |
| 559 | conn->gssenc = false; |
| 560 | } |
| 561 | #endif |
| 562 | #ifdef ENABLE_SSPI |
| 563 | if (conn->sspitarget) |
| 564 | { |
| 565 | free(conn->sspitarget); |
| 566 | conn->sspitarget = NULL; |
| 567 | } |
| 568 | if (conn->sspicred) |
| 569 | { |
no test coverage detected