@@ -86,6 +86,28 @@ impl OwnedSocket {
86
86
/// as the existing `OwnedSocket` instance.
87
87
#[ stable( feature = "io_safety" , since = "1.63.0" ) ]
88
88
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 > {
89
111
let mut info = unsafe { mem:: zeroed :: < c:: WSAPROTOCOL_INFO > ( ) } ;
90
112
let result = unsafe {
91
113
c:: WSADuplicateSocketW ( self . as_raw_socket ( ) , c:: GetCurrentProcessId ( ) , & mut info)
@@ -133,20 +155,6 @@ impl OwnedSocket {
133
155
}
134
156
}
135
157
}
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
- }
150
158
}
151
159
152
160
/// Returns the last error from the Windows socket interface.
0 commit comments