# HG changeset patch # User Ivo Smits # Date 1415381859 -3600 # Node ID df53bdd49507cbe30db7a3fa0b41ea515ece90e3 # Parent 0fc3f42a855597ff52bd3a9ad89e0c4201880fab# Parent 5e717aac4c1d7c8fe288e23970092812e9d410b1 Merge diff -r 0fc3f42a8555 -r df53bdd49507 Remoting/RemotingManager.cs --- a/Remoting/RemotingManager.cs Mon Nov 03 18:29:58 2014 +0100 +++ b/Remoting/RemotingManager.cs Fri Nov 07 18:37:39 2014 +0100 @@ -17,7 +17,7 @@ public class RemotingManager { Dictionary pendingCalls = new Dictionary(); Dictionary waitingCallThreads = new Dictionary(); - Boolean Closed = false; + public Boolean Closed { get; private set; } IDictionary incomingCallContext = new Dictionary(); [ThreadStatic] @@ -25,6 +25,7 @@ public event Action OnDebugLog; public event Action OnErrorLog; + public event Action OnClosed; private void DebugLog(String text, params Object[] args) { if (OnDebugLog != null) OnDebugLog(String.Format(text, args)); @@ -42,6 +43,7 @@ public RemotingManager(PacketStream stream, Object localRoot) { this.stream = stream; this.LocalRoot = localRoot; + this.Closed = false; stream.BeginReadPacketFast(ReceiveCallback, null); } @@ -135,6 +137,7 @@ streamChannels.Clear(); } ErrorLog(ex); + if (OnClosed != null) OnClosed(this); } } private void SendObject(Object obj) { diff -r 0fc3f42a8555 -r df53bdd49507 Windows/WindowsNamedPipe.cs --- a/Windows/WindowsNamedPipe.cs Mon Nov 03 18:29:58 2014 +0100 +++ b/Windows/WindowsNamedPipe.cs Fri Nov 07 18:37:39 2014 +0100 @@ -28,6 +28,9 @@ static extern unsafe bool ConnectNamedPipe(SafeFileHandle hNamedPipe, NativeOverlapped* lpOverlapped); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern unsafe bool GetNamedPipeInfo(SafeFileHandle hNamedPipe, out UInt32 lpFlags, IntPtr lpOutBufferSize, IntPtr lpInBufferSize, IntPtr lpMaxInstances); + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CancelIo(SafeFileHandle hFile); const UInt32 PIPE_ACCESS_DUPLEX = 0x00000003; const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000; @@ -60,6 +63,9 @@ } public unsafe void WaitForClient() { + WaitForClient(-1); + } + public unsafe void WaitForClient(int millisecondsTimeout) { uint nread; using (ManualResetEvent evt = new ManualResetEvent(false)) { NativeOverlapped overlapped = new NativeOverlapped(); @@ -67,7 +73,10 @@ if (!ConnectNamedPipe(PipeHandle, &overlapped)) { int err = Marshal.GetLastWin32Error(); if (err != 997) throw new Win32Exception(err); - evt.WaitOne(); + if (!evt.WaitOne(millisecondsTimeout)) { + CancelIo(PipeHandle); + throw new TimeoutException("The operation timed out"); + } if (!GetOverlappedResult(PipeHandle, &overlapped, out nread, false)) throw new Win32Exception(Marshal.GetLastWin32Error()); } }