File tree 2 files changed +18
-20
lines changed
2 files changed +18
-20
lines changed Original file line number Diff line number Diff line change @@ -282,6 +282,8 @@ pub(crate) use libc::{TCP_KEEPCNT, TCP_KEEPINTVL};
282
282
// See this type in the Windows file.
283
283
pub ( crate ) type Bool = c_int ;
284
284
285
+ #[ cfg( target_os = "cygwin" ) ]
286
+ use libc:: SO_PEERCRED ;
285
287
#[ cfg( any(
286
288
target_os = "ios" ,
287
289
target_os = "visionos" ,
@@ -1499,6 +1501,20 @@ impl crate::Socket {
1499
1501
}
1500
1502
}
1501
1503
1504
+ /// Sets `SO_PEERCRED` to null on the socket.
1505
+ /// It disables the initial handshake of unix domain sockets.
1506
+ #[ cfg( target_os = "cygwin" ) ]
1507
+ pub fn set_no_peercred ( & self ) -> io:: Result < ( ) > {
1508
+ syscall ! ( setsockopt(
1509
+ self . as_raw( ) ,
1510
+ SOL_SOCKET ,
1511
+ SO_PEERCRED ,
1512
+ ptr:: null_mut( ) ,
1513
+ 0 ,
1514
+ ) )
1515
+ . map ( |_| ( ) )
1516
+ }
1517
+
1502
1518
/// Sets `SO_NOSIGPIPE` on the socket.
1503
1519
#[ cfg( all(
1504
1520
feature = "all" ,
Original file line number Diff line number Diff line change @@ -557,24 +557,6 @@ fn unix_sockets_supported() -> bool {
557
557
true
558
558
}
559
559
560
- // An extension on cygwin. It disables initial handshake on AF_UNIX sockets.
561
- // https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=697b9afe0
562
- #[ cfg( target_os = "cygwin" ) ]
563
- fn set_no_peercred ( s : & Socket ) {
564
- let res = unsafe {
565
- libc:: setsockopt (
566
- s. as_raw_fd ( ) ,
567
- libc:: SOL_SOCKET ,
568
- libc:: SO_PEERCRED ,
569
- std:: ptr:: null ( ) ,
570
- 0 ,
571
- )
572
- } ;
573
- if res == -1 {
574
- panic ! ( "{:?}" , std:: io:: Error :: last_os_error( ) ) ;
575
- }
576
- }
577
-
578
560
#[ test]
579
561
fn unix ( ) {
580
562
if !unix_sockets_supported ( ) {
@@ -590,13 +572,13 @@ fn unix() {
590
572
591
573
let listener = Socket :: new ( Domain :: UNIX , Type :: STREAM , None ) . unwrap ( ) ;
592
574
#[ cfg( target_os = "cygwin" ) ]
593
- set_no_peercred ( & listener ) ;
575
+ listener . set_no_peercred ( ) . unwrap ( ) ;
594
576
listener. bind ( & addr) . unwrap ( ) ;
595
577
listener. listen ( 10 ) . unwrap ( ) ;
596
578
597
579
let mut a = Socket :: new ( Domain :: UNIX , Type :: STREAM , None ) . unwrap ( ) ;
598
580
#[ cfg( target_os = "cygwin" ) ]
599
- set_no_peercred ( & a ) ;
581
+ a . set_no_peercred ( ) . unwrap ( ) ;
600
582
a. connect ( & addr) . unwrap ( ) ;
601
583
let mut b = listener. accept ( ) . unwrap ( ) . 0 ;
602
584
You can’t perform that action at this time.
0 commit comments