SetUnmanagedStructures() private method

private SetUnmanagedStructures ( byte buffer, int addressBufferLength ) : void
buffer byte
addressBufferLength int
return void
コード例 #1
0
        public static unsafe SocketError AcceptAsync(Socket socket, SafeCloseSocket handle, SafeCloseSocket acceptHandle, int receiveSize, int socketAddressSize, AcceptOverlappedAsyncResult asyncResult)
        {
            // The buffer needs to contain the requested data plus room for two sockaddrs and 16 bytes
            // of associated data for each.
            int addressBufferSize = socketAddressSize + 16;

            byte[] buffer = new byte[receiveSize + ((addressBufferSize) * 2)];

            // Set up asyncResult for overlapped AcceptEx.
            // This call will use completion ports on WinNT.
            asyncResult.SetUnmanagedStructures(buffer, addressBufferSize);

            // This can throw ObjectDisposedException.
            int         bytesTransferred;
            SocketError errorCode = SocketError.Success;

            if (!socket.AcceptEx(
                    handle,
                    acceptHandle,
                    Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult.Buffer, 0),
                    receiveSize,
                    addressBufferSize,
                    addressBufferSize,
                    out bytesTransferred,
                    asyncResult.OverlappedHandle))
            {
                errorCode = GetLastSocketError();
            }

            return(errorCode);
        }
コード例 #2
0
ファイル: SocketPal.Windows.cs プロジェクト: zeroyou/corefx
        public static unsafe SocketError AcceptAsync(Socket socket, SafeCloseSocket handle, SafeCloseSocket acceptHandle, int receiveSize, int socketAddressSize, AcceptOverlappedAsyncResult asyncResult)
        {
            // The buffer needs to contain the requested data plus room for two sockaddrs and 16 bytes
            // of associated data for each.
            int addressBufferSize = socketAddressSize + 16;

            byte[] buffer = new byte[receiveSize + ((addressBufferSize) * 2)];

            // Set up asyncResult for overlapped AcceptEx.
            // This call will use completion ports on WinNT.
            asyncResult.SetUnmanagedStructures(buffer, addressBufferSize);
            try
            {
                // This can throw ObjectDisposedException.
                int  bytesTransferred;
                bool success = socket.AcceptEx(
                    handle,
                    acceptHandle,
                    Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult.Buffer, 0),
                    receiveSize,
                    addressBufferSize,
                    addressBufferSize,
                    out bytesTransferred,
                    asyncResult.DangerousOverlappedPointer); // SafeHandle was just created in SetUnmanagedStructures

                return(asyncResult.ProcessOverlappedResult(success, 0));
            }
            catch
            {
                asyncResult.ReleaseUnmanagedStructures();
                throw;
            }
        }
コード例 #3
0
ファイル: Socket.cs プロジェクト: REALTOBIZ/mono
        private void DoBeginAccept(Socket acceptSocket, int receiveSize, AcceptOverlappedAsyncResult asyncResult)
        {
            if (m_RightEndPoint==null) {
                throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustbind));
            }

            if(!isListening){
                throw new InvalidOperationException(SR.GetString(SR.net_sockets_mustlisten));
            }

            // if a acceptSocket isn't specified, then we need to create it.
            if (acceptSocket == null) {
                acceptSocket = new Socket(addressFamily,socketType,protocolType);
            }
            else
            {
                if (acceptSocket.m_RightEndPoint != null) {
                    throw new InvalidOperationException(SR.GetString(SR.net_sockets_namedmustnotbebound, "acceptSocket"));
                }
            }
            asyncResult.AcceptSocket = acceptSocket;

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginAccept() AcceptSocket:" + ValidationHelper.HashString(acceptSocket));

            //the buffer needs to contain the requested data plus room for two sockaddrs and 16 bytes
            //of associated data for each.
            int addressBufferSize = m_RightEndPoint.Serialize().Size + 16;
            byte[] buffer = new byte[receiveSize + ((addressBufferSize) * 2)];

            //
            // Set up asyncResult for overlapped AcceptEx.
            // This call will use
            // completion ports on WinNT
            //

            asyncResult.SetUnmanagedStructures(buffer, addressBufferSize);

            // This can throw ObjectDisposedException.
            int bytesTransferred;
            SocketError errorCode = SocketError.Success;
            if (!AcceptEx(
                m_Handle,
                acceptSocket.m_Handle,
                Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult.Buffer, 0),
                receiveSize,
                addressBufferSize,
                addressBufferSize,
                out bytesTransferred,
                asyncResult.OverlappedHandle))
            {
                errorCode = (SocketError)Marshal.GetLastWin32Error();
            }
            errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginAccept() UnsafeNclNativeMethods.OSSOCK.AcceptEx returns:" + errorCode.ToString() + ValidationHelper.HashString(asyncResult));

            //
            // if the asynchronous native call fails synchronously
            // we'll throw a SocketException
            //
            if (errorCode!=SocketError.Success) {
                SocketException socketException = new SocketException(errorCode);
                UpdateStatusAfterSocketError(socketException);
                if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "BeginAccept", socketException);
                throw socketException;
            }
        }
