@@ -86,6 +86,28 @@ impl OwnedSocket {
8686 /// as the existing `OwnedSocket` instance.
8787 #[ stable( feature = "io_safety" , since = "1.63.0" ) ]
8888 pub fn try_clone ( & self ) -> io:: Result < Self > {
89+ self . as_socket ( ) . try_clone_to_owned ( )
90+ }
91+
92+ // FIXME(strict_provenance_magic): we defined RawSocket to be a u64 ;-;
93+ #[ cfg( not( target_vendor = "uwp" ) ) ]
94+ pub ( crate ) fn set_no_inherit ( & self ) -> io:: Result < ( ) > {
95+ cvt ( unsafe {
96+ c:: SetHandleInformation ( self . as_raw_socket ( ) as c:: HANDLE , c:: HANDLE_FLAG_INHERIT , 0 )
97+ } )
98+ . map ( drop)
99+ }
100+
101+ #[ cfg( target_vendor = "uwp" ) ]
102+ pub ( crate ) fn set_no_inherit ( & self ) -> io:: Result < ( ) > {
103+ Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "Unavailable on UWP" ) )
104+ }
105+ }
106+
107+ impl BorrowedSocket < ' _ > {
108+ /// Creates a new `OwnedSocket` instance that shares the same underlying
109+ /// object as the existing `BorrowedSocket` instance.
110+ pub fn try_clone_to_owned ( & self ) -> io:: Result < OwnedSocket > {
89111 let mut info = unsafe { mem:: zeroed :: < c:: WSAPROTOCOL_INFO > ( ) } ;
90112 let result = unsafe {
91113 c:: WSADuplicateSocketW ( self . as_raw_socket ( ) , c:: GetCurrentProcessId ( ) , & mut info)
@@ -133,20 +155,6 @@ impl OwnedSocket {
133155 }
134156 }
135157 }
136-
137- // FIXME(strict_provenance_magic): we defined RawSocket to be a u64 ;-;
138- #[ cfg( not( target_vendor = "uwp" ) ) ]
139- pub ( crate ) fn set_no_inherit ( & self ) -> io:: Result < ( ) > {
140- cvt ( unsafe {
141- c:: SetHandleInformation ( self . as_raw_socket ( ) as c:: HANDLE , c:: HANDLE_FLAG_INHERIT , 0 )
142- } )
143- . map ( drop)
144- }
145-
146- #[ cfg( target_vendor = "uwp" ) ]
147- pub ( crate ) fn set_no_inherit ( & self ) -> io:: Result < ( ) > {
148- Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "Unavailable on UWP" ) )
149- }
150158}
151159
152160/// Returns the last error from the Windows socket interface.
0 commit comments