xref: /wasmtime-44.0.1/crates/test-programs/src/bin/p3_sockets_udp_send.rs (revision 7e0331c2)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use test_programs::p3::wasi::sockets::types::{
2     IpAddress, IpAddressFamily, IpSocketAddress, UdpSocket,
3 };
4 
5 struct Component;
6 
7 test_programs::p3::export!(Component);
8 
9 // Send without prior `bind` or `connect` performs an implicit bind.
10 async fn test_udp_send_without_bind_or_connect(family: IpAddressFamily) {
11     let message = b"Hello, world!";
12     let remote_addr = IpSocketAddress::new(IpAddress::new_loopback(family), 42);
13 
14     let sock = UdpSocket::create(family).unwrap();
15 
16     assert!(matches!(sock.get_local_address(), Err(_)));
17 
18     assert!(matches!(
19         sock.send(message.to_vec(), Some(remote_addr)).await,
20         Ok(_)
21     ));
22 
23     assert!(matches!(sock.get_local_address(), Ok(_)));
24     assert!(matches!(sock.get_remote_address(), Err(_)));
25 }
26 
27 impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
28     async fn run() -> Result<(), ()> {
29         test_udp_send_without_bind_or_connect(IpAddressFamily::Ipv4).await;
30         test_udp_send_without_bind_or_connect(IpAddressFamily::Ipv6).await;
31 
32         Ok(())
33     }
34 }
35 
36 fn main() {}
37 

served by {OpenGrok

Last Index Update: Fri May 15 20:09:11 GMT 2026