11module ;
22
3- #ifndef _WIN32
3+ // The socket interface is chosen by the C library, not by the operating
4+ // system. On Windows with the platform's own C runtime it is Windows Sockets;
5+ // where the C library is POSIX-shaped (openkal-musl, selected in mcpp.toml by
6+ // `cfg(c-abi = "musl")`) it is the POSIX interface on every system, Windows
7+ // included.
8+ #if defined(_WIN32) && !defined(TINYHTTPS_POSIX_SOCKETS)
9+ #define TINYHTTPS_WINSOCK 1
10+ #endif
11+
12+ #ifndef TINYHTTPS_WINSOCK
413#include < sys/types.h>
514#include < sys/socket.h>
615#include < netdb.h>
@@ -14,7 +23,7 @@ import std;
1423
1524// mcpplibs.tinyhttps:platform — the one place OS-specific networking quirks
1625// live. Everything else (socket.cppm, http.cppm…) stays portable and branches
17- // on `platform::is_windows ` with `if constexpr`, never raw #ifdef.
26+ // on `platform::uses_winsock ` with `if constexpr`, never raw #ifdef.
1827//
1928// ── The platforms this library is known to run on, and what differs ──────────
2029//
@@ -26,7 +35,7 @@ import std;
2635// | Windows | nothing to do | no SIGPIPE, neither macro |
2736// | above openkal | MSG_NOSIGNAL, and moot | see below |
2837//
29- // ⭐ ABOVE openkal there are no signals at all, so the hazard issue #16
38+ // ABOVE openkal there are no signals at all, so the hazard issue #16
3039// describes cannot arise — and the same code is nevertheless correct there
3140// without a branch. openkal-musl defines MSG_NOSIGNAL
3241// (`musl/include/sys/socket.h:344`) and accepts it as a no-op, in its own words:
@@ -36,7 +45,7 @@ import std;
3645// -ENOSYS (`:550`, `:592-593`). SO_NOSIGPIPE is a BSD spelling that musl does
3746// not define, so `socket.cppm`'s `#ifdef` for it simply does not compile in.
3847//
39- // ⚠️ One difference that IS live above openkal: connect() completes before it
48+ // One difference that IS live above openkal: connect() completes before it
4049// returns even on a non-blocking descriptor, because `kal_net_connect` has no
4150// form that begins a connection and reports its outcome later
4251// (`port/src/okm_net.c:454-467`). `Socket::connect_addrinfo` therefore never
@@ -58,14 +67,14 @@ import std;
5867namespace mcpplibs ::tinyhttps::platform {
5968
6069// Compile-time platform flag for `if constexpr` at call sites.
61- export inline constexpr bool is_windows =
62- #ifdef _WIN32
70+ export inline constexpr bool uses_winsock =
71+ #ifdef TINYHTTPS_WINSOCK
6372 true ;
6473#else
6574 false ;
6675#endif
6776
68- #ifndef _WIN32
77+ #ifndef TINYHTTPS_WINSOCK
6978
7079namespace {
7180
@@ -185,7 +194,7 @@ inline std::vector<std::string> dns_query_a(const std::string& server, const cha
185194
186195} // anonymous namespace
187196
188- #endif // !_WIN32
197+ #endif // !TINYHTTPS_WINSOCK
189198
190199// True when libc's own resolver has a usable config (/etc/resolv.conf). When
191200// false, callers should prefer resolve_fallback() to avoid a multi-second stall
@@ -195,9 +204,9 @@ inline std::vector<std::string> dns_query_a(const std::string& server, const cha
195204// `if constexpr` still compiles its discarded branch, which would reference the
196205// POSIX-only helpers above that don't exist on Windows. Concentrating that
197206// preprocessor divergence here is exactly why this platform module exists; call
198- // sites elsewhere branch on `is_windows ` with `if constexpr`.
207+ // sites elsewhere branch on `uses_winsock ` with `if constexpr`.
199208export bool system_resolver_configured () {
200- #ifdef _WIN32
209+ #ifdef TINYHTTPS_WINSOCK
201210 return true ;
202211#else
203212 std::error_code ec;
@@ -211,7 +220,7 @@ export bool system_resolver_configured() {
211220// on query failure. A numeric host is returned unchanged.
212221export std::vector<std::string> resolve_fallback ([[maybe_unused]] const char * host,
213222 [[maybe_unused]] int timeoutMs) {
214- #ifdef _WIN32
223+ #ifdef TINYHTTPS_WINSOCK
215224 return {};
216225#else
217226 if (is_numeric_host (host)) return { std::string (host) };
0 commit comments