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


C# SocketAsyncEventArgs.StartOperationReceive方法代码示例

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


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

示例1: ReceiveAsync

        public bool ReceiveAsync(SocketAsyncEventArgs e)
        {
            bool retval;

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

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

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

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

            // Local vars for sync completion of native call.
            SocketFlags flags;
            int bytesTransferred;
            SocketError socketError;

            // Wrap native methods with try/catch so event args object can be cleaned up.
            try
            {
                socketError = e.DoOperationReceive(_handle, out flags, out bytesTransferred);
            }
            catch (Exception ex)
            {
                // Clear in-use flag on event args object. 
                e.Complete();
                throw ex;
            }

            // Handle completion when completion port is not posted.
            if (socketError != SocketError.Success && socketError != SocketError.IOPending)
            {
                e.FinishOperationSyncFailure(socketError, bytesTransferred, flags);
                retval = false;
            }
            else
            {
                retval = true;
            }

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

示例2: ReceiveAsync

 /// <summary>
 /// Begins an asynchronous request to receive data from a connected <see cref="T:System.Net.Sockets.Socket"/> object.
 /// </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="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 was invalid. The <see cref="P:System.Net.Sockets.SocketAsyncEventArgs.Buffer"/> or <see cref="P:System.Net.Sockets.SocketAsyncEventArgs.BufferList"/> properties on the <paramref name="e"/> parameter must reference valid buffers. One or the other of these properties may be set, but not both at the same time.</exception><exception cref="T:System.InvalidOperationException">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.NotSupportedException">Windows XP or later is required for this method.</exception><exception cref="T:System.ObjectDisposedException">The <see cref="T:System.Net.Sockets.Socket"/> has been closed. </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>
 public bool ReceiveAsync(SocketAsyncEventArgs e)
 {
     if (Socket.s_LoggingEnabled)
     Logging.Enter(Logging.Sockets, (object) this, "ReceiveAsync", "");
       if (this.CleanedUp)
     throw new ObjectDisposedException(this.GetType().FullName);
       e.StartOperationCommon(this);
       e.StartOperationReceive();
       this.BindToCompletionPort();
       SocketFlags socketFlags = e.m_SocketFlags;
       int bytesTransferred;
       SocketError socketError;
       try
       {
     socketError = e.m_Buffer == null ? UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, e.m_WSABufferArray, e.m_WSABufferArray.Length, out bytesTransferred, out socketFlags, (SafeHandle) e.m_PtrNativeOverlapped, IntPtr.Zero) : UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, ref e.m_WSABuffer, 1, out bytesTransferred, out socketFlags, (SafeHandle) e.m_PtrNativeOverlapped, IntPtr.Zero);
       }
       catch (Exception ex)
       {
     e.Complete();
     throw ex;
       }
       if (socketError != SocketError.Success)
     socketError = (SocketError) Marshal.GetLastWin32Error();
       bool flag;
       if (socketError != SocketError.Success && socketError != SocketError.IOPending)
       {
     e.FinishOperationSyncFailure(socketError, bytesTransferred, socketFlags);
     flag = false;
       }
       else
     flag = true;
       if (Socket.s_LoggingEnabled)
     Logging.Exit(Logging.Sockets, (object) this, "ReceiveAsync", (object) (bool) (flag ? 1 : 0));
       return flag;
 }
开发者ID:korifey,项目名称:hackathon-Ideaphone,代码行数:43,代码来源:Socket.cs

示例3: ReceiveAsync

        //
        // ReceiveAsync
        // 
        public bool ReceiveAsync(SocketAsyncEventArgs e) {

            bool retval;

            if(s_LoggingEnabled) Logging.Enter(Logging.Sockets, this, "ReceiveAsync", "");

            // Throw if socket disposed
            if(CleanedUp) {
                throw new ObjectDisposedException(GetType().FullName);
            }

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

            // Local vars for [....] completion of native call.
            SocketFlags flags = e.m_SocketFlags;
            int bytesTransferred;
            SocketError socketError;

            // Wrap native methods with try/catch so event args object can be cleaned up
            try {
                if(e.m_Buffer != null) {
                    // Single buffer case
                    socketError = UnsafeNclNativeMethods.OSSOCK.WSARecv(
                        m_Handle,
                        ref e.m_WSABuffer,
                        1,
                        out bytesTransferred,
                        ref flags,
                        e.m_PtrNativeOverlapped,
                        IntPtr.Zero);
                } else {
                    // Multi buffer case
                    socketError = UnsafeNclNativeMethods.OSSOCK.WSARecv(
                        m_Handle,
                        e.m_WSABufferArray,
                        e.m_WSABufferArray.Length,
                        out bytesTransferred,
                        ref flags,
                        e.m_PtrNativeOverlapped,
                        IntPtr.Zero);
                }
            }
            catch(Exception ex) {
                // clear in-use on event arg object 
                e.Complete();
                throw ex;
            }

            // Native method emits single catch-all error code when error occurs.
            // Must get Win32 error for specific error code.
            if(socketError != SocketError.Success) {
                socketError = (SocketError)Marshal.GetLastWin32Error();
            }

            // Handle completion when completion port is not posted.
            if(socketError != SocketError.Success && socketError != SocketError.IOPending) {
                e.FinishOperationSyncFailure(socketError, bytesTransferred, flags);
                retval = false;
            } else {
                retval = true;
            }

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

示例4: ReceiveAsync

 public bool ReceiveAsync(SocketAsyncEventArgs e)
 {
     bool flag;
     int num;
     SocketError error;
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "ReceiveAsync", "");
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     e.StartOperationCommon(this);
     e.StartOperationReceive();
     this.BindToCompletionPort();
     SocketFlags socketFlags = e.m_SocketFlags;
     try
     {
         if (e.m_Buffer != null)
         {
             error = UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, ref e.m_WSABuffer, 1, out num, ref socketFlags, e.m_PtrNativeOverlapped, IntPtr.Zero);
         }
         else
         {
             error = UnsafeNclNativeMethods.OSSOCK.WSARecv(this.m_Handle, e.m_WSABufferArray, e.m_WSABufferArray.Length, out num, ref socketFlags, e.m_PtrNativeOverlapped, IntPtr.Zero);
         }
     }
     catch (Exception exception)
     {
         e.Complete();
         throw exception;
     }
     if (error != SocketError.Success)
     {
         error = (SocketError) Marshal.GetLastWin32Error();
     }
     if ((error != SocketError.Success) && (error != SocketError.IOPending))
     {
         e.FinishOperationSyncFailure(error, num, socketFlags);
         flag = false;
     }
     else
     {
         flag = true;
     }
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "ReceiveAsync", flag);
     }
     return flag;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:52,代码来源:Socket.cs


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