• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# MultipleAddressConnectAsyncResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MultipleAddressConnectAsyncResult的典型用法代码示例。如果您正苦于以下问题:C# MultipleAddressConnectAsyncResult类的具体用法?C# MultipleAddressConnectAsyncResult怎么用?C# MultipleAddressConnectAsyncResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MultipleAddressConnectAsyncResult类属于命名空间,在下文中一共展示了MultipleAddressConnectAsyncResult类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PostOneBeginConnect

        // Disable CS0162: Unreachable code detected
        //
        // SuportsMultipleConnectAttempts is a constant; when false, the following lines will trigger CS0162.
#pragma warning disable 162, 429
        private static object PostOneBeginConnect(MultipleAddressConnectAsyncResult context)
        {
            IPAddress currentAddressSnapshot = context._addresses[context._index];

            if (!context._socket.CanTryAddressFamily(currentAddressSnapshot.AddressFamily))
            {
                return context._lastException != null ? context._lastException : new ArgumentException(SR.net_invalidAddressList, "context");
            }

            try
            {
                EndPoint endPoint = new IPEndPoint(currentAddressSnapshot, context._port);

                // Do the necessary security demand.
                context._socket.CheckCacheRemote(ref endPoint, true);

                Socket connectSocket = context._socket;
                if (!SocketPal.SupportsMultipleConnectAttempts && !context._isUserConnectAttempt)
                {
                    context._lastAttemptSocket = new Socket(context._socket._addressFamily, context._socket._socketType, context._socket._protocolType);
                    if (context._socket.IsDualMode)
                    {
                        context._lastAttemptSocket.DualMode = true;
                    }

                    connectSocket = context._lastAttemptSocket;
                }

                IAsyncResult connectResult = connectSocket.UnsafeBeginConnect(endPoint, CachedMultipleAddressConnectCallback, context);
                if (connectResult.CompletedSynchronously)
                {
                    return connectResult;
                }
            }
            catch (Exception exception)
            {
                if (exception is OutOfMemoryException)
                {
                    throw;
                }

                return exception;
            }

            return null;
        }
开发者ID:ReedKimble,项目名称:corefx,代码行数:50,代码来源:Socket.cs


示例2: DoMultipleAddressConnectCallback

        // This is like a regular async callback worker, except the result can be an exception.  This is a useful pattern when
        // processing should continue whether or not an async step failed.
        private static bool DoMultipleAddressConnectCallback(object result, MultipleAddressConnectAsyncResult context)
        {
            while (result != null)
            {
                Exception ex = result as Exception;
                if (ex == null)
                {
                    try
                    {
                        if (SocketPal.SupportsMultipleConnectAttempts || context._isUserConnectAttempt)
                        {
                            context._socket.EndConnect((IAsyncResult)result);
                        }
                        else
                        {
                            Debug.Assert(context._lastAttemptSocket != null);
                            context._lastAttemptSocket.EndConnect((IAsyncResult)result);
                        }
                    }
                    catch (Exception exception)
                    {
                        ex = exception;
                    }
                }

                if (!SocketPal.SupportsMultipleConnectAttempts && !context._isUserConnectAttempt && context._lastAttemptSocket != null)
                {
                    context._lastAttemptSocket.Dispose();
                }

                if (ex == null)
                {
                    if (!SocketPal.SupportsMultipleConnectAttempts && !context._isUserConnectAttempt)
                    {
                        context._isUserConnectAttempt = true;
                        result = PostOneBeginConnect(context);
                    }
                    else
                    {
                        // Don't invoke the callback from here, because we're probably inside
                        // a catch-all block that would eat exceptions from the callback.
                        // Instead tell our caller to invoke the callback outside of its catchall.
                        return true;
                    }
                }
                else
                {
                    if (++context._index >= context._addresses.Length || context._isUserConnectAttempt)
                    {
                        throw ex;
                    }

                    context._lastException = ex;
                    result = PostOneBeginConnect(context);
                }
            }

            // Don't invoke the callback at all, because we've posted another async connection attempt.
            return false;
        }
开发者ID:ReedKimble,项目名称:corefx,代码行数:62,代码来源:Socket.cs


示例3: BeginConnect

        internal IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
        {
            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "BeginConnect", addresses);
            }
            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (addresses == null)
            {
                throw new ArgumentNullException("addresses");
            }
            if (addresses.Length == 0)
            {
                throw new ArgumentException(SR.net_invalidAddressList, "addresses");
            }
            if (!TcpValidationHelpers.ValidatePortNumber(port))
            {
                throw new ArgumentOutOfRangeException("port");
            }
            if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6)
            {
                throw new NotSupportedException(SR.net_invalidversion);
            }

            if (_isListening)
            {
                throw new InvalidOperationException(SR.net_sockets_mustnotlisten);
            }

            // Set up the result to capture the context.  No need for a lock.
            MultipleAddressConnectAsyncResult result = new MultipleAddressConnectAsyncResult(addresses, port, this, state, requestCallback);
            result.StartPostingAsyncOp(false);

            if (DoMultipleAddressConnectCallback(PostOneBeginConnect(result), result))
            {
                // If the call completes synchronously, invoke the callback from here.
                result.InvokeCallback();
            }

            // Finished posting async op.  Possibly will call callback.
            result.FinishPostingAsyncOp(ref Caches.ConnectClosureCache);

            if (s_loggingEnabled)
            {
                Logging.Exit(Logging.Sockets, this, "BeginConnect", result);
            }
            return result;
        }
