This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified Dns.GetHostAddressesAsync to be truly async (#26850)
* Modified Dns.GetHostAddressesAsync to be truly async * Applied code review recommendations * Unix build fix * Unix build fix #2 * Unix build fix #3 * NETFX build fix * Fixed useGetHostByName logic * Simplified ProcessResult code * Cleaned up cancel code * cleanup
- Loading branch information
1 parent
14185df
commit d3ff31e
Showing
15 changed files
with
523 additions
and
88 deletions.
There are no files selected for viewing
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,25 @@ | ||
// 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.Net.Internals; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace System.Net.Sockets | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
internal unsafe struct AddressInfoEx | ||
{ | ||
internal AddressInfoHints ai_flags; | ||
internal AddressFamily ai_family; | ||
internal SocketType ai_socktype; | ||
internal ProtocolFamily ai_protocol; | ||
internal int ai_addrlen; | ||
internal IntPtr ai_canonname; // Ptr to the canonical name - check for NULL | ||
internal byte* ai_addr; // Ptr to the sockaddr structure | ||
internal IntPtr ai_blob; // Unused ptr to blob data about provider | ||
internal int ai_bloblen; | ||
internal IntPtr ai_provider; // Unused ptr to the namespace provider guid | ||
internal AddressInfoEx* ai_next; // Next structure in linked list | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Common/src/Interop/Windows/Winsock/Interop.GetAddrInfoExW.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,36 @@ | ||
// 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; | ||
using System.Threading; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Winsock | ||
{ | ||
internal const string GetAddrInfoExCancelFunctionName = "GetAddrInfoExCancel"; | ||
|
||
internal unsafe delegate void LPLOOKUPSERVICE_COMPLETION_ROUTINE([In] int dwError, [In] int dwBytes, [In] NativeOverlapped* lpOverlapped); | ||
|
||
[DllImport(Interop.Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static extern unsafe int GetAddrInfoExW( | ||
[In] string pName, | ||
[In] string pServiceName, | ||
[In] int dwNamespace, | ||
[In] IntPtr lpNspId, | ||
[In] ref AddressInfoEx pHints, | ||
[Out] out AddressInfoEx* ppResult, | ||
[In] IntPtr timeout, | ||
[In] ref NativeOverlapped lpOverlapped, | ||
[In] LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine, | ||
[Out] out IntPtr lpNameHandle | ||
); | ||
|
||
[DllImport("ws2_32.dll", ExactSpelling = true, SetLastError = true)] | ||
internal static extern unsafe void FreeAddrInfoEx([In] AddressInfoEx* pAddrInfo); | ||
} | ||
} | ||
|
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
29 changes: 29 additions & 0 deletions
29
src/System.Net.NameResolution/src/System/Net/DnsResolveAsyncResult.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,29 @@ | ||
// 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. | ||
|
||
namespace System.Net | ||
{ | ||
internal sealed class DnsResolveAsyncResult : ContextAwareResult | ||
{ | ||
internal string HostName { get; } | ||
internal bool IncludeIPv6 { get; } | ||
internal IPAddress IpAddress { get; } | ||
|
||
// Forward lookup | ||
internal DnsResolveAsyncResult(string hostName, object myObject, bool includeIPv6, object myState, AsyncCallback myCallBack) | ||
: base(myObject, myState, myCallBack) | ||
{ | ||
HostName = hostName; | ||
IncludeIPv6 = includeIPv6; | ||
} | ||
|
||
// Reverse lookup | ||
internal DnsResolveAsyncResult(IPAddress ipAddress, object myObject, bool includeIPv6, object myState, AsyncCallback myCallBack) | ||
: base(myObject, myState, myCallBack) | ||
{ | ||
IncludeIPv6 = includeIPv6; | ||
IpAddress = ipAddress; | ||
} | ||
} | ||
} |
Oops, something went wrong.