Skip to content

Commit 5f6e324

Browse files
committed
std.os.windows: restore sendmsg, sendto, recvfrom
These regressed with 1a99888 I'm not ready to tackle std.posix quite yet
1 parent d4a191f commit 5f6e324

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/std/os/windows.zig

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,40 @@ pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.so
16901690
return ws2_32.getpeername(s, name, @as(*i32, @ptrCast(namelen)));
16911691
}
16921692

1693+
pub fn sendmsg(
1694+
s: ws2_32.SOCKET,
1695+
msg: *ws2_32.WSAMSG_const,
1696+
flags: u32,
1697+
) i32 {
1698+
var bytes_send: DWORD = undefined;
1699+
if (ws2_32.WSASendMsg(s, msg, flags, &bytes_send, null, null) == ws2_32.SOCKET_ERROR) {
1700+
return ws2_32.SOCKET_ERROR;
1701+
} else {
1702+
return @as(i32, @as(u31, @intCast(bytes_send)));
1703+
}
1704+
}
1705+
1706+
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 {
1707+
var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = @constCast(buf) };
1708+
var bytes_send: DWORD = undefined;
1709+
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) {
1710+
return ws2_32.SOCKET_ERROR;
1711+
} else {
1712+
return @as(i32, @as(u31, @intCast(bytes_send)));
1713+
}
1714+
}
1715+
1716+
pub fn recvfrom(s: ws2_32.SOCKET, buf: [*]u8, len: usize, flags: u32, from: ?*ws2_32.sockaddr, from_len: ?*ws2_32.socklen_t) i32 {
1717+
var buffer = ws2_32.WSABUF{ .len = @as(u31, @truncate(len)), .buf = buf };
1718+
var bytes_received: DWORD = undefined;
1719+
var flags_inout = flags;
1720+
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) {
1721+
return ws2_32.SOCKET_ERROR;
1722+
} else {
1723+
return @as(i32, @as(u31, @intCast(bytes_received)));
1724+
}
1725+
}
1726+
16931727
pub fn poll(fds: [*]ws2_32.pollfd, n: c_ulong, timeout: i32) i32 {
16941728
return ws2_32.WSAPoll(fds, n, timeout);
16951729
}

0 commit comments

Comments
 (0)