60
60
// Disallow warnings in examples.
61
61
#![ doc( test( attr( deny( warnings) ) ) ) ]
62
62
63
+ #[ cfg( not( target_os = "wasi" ) ) ]
63
64
use std:: fmt;
64
- #[ cfg( not( target_os = "redox" ) ) ]
65
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
65
66
use std:: io:: IoSlice ;
66
- #[ cfg( not( target_os = "redox" ) ) ]
67
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
67
68
use std:: marker:: PhantomData ;
68
- #[ cfg( not( target_os = "redox" ) ) ]
69
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
69
70
use std:: mem;
71
+ #[ cfg( not( target_os = "wasi" ) ) ]
70
72
use std:: mem:: MaybeUninit ;
71
73
use std:: net:: SocketAddr ;
74
+ #[ cfg( not( target_os = "wasi" ) ) ]
72
75
use std:: ops:: { Deref , DerefMut } ;
73
76
use std:: time:: Duration ;
74
77
@@ -109,7 +112,7 @@ macro_rules! from {
109
112
( $from: ty, $for: ty) => {
110
113
impl From <$from> for $for {
111
114
fn from( socket: $from) -> $for {
112
- #[ cfg( unix) ]
115
+ #[ cfg( any ( unix, target_os = "wasi" ) ) ]
113
116
unsafe {
114
117
<$for>:: from_raw_fd( socket. into_raw_fd( ) )
115
118
}
@@ -178,9 +181,10 @@ mod sockref;
178
181
179
182
#[ cfg_attr( unix, path = "sys/unix.rs" ) ]
180
183
#[ cfg_attr( windows, path = "sys/windows.rs" ) ]
184
+ #[ cfg_attr( target_os = "wasi" , path = "sys/wasi.rs" ) ]
181
185
mod sys;
182
186
183
- #[ cfg( not( any( windows, unix) ) ) ]
187
+ #[ cfg( not( any( windows, unix, all ( target_os = "wasi" , target_env = "p2" ) ) ) ) ]
184
188
compile_error ! ( "Socket2 doesn't support the compile target" ) ;
185
189
186
190
use sys:: c_int;
@@ -218,6 +222,7 @@ impl Domain {
218
222
pub const IPV6 : Domain = Domain ( sys:: AF_INET6 ) ;
219
223
220
224
/// Domain for Unix socket communication, corresponding to `AF_UNIX`.
225
+ #[ cfg( not( target_os = "wasi" ) ) ]
221
226
pub const UNIX : Domain = Domain ( sys:: AF_UNIX ) ;
222
227
223
228
/// Returns the correct domain for `address`.
@@ -271,11 +276,14 @@ impl Type {
271
276
pub const DCCP : Type = Type ( sys:: SOCK_DCCP ) ;
272
277
273
278
/// Type corresponding to `SOCK_SEQPACKET`.
274
- #[ cfg( all( feature = "all" , not( target_os = "espidf" ) ) ) ]
279
+ #[ cfg( all( feature = "all" , not( any ( target_os = "espidf" , target_os = "wasi" ) ) ) ) ]
275
280
pub const SEQPACKET : Type = Type ( sys:: SOCK_SEQPACKET ) ;
276
281
277
282
/// Type corresponding to `SOCK_RAW`.
278
- #[ 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
+ ) ) ]
279
287
pub const RAW : Type = Type ( sys:: SOCK_RAW ) ;
280
288
}
281
289
@@ -302,18 +310,20 @@ impl From<Type> for c_int {
302
310
pub struct Protocol ( c_int ) ;
303
311
304
312
impl Protocol {
305
- /// Protocol corresponding to `ICMPv4`.
306
- pub const ICMPV4 : Protocol = Protocol ( sys:: IPPROTO_ICMP ) ;
307
-
308
- /// Protocol corresponding to `ICMPv6`.
309
- pub const ICMPV6 : Protocol = Protocol ( sys:: IPPROTO_ICMPV6 ) ;
310
-
311
313
/// Protocol corresponding to `TCP`.
312
314
pub const TCP : Protocol = Protocol ( sys:: IPPROTO_TCP ) ;
313
315
314
316
/// Protocol corresponding to `UDP`.
315
317
pub const UDP : Protocol = Protocol ( sys:: IPPROTO_UDP ) ;
316
318
319
+ #[ cfg( not( target_os = "wasi" ) ) ]
320
+ /// Protocol corresponding to `ICMPv4`.
321
+ pub const ICMPV4 : Protocol = Protocol ( sys:: IPPROTO_ICMP ) ;
322
+
323
+ #[ cfg( not( target_os = "wasi" ) ) ]
324
+ /// Protocol corresponding to `ICMPv6`.
325
+ pub const ICMPV6 : Protocol = Protocol ( sys:: IPPROTO_ICMPV6 ) ;
326
+
317
327
#[ cfg( target_os = "linux" ) ]
318
328
/// Protocol corresponding to `MPTCP`.
319
329
pub const MPTCP : Protocol = Protocol ( sys:: IPPROTO_MPTCP ) ;
@@ -358,11 +368,11 @@ impl From<Protocol> for c_int {
358
368
/// Flags for incoming messages.
359
369
///
360
370
/// Flags provide additional information about incoming messages.
361
- #[ cfg( not( target_os = "redox" ) ) ]
371
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
362
372
#[ derive( Copy , Clone , Eq , PartialEq ) ]
363
373
pub struct RecvFlags ( c_int ) ;
364
374
365
- #[ cfg( not( target_os = "redox" ) ) ]
375
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
366
376
impl RecvFlags {
367
377
/// Check if the message contains a truncated datagram.
368
378
///
@@ -380,15 +390,18 @@ impl RecvFlags {
380
390
/// A version of [`IoSliceMut`] that allows the buffer to be uninitialised.
381
391
///
382
392
/// [`IoSliceMut`]: std::io::IoSliceMut
393
+ #[ cfg( not( target_os = "wasi" ) ) ]
383
394
#[ repr( transparent) ]
384
395
pub struct MaybeUninitSlice < ' a > ( sys:: MaybeUninitSlice < ' a > ) ;
385
396
397
+ #[ cfg( not( target_os = "wasi" ) ) ]
386
398
impl < ' a > fmt:: Debug for MaybeUninitSlice < ' a > {
387
399
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
388
400
fmt:: Debug :: fmt ( self . 0 . as_slice ( ) , fmt)
389
401
}
390
402
}
391
403
404
+ #[ cfg( not( target_os = "wasi" ) ) ]
392
405
impl < ' a > MaybeUninitSlice < ' a > {
393
406
/// Creates a new `MaybeUninitSlice` wrapping a byte slice.
394
407
///
@@ -400,6 +413,7 @@ impl<'a> MaybeUninitSlice<'a> {
400
413
}
401
414
}
402
415
416
+ #[ cfg( not( target_os = "wasi" ) ) ]
403
417
impl < ' a > Deref for MaybeUninitSlice < ' a > {
404
418
type Target = [ MaybeUninit < u8 > ] ;
405
419
@@ -408,6 +422,7 @@ impl<'a> Deref for MaybeUninitSlice<'a> {
408
422
}
409
423
}
410
424
425
+ #[ cfg( not( target_os = "wasi" ) ) ]
411
426
impl < ' a > DerefMut for MaybeUninitSlice < ' a > {
412
427
fn deref_mut ( & mut self ) -> & mut [ MaybeUninit < u8 > ] {
413
428
self . 0 . as_mut_slice ( )
@@ -514,6 +529,7 @@ impl TcpKeepalive {
514
529
target_os = "macos" ,
515
530
target_os = "netbsd" ,
516
531
target_os = "tvos" ,
532
+ target_os = "wasi" ,
517
533
target_os = "watchos" ,
518
534
target_os = "windows" ,
519
535
) ) ]
@@ -542,6 +558,7 @@ impl TcpKeepalive {
542
558
target_os = "macos" ,
543
559
target_os = "netbsd" ,
544
560
target_os = "tvos" ,
561
+ target_os = "wasi" ,
545
562
target_os = "watchos" ,
546
563
)
547
564
) ) ]
@@ -557,14 +574,14 @@ impl TcpKeepalive {
557
574
///
558
575
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`]
559
576
/// for the variant used by `recvmsg(2)`.
560
- #[ cfg( not( target_os = "redox" ) ) ]
577
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
561
578
pub struct MsgHdr < ' addr , ' bufs , ' control > {
562
579
inner : sys:: msghdr ,
563
580
#[ allow( clippy:: type_complexity) ]
564
581
_lifetimes : PhantomData < ( & ' addr SockAddr , & ' bufs IoSlice < ' bufs > , & ' control [ u8 ] ) > ,
565
582
}
566
583
567
- #[ cfg( not( target_os = "redox" ) ) ]
584
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
568
585
impl < ' addr , ' bufs , ' control > MsgHdr < ' addr , ' bufs , ' control > {
569
586
/// Create a new `MsgHdr` with all empty/zero fields.
570
587
#[ allow( clippy:: new_without_default) ]
@@ -614,7 +631,7 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
614
631
}
615
632
}
616
633
617
- #[ cfg( not( target_os = "redox" ) ) ]
634
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
618
635
impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdr < ' name , ' bufs , ' control > {
619
636
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
620
637
"MsgHdr" . fmt ( fmt)
@@ -625,7 +642,7 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> {
625
642
///
626
643
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for
627
644
/// the variant used by `sendmsg(2)`.
628
- #[ cfg( not( target_os = "redox" ) ) ]
645
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
629
646
pub struct MsgHdrMut < ' addr , ' bufs , ' control > {
630
647
inner : sys:: msghdr ,
631
648
#[ allow( clippy:: type_complexity) ]
@@ -636,7 +653,7 @@ pub struct MsgHdrMut<'addr, 'bufs, 'control> {
636
653
) > ,
637
654
}
638
655
639
- #[ cfg( not( target_os = "redox" ) ) ]
656
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
640
657
impl < ' addr , ' bufs , ' control > MsgHdrMut < ' addr , ' bufs , ' control > {
641
658
/// Create a new `MsgHdrMut` with all empty/zero fields.
642
659
#[ allow( clippy:: new_without_default) ]
@@ -691,7 +708,7 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
691
708
}
692
709
}
693
710
694
- #[ cfg( not( target_os = "redox" ) ) ]
711
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
695
712
impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdrMut < ' name , ' bufs , ' control > {
696
713
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
697
714
"MsgHdrMut" . fmt ( fmt)
0 commit comments