9
9
#[ cfg( not( target_os = "redox" ) ) ]
10
10
use std:: io:: { IoSlice , IoSliceMut } ;
11
11
use std:: io:: { Read , Write } ;
12
- use std:: mem:: { self , size_of_val, MaybeUninit } ;
12
+ use std:: mem:: { self , size_of , size_of_val, MaybeUninit } ;
13
13
use std:: net:: Shutdown ;
14
14
use std:: net:: { self , Ipv4Addr , Ipv6Addr } ;
15
15
#[ cfg( feature = "all" ) ]
@@ -435,8 +435,15 @@ impl crate::Socket {
435
435
///
436
436
/// Only supported on Apple platforms (`target_vendor = "apple"`).
437
437
#[ cfg( all( feature = "all" , target_vendor = "apple" ) ) ]
438
- pub fn set_nosigpipe ( & self ) -> io:: Result < ( ) > {
439
- unsafe { setsockopt ( self . inner , libc:: SOL_SOCKET , libc:: SO_NOSIGPIPE , 1i32 ) }
438
+ pub fn set_nosigpipe ( & self , nosigpipe : bool ) -> io:: Result < ( ) > {
439
+ unsafe {
440
+ setsockopt :: < c_int > (
441
+ self . inner ,
442
+ libc:: SOL_SOCKET ,
443
+ libc:: SO_NOSIGPIPE ,
444
+ nosigpipe as _ ,
445
+ )
446
+ }
440
447
}
441
448
}
442
449
@@ -467,7 +474,7 @@ fn fcntl_remove(fd: SysSocket, get_cmd: c_int, set_cmd: c_int, flag: c_int) -> i
467
474
/// Caller must ensure `T` is the correct type for `opt` and `val`.
468
475
unsafe fn getsockopt < T > ( fd : SysSocket , opt : c_int , val : c_int ) -> io:: Result < T > {
469
476
let mut payload: MaybeUninit < T > = MaybeUninit :: uninit ( ) ;
470
- let mut len = mem :: size_of :: < T > ( ) as libc:: socklen_t ;
477
+ let mut len = size_of :: < T > ( ) as libc:: socklen_t ;
471
478
syscall ! ( getsockopt(
472
479
fd,
473
480
opt,
@@ -476,18 +483,15 @@ unsafe fn getsockopt<T>(fd: SysSocket, opt: c_int, val: c_int) -> io::Result<T>
476
483
& mut len,
477
484
) )
478
485
. map ( |_| {
479
- debug_assert_eq ! ( len as usize , mem :: size_of:: <T >( ) ) ;
486
+ debug_assert_eq ! ( len as usize , size_of:: <T >( ) ) ;
480
487
// Safety: `getsockopt` initialised `payload` for us.
481
488
payload. assume_init ( )
482
489
} )
483
490
}
484
491
485
492
/// Caller must ensure `T` is the correct type for `opt` and `val`.
486
493
#[ cfg( all( feature = "all" , target_vendor = "apple" ) ) ]
487
- unsafe fn setsockopt < T > ( fd : SysSocket , opt : c_int , val : c_int , payload : T ) -> io:: Result < ( ) >
488
- where
489
- T : Copy ,
490
- {
494
+ unsafe fn setsockopt < T > ( fd : SysSocket , opt : c_int , val : c_int , payload : T ) -> io:: Result < ( ) > {
491
495
let payload = & payload as * const T as * const c_void ;
492
496
syscall ! ( setsockopt(
493
497
fd,
@@ -499,6 +503,15 @@ where
499
503
. map ( |_| ( ) )
500
504
}
501
505
506
+ /*
507
+ setsockopt::<c_int>(
508
+ self.inner,
509
+ libc::SOL_SOCKET,
510
+ libc::SO_NOSIGPIPE,
511
+ nosigpipe as _,
512
+ )
513
+ */
514
+
502
515
#[ repr( transparent) ] // Required during rewriting.
503
516
pub struct Socket {
504
517
fd : SysSocket ,
0 commit comments