From 586d06a50b572e7f7f91ea344aee870d68d87e63 Mon Sep 17 00:00:00 2001 From: Ning Wu Date: Tue, 30 Jul 2024 11:27:00 +0800 Subject: [PATCH] Fix error handling for non-blocking socket on Windows The connection fails with a non-blocking socket error when using psql on Windows to connect to a PostgreSQL server with GSSAPI enabled. On Windows, the socket error code is obtained by WSAGetLastError() instead of errno. This causes the value of errno to be incorrect when handling with non-blocking socket error. By using the SOCK_ERRNO macro to ensure that all platforms can get the error code correctly. Authored-by: Ning Wu --- src/interfaces/libpq/fe-secure-gssapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/libpq/fe-secure-gssapi.c b/src/interfaces/libpq/fe-secure-gssapi.c index ce183bc04b4c..7207543deccc 100644 --- a/src/interfaces/libpq/fe-secure-gssapi.c +++ b/src/interfaces/libpq/fe-secure-gssapi.c @@ -430,7 +430,7 @@ gss_read(PGconn *conn, void *recv_buffer, size_t length, ssize_t *ret) *ret = pqsecure_raw_read(conn, recv_buffer, length); if (*ret < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) + if (SOCK_ERRNO == EAGAIN || SOCK_ERRNO == EWOULDBLOCK || SOCK_ERRNO == EINTR) return PGRES_POLLING_READING; else return PGRES_POLLING_FAILED;