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


C# OverlappedAsyncResult.GetSocketAddressPtr方法代码示例

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


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

示例1: DoBeginReceiveFrom

        private void DoBeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint endPointSnapshot, SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
        {
            EndPoint oldEndPoint = m_RightEndPoint;
            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginReceiveFrom() size:" + size.ToString());

            // Guarantee to call CheckAsyncCallOverlappedResult if we call SetUnamangedStructures with a cache in order to
            // avoid a Socket leak in case of error.
            SocketError errorCode = SocketError.SocketError;
            try
            {
                // Set up asyncResult for overlapped WSARecvFrom.
                // This call will use completion ports on WinNT and Overlapped IO on Win9x.
                asyncResult.SetUnmanagedStructures(buffer, offset, size, socketAddress, true /* pin remoteEP*/, ref Caches.ReceiveOverlappedCache);

                // save a copy of the original EndPoint in the asyncResult
                asyncResult.SocketAddressOriginal = endPointSnapshot.Serialize();

                if (m_RightEndPoint == null) {
                    m_RightEndPoint = endPointSnapshot;
                }

                int bytesTransferred;
                errorCode = UnsafeNclNativeMethods.OSSOCK.WSARecvFrom(
                    m_Handle,
                    ref asyncResult.m_SingleBuffer,
                    1,
                    out bytesTransferred,
                    ref socketFlags,
                    asyncResult.GetSocketAddressPtr(),
                    asyncResult.GetSocketAddressSizePtr(),
                    asyncResult.OverlappedHandle,
                    IntPtr.Zero );

                if (errorCode!=SocketError.Success) {
                    errorCode = (SocketError)Marshal.GetLastWin32Error();
                }
                GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginReceiveFrom() UnsafeNclNativeMethods.OSSOCK.WSARecvFrom returns:" + errorCode.ToString() + " size:" + size.ToString() + " returning AsyncResult:" + ValidationHelper.HashString(asyncResult));
            }
            catch (ObjectDisposedException)
            {
                m_RightEndPoint = oldEndPoint;
                throw;
            }
            finally
            {
                errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
            }

            //
            // if the asynchronous native call fails synchronously
            // we'll throw a SocketException
            //
            if (errorCode!=SocketError.Success) {
                //
                // update our internal state after this socket error and throw
                //
                m_RightEndPoint = oldEndPoint;
                asyncResult.ExtractCache(ref Caches.ReceiveOverlappedCache);
                SocketException socketException = new SocketException(errorCode);
                UpdateStatusAfterSocketError(socketException);
                if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "BeginReceiveFrom", socketException);
                throw socketException;
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginReceiveFrom() size:" + size.ToString() + " returning AsyncResult:" + ValidationHelper.HashString(asyncResult));
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:66,代码来源:Socket.cs

示例2: ReceiveFromAsync

        public static unsafe SocketError ReceiveFromAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
        {
            // Set up asyncResult for overlapped WSARecvFrom.
            // This call will use completion ports on WinNT and Overlapped IO on Win9x.
            asyncResult.SetUnmanagedStructures(buffer, offset, count, socketAddress, true);

            int bytesTransferred;
            SocketError errorCode = Interop.Winsock.WSARecvFrom(
                handle,
                ref asyncResult._singleBuffer,
                1,
                out bytesTransferred,
                ref socketFlags,
                asyncResult.GetSocketAddressPtr(),
                asyncResult.GetSocketAddressSizePtr(),
                asyncResult.OverlappedHandle,
                IntPtr.Zero);

            if (errorCode != SocketError.Success)
            {
                errorCode = GetLastSocketError();
            }

            return errorCode;
        }
开发者ID:vbouret,项目名称:corefx,代码行数:25,代码来源:SocketPal.Windows.cs

示例3: DoBeginSendTo

 private void DoBeginSendTo(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint endPointSnapshot, SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
 {
     EndPoint endPoint = this.m_RightEndPoint;
       SocketError socketError = SocketError.SocketError;
       try
       {
     asyncResult.SetUnmanagedStructures(buffer, offset, size, socketAddress, false, ref this.Caches.SendOverlappedCache);
     if (this.m_RightEndPoint == null)
       this.m_RightEndPoint = endPointSnapshot;
     int bytesTransferred;
     socketError = UnsafeNclNativeMethods.OSSOCK.WSASendTo(this.m_Handle, ref asyncResult.m_SingleBuffer, 1, out bytesTransferred, socketFlags, asyncResult.GetSocketAddressPtr(), asyncResult.SocketAddress.Size, asyncResult.OverlappedHandle, IntPtr.Zero);
     if (socketError != SocketError.Success)
       socketError = (SocketError) Marshal.GetLastWin32Error();
       }
       catch (ObjectDisposedException ex)
       {
     this.m_RightEndPoint = endPoint;
     throw;
       }
       finally
       {
     socketError = asyncResult.CheckAsyncCallOverlappedResult(socketError);
       }
       if (socketError == SocketError.Success)
     return;
       this.m_RightEndPoint = endPoint;
       asyncResult.ExtractCache(ref this.Caches.SendOverlappedCache);
       SocketException socketException = new SocketException(socketError);
       this.UpdateStatusAfterSocketError(socketException);
       if (Socket.s_LoggingEnabled)
     Logging.Exception(Logging.Sockets, (object) this, "BeginSendTo", (Exception) socketException);
       throw socketException;
 }
开发者ID:korifey,项目名称:hackathon-Ideaphone,代码行数:33,代码来源:Socket.cs

示例4: SendToAsync

        public static unsafe SocketError SendToAsync(SafeCloseSocket handle, byte[] buffer, int offset, int count, SocketFlags socketFlags, Internals.SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
        {
            // Set up asyncResult for overlapped WSASendTo.
            // This call will use completion ports.
            asyncResult.SetUnmanagedStructures(buffer, offset, count, socketAddress, false /* don't pin RemoteEP*/);

            int bytesTransferred;
            SocketError errorCode = Interop.Winsock.WSASendTo(
                handle,
                ref asyncResult._singleBuffer,
                1, // There is only ever 1 buffer being sent.
                out bytesTransferred,
                socketFlags,
                asyncResult.GetSocketAddressPtr(),
                asyncResult.SocketAddress.Size,
                asyncResult.OverlappedHandle,
                IntPtr.Zero);

            if (errorCode != SocketError.Success)
            {
                errorCode = GetLastSocketError();
            }

            return errorCode;
        }
开发者ID:vbouret,项目名称:corefx,代码行数:25,代码来源:SocketPal.Windows.cs

示例5: DoBeginReceiveFrom

 private void DoBeginReceiveFrom(byte[] buffer, int offset, int size, SocketFlags socketFlags, EndPoint endPointSnapshot, SocketAddress socketAddress, OverlappedAsyncResult asyncResult)
 {
     EndPoint rightEndPoint = this.m_RightEndPoint;
     SocketError socketError = SocketError.SocketError;
     try
     {
         int num;
         asyncResult.SetUnmanagedStructures(buffer, offset, size, socketAddress, true, ref this.Caches.ReceiveOverlappedCache);
         asyncResult.SocketAddressOriginal = endPointSnapshot.Serialize();
         if (this.m_RightEndPoint == null)
         {
             this.m_RightEndPoint = endPointSnapshot;
         }
         socketError = UnsafeNclNativeMethods.OSSOCK.WSARecvFrom(this.m_Handle, ref asyncResult.m_SingleBuffer, 1, out num, ref socketFlags, asyncResult.GetSocketAddressPtr(), asyncResult.GetSocketAddressSizePtr(), asyncResult.OverlappedHandle, IntPtr.Zero);
         if (socketError != SocketError.Success)
         {
             socketError = (SocketError) Marshal.GetLastWin32Error();
         }
     }
     catch (ObjectDisposedException)
     {
         this.m_RightEndPoint = rightEndPoint;
         throw;
     }
     finally
     {
         socketError = asyncResult.CheckAsyncCallOverlappedResult(socketError);
     }
     if (socketError != SocketError.Success)
     {
         this.m_RightEndPoint = rightEndPoint;
         asyncResult.ExtractCache(ref this.Caches.ReceiveOverlappedCache);
         SocketException socketException = new SocketException(socketError);
         this.UpdateStatusAfterSocketError(socketException);
         if (s_LoggingEnabled)
         {
             Logging.Exception(Logging.Sockets, this, "BeginReceiveFrom", socketException);
         }
         throw socketException;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:41,代码来源:Socket.cs


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