58
58
// Disallow warnings in examples.
59
59
#![ doc( test( attr( deny( warnings) ) ) ) ]
60
60
61
+ #[ cfg( not( target_os = "wasi" ) ) ]
61
62
use std:: fmt;
62
- #[ cfg( not( target_os = "redox" ) ) ]
63
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
63
64
use std:: io:: IoSlice ;
64
- #[ cfg( not( target_os = "redox" ) ) ]
65
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
65
66
use std:: marker:: PhantomData ;
66
- #[ cfg( not( target_os = "redox" ) ) ]
67
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
67
68
use std:: mem;
69
+ #[ cfg( not( target_os = "wasi" ) ) ]
68
70
use std:: mem:: MaybeUninit ;
69
71
use std:: net:: SocketAddr ;
72
+ #[ cfg( not( target_os = "wasi" ) ) ]
70
73
use std:: ops:: { Deref , DerefMut } ;
71
74
use std:: time:: Duration ;
72
75
@@ -107,7 +110,7 @@ macro_rules! from {
107
110
( $from: ty, $for: ty) => {
108
111
impl From <$from> for $for {
109
112
fn from( socket: $from) -> $for {
110
- #[ cfg( unix) ]
113
+ #[ cfg( any ( unix, target_os = "wasi" ) ) ]
111
114
unsafe {
112
115
<$for>:: from_raw_fd( socket. into_raw_fd( ) )
113
116
}
@@ -176,9 +179,10 @@ mod sockref;
176
179
177
180
#[ cfg_attr( unix, path = "sys/unix.rs" ) ]
178
181
#[ cfg_attr( windows, path = "sys/windows.rs" ) ]
182
+ #[ cfg_attr( target_os = "wasi" , path = "sys/wasi.rs" ) ]
179
183
mod sys;
180
184
181
- #[ cfg( not( any( windows, unix) ) ) ]
185
+ #[ cfg( not( any( windows, unix, all ( target_os = "wasi" , target_env = "p2" ) ) ) ) ]
182
186
compile_error ! ( "Socket2 doesn't support the compile target" ) ;
183
187
184
188
use sys:: c_int;
@@ -216,6 +220,7 @@ impl Domain {
216
220
pub const IPV6 : Domain = Domain ( sys:: AF_INET6 ) ;
217
221
218
222
/// Domain for Unix socket communication, corresponding to `AF_UNIX`.
223
+ #[ cfg( not( target_os = "wasi" ) ) ]
219
224
pub const UNIX : Domain = Domain ( sys:: AF_UNIX ) ;
220
225
221
226
/// Returns the correct domain for `address`.
@@ -270,15 +275,24 @@ impl Type {
270
275
pub const DCCP : Type = Type ( sys:: SOCK_DCCP ) ;
271
276
272
277
/// Type corresponding to `SOCK_SEQPACKET`.
273
- #[ cfg( all( feature = "all" , not( target_os = "espidf" ) ) ) ]
274
- #[ cfg_attr( docsrs, doc( cfg( all( feature = "all" , not( target_os = "espidf" ) ) ) ) ) ]
278
+ #[ cfg( all( feature = "all" , not( any( target_os = "espidf" , target_os = "wasi" ) ) ) ) ]
279
+ #[ cfg_attr(
280
+ docsrs,
281
+ doc( cfg( all( feature = "all" , not( any( target_os = "espidf" , target_os = "wasi" ) ) ) ) )
282
+ ) ]
275
283
pub const SEQPACKET : Type = Type ( sys:: SOCK_SEQPACKET ) ;
276
284
277
285
/// Type corresponding to `SOCK_RAW`.
278
- #[ 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
+ ) ) ]
279
290
#[ cfg_attr(
280
291
docsrs,
281
- doc( cfg( all( feature = "all" , not( any( target_os = "redox" , target_os = "espidf" ) ) ) ) )
292
+ doc( cfg( all(
293
+ feature = "all" ,
294
+ not( any( target_os = "redox" , target_os = "espidf" , target_os = "wasi" ) )
295
+ ) ) )
282
296
) ]
283
297
pub const RAW : Type = Type ( sys:: SOCK_RAW ) ;
284
298
}
@@ -306,18 +320,20 @@ impl From<Type> for c_int {
306
320
pub struct Protocol ( c_int ) ;
307
321
308
322
impl Protocol {
309
- /// Protocol corresponding to `ICMPv4`.
310
- pub const ICMPV4 : Protocol = Protocol ( sys:: IPPROTO_ICMP ) ;
311
-
312
- /// Protocol corresponding to `ICMPv6`.
313
- pub const ICMPV6 : Protocol = Protocol ( sys:: IPPROTO_ICMPV6 ) ;
314
-
315
323
/// Protocol corresponding to `TCP`.
316
324
pub const TCP : Protocol = Protocol ( sys:: IPPROTO_TCP ) ;
317
325
318
326
/// Protocol corresponding to `UDP`.
319
327
pub const UDP : Protocol = Protocol ( sys:: IPPROTO_UDP ) ;
320
328
329
+ #[ cfg( not( target_os = "wasi" ) ) ]
330
+ /// Protocol corresponding to `ICMPv4`.
331
+ pub const ICMPV4 : Protocol = Protocol ( sys:: IPPROTO_ICMP ) ;
332
+
333
+ #[ cfg( not( target_os = "wasi" ) ) ]
334
+ /// Protocol corresponding to `ICMPv6`.
335
+ pub const ICMPV6 : Protocol = Protocol ( sys:: IPPROTO_ICMPV6 ) ;
336
+
321
337
#[ cfg( target_os = "linux" ) ]
322
338
/// Protocol corresponding to `MPTCP`.
323
339
pub const MPTCP : Protocol = Protocol ( sys:: IPPROTO_MPTCP ) ;
@@ -363,12 +379,12 @@ impl From<Protocol> for c_int {
363
379
/// Flags for incoming messages.
364
380
///
365
381
/// Flags provide additional information about incoming messages.
366
- #[ cfg( not( target_os = "redox" ) ) ]
367
- #[ cfg_attr( docsrs, doc( cfg( not( target_os = "redox" ) ) ) ) ]
382
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
383
+ #[ cfg_attr( docsrs, doc( cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ) ) ]
368
384
#[ derive( Copy , Clone , Eq , PartialEq ) ]
369
385
pub struct RecvFlags ( c_int ) ;
370
386
371
- #[ cfg( not( target_os = "redox" ) ) ]
387
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
372
388
impl RecvFlags {
373
389
/// Check if the message contains a truncated datagram.
374
390
///
@@ -386,15 +402,18 @@ impl RecvFlags {
386
402
/// A version of [`IoSliceMut`] that allows the buffer to be uninitialised.
387
403
///
388
404
/// [`IoSliceMut`]: std::io::IoSliceMut
405
+ #[ cfg( not( target_os = "wasi" ) ) ]
389
406
#[ repr( transparent) ]
390
407
pub struct MaybeUninitSlice < ' a > ( sys:: MaybeUninitSlice < ' a > ) ;
391
408
409
+ #[ cfg( not( target_os = "wasi" ) ) ]
392
410
impl < ' a > fmt:: Debug for MaybeUninitSlice < ' a > {
393
411
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
394
412
fmt:: Debug :: fmt ( self . 0 . as_slice ( ) , fmt)
395
413
}
396
414
}
397
415
416
+ #[ cfg( not( target_os = "wasi" ) ) ]
398
417
impl < ' a > MaybeUninitSlice < ' a > {
399
418
/// Creates a new `MaybeUninitSlice` wrapping a byte slice.
400
419
///
@@ -406,6 +425,7 @@ impl<'a> MaybeUninitSlice<'a> {
406
425
}
407
426
}
408
427
428
+ #[ cfg( not( target_os = "wasi" ) ) ]
409
429
impl < ' a > Deref for MaybeUninitSlice < ' a > {
410
430
type Target = [ MaybeUninit < u8 > ] ;
411
431
@@ -414,6 +434,7 @@ impl<'a> Deref for MaybeUninitSlice<'a> {
414
434
}
415
435
}
416
436
437
+ #[ cfg( not( target_os = "wasi" ) ) ]
417
438
impl < ' a > DerefMut for MaybeUninitSlice < ' a > {
418
439
fn deref_mut ( & mut self ) -> & mut [ MaybeUninit < u8 > ] {
419
440
self . 0 . as_mut_slice ( )
@@ -520,6 +541,7 @@ impl TcpKeepalive {
520
541
target_os = "macos" ,
521
542
target_os = "netbsd" ,
522
543
target_os = "tvos" ,
544
+ target_os = "wasi" ,
523
545
target_os = "watchos" ,
524
546
target_os = "windows" ,
525
547
) ) ]
@@ -537,6 +559,7 @@ impl TcpKeepalive {
537
559
target_os = "macos" ,
538
560
target_os = "netbsd" ,
539
561
target_os = "tvos" ,
562
+ target_os = "wasi" ,
540
563
target_os = "watchos" ,
541
564
target_os = "windows" ,
542
565
) ) )
@@ -566,6 +589,7 @@ impl TcpKeepalive {
566
589
target_os = "macos" ,
567
590
target_os = "netbsd" ,
568
591
target_os = "tvos" ,
592
+ target_os = "wasi" ,
569
593
target_os = "watchos" ,
570
594
)
571
595
) ) ]
@@ -585,6 +609,7 @@ impl TcpKeepalive {
585
609
target_os = "macos" ,
586
610
target_os = "netbsd" ,
587
611
target_os = "tvos" ,
612
+ target_os = "wasi" ,
588
613
target_os = "watchos" ,
589
614
)
590
615
) ) )
@@ -601,14 +626,14 @@ impl TcpKeepalive {
601
626
///
602
627
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`]
603
628
/// for the variant used by `recvmsg(2)`.
604
- #[ cfg( not( target_os = "redox" ) ) ]
629
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
605
630
pub struct MsgHdr < ' addr , ' bufs , ' control > {
606
631
inner : sys:: msghdr ,
607
632
#[ allow( clippy:: type_complexity) ]
608
633
_lifetimes : PhantomData < ( & ' addr SockAddr , & ' bufs IoSlice < ' bufs > , & ' control [ u8 ] ) > ,
609
634
}
610
635
611
- #[ cfg( not( target_os = "redox" ) ) ]
636
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
612
637
impl < ' addr , ' bufs , ' control > MsgHdr < ' addr , ' bufs , ' control > {
613
638
/// Create a new `MsgHdr` with all empty/zero fields.
614
639
#[ allow( clippy:: new_without_default) ]
@@ -658,7 +683,7 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
658
683
}
659
684
}
660
685
661
- #[ cfg( not( target_os = "redox" ) ) ]
686
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
662
687
impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdr < ' name , ' bufs , ' control > {
663
688
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
664
689
"MsgHdr" . fmt ( fmt)
@@ -669,7 +694,7 @@ impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> {
669
694
///
670
695
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for
671
696
/// the variant used by `sendmsg(2)`.
672
- #[ cfg( not( target_os = "redox" ) ) ]
697
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
673
698
pub struct MsgHdrMut < ' addr , ' bufs , ' control > {
674
699
inner : sys:: msghdr ,
675
700
#[ allow( clippy:: type_complexity) ]
@@ -680,7 +705,7 @@ pub struct MsgHdrMut<'addr, 'bufs, 'control> {
680
705
) > ,
681
706
}
682
707
683
- #[ cfg( not( target_os = "redox" ) ) ]
708
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
684
709
impl < ' addr , ' bufs , ' control > MsgHdrMut < ' addr , ' bufs , ' control > {
685
710
/// Create a new `MsgHdrMut` with all empty/zero fields.
686
711
#[ allow( clippy:: new_without_default) ]
@@ -735,7 +760,7 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
735
760
}
736
761
}
737
762
738
- #[ cfg( not( target_os = "redox" ) ) ]
763
+ #[ cfg( not( any ( target_os = "redox" , target_os = "wasi" ) ) ) ]
739
764
impl < ' name , ' bufs , ' control > fmt:: Debug for MsgHdrMut < ' name , ' bufs , ' control > {
740
765
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
741
766
"MsgHdrMut" . fmt ( fmt)
0 commit comments