File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77
88## [ Unreleased]
99
10+ ## Fixed
11+
12+ - Ensure ` UnixStream::into_raw_fd ` doesn't close the file descriptor ([ #855 ] ( https://github.com/async-rs/async-std/issues/855 ) )
13+
1014# [ 1.6.3] - 2020-07-31
1115
1216## Added
Original file line number Diff line number Diff line change @@ -252,6 +252,6 @@ impl FromRawFd for UnixStream {
252252
253253impl IntoRawFd for UnixStream {
254254 fn into_raw_fd ( self ) -> RawFd {
255- self . as_raw_fd ( )
255+ ( * self . watcher ) . get_ref ( ) . try_clone ( ) . unwrap ( ) . into_raw_fd ( )
256256 }
257257}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ fn send_recv() -> io::Result<()> {
2727}
2828
2929#[ test]
30- fn into_raw_fd ( ) -> io:: Result < ( ) > {
30+ fn into_raw_fd_datagram ( ) -> io:: Result < ( ) > {
3131 use async_std:: os:: unix:: io:: { FromRawFd , IntoRawFd } ;
3232 task:: block_on ( async {
3333 let ( socket1, socket2) = UnixDatagram :: pair ( ) . unwrap ( ) ;
@@ -43,6 +43,23 @@ fn into_raw_fd() -> io::Result<()> {
4343 } )
4444}
4545
46+ #[ test]
47+ fn into_raw_fd_stream ( ) -> io:: Result < ( ) > {
48+ use async_std:: os:: unix:: io:: { FromRawFd , IntoRawFd } ;
49+ task:: block_on ( async {
50+ let ( mut socket1, socket2) = UnixStream :: pair ( ) . unwrap ( ) ;
51+ socket1. write ( JULIUS_CAESAR ) . await ?;
52+
53+ let mut buf = vec ! [ 0 ; 1024 ] ;
54+
55+ let mut socket2 = unsafe { UnixStream :: from_raw_fd ( socket2. into_raw_fd ( ) ) } ;
56+ let n = socket2. read ( & mut buf) . await ?;
57+ assert_eq ! ( & buf[ ..n] , JULIUS_CAESAR ) ;
58+
59+ Ok ( ( ) )
60+ } )
61+ }
62+
4663const PING : & [ u8 ] = b"ping" ;
4764const PONG : & [ u8 ] = b"pong" ;
4865const TEST_TIMEOUT : Duration = Duration :: from_secs ( 3 ) ;
You can’t perform that action at this time.
0 commit comments