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


C# OverlappedAsyncResult.GetHashCode方法代码示例

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


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

示例1: BeginReceive

        /*++

        Routine Description:

           BeginReceive - Async implimentation of Recv call,

           Called when we want to start an async receive.
           We kick off the receive, and if it completes synchronously we'll
           call the callback. Otherwise we'll return an IASyncResult, which
           the caller can use to wait on or retrieve the final status, as needed.

           Uses Winsock 2 overlapped I/O.

        Arguments:

           ReadBuffer - status line that we wish to parse
           Index - Offset into ReadBuffer to begin reading from
           Size - Size of Buffer to recv
           Callback - Delegate function that holds callback, called on completeion of I/O
           State - State used to track callback, set by caller, not required

        Return Value:

           IAsyncResult - Async result used to retreive result

        --*/


        /// <include file='doc\Socket.uex' path='docs/doc[@for="Socket.BeginReceive"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, Object state) {
            if (CleanedUp) {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            //
            // parameter validation
            //
            if (buffer==null) {
                throw new ArgumentNullException("buffer");
            }
            if (offset<0 || offset>buffer.Length) {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (size<0 || size>buffer.Length-offset) {
                throw new ArgumentOutOfRangeException("size");
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::BeginReceive() size:" + size.ToString());

            //
            // Allocate the async result and the event we'll pass to the
            // thread pool.
            //
            OverlappedAsyncResult asyncResult =
                new OverlappedAsyncResult(
                    this,
                    state,
                    callback );

            //
            // Set up asyncResult for overlapped WSARecv.
            // This call will use
            // completion ports on WinNT and Overlapped IO on Win9x.
            //

            asyncResult.SetUnmanagedStructures(
                                          buffer,
                                          offset,
                                          size,
                                          socketFlags,
                                          null,
                                          false // don't pin null RemoteEP
                                          );

            //
            // Get the Receive going.
            //

            int errorCode =
                UnsafeNclNativeMethods.OSSOCK.WSARecv(
                    m_Handle,
                    ref asyncResult.m_WSABuffer,
                    1,
                    OverlappedAsyncResult.m_BytesTransferred,
                    ref asyncResult.m_Flags,
                    asyncResult.IntOverlapped,
                    IntPtr.Zero );

            if (errorCode!=SocketErrors.Success) {
                errorCode = Marshal.GetLastWin32Error();
            }

#if COMNET_PERFLOGGING
long timer = 0;
Microsoft.Win32.SafeNativeMethods.QueryPerformanceCounter(out timer);
Console.WriteLine(timer + ", Socket#" + this.m_Handle + "::WSARecv(" + asyncResult.GetHashCode() + " 0x" + ((long)asyncResult.IntOverlapped).ToString("X8") + ") returns:" + errorCode);
#endif // #if COMNET_PERFLOGGING

//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:socket.cs


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