Windows: full module parity and runtime-qualified test suite
- Net/IO: Winsock sockets (UdpSocket, TlsClientStream, WebSocketClient), HttpServer port with a loopback wake socket replacing eventfd, and the select-based IO backend built on Windows (ws2_32). - Net: implement StaticFileResolver::open_safe and OpenedStaticFile on Windows (reparse-point rejection plus canonical containment check on the opened handle) and widen native handles to intptr_t. - Plugin: hot reload works on Windows by loading a fresh copy while the old DLL stays mapped; enable the reload, discovery and FSM service reload tests and retire the plugin file by rename instead of replacement. - Update: activation pointer as a directory junction on Windows. - Stacktrace: portable path comparison for wide native strings. - Docs/targets: every module allowlisted on Windows; record the Wine run (2000 tests, 1977 passed, 23 skipped, 0 failed). - CMake: add -Wa,-mbig-obj for GNU MinGW targets (COFF section limit). - Async: fix the FuturePool stopped-after-close test to wait for the executor to release its admission slot instead of racing it. Windows and Linux suites both pass: Windows 2000/1977/23 skips/0 failed, Linux 2027/2023/4 skips/0 failed.
This commit is contained in:
1 parent
1b1947340f
commit
b3c959b920
32 files changed
+1836
-401
No files matched your search
@@ -12,16 +12,44 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#ifndef SHUT_RDWR
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
#endif
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
using SocketLength = int;
|
||||
inline void close_socket(int fd) noexcept
|
||||
{
|
||||
(void)::closesocket(static_cast<SOCKET>(fd));
|
||||
}
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
using SocketLength = socklen_t;
|
||||
inline void close_socket(int fd) noexcept
|
||||
{
|
||||
(void)::close(fd);
|
||||
}
|
||||
#endif
|
||||
#include <atomic>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <netinet/in.h>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
@@ -40,13 +68,14 @@ namespace
|
||||
{
|
||||
fd = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
int yes = 1;
|
||||
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
||||
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<const char*>(&yes), sizeof(yes));
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
addr.sin_port = 0;
|
||||
::bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
|
||||
socklen_t len = sizeof(addr);
|
||||
SocketLength len = sizeof(addr);
|
||||
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
|
||||
port = ntohs(addr.sin_port);
|
||||
::listen(fd, 1);
|
||||
@@ -55,15 +84,15 @@ namespace
|
||||
int conn = ::accept(fd, nullptr, nullptr);
|
||||
if (conn < 0) return;
|
||||
char buf[4096];
|
||||
const auto n = ::read(conn, buf, sizeof(buf));
|
||||
const auto n = ::recv(conn, buf, sizeof(buf), 0);
|
||||
if (n > 0) last_request.assign(buf, buf + n);
|
||||
const std::string resp =
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: " +
|
||||
std::to_string(body.size()) +
|
||||
"\r\nConnection: close\r\n\r\n" + body;
|
||||
[[maybe_unused]] auto w =
|
||||
::write(conn, resp.data(), resp.size());
|
||||
::close(conn);
|
||||
::send(conn, resp.data(), resp.size(), 0);
|
||||
close_socket(conn);
|
||||
served = true;
|
||||
});
|
||||
}
|
||||
@@ -71,7 +100,7 @@ namespace
|
||||
~OneShotServer()
|
||||
{
|
||||
if (worker.joinable()) worker.join();
|
||||
if (fd >= 0) ::close(fd);
|
||||
if (fd >= 0) close_socket(fd);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -120,12 +149,12 @@ namespace
|
||||
|
||||
const auto cert_path = dir / (std::string{"cert_"} + tag + ".pem");
|
||||
const auto key_path = dir / (std::string{"key_"} + tag + ".pem");
|
||||
FILE* cf = std::fopen(cert_path.c_str(), "wb");
|
||||
FILE* cf = std::fopen(cert_path.string().c_str(), "wb");
|
||||
Void::Testing::require(cf != nullptr);
|
||||
Void::Testing::require(PEM_write_X509(cf, cert.get()) == 1);
|
||||
std::fclose(cf);
|
||||
|
||||
FILE* kf = std::fopen(key_path.c_str(), "wb");
|
||||
FILE* kf = std::fopen(key_path.string().c_str(), "wb");
|
||||
Void::Testing::require(kf != nullptr);
|
||||
Void::Testing::require(PEM_write_PrivateKey(kf, pkey.get(), nullptr,
|
||||
nullptr, 0, nullptr,
|
||||
@@ -145,15 +174,18 @@ namespace
|
||||
ctx = SSL_CTX_new(TLS_server_method());
|
||||
Void::Testing::require(ctx != nullptr);
|
||||
Void::Testing::require(
|
||||
SSL_CTX_use_certificate_file(ctx, creds.cert_file.c_str(),
|
||||
SSL_FILETYPE_PEM) == 1);
|
||||
SSL_CTX_use_certificate_file(ctx,
|
||||
creds.cert_file.string().c_str(),
|
||||
SSL_FILETYPE_PEM) == 1);
|
||||
Void::Testing::require(
|
||||
SSL_CTX_use_PrivateKey_file(ctx, creds.key_file.c_str(),
|
||||
SSL_CTX_use_PrivateKey_file(ctx,
|
||||
creds.key_file.string().c_str(),
|
||||
SSL_FILETYPE_PEM) == 1);
|
||||
|
||||
fd = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
int yes = 1;
|
||||
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
||||
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<const char*>(&yes), sizeof(yes));
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
@@ -161,7 +193,7 @@ namespace
|
||||
Void::Testing::require(
|
||||
::bind(fd, reinterpret_cast<sockaddr*>(&addr),
|
||||
sizeof(addr)) == 0);
|
||||
socklen_t len = sizeof(addr);
|
||||
SocketLength len = sizeof(addr);
|
||||
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
|
||||
port = ntohs(addr.sin_port);
|
||||
Void::Testing::require(::listen(fd, 1) == 0);
|
||||
@@ -183,14 +215,14 @@ namespace
|
||||
SSL_shutdown(ssl);
|
||||
}
|
||||
SSL_free(ssl);
|
||||
::close(conn);
|
||||
close_socket(conn);
|
||||
});
|
||||
}
|
||||
|
||||
~OneShotTlsServer()
|
||||
{
|
||||
if (worker.joinable()) worker.join();
|
||||
if (fd >= 0) ::close(fd);
|
||||
if (fd >= 0) close_socket(fd);
|
||||
if (ctx != nullptr) SSL_CTX_free(ctx);
|
||||
}
|
||||
};
|
||||
@@ -256,13 +288,14 @@ Void::Testing::Test http_client_timeout_bounds_a_stalled_server()
|
||||
{
|
||||
fd = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
int yes = 1;
|
||||
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
||||
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<const char*>(&yes), sizeof(yes));
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
addr.sin_port = 0;
|
||||
::bind(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
|
||||
socklen_t len = sizeof(addr);
|
||||
SocketLength len = sizeof(addr);
|
||||
::getsockname(fd, reinterpret_cast<sockaddr*>(&addr), &len);
|
||||
port = ntohs(addr.sin_port);
|
||||
::listen(fd, 1);
|
||||
@@ -273,10 +306,14 @@ Void::Testing::Test http_client_timeout_bounds_a_stalled_server()
|
||||
|
||||
~StallServer()
|
||||
{
|
||||
if (fd >= 0) ::shutdown(fd, SHUT_RDWR);
|
||||
// Close the listener first: on Windows, shutdown() does not wake a
|
||||
// thread blocked in accept().
|
||||
if (fd >= 0) {
|
||||
close_socket(fd);
|
||||
fd = -1;
|
||||
}
|
||||
if (worker.joinable()) worker.join();
|
||||
if (conn >= 0) ::close(conn);
|
||||
if (fd >= 0) ::close(fd);
|
||||
if (conn >= 0) close_socket(conn);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user