6161#![ doc( test( attr( deny( warnings) ) ) ) ]
6262
6363use std:: fmt;
64- #[ cfg( not( target_os = "redox" ) ) ]
64+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
6565use std:: io:: IoSlice ;
66- #[ cfg( not( target_os = "redox" ) ) ]
66+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
6767use std:: marker:: PhantomData ;
68- #[ cfg( not( target_os = "redox" ) ) ]
68+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
6969use std:: mem;
7070use std:: mem:: MaybeUninit ;
7171use std:: net:: SocketAddr ;
@@ -109,7 +109,7 @@ macro_rules! from {
109109 ( $from: ty, $for: ty) => {
110110 impl From <$from> for $for {
111111 fn from( socket: $from) -> $for {
112- #[ cfg( unix) ]
112+ #[ cfg( any ( unix, all ( target_os = "wasi" , not ( target_env = "p1" ) ) ) ) ]
113113 unsafe {
114114 <$for>:: from_raw_fd( socket. into_raw_fd( ) )
115115 }
@@ -176,11 +176,11 @@ mod sockaddr;
176176mod socket;
177177mod sockref;
178178
179- #[ cfg_attr( unix, path = "sys/unix.rs" ) ]
179+ #[ cfg_attr( any ( unix, all ( target_os = "wasi" , not ( target_env = "p1" ) ) ) , path = "sys/unix.rs" ) ]
180180#[ cfg_attr( windows, path = "sys/windows.rs" ) ]
181181mod sys;
182182
183- #[ cfg( not( any( windows, unix) ) ) ]
183+ #[ cfg( not( any( windows, unix, all ( target_os = "wasi" , not ( target_env = "p1" ) ) ) ) ) ]
184184compile_error ! ( "Socket2 doesn't support the compile target" ) ;
185185
186186use sys:: c_int;
@@ -192,6 +192,7 @@ pub use sockaddr::{sa_family_t, socklen_t, SockAddr, SockAddrStorage};
192192 target_os = "netbsd" ,
193193 target_os = "redox" ,
194194 target_os = "solaris" ,
195+ target_os = "wasi" ,
195196) ) ) ]
196197pub use socket:: InterfaceIndexOrAddress ;
197198pub use socket:: Socket ;
@@ -221,6 +222,7 @@ impl Domain {
221222 pub const IPV6 : Domain = Domain ( sys:: AF_INET6 ) ;
222223
223224 /// Domain for Unix socket communication, corresponding to `AF_UNIX`.
225+ #[ cfg( not( target_os = "wasi" ) ) ]
224226 pub const UNIX : Domain = Domain ( sys:: AF_UNIX ) ;
225227
226228 /// Returns the correct domain for `address`.
@@ -274,11 +276,14 @@ impl Type {
274276 pub const DCCP : Type = Type ( sys:: SOCK_DCCP ) ;
275277
276278 /// Type corresponding to `SOCK_SEQPACKET`.
277- #[ cfg( all( feature = "all" , not( target_os = "espidf" ) ) ) ]
279+ #[ cfg( all( feature = "all" , not( any ( target_os = "espidf" , target_os = "wasi" ) ) ) ) ]
278280 pub const SEQPACKET : Type = Type ( sys:: SOCK_SEQPACKET ) ;
279281
280282 /// Type corresponding to `SOCK_RAW`.
281- #[ cfg( all( feature = "all" , not( any( target_os = "redox" , target_os = "espidf" ) ) ) ) ]
283+ #[ cfg( all(
284+ feature = "all" ,
285+ not( any( target_os = "redox" , target_os = "espidf" , target_os = "wasi" ) )
286+ ) ) ]
282287 pub const RAW : Type = Type ( sys:: SOCK_RAW ) ;
283288}
284289
@@ -306,9 +311,11 @@ pub struct Protocol(c_int);
306311
307312impl Protocol {
308313 /// Protocol corresponding to `ICMPv4`.
314+ #[ cfg( not( target_os = "wasi" ) ) ]
309315 pub const ICMPV4 : Protocol = Protocol ( sys:: IPPROTO_ICMP ) ;
310316
311317 /// Protocol corresponding to `ICMPv6`.
318+ #[ cfg( not( target_os = "wasi" ) ) ]
312319 pub const ICMPV6 : Protocol = Protocol ( sys:: IPPROTO_ICMPV6 ) ;
313320
314321 /// Protocol corresponding to `TCP`.
@@ -361,11 +368,11 @@ impl From<Protocol> for c_int {
361368/// Flags for incoming messages.
362369///
363370/// Flags provide additional information about incoming messages.
364- #[ cfg( not( target_os = "redox" ) ) ]
371+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
365372#[ derive( Copy , Clone , Eq , PartialEq ) ]
366373pub struct RecvFlags ( c_int ) ;
367374
368- #[ cfg( not( target_os = "redox" ) ) ]
375+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
369376impl RecvFlags {
370377 /// Check if the message contains a truncated datagram.
371378 ///
@@ -518,6 +525,7 @@ impl TcpKeepalive {
518525 target_os = "watchos" ,
519526 target_os = "windows" ,
520527 target_os = "cygwin" ,
528+ all( target_os = "wasi" , not( target_env = "p1" ) ) ,
521529 ) ) ]
522530 pub const fn with_interval ( self , interval : Duration ) -> Self {
523531 Self {
@@ -547,6 +555,7 @@ impl TcpKeepalive {
547555 target_os = "watchos" ,
548556 target_os = "cygwin" ,
549557 target_os = "windows" ,
558+ all( target_os = "wasi" , not( target_env = "p1" ) ) ,
550559 )
551560 ) ) ]
552561 pub const fn with_retries ( self , retries : u32 ) -> Self {
@@ -561,15 +570,15 @@ impl TcpKeepalive {
561570///
562571/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`]
563572/// for the variant used by `recvmsg(2)`.
564- #[ cfg( not( target_os = "redox" ) ) ]
573+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
565574#[ repr( transparent) ]
566575pub struct MsgHdr < ' addr , ' bufs , ' control > {
567576 inner : sys:: msghdr ,
568577 #[ allow( clippy:: type_complexity) ]
569578 _lifetimes : PhantomData < ( & ' addr SockAddr , & ' bufs IoSlice < ' bufs > , & ' control [ u8 ] ) > ,
570579}
571580
572- #[ cfg( not( target_os = "redox" ) ) ]
581+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
573582impl < ' addr , ' bufs , ' control > MsgHdr < ' addr , ' bufs , ' control > {
574583 /// Create a new `MsgHdr` with all empty/zero fields.
575584 #[ allow( clippy:: new_without_default) ]
@@ -619,7 +628,7 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
619628 }
620629}
621630
622- #[ cfg( not( target_os = "redox" ) ) ]
631+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
623632impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdr < ' name , ' bufs , ' control > {
624633 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
625634 "MsgHdr" . fmt ( fmt)
@@ -630,7 +639,7 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> {
630639///
631640/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for
632641/// the variant used by `sendmsg(2)`.
633- #[ cfg( not( target_os = "redox" ) ) ]
642+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
634643#[ repr( transparent) ]
635644pub struct MsgHdrMut < ' addr , ' bufs , ' control > {
636645 inner : sys:: msghdr ,
@@ -642,7 +651,7 @@ pub struct MsgHdrMut<'addr, 'bufs, 'control> {
642651 ) > ,
643652}
644653
645- #[ cfg( not( target_os = "redox" ) ) ]
654+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
646655impl < ' addr , ' bufs , ' control > MsgHdrMut < ' addr , ' bufs , ' control > {
647656 /// Create a new `MsgHdrMut` with all empty/zero fields.
648657 #[ allow( clippy:: new_without_default) ]
@@ -697,7 +706,7 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
697706 }
698707}
699708
700- #[ cfg( not( target_os = "redox" ) ) ]
709+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
701710impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdrMut < ' name , ' bufs , ' control > {
702711 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
703712 "MsgHdrMut" . fmt ( fmt)
0 commit comments