コード例 #1
0
        private static IPHostEntry HostResolutionEndHelper(IAsyncResult asyncResult)
        {
            //
            // parameter validation
            //
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            ResolveAsyncResult castedResult = asyncResult as ResolveAsyncResult;

            if (castedResult == null)
            {
                throw new ArgumentException(SR.GetString(SR.net_io_invalidasyncresult), "asyncResult");
            }
            if (castedResult.EndCalled)
            {
                throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndResolve"));
            }

            GlobalLog.Print("Dns.HostResolutionEndHelper");

            castedResult.InternalWaitForCompletion();
            castedResult.EndCalled = true;

            Exception exception = castedResult.Result as Exception;

            if (exception != null)
            {
                throw exception;
            }

            return((IPHostEntry)castedResult.Result);
        }
コード例 #2
0
ファイル: DNS.cs プロジェクト: thiagodin/corefx
        private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.net_invalid_ip_addr, "address");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + address);

            // Set up the context, possibly flow.
            ResolveAsyncResult asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);

            if (flowContext)
            {
                asyncResult.StartPostingAsyncOp(false);
            }

            // Start the resolve.
            Task.Factory.StartNew(
                s => ResolveCallback(s),
                asyncResult,
                CancellationToken.None,
                TaskCreationOptions.DenyChildAttach,
                TaskScheduler.Default);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return(asyncResult);
        }
コード例 #3
0
        private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
        {
            s_DnsPermission.Demand();

            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.GetString(SR.net_invalid_ip_addr), "address");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + address);

            // Set up the context, possibly flow.
            ResolveAsyncResult asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);

            if (flowContext)
            {
                asyncResult.StartPostingAsyncOp(false);
            }

            // Start the resolve.
            ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, asyncResult);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return(asyncResult);
        }
コード例 #4
0
        private static void ResolveCallback(object context)
        {
            ResolveAsyncResult result = (ResolveAsyncResult)context;
            IPHostEntry        hostEntry;

            try
            {
                if (result.address != null)
                {
                    hostEntry = InternalGetHostByAddress(result.address, result.includeIPv6, false);
                }
                else
                {
                    hostEntry = InternalGetHostByName(result.hostName, result.includeIPv6);
                }
            }
            catch (Exception exception)
            {
                if (exception is OutOfMemoryException || exception is ThreadAbortException || exception is StackOverflowException)
                {
                    throw;
                }

                result.InvokeCallback(exception);
                return;
            }

            result.InvokeCallback(hostEntry);
        }
コード例 #5
0
        private static IPHostEntry HostResolutionEndHelper(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            ResolveAsyncResult result = asyncResult as ResolveAsyncResult;

            if (result == null)
            {
                throw new ArgumentException(SR.GetString("net_io_invalidasyncresult"), "asyncResult");
            }
            if (result.EndCalled)
            {
                throw new InvalidOperationException(SR.GetString("net_io_invalidendcall", new object[] { "EndResolve" }));
            }
            result.InternalWaitForCompletion();
            result.EndCalled = true;
            Exception exception = result.Result as Exception;

            if (exception != null)
            {
                throw exception;
            }
            return((IPHostEntry)result.Result);
        }
