tests/server: fix to check against winsock2 error codes on Windows

Windows's winsock2 returns socket errors via `WSAGetLastError()` and
not via `errno` like most systems out there. This was covered by
switching to the `SOCKERRNO` curl macro earlier. But, on Windows the
returned socket error codes have different values than the standard
POSIX errno values. Existing code was using the POSIX values for all
these checks. Meaning they never actually matched on Windows.

This patch defines a set of `SOCKERRNO` constants that map to the
correct socket error values for Windows and other platforms.

The reverse issue exists in core curl code, which redefines POSIX errno
values to winsock2 ones, breaking non-socket uses on Windows.

Cherry-picked from #15000
Follow-up to adcfd4fb3e #16553
Bug: https://github.com/curl/curl/pull/16553#issuecomment-2704679377

Closes #16612
This commit is contained in:
Viktor Szakats 2025-03-06 22:13:39 +01:00
parent 25f8486f26
commit abf80aae38
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
6 changed files with 32 additions and 28 deletions

View file

@ -299,7 +299,7 @@ int wait_ms(int timeout_ms)
if(r != -1)
break;
error = errno;
if(error && (error != EINTR))
if(error && (error != SOCKEINTR))
break;
pending_ms = timeout_ms - (int)timediff(tvnow(), initial_tv);
if(pending_ms <= 0)
@ -866,7 +866,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
}
strcpy(sau->sun_path, unix_socket);
rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
if(0 != rc && SOCKERRNO == EADDRINUSE) {
if(0 != rc && SOCKERRNO == SOCKEADDRINUSE) {
struct_stat statbuf;
/* socket already exists. Perhaps it is stale? */
curl_socket_t unixfd = socket(AF_UNIX, SOCK_STREAM, 0);
@ -879,7 +879,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
rc = connect(unixfd, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
error = SOCKERRNO;
sclose(unixfd);
if(0 != rc && ECONNREFUSED != error) {
if(0 != rc && SOCKECONNREFUSED != error) {
logmsg("Failed to connect to %s (%d) %s",
unix_socket, error, sstrerror(error));
return rc;