zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4cf535a01b06c301239fb888dbdf87831c568867 (tree)
parent d9d3268cc1fe6b581ccb44606346cb6847d557a5
Author: daurnimator <quae@daurnimator.com>
Date:   Wed, 13 Nov 2019 18:23:21 +1100

std: add WSASocketW for windows

Diffstat:
Mlib/std/os/windows.zig | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig @@ -608,6 +608,27 @@ pub fn GetFileAttributesW(lpFileName: [*]const u16) GetFileAttributesError!DWORD return rc; } +pub fn WSASocketW( + af: i32, + socket_type: i32, + protocol: i32, + protocolInfo: ?*ws2_32.WSAPROTOCOL_INFOW, + g: ws2_32.GROUP, + dwFlags: DWORD, +) !ws2_32.SOCKET { + const rc = ws2_32.WSASocketW(af, socket_type, protocol, protocolInfo, g, dwFlags); + if (rc == ws2_32.INVALID_SOCKET) { + switch (ws2_32.WSAGetLastError()) { + ws2_32.WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported, + ws2_32.WSAEMFILE => return error.ProcessFdQuotaExceeded, + ws2_32.WSAENOBUFS => return error.SystemResources, + ws2_32.WSAEPROTONOSUPPORT => return error.ProtocolNotSupported, + else => |err| return unexpectedWSAError(err), + } + } + return rc; +} + const GetModuleFileNameError = error{Unexpected}; pub fn GetModuleFileNameW(hModule: ?HMODULE, buf_ptr: [*]u16, buf_len: DWORD) GetModuleFileNameError![]u16 { @@ -905,6 +926,10 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { return error.Unexpected; } +pub fn unexpectedWSAError(err: c_int) std.os.UnexpectedError { + return unexpectedError(@intCast(DWORD, err)); +} + /// Call this when you made a windows NtDll call /// and you get an unexpected status. pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError {