From d39a49c1e459804831302807c724fa6512e90cf0 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 8 Apr 2024 04:24:49 +0300 Subject: Support TLS handshake directly without SSLRequest negotiation By skipping SSLRequest, you can eliminate one round-trip when establishing a TLS connection. It is also more friendly to generic TLS proxies that don't understand the PostgreSQL protocol. This is disabled by default in libpq, because the direct TLS handshake will fail with old server versions. It can be enabled with the sslnegotation=direct option. It will still fall back to the negotiated TLS handshake if the server rejects the direct attempt, either because it is an older version or the server doesn't support TLS at all, but the fallback can be disabled with the sslnegotiation=requiredirect option. Author: Greg Stark, Heikki Linnakangas Reviewed-by: Matthias van de Meent, Jacob Champion --- src/backend/libpq/pqcomm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/backend/libpq/pqcomm.c') diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index dcea5648acd..2cee49a2085 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -1116,15 +1116,17 @@ pq_discardbytes(size_t len) } /* -------------------------------- - * pq_buffer_has_data - is any buffered data available to read? + * pq_buffer_remaining_data - return number of bytes in receive buffer * - * This will *not* attempt to read more data. + * This will *not* attempt to read more data. And reading up to that number of + * bytes should not cause reading any more data either. * -------------------------------- */ -bool -pq_buffer_has_data(void) +ssize_t +pq_buffer_remaining_data(void) { - return (PqRecvPointer < PqRecvLength); + Assert(PqRecvLength >= PqRecvPointer); + return (PqRecvLength - PqRecvPointer); } -- cgit v1.2.3