コード例 #6
0
        // Helpers for async GetHostByName, ResolveToAddresses, and Resolve - they're almost identical

        private static IAsyncResult HostResolutionBeginHelper(string hostName, bool useGetHostByName, bool flowContext, bool includeIPv6, bool throwOnIPAny, AsyncCallback requestCallback, object state)
        {
            s_DnsPermission.Demand();

            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + hostName);

            // See if it's an IP Address.
            IPAddress          address;
            ResolveAsyncResult asyncResult;

            if (TryParseAsIP(hostName, out address))
            {
                if (throwOnIPAny && (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)))
                {
                    throw new ArgumentException(SR.GetString(SR.net_invalid_ip_addr), "hostNameOrAddress");
                }

                asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);

                if (useGetHostByName)
                {
                    IPHostEntry hostEntry = new IPHostEntry();
                    hostEntry.AddressList = new IPAddress[] { address };
                    hostEntry.Aliases     = new string[0];
                    hostEntry.HostName    = address.ToString();
                    asyncResult.StartPostingAsyncOp(false);
                    asyncResult.InvokeCallback(hostEntry);
                    asyncResult.FinishPostingAsyncOp();
                    return(asyncResult);
                }
            }
            else
            {
                asyncResult = new ResolveAsyncResult(hostName, null, includeIPv6, state, requestCallback);
            }

            // Set up the context, possibly flow.
            if (flowContext)
            {
                asyncResult.StartPostingAsyncOp(false);
            }

            // Start the resolve.
            ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, asyncResult);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return(asyncResult);
        }
コード例 #7
0
ファイル: DNS.cs プロジェクト: zuhuizou/corefx
        // Helpers for async GetHostByName, ResolveToAddresses, and Resolve - they're almost identical
        // If hostName is an IPString and justReturnParsedIP==true then no reverse lookup will be attempted, but the original address is returned.
        private static IAsyncResult HostResolutionBeginHelper(string hostName, bool justReturnParsedIp, AsyncCallback requestCallback, object state)
        {
            if (hostName == null)
            {
                throw new ArgumentNullException(nameof(hostName));
            }

            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("Dns.HostResolutionBeginHelper: " + hostName);
            }

            // See if it's an IP Address.
            IPAddress          address;
            ResolveAsyncResult asyncResult;

            if (IPAddress.TryParse(hostName, out address))
            {
                if ((address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)))
                {
                    throw new ArgumentException(SR.net_invalid_ip_addr, "hostNameOrAddress");
                }

                asyncResult = new ResolveAsyncResult(address, null, true, state, requestCallback);

                if (justReturnParsedIp)
                {
                    IPHostEntry hostEntry = NameResolutionUtilities.GetUnresolvedAnswer(address);
                    asyncResult.StartPostingAsyncOp(false);
                    asyncResult.InvokeCallback(hostEntry);
                    asyncResult.FinishPostingAsyncOp();
                    return(asyncResult);
                }
            }
            else
            {
                asyncResult = new ResolveAsyncResult(hostName, null, true, state, requestCallback);
            }

            // Set up the context, possibly flow.
            asyncResult.StartPostingAsyncOp(false);

            // Start the resolve.
            Task.Factory.StartNew(
                s => ResolveCallback(s),
                asyncResult,
                CancellationToken.None,
                TaskCreationOptions.DenyChildAttach,
                TaskScheduler.Default);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return(asyncResult);
        }
コード例 #8
0
        private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
        {
            s_DnsPermission.Demand();
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.GetString("net_invalid_ip_addr"), "address");
            }
            ResolveAsyncResult result = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);

            if (flowContext)
            {
                result.StartPostingAsyncOp(false);
            }
            ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, result);
            result.FinishPostingAsyncOp();
            return(result);
        }
コード例 #9
0
        private static IAsyncResult HostResolutionBeginHelper(string hostName, bool justReturnParsedIp, bool flowContext, bool includeIPv6, bool throwOnIPAny, AsyncCallback requestCallback, object state)
        {
            IPAddress          address;
            ResolveAsyncResult result;

            s_DnsPermission.Demand();
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (IPAddress.TryParse(hostName, out address))
            {
                if (throwOnIPAny && (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)))
                {
                    throw new ArgumentException(SR.GetString("net_invalid_ip_addr"), "hostNameOrAddress");
                }
                result = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);
                if (justReturnParsedIp)
                {
                    IPHostEntry unresolveAnswer = GetUnresolveAnswer(address);
                    result.StartPostingAsyncOp(false);
                    result.InvokeCallback(unresolveAnswer);
                    result.FinishPostingAsyncOp();
                    return(result);
                }
            }
            else
            {
                result = new ResolveAsyncResult(hostName, null, includeIPv6, state, requestCallback);
            }
            if (flowContext)
            {
                result.StartPostingAsyncOp(false);
            }
            ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, result);
            result.FinishPostingAsyncOp();
            return(result);
        }