コード例 #4
0
ファイル: SocketPal.Windows.cs プロジェクト: vbouret/corefx
        public static unsafe SocketError AcceptAsync(Socket socket, SafeCloseSocket handle, SafeCloseSocket acceptHandle, int receiveSize, int socketAddressSize, AcceptOverlappedAsyncResult asyncResult)
        {
            // The buffer needs to contain the requested data plus room for two sockaddrs and 16 bytes
            // of associated data for each.
            int addressBufferSize = socketAddressSize + 16;
            byte[] buffer = new byte[receiveSize + ((addressBufferSize) * 2)];

            // Set up asyncResult for overlapped AcceptEx.
            // This call will use completion ports on WinNT.
            asyncResult.SetUnmanagedStructures(buffer, addressBufferSize);

            // This can throw ObjectDisposedException.
            int bytesTransferred;
            SocketError errorCode = SocketError.Success;
            if (!socket.AcceptEx(
                handle,
                acceptHandle,
                Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult.Buffer, 0),
                receiveSize,
                addressBufferSize,
                addressBufferSize,
                out bytesTransferred,
                asyncResult.OverlappedHandle))
            {
                errorCode = GetLastSocketError();
            }

            return errorCode;
        }
コード例 #5
0
ファイル: Socket.cs プロジェクト: korifey/hackathon-Ideaphone
 private void DoBeginAccept(Socket acceptSocket, int receiveSize, AcceptOverlappedAsyncResult asyncResult)
 {
     if (this.m_RightEndPoint == null)
     throw new InvalidOperationException(SR.GetString("net_sockets_mustbind"));
       if (!this.isListening)
     throw new InvalidOperationException(SR.GetString("net_sockets_mustlisten"));
       if (acceptSocket == null)
     acceptSocket = new Socket(this.addressFamily, this.socketType, this.protocolType);
       else if (acceptSocket.m_RightEndPoint != null)
     throw new InvalidOperationException(SR.GetString("net_sockets_namedmustnotbebound", new object[1]
     {
       (object) "acceptSocket"
     }));
       asyncResult.AcceptSocket = acceptSocket;
       int num = this.m_RightEndPoint.Serialize().Size + 16;
       byte[] buffer = new byte[receiveSize + num * 2];
       asyncResult.SetUnmanagedStructures(buffer, num);
       SocketError errorCode = SocketError.Success;
       int bytesReceived;
       if (!this.AcceptEx(this.m_Handle, acceptSocket.m_Handle, Marshal.UnsafeAddrOfPinnedArrayElement((Array) asyncResult.Buffer, 0), receiveSize, num, num, out bytesReceived, asyncResult.OverlappedHandle))
     errorCode = (SocketError) Marshal.GetLastWin32Error();
       SocketError socketError = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
       if (socketError == SocketError.Success)
     return;
       SocketException socketException = new SocketException(socketError);
       this.UpdateStatusAfterSocketError(socketException);
       if (Socket.s_LoggingEnabled)
     Logging.Exception(Logging.Sockets, (object) this, "BeginAccept", (Exception) socketException);
       throw socketException;
 }
コード例 #6
0
 private void DoBeginAccept(Socket acceptSocket, int receiveSize, AcceptOverlappedAsyncResult asyncResult)
 {
     int num2;
     if (!ComNetOS.IsWinNt)
     {
         throw new PlatformNotSupportedException(SR.GetString("WinNTRequired"));
     }
     if (this.m_RightEndPoint == null)
     {
         throw new InvalidOperationException(SR.GetString("net_sockets_mustbind"));
     }
     if (!this.isListening)
     {
         throw new InvalidOperationException(SR.GetString("net_sockets_mustlisten"));
     }
     if (acceptSocket == null)
     {
         acceptSocket = new Socket(this.addressFamily, this.socketType, this.protocolType);
     }
     else if (acceptSocket.m_RightEndPoint != null)
     {
         throw new InvalidOperationException(SR.GetString("net_sockets_namedmustnotbebound", new object[] { "acceptSocket" }));
     }
     asyncResult.AcceptSocket = acceptSocket;
     int addressBufferLength = this.m_RightEndPoint.Serialize().Size + 0x10;
     byte[] buffer = new byte[receiveSize + (addressBufferLength * 2)];
     asyncResult.SetUnmanagedStructures(buffer, addressBufferLength);
     SocketError success = SocketError.Success;
     if (!this.AcceptEx(this.m_Handle, acceptSocket.m_Handle, Marshal.UnsafeAddrOfPinnedArrayElement(asyncResult.Buffer, 0), receiveSize, addressBufferLength, addressBufferLength, out num2, asyncResult.OverlappedHandle))
     {
         success = (SocketError) Marshal.GetLastWin32Error();
     }
     success = asyncResult.CheckAsyncCallOverlappedResult(success);
     if (success != SocketError.Success)
     {
         SocketException socketException = new SocketException(success);
         this.UpdateStatusAfterSocketError(socketException);
         if (s_LoggingEnabled)
         {
             Logging.Exception(Logging.Sockets, this, "BeginAccept", socketException);
         }
         throw socketException;
     }
 }