From cd333165f30224cb1e2a3c637fc97adf0feeb3b8 Mon Sep 17 00:00:00 2001 From: Adit Makwana Date: Thu, 16 Feb 2023 10:17:17 +0100 Subject: [PATCH] rewrite error for real error after closesocket() --- src/bsd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bsd.c b/src/bsd.c index 33ecb443..fff69340 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -300,10 +300,17 @@ LIBUS_SOCKET_DESCRIPTOR bsd_create_socket(int domain, int type, int protocol) { } void bsd_close_socket(LIBUS_SOCKET_DESCRIPTOR fd) { + // errno is rewritten by close(fd), and the actual error number is lost. #ifdef _WIN32 + DWORD error; + error = GetLastError(); closesocket(fd); + SetLastError(error); #else + int error; + error = errno; close(fd); + errno = error; #endif }