diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-07-15 14:23:25 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-15 14:24:06 -0700 |
| commit | 5f6e3245d131a44d5fd8552baa35e341bf99a4b9 (patch) | |
| tree | d2e619b1fb41098621151a223f58e93ea86edfaa /lib/std/os | |
| parent | d4a191fc0a8e34c818dfea50966d902f37b36c8b (diff) | |
| download | zig-5f6e3245d131a44d5fd8552baa35e341bf99a4b9.tar.gz zig-5f6e3245d131a44d5fd8552baa35e341bf99a4b9.zip | |
std.os.windows: restore sendmsg, sendto, recvfrom
These regressed with 1a998886c863a1829d649f196093f1058cd9cf13
I'm not ready to tackle std.posix quite yet
Diffstat (limited to 'lib/std/os')
| -rw-r--r-- | lib/std/os/windows.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 52a227df28..829a8c37cc 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1690,6 +1690,40 @@ pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.so return ws2_32.getpeername(s, name, @as(*i32, @ptrCast(namelen))); } +pub fn sendmsg( + s: ws2_32.SOCKET, + msg: *ws2_32.WSAMSG_const, + flags: u32, +) i32 { + var bytes_send: DWORD = undefined; + if (ws2_32.WSASendMsg(s, msg, flags, &bytes_send, null, null) == ws2_32.SOCKET_ERROR) { + return ws2_32.SOCKET_ERROR; + } else { + return @as(i32, @as(u31, @intCast(bytes_send))); + } +} + +pub fn sendto(s: ws2_32.SOCKET, buf: [*]const u8, len: usize, flags: u32, to: ?*const ws2_32.sockaddr, to_len: ws2_32.socklen_t) i32 { + var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = @constCast(buf) }; + var bytes_send: DWORD = undefined; + if (ws2_32.WSASendTo(s, @as([*]ws2_32.WSABUF, @ptrCast(&buffer)), 1, &bytes_send, flags, to, @as(i32, @intCast(to_len)), null, null) == ws2_32.SOCKET_ERROR) { + return ws2_32.SOCKET_ERROR; + } else { + return @as(i32, @as(u31, @intCast(bytes_send))); + } +} + +pub fn recvfrom(s: ws2_32.SOCKET, buf: [*]u8, len: usize, flags: u32, from: ?*ws2_32.sockaddr, from_len: ?*ws2_32.socklen_t) i32 { + var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = buf }; + var bytes_received: DWORD = undefined; + var flags_inout = flags; + if (ws2_32.WSARecvFrom(s, @as([*]ws2_32.WSABUF, @ptrCast(&buffer)), 1, &bytes_received, &flags_inout, from, @as(?*i32, @ptrCast(from_len)), null, null) == ws2_32.SOCKET_ERROR) { + return ws2_32.SOCKET_ERROR; + } else { + return @as(i32, @as(u31, @intCast(bytes_received))); + } +} + pub fn poll(fds: [*]ws2_32.pollfd, n: c_ulong, timeout: i32) i32 { return ws2_32.WSAPoll(fds, n, timeout); } |
