# HG changeset patch # User Ivo Smits # Date 1358522990 -3600 # Node ID 9533a87363f3de85a34536c06ded2129d91bdd2c # Parent 9525fb2d14ec4d13d849fe2360154554d8fe1d4f Fixed deadlock in QueuedPacketStream diff -r 9525fb2d14ec -r 9533a87363f3 Util/ArrayUtil.cs --- a/Util/ArrayUtil.cs Wed Jan 16 23:27:06 2013 +0100 +++ b/Util/ArrayUtil.cs Fri Jan 18 16:29:50 2013 +0100 @@ -19,6 +19,9 @@ input.CopyTo(output, 0); return output; } + public static T[] ToArray(ArraySegment input) { + return Slice(input.Array, input.Offset, input.Count); + } public static IList ToList(IEnumerable input) { return new List(input); } diff -r 9525fb2d14ec -r 9533a87363f3 Util/QueuedPacketStream.cs --- a/Util/QueuedPacketStream.cs Wed Jan 16 23:27:06 2013 +0100 +++ b/Util/QueuedPacketStream.cs Fri Jan 18 16:29:50 2013 +0100 @@ -20,8 +20,7 @@ } protected void AddReadBufferCopy(Byte[] buffer, int offset, int count) { - Byte[] store; - store = new Byte[count]; + Byte[] store = new Byte[count]; Buffer.BlockCopy(buffer, offset, store, 0, count); AddReadBufferNoCopy(store); } @@ -125,15 +124,17 @@ } private IAsyncResult BeginAsyncReadOperation(AsyncResult ar) { + Boolean synccompleted = false; lock (ReceiveQueue) { if (AsyncReceiveOperation != null) throw new InvalidOperationException("Another asynchronous operation is in progress"); if (ReceiveBuffer != null || ReceiveQueue.Count > 0) { - ar.SetCompleted(true); + synccompleted = true; } else { if (Closed) throw new ObjectDisposedException("QueuedPacketStream", "The connection has been closed"); AsyncReceiveOperation = ar; } } + if (synccompleted) ar.SetCompleted(true); return ar; } private void EndAsyncReadOperation(AsyncResult ar) {