-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Socket.DuplicateAndClose() for Windows (#1858)
* reimplement socket duplication, fix #1760 * additional cleanup * ungroup PNSE tests, no RemoteExecutor timeout * address review findings * fix path for Interop.WSADuplicateSocket.cs * remove swallowing in Socket(SocketInformation) * review suggestions * make sure duplicate socket is not inheritable * remove debug code leftover * harden SocketPal.CreateSocket() * blittable WSAPROTOCOL_INFOW * additional naming fixes, default System.Net.Sockets.sln configurations to Windows_NT again * disposal on errors, improve comments, more tests * nits * handle GetSockName() error
- Loading branch information
Showing
18 changed files
with
715 additions
and
85 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.HandleInformation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Win32.SafeHandles; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Kernel32 | ||
{ | ||
[Flags] | ||
internal enum HandleFlags : uint | ||
{ | ||
None = 0, | ||
HANDLE_FLAG_INHERIT = 1, | ||
HANDLE_FLAG_PROTECT_FROM_CLOSE = 2 | ||
} | ||
|
||
[DllImport(Libraries.Kernel32, SetLastError = true)] | ||
internal static extern bool SetHandleInformation(SafeHandle hObject, HandleFlags dwMask, HandleFlags dwFlags); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSADuplicateSocket.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Net.Sockets; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Winsock | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal unsafe struct WSAPROTOCOLCHAIN | ||
{ | ||
private const int MAX_PROTOCOL_CHAIN = 7; | ||
|
||
internal int ChainLen; | ||
internal fixed uint ChainEntries[MAX_PROTOCOL_CHAIN]; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
internal unsafe struct WSAPROTOCOL_INFOW | ||
{ | ||
private const int WSAPROTOCOL_LEN = 255; | ||
|
||
internal uint dwServiceFlags1; | ||
internal uint dwServiceFlags2; | ||
internal uint dwServiceFlags3; | ||
internal uint dwServiceFlags4; | ||
internal uint dwProviderFlags; | ||
internal Guid ProviderId; | ||
internal uint dwCatalogEntryId; | ||
internal WSAPROTOCOLCHAIN ProtocolChain; | ||
internal int iVersion; | ||
internal AddressFamily iAddressFamily; | ||
internal int iMaxSockAddr; | ||
internal int iMinSockAddr; | ||
internal SocketType iSocketType; | ||
internal ProtocolType iProtocol; | ||
internal int iProtocolMaxOffset; | ||
internal int iNetworkByteOrder; | ||
internal int iSecurityScheme; | ||
internal uint dwMessageSize; | ||
internal uint dwProviderReserved; | ||
internal fixed char szProtocol[WSAPROTOCOL_LEN + 1]; | ||
} | ||
|
||
[DllImport(Interop.Libraries.Ws2_32, CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static extern unsafe int WSADuplicateSocket( | ||
[In] SafeSocketHandle s, | ||
[In] uint dwProcessId, | ||
[In] WSAPROTOCOL_INFOW* lpProtocolInfo | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.