Skip to content

Commit e83da48

Browse files
authored
Use the same TcpSocket in WASIp{2,3} (#11386)
* Use the same `TcpSocket` in WASIp{2,3} This is the same as #11384 except for `TcpSocket` to share the implementation of TCP across WASIp{2,3} and avoid duplicating code between the two. * Fix CI issues * Review comments * Trim "TCP allowed?" checks Like UDP only perform the check on socket creation, not after it's created.
1 parent af40b57 commit e83da48

File tree

15 files changed

+1001
-1309
lines changed

15 files changed

+1001
-1309
lines changed
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
//! This test assumes that it will be run without tcp support enabled
2-
use test_programs::wasi::sockets::{
3-
network::IpAddress,
4-
tcp::{ErrorCode, IpAddressFamily, IpSocketAddress, Network, TcpSocket},
5-
};
62
7-
fn main() {
8-
let net = Network::default();
9-
let family = IpAddressFamily::Ipv4;
10-
let remote1 = IpSocketAddress::new(IpAddress::new_loopback(family), 4321);
11-
let sock = TcpSocket::new(family).unwrap();
12-
13-
let bind = sock.blocking_bind(&net, remote1);
14-
eprintln!("Result of binding: {bind:?}");
15-
assert!(matches!(bind, Err(ErrorCode::AccessDenied)));
3+
#![deny(warnings)]
164

17-
let listen = sock.blocking_listen();
18-
eprintln!("Result of listen: {listen:?}");
19-
assert!(matches!(listen, Err(ErrorCode::AccessDenied)));
5+
use test_programs::wasi::sockets::tcp::{ErrorCode, IpAddressFamily, TcpSocket};
206

21-
let connect = sock.blocking_connect(&net, remote1);
22-
eprintln!("Result of connect: {connect:?}");
23-
assert!(matches!(connect, Err(ErrorCode::AccessDenied)));
24-
25-
let accept = sock.blocking_accept();
26-
eprintln!("Result of accept: {accept:?}");
27-
assert!(matches!(accept, Err(ErrorCode::AccessDenied)));
7+
fn main() {
8+
assert!(matches!(
9+
TcpSocket::new(IpAddressFamily::Ipv4),
10+
Err(ErrorCode::AccessDenied)
11+
));
2812
}

crates/wasi/src/p2/bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ mod async_io {
393393
// Configure all other resources to be concrete types defined in
394394
// this crate
395395
"wasi:sockets/network/network": crate::p2::network::Network,
396-
"wasi:sockets/tcp/tcp-socket": crate::p2::tcp::TcpSocket,
396+
"wasi:sockets/tcp/tcp-socket": crate::sockets::TcpSocket,
397397
"wasi:sockets/udp/udp-socket": crate::sockets::UdpSocket,
398398
"wasi:sockets/udp/incoming-datagram-stream": crate::p2::udp::IncomingDatagramStream,
399399
"wasi:sockets/udp/outgoing-datagram-stream": crate::p2::udp::OutgoingDatagramStream,

0 commit comments

Comments
 (0)