Fixes #13893 - some standard library networking tests are failing on Windows

This commit is contained in:
Binary Craft 2023-02-24 11:03:27 +08:00 committed by Andrew Kelley
parent e41bc640c6
commit a7a709aaa9
2 changed files with 26 additions and 1 deletions

View File

@ -2068,7 +2068,7 @@ pub fn loadWinsockExtensionFunction(comptime T: type, sock: ws2_32.SOCKET, guid:
ws2_32.SIO_GET_EXTENSION_FUNCTION_POINTER,
@ptrCast(*const anyopaque, &guid),
@sizeOf(GUID),
@intToPtr(?*anyopaque, @ptrToInt(function)),
@intToPtr(?*anyopaque, @ptrToInt(&function)),
@sizeOf(T),
&num_bytes,
null,

View File

@ -63,3 +63,28 @@ test "removeDotDirs" {
try testRemoveDotDirs("a\\b\\..\\", "a\\");
try testRemoveDotDirs("a\\b\\..\\c", "a\\c");
}
test "loadWinsockExtensionFunction" {
_ = try windows.WSAStartup(2, 2);
defer windows.WSACleanup() catch unreachable;
const LPFN_CONNECTEX = *const fn (
Socket: windows.ws2_32.SOCKET,
SockAddr: *const windows.ws2_32.sockaddr,
SockLen: std.os.socklen_t,
SendBuf: ?*const anyopaque,
SendBufLen: windows.DWORD,
BytesSent: *windows.DWORD,
Overlapped: *windows.OVERLAPPED,
) callconv(windows.WINAPI) windows.BOOL;
_ = windows.loadWinsockExtensionFunction(
LPFN_CONNECTEX,
try std.os.socket(std.os.AF.INET, std.os.SOCK.DGRAM, 0),
windows.ws2_32.WSAID_CONNECTEX,
) catch |err| switch (err) {
error.OperationNotSupported => unreachable,
error.ShortRead => unreachable,
else => |e| return e,
};
}