wserrno.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "compat/wserrno.h"
11 
12 #if _SQUID_WINDOWS_ || _SQUID_MINGW_
13 
14 #include <unordered_map>
15 
16 void
17 SetErrnoFromWsaError()
18 {
19  // POSIX codes which socket API users may care about
20  static const auto *CodeMap = new std::unordered_map<int, int> {
21  { WSAECONNABORTED, ECONNABORTED },
22  { WSAEINPROGRESS, EINPROGRESS },
23  { WSAEAFNOSUPPORT, EAFNOSUPPORT },
24  { WSAEINVAL, EINVAL },
25  { WSAEISCONN, EISCONN },
26  { WSAEWOULDBLOCK, EWOULDBLOCK },
27  // no Windows error code maps to EAGAIN
28  { WSAEALREADY, EALREADY },
29  { WSAEINTR, EINTR },
30  // no Windows error code maps to ERESTART
31  { WSAEMFILE, EMFILE },
32  // no Windows error code maps to ENFILE
33  { WSAECONNRESET, ECONNRESET }
34  };
35 
36  const auto wsa = WSAGetLastError();
37  const auto itr = CodeMap->find(wsa);
38  if (itr != CodeMap->cend())
39  errno = itr->second;
40  else
41  errno = wsa;
42 }
43 
44 #endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */

 

Introduction

Documentation

Support

Miscellaneous