开发者ID:ReedKimble,项目名称:corefx,代码行数:52,代码来源:Socket.cs


示例4: DoDnsCallback

 private static bool DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context)
 {
     IPAddress[] addresses = DnsAPMExtensions.EndGetHostAddresses(result);
     context._addresses = addresses;
     return DoMultipleAddressConnectCallback(PostOneBeginConnect(context), context);
 }
开发者ID:ReedKimble,项目名称:corefx,代码行数:6,代码来源:Socket.cs


示例5: DoMultipleAddressConnectCallback

        // This is like a regular async callback worker, except the result can be an exception.  This is a useful pattern when
        // processing should continue whether or not an async step failed.
        private static bool DoMultipleAddressConnectCallback(object result, MultipleAddressConnectAsyncResult context)
        {
            while (result != null)
            {
                Exception ex = result as Exception;
                if (ex == null)
                {
                    try
                    {
                        context.socket.EndConnect((IAsyncResult) result);
                    }
                    catch (Exception exception)
                    {
                        ex = exception;
                    }
                }

                if (ex == null)
                {
                    // Don't invoke the callback from here, because we're probably inside
                    // a catch-all block that would eat exceptions from the callback.
                    // Instead tell our caller to invoke the callback outside of its catchall.
                    return true;
                }
                else
                {
                    if (++context.index >= context.addresses.Length)
                        throw ex;

                    context.lastException = ex;
                    result = PostOneBeginConnect(context);
                }
            }

            // Don't invoke the callback at all, because we've posted another async connection attempt
            return false;
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:39,代码来源:Socket.cs


示例6: BeginConnect

        public IAsyncResult BeginConnect(string host, int port, AsyncCallback requestCallback, object state)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, host);
            if (CleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (!TcpValidationHelpers.ValidatePortNumber(port))
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }
            if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6)
            {
                throw new NotSupportedException(SR.net_invalidversion);
            }

            if (_isListening)
            {
                throw new InvalidOperationException(SR.net_sockets_mustnotlisten);
            }

            IPAddress parsedAddress;
            if (IPAddress.TryParse(host, out parsedAddress))
            {
                IAsyncResult r = BeginConnect(parsedAddress, port, requestCallback, state);
                if (NetEventSource.IsEnabled) NetEventSource.Exit(this, r);
                return r;
            }

            ThrowIfNotSupportsMultipleConnectAttempts();

            // Here, want to flow the context.  No need to lock.
            MultipleAddressConnectAsyncResult result = new MultipleAddressConnectAsyncResult(null, port, this, state, requestCallback);
            result.StartPostingAsyncOp(false);

            IAsyncResult dnsResult = DnsAPMExtensions.BeginGetHostAddresses(host, new AsyncCallback(DnsCallback), result);
            if (dnsResult.CompletedSynchronously)
            {
                if (DoDnsCallback(dnsResult, result))
                {
                    result.InvokeCallback();
                }
            }

            // Done posting.
            result.FinishPostingAsyncOp(ref Caches.ConnectClosureCache);

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this, result);
            return result;
        }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:55,代码来源:Socket.cs


