protected byte[] ReadBuffer(int len) { byte[] array = new byte[4]; byte[] array2 = new byte[len]; byte[] array3 = new byte[len]; int i = 0; while (i < len) { if (!NamedPipeBase.ReadFile(this.pipeHandle.DangerousGetHandle(), array2, (uint)(len - i), array, 0u)) { if ((long)NamedPipeBase.GetLastError() == 109L) { throw new EndOfStreamException(); } throw new IOException(string.Format("ReadBuffer sees error {0}", NamedPipeBase.GetLastError())); } else { int num = BitConverter.ToInt32(array, 0); Array.Copy(array2, 0, array3, i, num); i += num; } } return(array3); }
private void Initialize(string pipeName) { this.pipeHandle = NamedPipeBase.CreateNamedPipe("\\\\.\\pipe\\" + pipeName, 3u, 6u, 255u, 4096u, 4096u, 0u, new IntPtr(0)); if (NamedPipeBase.ConnectNamedPipe(this.pipeHandle, new IntPtr(0)) == 0) { throw new IOException(string.Format("Unable to open pipe: {0}.", NamedPipeBase.GetLastError())); } }
protected void WriteBuffer(byte[] buffer, int len) { byte[] array = new byte[4]; for (int i = 0; i < len; i = 0) { if (!NamedPipeBase.WriteFile(this.pipeHandle.DangerousGetHandle(), buffer, (uint)(len - i), array, 0u)) { throw new IOException(string.Format("ReadBuffer sees error {0}", NamedPipeBase.GetLastError())); } i += BitConverter.ToInt32(array, 0); Array.Copy(buffer, i, buffer, 0, len - i); len -= i; } NamedPipeBase.FlushFileBuffers(this.pipeHandle.DangerousGetHandle()); }