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,14 @@ mod sockaddr;
176176mod socket;
177177mod sockref;
178178
179- #[ cfg_attr( unix, path = "sys/unix.rs" ) ]
179+ #[ cfg_attr(
180+ any( unix, all( target_os = "wasi" , not( target_env = "p1" ) ) ) ,
181+ path = "sys/unix.rs"
182+ ) ]
180183#[ cfg_attr( windows, path = "sys/windows.rs" ) ]
181184mod sys;
182185
183- #[ cfg( not( any( windows, unix) ) ) ]
186+ #[ cfg( not( any( windows, unix, all ( target_os = "wasi" , not ( target_env = "p1" ) ) ) ) ) ]
184187compile_error ! ( "Socket2 doesn't support the compile target" ) ;
185188
186189use sys:: c_int;
@@ -192,6 +195,7 @@ pub use sockaddr::{sa_family_t, socklen_t, SockAddr, SockAddrStorage};
192195 target_os = "netbsd" ,
193196 target_os = "redox" ,
194197 target_os = "solaris" ,
198+ target_os = "wasi" ,
195199) ) ) ]
196200pub use socket:: InterfaceIndexOrAddress ;
197201pub use socket:: Socket ;
@@ -221,6 +225,7 @@ impl Domain {
221225 pub const IPV6 : Domain = Domain ( sys:: AF_INET6 ) ;
222226
223227 /// Domain for Unix socket communication, corresponding to `AF_UNIX`.
228+ #[ cfg( not( target_os = "wasi" ) ) ]
224229 pub const UNIX : Domain = Domain ( sys:: AF_UNIX ) ;
225230
226231 /// Returns the correct domain for `address`.
@@ -274,11 +279,14 @@ impl Type {
274279 pub const DCCP : Type = Type ( sys:: SOCK_DCCP ) ;
275280
276281 /// Type corresponding to `SOCK_SEQPACKET`.
277- #[ cfg( all( feature = "all" , not( target_os = "espidf" ) ) ) ]
282+ #[ cfg( all( feature = "all" , not( any ( target_os = "espidf" , target_os = "wasi" ) ) ) ) ]
278283 pub const SEQPACKET : Type = Type ( sys:: SOCK_SEQPACKET ) ;
279284
280285 /// Type corresponding to `SOCK_RAW`.
281- #[ cfg( all( feature = "all" , not( any( target_os = "redox" , target_os = "espidf" ) ) ) ) ]
286+ #[ cfg( all(
287+ feature = "all" ,
288+ not( any( target_os = "redox" , target_os = "espidf" , target_os = "wasi" ) )
289+ ) ) ]
282290 pub const RAW : Type = Type ( sys:: SOCK_RAW ) ;
283291}
284292
@@ -306,9 +314,11 @@ pub struct Protocol(c_int);
306314
307315impl Protocol {
308316 /// Protocol corresponding to `ICMPv4`.
317+ #[ cfg( not( target_os = "wasi" ) ) ]
309318 pub const ICMPV4 : Protocol = Protocol ( sys:: IPPROTO_ICMP ) ;
310319
311320 /// Protocol corresponding to `ICMPv6`.
321+ #[ cfg( not( target_os = "wasi" ) ) ]
312322 pub const ICMPV6 : Protocol = Protocol ( sys:: IPPROTO_ICMPV6 ) ;
313323
314324 /// Protocol corresponding to `TCP`.
@@ -361,11 +371,11 @@ impl From<Protocol> for c_int {
361371/// Flags for incoming messages.
362372///
363373/// Flags provide additional information about incoming messages.
364- #[ cfg( not( target_os = "redox" ) ) ]
374+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
365375#[ derive( Copy , Clone , Eq , PartialEq ) ]
366376pub struct RecvFlags ( c_int ) ;
367377
368- #[ cfg( not( target_os = "redox" ) ) ]
378+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
369379impl RecvFlags {
370380 /// Check if the message contains a truncated datagram.
371381 ///
@@ -518,6 +528,7 @@ impl TcpKeepalive {
518528 target_os = "watchos" ,
519529 target_os = "windows" ,
520530 target_os = "cygwin" ,
531+ all( target_os = "wasi" , not( target_env = "p1" ) ) ,
521532 ) ) ]
522533 pub const fn with_interval ( self , interval : Duration ) -> Self {
523534 Self {
@@ -547,6 +558,7 @@ impl TcpKeepalive {
547558 target_os = "watchos" ,
548559 target_os = "cygwin" ,
549560 target_os = "windows" ,
561+ all( target_os = "wasi" , not( target_env = "p1" ) ) ,
550562 )
551563 ) ) ]
552564 pub const fn with_retries ( self , retries : u32 ) -> Self {
@@ -561,15 +573,15 @@ impl TcpKeepalive {
561573///
562574/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`]
563575/// for the variant used by `recvmsg(2)`.
564- #[ cfg( not( target_os = "redox" ) ) ]
576+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
565577#[ repr( transparent) ]
566578pub struct MsgHdr < ' addr , ' bufs , ' control > {
567579 inner : sys:: msghdr ,
568580 #[ allow( clippy:: type_complexity) ]
569581 _lifetimes : PhantomData < ( & ' addr SockAddr , & ' bufs IoSlice < ' bufs > , & ' control [ u8 ] ) > ,
570582}
571583
572- #[ cfg( not( target_os = "redox" ) ) ]
584+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
573585impl < ' addr , ' bufs , ' control > MsgHdr < ' addr , ' bufs , ' control > {
574586 /// Create a new `MsgHdr` with all empty/zero fields.
575587 #[ allow( clippy:: new_without_default) ]
@@ -619,7 +631,7 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
619631 }
620632}
621633
622- #[ cfg( not( target_os = "redox" ) ) ]
634+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
623635impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdr < ' name , ' bufs , ' control > {
624636 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
625637 "MsgHdr" . fmt ( fmt)
@@ -630,7 +642,7 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> {
630642///
631643/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for
632644/// the variant used by `sendmsg(2)`.
633- #[ cfg( not( target_os = "redox" ) ) ]
645+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
634646#[ repr( transparent) ]
635647pub struct MsgHdrMut < ' addr , ' bufs , ' control > {
636648 inner : sys:: msghdr ,
@@ -642,7 +654,7 @@ pub struct MsgHdrMut<'addr, 'bufs, 'control> {
642654 ) > ,
643655}
644656
645- #[ cfg( not( target_os = "redox" ) ) ]
657+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
646658impl < ' addr , ' bufs , ' control > MsgHdrMut < ' addr , ' bufs , ' control > {
647659 /// Create a new `MsgHdrMut` with all empty/zero fields.
648660 #[ allow( clippy:: new_without_default) ]
@@ -697,7 +709,7 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
697709 }
698710}
699711
700- #[ cfg( not( target_os = "redox" ) ) ]
712+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
701713impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdrMut < ' name , ' bufs , ' control > {
702714 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
703715 "MsgHdrMut" . fmt ( fmt)
0 commit comments