示例7: PostOneBeginConnect

        private static object PostOneBeginConnect(MultipleAddressConnectAsyncResult context)
        {
            IPAddress currentAddressSnapshot = context.addresses[context.index];

            if (!context.socket.CanTryAddressFamily(currentAddressSnapshot.AddressFamily))
            {
                return context.lastException != null ? context.lastException : new ArgumentException(SR.GetString(SR.net_invalidAddressList), "context");
            }

            try
            {
                EndPoint endPoint = new IPEndPoint(currentAddressSnapshot, context.port);
                // MSRC 11081 - Do the necessary security demand
                context.socket.CheckCacheRemote(ref endPoint, true);

                IAsyncResult connectResult = context.socket.UnsafeBeginConnect(endPoint, 
                    new AsyncCallback(MultipleAddressConnectCallback), context);

                if (connectResult.CompletedSynchronously)
                {
                    return connectResult;
                }
            }
            catch (Exception exception)
            {
                if (exception is OutOfMemoryException || exception is StackOverflowException || exception is ThreadAbortException)
                    throw;

                return exception;
            }

            return null;
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:33,代码来源:Socket.cs


示例8: DoMultipleAddressConnectCallback

        // This is like a regular async callback worker, except the result can be an exception.  This is a useful pattern when
        // processing should continue whether or not an async step failed.
        private static void DoMultipleAddressConnectCallback(object result, MultipleAddressConnectAsyncResult context)
        {
            while (result != null)
            {
                Exception ex = result as Exception;
                if (ex == null)
                {
                    try
                    {
                        context.socket.EndConnect((IAsyncResult) result);
                    }
                    catch (Exception exception)
                    {
                        if (exception is ThreadAbortException || exception is StackOverflowException || exception is OutOfMemoryException)
                            throw;

                        ex = exception;
                    }
                    catch
                    {
                        ex = new Exception(SR.GetString(SR.net_nonClsCompliantException));
                    }
                }

                if (ex == null)
                {
                    context.InvokeCallback();
                    break;
                }
                else
                {
                    if (++context.index >= context.addresses.Length)
                        throw ex;

                    context.lastException = ex;
                    result = PostOneBeginConnect(context);
                }
            }
        }
开发者ID:svermeulen,项目名称:iris,代码行数:41,代码来源:socket.cs


示例9: PostOneBeginConnect

        private static object PostOneBeginConnect(MultipleAddressConnectAsyncResult context)
        {
            if (context.addresses[context.index].AddressFamily != context.socket.AddressFamily)
            {
                return context.lastException != null ? context.lastException : new ArgumentException(SR.GetString(SR.net_invalidAddressList), "context");
            }

            try
            {
                IAsyncResult connectResult = context.socket.UnsafeBeginConnect(new IPEndPoint(context.addresses[context.index], context.port), new AsyncCallback(MultipleAddressConnectCallback), context);
                if (connectResult.CompletedSynchronously)
                {
                    return connectResult;
                }
            }
            catch (Exception exception)
            {
                if (exception is OutOfMemoryException || exception is StackOverflowException || exception is ThreadAbortException)
                    throw;

                return exception;
            }

            return null;
        }
开发者ID:svermeulen,项目名称:iris,代码行数:25,代码来源:socket.cs


示例10: DoDnsCallback

 private static void DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context)
 {
     IPAddress[] addresses = Dns.EndGetHostAddresses(result);
     context.addresses = addresses;
     DoMultipleAddressConnectCallback(PostOneBeginConnect(context), context);
 }
开发者ID:svermeulen,项目名称:iris,代码行数:6,代码来源:socket.cs


示例11: BeginConnect

 public IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
 {
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "BeginConnect", addresses);
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (addresses == null)
     {
         throw new ArgumentNullException("addresses");
     }
     if (addresses.Length == 0)
     {
         throw new ArgumentException(SR.GetString("net_invalidAddressList"), "addresses");
     }
     if (!ValidationHelper.ValidateTcpPort(port))
     {
         throw new ArgumentOutOfRangeException("port");
     }
     if ((this.addressFamily != System.Net.Sockets.AddressFamily.InterNetwork) && (this.addressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6))
     {
         throw new NotSupportedException(SR.GetString("net_invalidversion"));
     }
     if (this.isListening)
     {
         throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten"));
     }
     MultipleAddressConnectAsyncResult context = new MultipleAddressConnectAsyncResult(addresses, port, this, state, requestCallback);
     context.StartPostingAsyncOp(false);
     if (DoMultipleAddressConnectCallback(PostOneBeginConnect(context), context))
     {
         context.InvokeCallback();
     }
     context.FinishPostingAsyncOp(ref this.Caches.ConnectClosureCache);
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "BeginConnect", context);
     }
     return context;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:43,代码来源:Socket.cs


示例12: PostOneBeginConnect

 private static object PostOneBeginConnect(MultipleAddressConnectAsyncResult context)
 {
     IPAddress address = context.addresses[context.index];
     if (address.AddressFamily != context.socket.AddressFamily)
     {
         if (context.lastException == null)
         {
             return new ArgumentException(SR.GetString("net_invalidAddressList"), "context");
         }
         return context.lastException;
     }
     try
     {
         EndPoint remoteEP = new IPEndPoint(address, context.port);
         context.socket.CheckCacheRemote(ref remoteEP, true);
         IAsyncResult result = context.socket.UnsafeBeginConnect(remoteEP, new AsyncCallback(Socket.MultipleAddressConnectCallback), context);
         if (result.CompletedSynchronously)
         {
             return result;
         }
     }
     catch (Exception exception)
     {
         if (((exception is OutOfMemoryException) || (exception is StackOverflowException)) || (exception is ThreadAbortException))
         {
             throw;
         }
         return exception;
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:Socket.cs


示例13: DoMultipleAddressConnectCallback

 private static bool DoMultipleAddressConnectCallback(object result, MultipleAddressConnectAsyncResult context)
 {
     while (result != null)
     {
         Exception exception = result as Exception;
         if (exception == null)
         {
             try
             {
                 context.socket.EndConnect((IAsyncResult) result);
             }
             catch (Exception exception2)
             {
                 exception = exception2;
             }
         }
         if (exception == null)
         {
             return true;
         }
         if (++context.index >= context.addresses.Length)
         {
             throw exception;
         }
         context.lastException = exception;
         result = PostOneBeginConnect(context);
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:Socket.cs



注:本文中的MultipleAddressConnectAsyncResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Murmur类代码示例发布时间:2022-05-24
下一篇:
C# MultipartContent类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap