Removed DeflateStream.UnmanagedRead Read loop. Fixes #19313.
authormarcos henrich <marcoshenrich@gmail.com>
Mon, 2 Jun 2014 07:22:33 +0000 (08:22 +0100)
committermarcos henrich <marcoshenrich@gmail.com>
Mon, 2 Jun 2014 07:22:33 +0000 (08:22 +0100)
If the base_stream was a NetworkStream UnmanagedRead loop would call base_stream.Read a second time and block until one byte was available to return. Without the loop UnmanagedRead will only read the base_stream once.

mcs/class/System/System.IO.Compression/DeflateStream.cs

index 02c0c9f6b02dc00345ba844de459196299aae41d..1a67e39e0c7eaa4134085efecfdaaaf1fcbead7a 100644 (file)
@@ -395,24 +395,15 @@ namespace System.IO.Compression
 
                int UnmanagedRead (IntPtr buffer, int length)
                {
-                       int total = 0;
-                       int n = 1;
-                       while (length > 0 && n > 0) {
-                               if (io_buffer == null)
-                                       io_buffer = new byte [BufferSize];
+                       if (io_buffer == null)
+                               io_buffer = new byte [BufferSize];
 
-                               int count = Math.Min (length, io_buffer.Length);
-                               n = base_stream.Read (io_buffer, 0, count);
-                               if (n > 0) {
-                                       Marshal.Copy (io_buffer, 0, buffer, n);
-                                       unsafe {
-                                               buffer = new IntPtr ((byte *) buffer.ToPointer () + n);
-                                       }
-                                       length -= n;
-                                       total += n;
-                               }
-                       }
-                       return total;
+                       int count = Math.Min (length, io_buffer.Length);
+                       int n = base_stream.Read (io_buffer, 0, count);
+                       if (n > 0)
+                               Marshal.Copy (io_buffer, 0, buffer, n);
+
+                       return n;
                }
 
 #if MONOTOUCH