File tree Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use crate::convert::TryFrom;
77use crate :: ffi:: c_void;
88use crate :: fmt;
99use crate :: fs;
10+ use crate :: io;
1011use crate :: marker:: PhantomData ;
1112use crate :: mem:: forget;
1213use crate :: ptr:: NonNull ;
@@ -114,7 +115,7 @@ impl BorrowedHandle<'_> {
114115impl OwnedHandle {
115116 /// Creates a new `OwnedHandle` instance that shares the same underlying file handle
116117 /// as the existing `OwnedHandle` instance.
117- pub fn try_clone ( & self ) -> crate :: io:: Result < FileDesc > {
118+ pub fn try_clone ( & self ) -> crate :: io:: Result < Self > {
118119 let handle = self . duplicate ( 0 , false , c:: DUPLICATE_SAME_ACCESS ) ?;
119120
120121 Ok ( unsafe { OwnedHandle :: from_raw_handle ( handle) } )
Original file line number Diff line number Diff line change 44
55use super :: raw:: { AsRawSocket , FromRawSocket , IntoRawSocket , RawSocket } ;
66use crate :: fmt;
7+ use crate :: io;
78use crate :: marker:: PhantomData ;
9+ use crate :: mem;
810use crate :: mem:: forget;
911use crate :: sys:: c;
1012use crate :: sys:: cvt;
@@ -91,7 +93,7 @@ impl OwnedSocket {
9193 } ;
9294
9395 if socket != c:: INVALID_SOCKET {
94- unsafe { Ok ( Self :: from_inner ( OwnedSocket :: from_raw_socket ( socket) ) ) }
96+ unsafe { Ok ( Self ( OwnedSocket :: from_raw_socket ( socket) ) ) }
9597 } else {
9698 let error = unsafe { c:: WSAGetLastError ( ) } ;
9799
@@ -115,14 +117,19 @@ impl OwnedSocket {
115117 }
116118
117119 unsafe {
118- let socket = Self :: from_inner ( OwnedSocket :: from_raw_socket ( socket) ) ;
120+ let socket = Self ( OwnedSocket :: from_raw_socket ( socket) ) ;
119121 socket. set_no_inherit ( ) ?;
120122 Ok ( socket)
121123 }
122124 }
123125 }
124126}
125127
128+ /// Returns the last error from the Windows socket interface.
129+ fn last_error ( ) -> io:: Error {
130+ io:: Error :: from_raw_os_error ( unsafe { c:: WSAGetLastError ( ) } )
131+ }
132+
126133impl AsRawSocket for BorrowedSocket < ' _ > {
127134 #[ inline]
128135 fn as_raw_socket ( & self ) -> RawSocket {
Original file line number Diff line number Diff line change @@ -455,7 +455,7 @@ impl File {
455455 }
456456
457457 pub fn duplicate ( & self ) -> io:: Result < File > {
458- Ok ( Self ( self . 0 . try_clone ( ) ?) )
458+ Ok ( Self { handle : self . handle . try_clone ( ) ? } )
459459 }
460460
461461 fn reparse_point < ' a > (
Original file line number Diff line number Diff line change @@ -208,7 +208,7 @@ impl Socket {
208208 }
209209
210210 pub fn duplicate ( & self ) -> io:: Result < Socket > {
211- Ok ( Self ( self . 0 . duplicate ( ) ?) )
211+ Ok ( Self ( self . 0 . try_clone ( ) ?) )
212212 }
213213
214214 fn recv_with_flags ( & self , buf : & mut [ u8 ] , flags : c_int ) -> io:: Result < usize > {
You can’t perform that action at this time.
0 commit comments