当前位置: 首页>>代码示例>>C#>>正文


C# SocketAsyncEventArgs.StartOperationWrapperConnect方法代码示例

本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.StartOperationWrapperConnect方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.StartOperationWrapperConnect方法的具体用法?C# SocketAsyncEventArgs.StartOperationWrapperConnect怎么用?C# SocketAsyncEventArgs.StartOperationWrapperConnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Sockets.SocketAsyncEventArgs的用法示例。


在下文中一共展示了SocketAsyncEventArgs.StartOperationWrapperConnect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectAsync

        public bool ConnectAsync(SocketAsyncEventArgs e)
        {
            bool retval;

            if (s_loggingEnabled)
            {
                Logging.Enter(Logging.Sockets, this, "ConnectAsync", "");
            }

            if (CleanedUp)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (e._bufferList != null)
            {
                throw new ArgumentException(SR.net_multibuffernotsupported, "BufferList");
            }
            if (e.RemoteEndPoint == null)
            {
                throw new ArgumentNullException("remoteEP");
            }
            if (_isListening)
            {
                throw new InvalidOperationException(SR.net_sockets_mustnotlisten);
            }

            // Check permissions for connect and prepare SocketAddress.
            EndPoint endPointSnapshot = e.RemoteEndPoint;
            DnsEndPoint dnsEP = endPointSnapshot as DnsEndPoint;

            if (dnsEP != null)
            {
                if (s_loggingEnabled)
                {
                    Logging.PrintInfo(Logging.Sockets, "Socket#" + Logging.HashString(this) + "::ConnectAsync " + SR.net_log_socket_connect_dnsendpoint);
                }

                if (dnsEP.AddressFamily != AddressFamily.Unspecified && !CanTryAddressFamily(dnsEP.AddressFamily))
                {
                    throw new NotSupportedException(SR.net_invalidversion);
                }

                MultipleConnectAsync multipleConnectAsync = new SingleSocketMultipleConnectAsync(this, true);

                e.StartOperationCommon(this);
                e.StartOperationWrapperConnect(multipleConnectAsync);

                retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
            }
            else
            {
                // Throw if remote address family doesn't match socket.
                if (!CanTryAddressFamily(e.RemoteEndPoint.AddressFamily))
                {
                    throw new NotSupportedException(SR.net_invalidversion);
                }

                e._socketAddress = CheckCacheRemote(ref endPointSnapshot, false);

                // Do wildcard bind if socket not bound.
                if (_rightEndPoint == null)
                {
                    if (endPointSnapshot.AddressFamily == AddressFamily.InterNetwork)
                    {
                        InternalBind(new IPEndPoint(IPAddress.Any, 0));
                    }
                    else
                    {
                        InternalBind(new IPEndPoint(IPAddress.IPv6Any, 0));
                    }
                }

                // Save the old RightEndPoint and prep new RightEndPoint.           
                EndPoint oldEndPoint = _rightEndPoint;
                if (_rightEndPoint == null)
                {
                    _rightEndPoint = endPointSnapshot;
                }

                // Prepare for the native call.
                e.StartOperationCommon(this);
                e.StartOperationConnect();

                // Make the native call.
                int bytesTransferred;
                SocketError socketError = SocketError.Success;
                try
                {
                    socketError = e.DoOperationConnect(this, _handle, out bytesTransferred);
                }
                catch (Exception ex)
                {
                    _rightEndPoint = oldEndPoint;

                    // Clear in-use flag on event args object. 
//.........这里部分代码省略.........
开发者ID:ReedKimble,项目名称:corefx,代码行数:101,代码来源:Socket.cs

示例2: ConnectAsync

        public static bool ConnectAsync(SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e) {

            bool retval;

            if (s_LoggingEnabled) Logging.Enter(Logging.Sockets, null, "ConnectAsync", "");

            // Throw if multiple buffers specified.
            if (e.m_BufferList != null) {
                throw new ArgumentException(SR.GetString(SR.net_multibuffernotsupported), "BufferList");
            }

            // Throw if RemoteEndPoint is null.
            if (e.RemoteEndPoint == null) {
                throw new ArgumentNullException("remoteEP");
            }

            EndPoint endPointSnapshot = e.RemoteEndPoint;
            DnsEndPoint dnsEP = endPointSnapshot as DnsEndPoint;

            if (dnsEP != null) {
                Socket attemptSocket = null;
                MultipleConnectAsync multipleConnectAsync = null;
                if (dnsEP.AddressFamily == AddressFamily.Unspecified) {
                    multipleConnectAsync = new MultipleSocketMultipleConnectAsync(socketType, protocolType);
                } else {
                    attemptSocket = new Socket(dnsEP.AddressFamily, socketType, protocolType);
                    multipleConnectAsync = new SingleSocketMultipleConnectAsync(attemptSocket, false);
                }

                e.StartOperationCommon(attemptSocket);
                e.StartOperationWrapperConnect(multipleConnectAsync);

                retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
            } else {
                Socket attemptSocket = new Socket(endPointSnapshot.AddressFamily, socketType, protocolType);
                retval = attemptSocket.ConnectAsync(e);
            }

            if (s_LoggingEnabled) Logging.Exit(Logging.Sockets, null, "ConnectAsync", retval);
            return retval;
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:41,代码来源:Socket.cs

示例3: ConnectAsync

        public static bool ConnectAsync(SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
        {
            bool retval;

            if (s_loggingEnabled)
            {
                NetEventSource.Enter(NetEventSource.ComponentType.Socket, null, nameof(ConnectAsync), "");
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e._bufferList != null)
            {
                throw new ArgumentException(SR.net_multibuffernotsupported, "BufferList");
            }
            if (e.RemoteEndPoint == null)
            {
                throw new ArgumentNullException("remoteEP");
            }

            EndPoint endPointSnapshot = e.RemoteEndPoint;
            DnsEndPoint dnsEP = endPointSnapshot as DnsEndPoint;

            if (dnsEP != null)
            {
                Socket attemptSocket = null;
                MultipleConnectAsync multipleConnectAsync = null;
                if (dnsEP.AddressFamily == AddressFamily.Unspecified)
                {
                    // Disable CS0162 and CS0429: Unreachable code detected
                    //
                    // SuportsMultipleConnectAttempts is a constant; when false, the following lines will trigger CS0162 or CS0429.
                    //
                    // This is the only *Connect* API that actually supports multiple endpoint attempts, as it's responsible 
                    // for creating each Socket instance and can create one per attempt (with the instance methods, once a 
                    // connect fails, on unix systems that socket can't be used for subsequent connect attempts).
#pragma warning disable 162, 429
                    multipleConnectAsync = SocketPal.SupportsMultipleConnectAttempts ?
                        (MultipleConnectAsync)(new DualSocketMultipleConnectAsync(socketType, protocolType)) :
                        (MultipleConnectAsync)(new MultipleSocketMultipleConnectAsync(socketType, protocolType));
#pragma warning restore
                }
                else
                {
                    attemptSocket = new Socket(dnsEP.AddressFamily, socketType, protocolType);
                    multipleConnectAsync = new SingleSocketMultipleConnectAsync(attemptSocket, false);
                }

                e.StartOperationCommon(attemptSocket);
                e.StartOperationWrapperConnect(multipleConnectAsync);

                retval = multipleConnectAsync.StartConnectAsync(e, dnsEP);
            }
            else
            {
                Socket attemptSocket = new Socket(endPointSnapshot.AddressFamily, socketType, protocolType);
                retval = attemptSocket.ConnectAsync(e);
            }

            if (s_loggingEnabled)
            {
                NetEventSource.Exit(NetEventSource.ComponentType.Socket, null, nameof(ConnectAsync), retval);
            }
            return retval;
        }
开发者ID:MichalStrehovsky,项目名称:corefx,代码行数:67,代码来源:Socket.cs

示例4: ConnectAsync

 /// <summary>
 /// Begins an asynchronous request for a connection to a remote host.
 /// </summary>
 /// 
 /// <returns>
 /// Returns true if the I/O operation is pending. The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed"/> event on the <paramref name="e"/> parameter will be raised upon completion of the operation. Returns false if the I/O operation completed synchronously. In this case, The <see cref="E:System.Net.Sockets.SocketAsyncEventArgs.Completed"/> event on the <paramref name="e"/> parameter will not be raised and the <paramref name="e"/> object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.
 /// </returns>
 /// <param name="socketType">One of the <see cref="T:System.Net.Sockets.SocketType"/> values.</param><param name="protocolType">One of the <see cref="T:System.Net.Sockets.ProtocolType"/> values.</param><param name="e">The <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> object to use for this asynchronous socket operation.</param><exception cref="T:System.ArgumentException">An argument is not valid. This exception occurs if multiple buffers are specified, the <see cref="P:System.Net.Sockets.SocketAsyncEventArgs.BufferList"/> property is not null. </exception><exception cref="T:System.ArgumentNullException">The <paramref name="e"/> parameter cannot be null and the <see cref="P:System.Net.Sockets.SocketAsyncEventArgs.RemoteEndPoint"/> cannot be null.</exception><exception cref="T:System.InvalidOperationException">The <see cref="T:System.Net.Sockets.Socket"/> is listening or a socket operation was already in progress using the <see cref="T:System.Net.Sockets.SocketAsyncEventArgs"/> object specified in the <paramref name="e"/> parameter.</exception><exception cref="T:System.Net.Sockets.SocketException">An error occurred when attempting to access the socket. See the Remarks section for more information.</exception><exception cref="T:System.NotSupportedException">Windows XP or later is required for this method. This exception also occurs if the local endpoint and the <see cref="P:System.Net.Sockets.SocketAsyncEventArgs.RemoteEndPoint"/> are not the same address family.</exception><exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.Socket"/> has been closed. </exception><exception cref="T:System.Security.SecurityException">A caller higher in the call stack does not have permission for the requested operation.</exception>
 public static bool ConnectAsync(SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (string) null, "ConnectAsync", "");
       if (e.m_BufferList != null)
     throw new ArgumentException(SR.GetString("net_multibuffernotsupported"), "BufferList");
       if (e.RemoteEndPoint == null)
     throw new ArgumentNullException("remoteEP");
       EndPoint remoteEndPoint = e.RemoteEndPoint;
       DnsEndPoint endPoint = remoteEndPoint as DnsEndPoint;
       bool flag;
       if (endPoint != null)
       {
     Socket socket = (Socket) null;
     MultipleConnectAsync args;
     if (endPoint.AddressFamily == AddressFamily.Unspecified)
     {
       args = (MultipleConnectAsync) new MultipleSocketMultipleConnectAsync(socketType, protocolType);
     }
     else
     {
       socket = new Socket(endPoint.AddressFamily, socketType, protocolType);
       args = (MultipleConnectAsync) new SingleSocketMultipleConnectAsync(socket, false);
     }
     e.StartOperationCommon(socket);
     e.StartOperationWrapperConnect(args);
     flag = args.StartConnectAsync(e, endPoint);
       }
       else
     flag = new Socket(remoteEndPoint.AddressFamily, socketType, protocolType).ConnectAsync(e);
       if (Socket.s_LoggingEnabled)
     Logging.Exit(Logging.Sockets, (string) null, "ConnectAsync", (object) (bool) (flag ? 1 : 0));
       return flag;
 }
开发者ID:korifey,项目名称:hackathon-Ideaphone,代码行数:42,代码来源:Socket.cs

示例5: ConnectAsync

 public bool ConnectAsync(SocketAsyncEventArgs e)
 {
     bool flag;
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "ConnectAsync", "");
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (e.m_BufferList != null)
     {
         throw new ArgumentException(SR.GetString("net_multibuffernotsupported"), "BufferList");
     }
     if (e.RemoteEndPoint == null)
     {
         throw new ArgumentNullException("remoteEP");
     }
     if (this.isListening)
     {
         throw new InvalidOperationException(SR.GetString("net_sockets_mustnotlisten"));
     }
     EndPoint remoteEndPoint = e.RemoteEndPoint;
     DnsEndPoint endPoint = remoteEndPoint as DnsEndPoint;
     if (endPoint != null)
     {
         if (s_LoggingEnabled)
         {
             Logging.PrintInfo(Logging.Sockets, "Socket#" + ValidationHelper.HashString(this) + "::ConnectAsync Connecting to a DnsEndPoint");
         }
         if ((endPoint.AddressFamily != System.Net.Sockets.AddressFamily.Unspecified) && (endPoint.AddressFamily != this.addressFamily))
         {
             throw new NotSupportedException(SR.GetString("net_invalidversion"));
         }
         MultipleConnectAsync args = new SingleSocketMultipleConnectAsync(this, true);
         e.StartOperationCommon(this);
         e.StartOperationWrapperConnect(args);
         flag = args.StartConnectAsync(e, endPoint);
     }
     else
     {
         int num;
         if (this.addressFamily != e.RemoteEndPoint.AddressFamily)
         {
             throw new NotSupportedException(SR.GetString("net_invalidversion"));
         }
         e.m_SocketAddress = this.CheckCacheRemote(ref remoteEndPoint, false);
         if (this.m_RightEndPoint == null)
         {
             if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
             {
                 this.InternalBind(new IPEndPoint(IPAddress.Any, 0));
             }
             else
             {
                 this.InternalBind(new IPEndPoint(IPAddress.IPv6Any, 0));
             }
         }
         EndPoint rightEndPoint = this.m_RightEndPoint;
         if (this.m_RightEndPoint == null)
         {
             this.m_RightEndPoint = remoteEndPoint;
         }
         e.StartOperationCommon(this);
         e.StartOperationConnect();
         this.BindToCompletionPort();
         SocketError success = SocketError.Success;
         try
         {
             if (!this.ConnectEx(this.m_Handle, e.m_PtrSocketAddressBuffer, e.m_SocketAddress.m_Size, e.m_PtrSingleBuffer, e.Count, out num, e.m_PtrNativeOverlapped))
             {
                 success = (SocketError) Marshal.GetLastWin32Error();
             }
         }
         catch (Exception exception)
         {
             this.m_RightEndPoint = rightEndPoint;
             e.Complete();
             throw exception;
         }
         if ((success != SocketError.Success) && (success != SocketError.IOPending))
         {
             e.FinishOperationSyncFailure(success, num, SocketFlags.None);
             flag = false;
         }
         else
         {
             flag = true;
         }
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "ConnectAsync", flag);
     }
     return flag;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:97,代码来源:Socket.cs


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