コード例 #10
0
ファイル: DNS.cs プロジェクト: zhiliangxu/corefx
        private static IPHostEntry HostResolutionEndHelper(IAsyncResult asyncResult)
        {
            //
            // parameter validation
            //
            if (asyncResult == null)
            {
                throw new ArgumentNullException(nameof(asyncResult));
            }
            ResolveAsyncResult castedResult = asyncResult as ResolveAsyncResult;

            if (castedResult == null)
            {
                throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
            }
            if (castedResult.EndCalled)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, nameof(EndResolve)));
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Info(null);
            }

            castedResult.InternalWaitForCompletion();
            castedResult.EndCalled = true;

            Exception exception = castedResult.Result as Exception;

            if (exception != null)
            {
                ExceptionDispatchInfo.Capture(exception).Throw();
            }

            return((IPHostEntry)castedResult.Result);
        }
コード例 #11
0
ファイル: DNS.cs プロジェクト: noahfalk/corefx
        private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.net_invalid_ip_addr, "address");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + address);

            // Set up the context, possibly flow.
            ResolveAsyncResult asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);
            if (flowContext)
            {
                asyncResult.StartPostingAsyncOp(false);
            }

            // Start the resolve.
            Task.Factory.StartNew(
                s => ResolveCallback(s),
                asyncResult,
                CancellationToken.None,
                TaskCreationOptions.DenyChildAttach,
                TaskScheduler.Default);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }
コード例 #12
0
ファイル: DNS.cs プロジェクト: noahfalk/corefx
        // Helpers for async GetHostByName, ResolveToAddresses, and Resolve - they're almost identical
        // If hostName is an IPString and justReturnParsedIP==true then no reverse lookup will be attempted, but the orriginal address is returned.
        private static IAsyncResult HostResolutionBeginHelper(string hostName, bool justReturnParsedIp, AsyncCallback requestCallback, object state)
        {
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + hostName);

            // See if it's an IP Address.
            IPAddress address;
            ResolveAsyncResult asyncResult;
            if (IPAddress.TryParse(hostName, out address))
            {
                if ((address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)))
                {
                    throw new ArgumentException(SR.net_invalid_ip_addr, "hostNameOrAddress");
                }

                asyncResult = new ResolveAsyncResult(address, null, true, state, requestCallback);

                if (justReturnParsedIp)
                {
                    IPHostEntry hostEntry = NameResolutionUtilities.GetUnresolvedAnswer(address);
                    asyncResult.StartPostingAsyncOp(false);
                    asyncResult.InvokeCallback(hostEntry);
                    asyncResult.FinishPostingAsyncOp();
                    return asyncResult;
                }
            }
            else
            {
                asyncResult = new ResolveAsyncResult(hostName, null, true, state, requestCallback);
            }

            // Set up the context, possibly flow.
            asyncResult.StartPostingAsyncOp(false);

            // Start the resolve.
            Task.Factory.StartNew(
                s => ResolveCallback(s),
                asyncResult,
                CancellationToken.None,
                TaskCreationOptions.DenyChildAttach,
                TaskScheduler.Default);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }
コード例 #13
0
ファイル: DNS.cs プロジェクト: REALTOBIZ/mono
        private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
        {
            //
            // demand Unrestricted DnsPermission for this call
            // 

            s_DnsPermission.Demand();

            if (address == null) {
                throw new ArgumentNullException("address");
            }

            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.GetString(SR.net_invalid_ip_addr), "address");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + address);

            // Set up the context, possibly flow.
            ResolveAsyncResult asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);
            if (flowContext)
            {
                asyncResult.StartPostingAsyncOp(false);
            }

            // Start the resolve.
            ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, asyncResult);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }
コード例 #14
0
ファイル: DNS.cs プロジェクト: REALTOBIZ/mono
        // Helpers for async GetHostByName, ResolveToAddresses, and Resolve - they're almost identical
        // If hostName is an IPString and justReturnParsedIP==true then no reverse lookup will be attempted, but the orriginal address is returned.
        private static IAsyncResult HostResolutionBeginHelper(string hostName, bool justReturnParsedIp, bool flowContext, bool includeIPv6, bool throwOnIPAny, AsyncCallback requestCallback, object state)
        {
            //
            // demand Unrestricted DnsPermission for this call
            // 

            s_DnsPermission.Demand();

            if (hostName == null) {
                throw new ArgumentNullException("hostName");
            }

            GlobalLog.Print("Dns.HostResolutionBeginHelper: " + hostName);

            // See if it's an IP Address.
            IPAddress address;
            ResolveAsyncResult asyncResult;
            if (IPAddress.TryParse(hostName, out address))
            {
                if (throwOnIPAny && (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)))
                {
                    throw new ArgumentException(SR.GetString(SR.net_invalid_ip_addr), "hostNameOrAddress");
                }

                asyncResult = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);

                if (justReturnParsedIp)
                {
                    IPHostEntry hostEntry = GetUnresolveAnswer(address);
                    asyncResult.StartPostingAsyncOp(false);
                    asyncResult.InvokeCallback(hostEntry);
                    asyncResult.FinishPostingAsyncOp();
                    return asyncResult;
                }
            }
            else
            {
                asyncResult = new ResolveAsyncResult(hostName, null, includeIPv6, state, requestCallback);
            }

            // Set up the context, possibly flow.
            if (flowContext)
            {
                asyncResult.StartPostingAsyncOp(false);
            }

            // Start the resolve.
            ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, asyncResult);

            // Finish the flowing, maybe it completed?  This does nothing if we didn't initiate the flowing above.
            asyncResult.FinishPostingAsyncOp();
            return asyncResult;
        }
コード例 #15
0
 private static IAsyncResult HostResolutionBeginHelper(string hostName, bool justReturnParsedIp, bool flowContext, bool includeIPv6, bool throwOnIPAny, AsyncCallback requestCallback, object state)
 {
     IPAddress address;
     ResolveAsyncResult result;
     s_DnsPermission.Demand();
     if (hostName == null)
     {
         throw new ArgumentNullException("hostName");
     }
     if (IPAddress.TryParse(hostName, out address))
     {
         if (throwOnIPAny && (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)))
         {
             throw new ArgumentException(SR.GetString("net_invalid_ip_addr"), "hostNameOrAddress");
         }
         result = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);
         if (justReturnParsedIp)
         {
             IPHostEntry unresolveAnswer = GetUnresolveAnswer(address);
             result.StartPostingAsyncOp(false);
             result.InvokeCallback(unresolveAnswer);
             result.FinishPostingAsyncOp();
             return result;
         }
     }
     else
     {
         result = new ResolveAsyncResult(hostName, null, includeIPv6, state, requestCallback);
     }
     if (flowContext)
     {
         result.StartPostingAsyncOp(false);
     }
     ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, result);
     result.FinishPostingAsyncOp();
     return result;
 }
コード例 #16
0
 private static IAsyncResult HostResolutionBeginHelper(IPAddress address, bool flowContext, bool includeIPv6, AsyncCallback requestCallback, object state)
 {
     s_DnsPermission.Demand();
     if (address == null)
     {
         throw new ArgumentNullException("address");
     }
     if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
     {
         throw new ArgumentException(SR.GetString("net_invalid_ip_addr"), "address");
     }
     ResolveAsyncResult result = new ResolveAsyncResult(address, null, includeIPv6, state, requestCallback);
     if (flowContext)
     {
         result.StartPostingAsyncOp(false);
     }
     ThreadPool.UnsafeQueueUserWorkItem(resolveCallback, result);
     result.FinishPostingAsyncOp();
     return result;
 }