File tree Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Original file line number Diff line number Diff line change @@ -624,7 +624,7 @@ impl<T: Write> AsyncWrite for Async<T> {
624
624
}
625
625
626
626
fn poll_close ( self : Pin < & mut Self > , _: & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
627
- Poll :: Ready ( self . source . shutdown_write ( ) )
627
+ Poll :: Ready ( sys :: shutdown_write ( self . source . raw ) )
628
628
}
629
629
}
630
630
@@ -653,7 +653,7 @@ where
653
653
}
654
654
655
655
fn poll_close ( self : Pin < & mut Self > , _: & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
656
- Poll :: Ready ( self . source . shutdown_write ( ) )
656
+ Poll :: Ready ( sys :: shutdown_write ( self . source . raw ) )
657
657
}
658
658
}
659
659
Original file line number Diff line number Diff line change 7
7
use std:: collections:: BTreeMap ;
8
8
use std:: fmt;
9
9
use std:: io;
10
- use std:: mem:: { self , ManuallyDrop } ;
11
- use std:: net:: { Shutdown , TcpStream } ;
10
+ use std:: mem;
12
11
#[ cfg( unix) ]
13
- use std:: os:: unix:: io:: { FromRawFd , RawFd } ;
12
+ use std:: os:: unix:: io:: RawFd ;
14
13
#[ cfg( windows) ]
15
- use std:: os:: windows:: io:: { FromRawSocket , RawSocket } ;
14
+ use std:: os:: windows:: io:: RawSocket ;
16
15
use std:: panic;
17
16
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
18
17
use std:: sync:: { Arc , Condvar , Mutex , MutexGuard } ;
@@ -740,21 +739,4 @@ impl Source {
740
739
} )
741
740
. await
742
741
}
743
-
744
- /// Shuts down the write side of the socket.
745
- ///
746
- /// If this source is not a socket, the `shutdown` syscall error is ignored.
747
- pub ( crate ) fn shutdown_write ( & self ) -> io:: Result < ( ) > {
748
- // This may not be a TCP stream, but that's okay - all we do is call `shutdown()` on it.
749
- #[ cfg( unix) ]
750
- let stream = unsafe { ManuallyDrop :: new ( TcpStream :: from_raw_fd ( self . raw ) ) } ;
751
- #[ cfg( windows) ]
752
- let stream = unsafe { ManuallyDrop :: new ( TcpStream :: from_raw_socket ( self . raw ) ) } ;
753
-
754
- // The only actual error may be ENOTCONN.
755
- match stream. shutdown ( Shutdown :: Write ) {
756
- Err ( err) if err. kind ( ) == io:: ErrorKind :: NotConnected => Err ( err) ,
757
- _ => Ok ( ( ) ) ,
758
- }
759
- }
760
742
}
Original file line number Diff line number Diff line change
1
+ use std:: io;
2
+ use std:: mem:: ManuallyDrop ;
3
+ use std:: net:: { Shutdown , TcpStream } ;
4
+ #[ cfg( unix) ]
5
+ use std:: os:: unix:: io:: { FromRawFd , RawFd } ;
6
+ #[ cfg( windows) ]
7
+ use std:: os:: windows:: io:: { FromRawSocket , RawSocket } ;
8
+
1
9
use cfg_if:: cfg_if;
2
10
3
11
#[ cfg( unix) ]
@@ -39,3 +47,24 @@ pub struct Event {
39
47
pub writable : bool ,
40
48
pub key : usize ,
41
49
}
50
+
51
+ /// Shuts down the write side of a socket.
52
+ ///
53
+ /// If this source is not a socket, the `shutdown()` syscall error is ignored.
54
+ pub fn shutdown_write ( #[ cfg( unix) ] raw : RawFd , #[ cfg( windows) ] raw : RawSocket ) -> io:: Result < ( ) > {
55
+ // This may not be a TCP stream, but that's okay. All we do is call `shutdown()` on the raw
56
+ // descriptor and ignore errors if it's not a socket.
57
+ let res = unsafe {
58
+ #[ cfg( unix) ]
59
+ let stream = ManuallyDrop :: new ( TcpStream :: from_raw_fd ( raw) ) ;
60
+ #[ cfg( windows) ]
61
+ let stream = ManuallyDrop :: new ( TcpStream :: from_raw_socket ( raw) ) ;
62
+ stream. shutdown ( Shutdown :: Write )
63
+ } ;
64
+
65
+ // The only actual error may be ENOTCONN, ignore everything else.
66
+ match res {
67
+ Err ( err) if err. kind ( ) == io:: ErrorKind :: NotConnected => Err ( err) ,
68
+ _ => Ok ( ( ) ) ,
69
+ }
70
+ }
You can’t perform that action at this time.
0 commit comments