Author: gonzalo
Date: 2005-04-10 23:39:30 -0400 (Sun, 10 Apr 2005)
New Revision: 42773
Modified:
trunk/mcs/class/System/System.Net/ChangeLog
trunk/mcs/class/System/System.Net/WebConnectionStream.cs
Log:
2005-04-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* WebConnectionStream.cs: provide a default callback when doing async.
read/write and waiting for a timeout so that the callback sets the
event and we don't block forever. Fixes bug #74539 take 3.
Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2005-04-11 03:21:09 UTC (rev
42772)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2005-04-11 03:39:30 UTC (rev
42773)
@@ -1,3 +1,9 @@
+2005-04-11 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * WebConnectionStream.cs: provide a default callback when doing async.
+ read/write and waiting for a timeout so that the callback sets the
+ event and we don't block forever. Fixes bug #74539 take 3.
+
2005-04-10 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* WebConnection.cs:
Modified: trunk/mcs/class/System/System.Net/WebConnectionStream.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebConnectionStream.cs 2005-04-11
03:21:09 UTC (rev 42772)
+++ trunk/mcs/class/System/System.Net/WebConnectionStream.cs 2005-04-11
03:39:30 UTC (rev 42773)
@@ -196,14 +196,31 @@
cnc.NextRead ();
}
-
- static void CallbackWrapper (IAsyncResult r)
+
+ void WriteCallbackWrapper (IAsyncResult r)
{
- WebAsyncResult result = (WebAsyncResult) r.AsyncState;
- result.InnerAsyncResult = r;
- result.DoCallback ();
+ WebAsyncResult result;
+ if (r.AsyncState != null) {
+ result = (WebAsyncResult) r.AsyncState;
+ result.InnerAsyncResult = r;
+ result.DoCallback ();
+ } else {
+ EndWrite (r);
+ }
}
+ void ReadCallbackWrapper (IAsyncResult r)
+ {
+ WebAsyncResult result;
+ if (r.AsyncState != null) {
+ result = (WebAsyncResult) r.AsyncState;
+ result.InnerAsyncResult = r;
+ result.DoCallback ();
+ } else {
+ EndRead (r);
+ }
+ }
+
public override int Read (byte [] buffer, int offset, int size)
{
if (!isRead)
@@ -212,7 +229,8 @@
if (totalRead >= contentLength)
return 0;
- WebAsyncResult res = (WebAsyncResult) BeginRead
(buffer, offset, size, null, null);
+ AsyncCallback cb = new AsyncCallback
(ReadCallbackWrapper);
+ WebAsyncResult res = (WebAsyncResult) BeginRead
(buffer, offset, size, cb, null);
if (!res.WaitUntilComplete (request.ReadWriteTimeout,
false)) {
cnc.Close (true);
throw new IOException ("Read timed out.");
@@ -263,7 +281,7 @@
}
if (cb != null)
- cb = new AsyncCallback (CallbackWrapper);
+ cb = new AsyncCallback (ReadCallbackWrapper);
if (contentLength != Int32.MaxValue && contentLength -
totalRead < size)
size = contentLength - totalRead;
@@ -298,7 +316,8 @@
if (totalRead >= contentLength && !nextReadCalled)
ReadAll ();
- return result.NBytes;
+ int nb = result.NBytes;
+ return (nb >= 0) ? nb : 0;
}
public override IAsyncResult BeginWrite (byte [] buffer, int
offset, int size,
@@ -333,7 +352,7 @@
AsyncCallback callback = null;
if (cb != null)
- callback = new AsyncCallback (CallbackWrapper);
+ callback = new AsyncCallback
(WriteCallbackWrapper);
if (sendChunked) {
WriteRequest ();
@@ -385,7 +404,8 @@
if (isRead)
throw new NotSupportedException ("This stream
does not allow writing");
- WebAsyncResult res = (WebAsyncResult) BeginWrite
(buffer, offset, size, null, null);
+ AsyncCallback cb = new AsyncCallback
(WriteCallbackWrapper);
+ WebAsyncResult res = (WebAsyncResult) BeginWrite
(buffer, offset, size, cb, null);
if (!res.WaitUntilComplete (request.ReadWriteTimeout,
false)) {
cnc.Close (true);
throw new IOException ("Write timed out.");
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches