os-rust/library/std/src/net
Trevor Gross b70654199a
Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichton
Hook up std::net to wasi-libc on wasm32-wasip2 target

One of the improvements of the `wasm32-wasip2` target over `wasm32-wasip1` is better support for networking. Right now, p2 is just re-using the `std::net` implementation from p1. This PR adds a new net module for p2 that makes use of net from `sys_common` and calls wasi-libc functions directly.

There are currently a few limitations:

- Duplicating a socket is not supported by WASIp2 (directly returns an error)
- Peeking is not yet implemented in wasi-libc (we could let wasi-libc handle this, but I opted to directly return an error instead)
- Vectored reads/writes are not supported by WASIp2 (the necessary functions are available in wasi-libc, but they call WASIp1 functions which do not support sockets, so I opted to directly return an error instead)
- Getting/setting `TCP_NODELAY` is faked in wasi-libc (uses the fake implementation instead of returning an error)
- Getting/setting `SO_LINGER` is not supported by WASIp2 (directly returns an error)
- Setting `SO_REUSEADDR` is faked in wasi-libc (since this is done from `sys_common`, the fake implementation is used instead of returning an error)
- Getting/setting `IPV6_V6ONLY` is not supported by WASIp2 and will always be set for IPv6 sockets (since this is done from `sys_common`, wasi-libc will return an error)
- UDP broadcast/multicast is not supported by WASIp2 (since this is configured from `sys_common`, wasi-libc will return appropriate errors)
- The `MSG_NOSIGNAL` send flag is a no-op because there are no signals in WASIp2 (since explicitly setting this flag would require a change to `sys_common` and the result would be exactly the same, I opted to not set it)

Do those decisions make sense?

While working on this PR, I noticed that there is a `std::os::wasi::net::TcpListenerExt` trait that adds a `sock_accept()` method to `std::net::TcpListener`. Now that WASIp2 supports standard accept, would it make sense to remove this?

cc `@alexcrichton`
2024-09-30 19:18:49 -04:00
..
ip_addr Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
socket_addr Fix SocketAddrV6: Display tests 2023-06-14 15:21:15 -04:00
tcp Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
udp Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
ip_addr.rs Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
mod.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
socket_addr.rs Fix std tests for wasm32-wasip2 target 2024-09-29 04:48:13 +02:00
tcp.rs Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichton 2024-09-30 19:18:49 -04:00
test.rs SeqCst->Relaxed in std::net::test. 2024-03-20 15:35:13 +01:00
udp.rs Rollup merge of #129638 - nickrum:wasip2-net, r=alexcrichton 2024-09-30 19:18:49 -04:00