@@ -14,22 +14,22 @@ test_programs::p3::export!(Component);
1414fn test_tcp_bind_ephemeral_port ( ip : IpAddress ) {
1515 let bind_addr = IpSocketAddress :: new ( ip, 0 ) ;
1616
17- let sock = TcpSocket :: new ( ip. family ( ) ) ;
17+ let sock = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
1818 sock. bind ( bind_addr) . unwrap ( ) ;
1919
20- let bound_addr = sock. local_address ( ) . unwrap ( ) ;
20+ let bound_addr = sock. get_local_address ( ) . unwrap ( ) ;
2121
2222 assert_eq ! ( bind_addr. ip( ) , bound_addr. ip( ) ) ;
2323 assert_ne ! ( bind_addr. port( ) , bound_addr. port( ) ) ;
2424}
2525
2626/// Bind a socket on a specified port.
2727fn test_tcp_bind_specific_port ( ip : IpAddress ) {
28- let sock = TcpSocket :: new ( ip. family ( ) ) ;
28+ let sock = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
2929
3030 let bind_addr = attempt_random_port ( ip, |bind_addr| sock. bind ( bind_addr) ) . unwrap ( ) ;
3131
32- let bound_addr = sock. local_address ( ) . unwrap ( ) ;
32+ let bound_addr = sock. get_local_address ( ) . unwrap ( ) ;
3333
3434 assert_eq ! ( bind_addr. ip( ) , bound_addr. ip( ) ) ;
3535 assert_eq ! ( bind_addr. port( ) , bound_addr. port( ) ) ;
@@ -39,22 +39,22 @@ fn test_tcp_bind_specific_port(ip: IpAddress) {
3939fn test_tcp_bind_addrinuse ( ip : IpAddress ) {
4040 let bind_addr = IpSocketAddress :: new ( ip, 0 ) ;
4141
42- let sock1 = TcpSocket :: new ( ip. family ( ) ) ;
42+ let sock1 = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
4343 sock1. bind ( bind_addr) . unwrap ( ) ;
4444 sock1. listen ( ) . unwrap ( ) ;
4545
46- let bound_addr = sock1. local_address ( ) . unwrap ( ) ;
46+ let bound_addr = sock1. get_local_address ( ) . unwrap ( ) ;
4747
48- let sock2 = TcpSocket :: new ( ip. family ( ) ) ;
48+ let sock2 = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
4949 assert_eq ! ( sock2. bind( bound_addr) , Err ( ErrorCode :: AddressInUse ) ) ;
5050}
5151
5252// The WASI runtime should set SO_REUSEADDR for us
5353async fn test_tcp_bind_reuseaddr ( ip : IpAddress ) {
54- let client = TcpSocket :: new ( ip. family ( ) ) ;
54+ let client = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
5555
5656 let bind_addr = {
57- let listener1 = TcpSocket :: new ( ip. family ( ) ) ;
57+ let listener1 = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
5858
5959 let bind_addr = attempt_random_port ( ip, |bind_addr| listener1. bind ( bind_addr) ) . unwrap ( ) ;
6060
@@ -97,7 +97,7 @@ async fn test_tcp_bind_reuseaddr(ip: IpAddress) {
9797 // time to see if we can reuse the address. This loop is bounded because it
9898 // should complete "quickly".
9999 for _ in 0 ..10 {
100- let listener2 = TcpSocket :: new ( ip. family ( ) ) ;
100+ let listener2 = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
101101 if listener2. bind ( bind_addr) . is_ok ( ) {
102102 listener2. listen ( ) . unwrap ( ) ;
103103 return ;
@@ -112,7 +112,7 @@ async fn test_tcp_bind_reuseaddr(ip: IpAddress) {
112112fn test_tcp_bind_addrnotavail ( ip : IpAddress ) {
113113 let bind_addr = IpSocketAddress :: new ( ip, 0 ) ;
114114
115- let sock = TcpSocket :: new ( ip. family ( ) ) ;
115+ let sock = TcpSocket :: create ( ip. family ( ) ) . unwrap ( ) ;
116116
117117 assert_eq ! ( sock. bind( bind_addr) , Err ( ErrorCode :: AddressNotBindable ) ) ;
118118}
@@ -124,7 +124,7 @@ fn test_tcp_bind_wrong_family(family: IpAddressFamily) {
124124 IpAddressFamily :: Ipv6 => IpAddress :: IPV4_LOOPBACK ,
125125 } ;
126126
127- let sock = TcpSocket :: new ( family) ;
127+ let sock = TcpSocket :: create ( family) . unwrap ( ) ;
128128 let result = sock. bind ( IpSocketAddress :: new ( wrong_ip, 0 ) ) ;
129129
130130 assert ! ( matches!( result, Err ( ErrorCode :: InvalidArgument ) ) ) ;
@@ -136,8 +136,8 @@ fn test_tcp_bind_non_unicast() {
136136 let ipv4_multicast = IpSocketAddress :: new ( IpAddress :: Ipv4 ( ( 224 , 254 , 0 , 0 ) ) , 0 ) ;
137137 let ipv6_multicast = IpSocketAddress :: new ( IpAddress :: Ipv6 ( ( 0xff00 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) , 0 ) ;
138138
139- let sock_v4 = TcpSocket :: new ( IpAddressFamily :: Ipv4 ) ;
140- let sock_v6 = TcpSocket :: new ( IpAddressFamily :: Ipv6 ) ;
139+ let sock_v4 = TcpSocket :: create ( IpAddressFamily :: Ipv4 ) . unwrap ( ) ;
140+ let sock_v6 = TcpSocket :: create ( IpAddressFamily :: Ipv6 ) . unwrap ( ) ;
141141
142142 assert ! ( matches!(
143143 sock_v4. bind( ipv4_broadcast) ,
@@ -154,7 +154,7 @@ fn test_tcp_bind_non_unicast() {
154154}
155155
156156fn test_tcp_bind_dual_stack ( ) {
157- let sock = TcpSocket :: new ( IpAddressFamily :: Ipv6 ) ;
157+ let sock = TcpSocket :: create ( IpAddressFamily :: Ipv6 ) . unwrap ( ) ;
158158 let addr = IpSocketAddress :: new ( IpAddress :: IPV4_MAPPED_LOOPBACK , 0 ) ;
159159
160160 // Binding an IPv4-mapped-IPv6 address on a ipv6-only socket should fail:
0 commit comments