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()); }
public NamedPipeClient(string name) { DateTime now = DateTime.Now; while (true) { this.pipeHandle = NamedPipeBase.CreateFile("\\\\.\\pipe\\" + name, 3221225472u, 0u, new IntPtr(0), 3u, 0u, new IntPtr(0)); if (!this.pipeHandle.IsInvalid) { return; } if (DateTime.Now.Subtract(now).TotalSeconds > 10.0) { break; } Thread.Sleep(200); } throw new IOException("Failed to connect to " + name); }
public void RunServer(NamedPipeBase.ServerHandler serverHandler) { bool flag = true; while (flag) { object request; try { request = this.ReadMessage(); } catch (EndOfStreamException) { break; } ISerializable request2 = null; flag = serverHandler(request, ref request2); this.SendMessage(request2); } }