Ejemplo n.º 1
0
        internal unsafe IAsyncResult BeginRead(byte[] data, int offset, int size, AsyncCallback callback, object state)
        {
            bool              flag;
            PipeAsyncResult   ar           = new PipeAsyncResult(callback);
            NativeOverlapped *lpOverlapped = new Overlapped(0, 0, IntPtr.Zero, ar).UnsafePack(IOCallback, data);

            ar._overlapped = lpOverlapped;
            fixed(byte *numRef = data)
            {
                flag = NativePipe.ReadFile(this._handle, numRef + offset, size, IntPtr.Zero, lpOverlapped);
            }

            if (!flag)
            {
                int errorCode = Marshal.GetLastWin32Error();
                if (errorCode == 0x6dL)
                {
                    ar.CallUserCallback();
                    return(ar);
                }
                if (errorCode != 0x3e5L)
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ReadFailure"), new object[] { GetMessage(errorCode) }));
                }
            }
            return(ar);
        }
Ejemplo n.º 2
0
        internal unsafe int Read(byte[] data, int offset, int length)
        {
            bool flag = false;
            int  lpNumberOfBytesRead = 0;

            fixed(byte *numRef = data)
            {
                flag = NativePipe.ReadFile(this._handle, numRef + offset, length, ref lpNumberOfBytesRead, IntPtr.Zero);
            }

            if (!flag)
            {
                int errorCode = Marshal.GetLastWin32Error();
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ReadFailure"), new object[] { GetMessage(errorCode) }));
            }
            return(lpNumberOfBytesRead);
        }
Ejemplo n.º 3
0
        internal unsafe int Read(byte[] data, int offset, int length)
        {
            bool status       = false;
            int  numBytesRead = 0;

            fixed(byte *p = data)
            {
                status = NativePipe.ReadFile(_handle, p + offset, length, ref numBytesRead, IntPtr.Zero);
            }

            if (!status)
            {
                int error = Marshal.GetLastWin32Error();
                throw new RemotingException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ReadFailure"), GetMessage(error)));
            }
            else
            {
                return(numBytesRead);
            }
        }
Ejemplo n.º 4
0
        internal unsafe IAsyncResult BeginRead(byte[] data, int offset, int size, AsyncCallback callback, object state)
        {
            PipeAsyncResult asyncResult = new PipeAsyncResult(callback);
            // Create a managed overlapped class
            // We will set the file offsets later
            Overlapped overlapped = new Overlapped(0, 0, IntPtr.Zero, asyncResult);

            // Pack the Overlapped class, and store it in the async result
            NativeOverlapped *intOverlapped;

            intOverlapped           = overlapped.UnsafePack(IOCallback, data);
            asyncResult._overlapped = intOverlapped;
            bool status;

            // pin the buffer and read data with overlapped
            fixed(byte *p = data)
            {
                status = NativePipe.ReadFile(_handle, p + offset, size, IntPtr.Zero, intOverlapped);
            }

            if (!status)
            {
                int error = Marshal.GetLastWin32Error();
                // For pipes, when they hit EOF, they will come here.
                if (error == NativePipe.ERROR_BROKEN_PIPE)
                {
                    // Not an error, but EOF.  AsyncFSCallback will NOT be
                    // called.  Call the user callback here.
                    asyncResult.CallUserCallback();
                    // EndRead will free the Overlapped struct correctly.
                }
                else if (error != NativePipe.ERROR_IO_PENDING)
                {
                    throw new RemotingException(String.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Ipc_ReadFailure"), GetMessage(error)));
                }
            }
            return(asyncResult);
        }