Author: gonzalo
Date: 2005-04-10 01:08:55 -0400 (Sun, 10 Apr 2005)
New Revision: 42750

Modified:
   trunk/mcs/class/System/System.Net/ChangeLog
   trunk/mcs/class/System/System.Net/WebConnection.cs
   trunk/mcs/class/System/System.Net/WebConnectionStream.cs
Log:
2005-04-10 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * WebConnection.cs: if we're reading chunked data and didn't use the
        stream to read, we gotta set the async. result as complete and invoke
        the callback. Don't call nstream.EndRead with the wrong IAsyncResult.

        * WebConnectionStream.cs: in EndRead, pass the correct IAsyncResult to
        cnc.EndRead. Lock on a field instead of 'this'.



Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2005-04-10 04:38:44 UTC (rev 
42749)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2005-04-10 05:08:55 UTC (rev 
42750)
@@ -1,3 +1,12 @@
+2005-04-10 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * WebConnection.cs: if we're reading chunked data and didn't use the
+       stream to read, we gotta set the async. result as complete and invoke
+       the callback. Don't call nstream.EndRead with the wrong IAsyncResult.
+
+       * WebConnectionStream.cs: in EndRead, pass the correct IAsyncResult to
+       cnc.EndRead. Lock on a field instead of 'this'.
+
 2005-04-09 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
        * HttpWebRequest.cs: throw the exception if we got an error, as now

Modified: trunk/mcs/class/System/System.Net/WebConnection.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebConnection.cs  2005-04-10 04:38:44 UTC 
(rev 42749)
+++ trunk/mcs/class/System/System.Net/WebConnection.cs  2005-04-10 05:08:55 UTC 
(rev 42750)
@@ -644,6 +644,7 @@
                        if (!chunkedRead || chunkStream.WantMore) {
                                try {
                                        result = nstream.BeginRead (buffer, 
offset, size, cb, state);
+                                       cb = null;
                                } catch (Exception) {
                                        HandleError 
(WebExceptionStatus.ReceiveFailure, null, "chunked BeginRead");
                                        throw;
@@ -651,8 +652,13 @@
                        }
 
                        if (chunkedRead) {
-                               WebAsyncResult wr = new WebAsyncResult (null, 
null, buffer, offset, size);
+                               WebAsyncResult wr = new WebAsyncResult (cb, 
state, buffer, offset, size);
                                wr.InnerAsyncResult = result;
+                               if (result == null) {
+                                       // Will be completed from the data in 
ChunkStream
+                                       wr.SetCompleted (true, (Exception) 
null);
+                                       wr.DoCallback ();
+                               }
                                return wr;
                        }
 
@@ -666,9 +672,10 @@
 
                        if (chunkedRead) {
                                WebAsyncResult wr = (WebAsyncResult) result;
+                               IAsyncResult inner = wr.InnerAsyncResult;
                                int nbytes = 0;
-                               if (wr.InnerAsyncResult != null)
-                                       nbytes = nstream.EndRead 
(wr.InnerAsyncResult);
+                               if (inner != null && !(inner is WebAsyncResult))
+                                       nbytes = nstream.EndRead (inner);
 
                                bool done = (nbytes == 0);
                                try {
@@ -688,7 +695,7 @@
                                        throw new WebException ("Read error", 
null, WebExceptionStatus.ReceiveFailure, null);
                                }
 
-                               return nbytes;
+                               return (nbytes != 0) ? nbytes : -1;
                        }
 
                        return nstream.EndRead (result);

Modified: trunk/mcs/class/System/System.Net/WebConnectionStream.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebConnectionStream.cs    2005-04-10 
04:38:44 UTC (rev 42749)
+++ trunk/mcs/class/System/System.Net/WebConnectionStream.cs    2005-04-10 
05:08:55 UTC (rev 42750)
@@ -57,6 +57,7 @@
                byte [] headers;
                bool disposed;
                bool headersSent;
+               object locker = new object ();
 
                public WebConnectionStream (WebConnection cnc)
                {
@@ -139,7 +140,7 @@
                        }
 
                        pending.WaitOne ();
-                       lock (this) {
+                       lock (locker) {
                                if (totalRead >= contentLength)
                                        return;
                                
@@ -227,7 +228,7 @@
                        if (size < 0 || offset < 0 || length < offset || length 
- offset < size)
                                throw new ArgumentOutOfRangeException ();
 
-                       lock (this) {
+                       lock (locker) {
                                pendingReads++;
                                pending.Reset ();
                        }
@@ -270,7 +271,7 @@
                        WebAsyncResult result = (WebAsyncResult) r;
 
                        if (!result.IsCompleted) {
-                               int nbytes = cnc.EndRead 
(result.InnerAsyncResult);
+                               int nbytes = cnc.EndRead (result);
                                bool finished = (nbytes == -1);
                                if (finished && result.NBytes > 0)
                                        nbytes = 0;
@@ -281,7 +282,7 @@
                                        contentLength = totalRead;
                        }
 
-                       lock (this) {
+                       lock (locker) {
                                pendingReads--;
                                if (pendingReads == 0)
                                        pending.Set ();
@@ -307,7 +308,7 @@
                                throw new ArgumentOutOfRangeException ();
 
                        if (sendChunked) {
-                               lock (this) {
+                               lock (locker) {
                                        pendingWrites++;
                                        pending.Reset ();
                                }
@@ -364,7 +365,7 @@
 
                        cnc.EndWrite (result.InnerAsyncResult);
                        if (sendChunked) {
-                               lock (this) {
+                               lock (locker) {
                                        pendingWrites--;
                                        if (pendingWrites == 0)
                                                pending.Set ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to