Author: gonzalo
Date: 2005-05-03 05:41:51 -0400 (Tue, 03 May 2005)
New Revision: 43916
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-05-03 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* WebConnection.cs: no need to use an AutoResetEvent.
* WebConnectionStream.cs: don't start any more reads on the socket
after getting a 0 signalling the end. This fixes Ben's infamous foo.cs
test.
Modified: trunk/mcs/class/System/System.Net/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net/ChangeLog 2005-05-03 07:24:27 UTC (rev
43915)
+++ trunk/mcs/class/System/System.Net/ChangeLog 2005-05-03 09:41:51 UTC (rev
43916)
@@ -1,3 +1,10 @@
+2005-05-03 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * WebConnection.cs: no need to use an AutoResetEvent.
+ * WebConnectionStream.cs: don't start any more reads on the socket
+ after getting a 0 signalling the end. This fixes Ben's infamous foo.cs
+ test.
+
2005-04-29 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* BasicClient.cs: firefox/IE just send latin1, stripping the high byte
Modified: trunk/mcs/class/System/System.Net/WebConnection.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebConnection.cs 2005-05-03 07:24:27 UTC
(rev 43915)
+++ trunk/mcs/class/System/System.Net/WebConnection.cs 2005-05-03 09:41:51 UTC
(rev 43916)
@@ -53,8 +53,7 @@
Socket socket;
object socketLock = new object ();
WebExceptionStatus status;
- bool busy;
- WaitOrTimerCallback initConn;
+ WaitCallback initConn;
bool keepAlive;
byte [] buffer;
static AsyncCallback readDoneDelegate = new AsyncCallback
(ReadDone);
@@ -63,10 +62,10 @@
internal WebConnectionData Data;
bool chunkedRead;
ChunkStream chunkStream;
- AutoResetEvent goAhead;
Queue queue;
bool reused;
int position;
+ bool busy;
bool ssl;
bool certsAvailable;
@@ -82,9 +81,8 @@
buffer = new byte [4096];
readState = ReadState.None;
Data = new WebConnectionData ();
- initConn = new WaitOrTimerCallback (InitConnection);
+ initConn = new WaitCallback (InitConnection);
abortHandler = new EventHandler (Abort);
- goAhead = new AutoResetEvent (true);
queue = group.Queue;
}
@@ -308,6 +306,7 @@
}
if (nread == 0) {
+ Environment.Exit (0);
cnc.HandleError
(WebExceptionStatus.ReceiveFailure, null, "ReadDone2");
return;
}
@@ -509,15 +508,16 @@
return -1;
}
- void InitConnection (object state, bool notUsed)
+ void InitConnection (object state)
{
HttpWebRequest request = (HttpWebRequest) state;
if (status == WebExceptionStatus.RequestCanceled) {
- busy = false;
- Data = new WebConnectionData ();
- goAhead.Set ();
- SendNext ();
+ lock (this) {
+ busy = false;
+ Data = new WebConnectionData ();
+ SendNext ();
+ }
return;
}
@@ -546,8 +546,7 @@
lock (this) {
if (!busy) {
busy = true;
- ThreadPool.RegisterWaitForSingleObject
(goAhead, initConn,
-
request, -1, true);
+ ThreadPool.QueueUserWorkItem (initConn,
request);
} else {
lock (queue) {
queue.Enqueue (request);
@@ -570,7 +569,6 @@
internal void NextRead ()
{
lock (this) {
- busy = false;
string header = (sPoint.UsesProxy) ?
"Proxy-Connection" : "Connection";
string cncHeader = (Data.Headers != null) ?
Data.Headers [header] : null;
bool keepAlive = (Data.Version ==
HttpVersion.Version11 && this.keepAlive);
@@ -584,12 +582,7 @@
Close (false);
}
- goAhead.Set ();
- lock (queue) {
- if (queue.Count > 0) {
- SendRequest ((HttpWebRequest)
queue.Dequeue ());
- }
- }
+ SendNext ();
}
}
@@ -679,7 +672,7 @@
IAsyncResult inner = wr.InnerAsyncResult;
if (inner != null && !(inner is WebAsyncResult))
nbytes = nstream.EndRead (inner);
- } else {
+ } else if (!(nsAsync is WebAsyncResult)) {
nbytes = nstream.EndRead (nsAsync);
wr = (WebAsyncResult) result;
}
@@ -834,7 +827,6 @@
internal void Close (bool sendNext)
{
lock (this) {
- busy = false;
if (nstream != null) {
try {
nstream.Close ();
@@ -849,7 +841,7 @@
socket = null;
}
- goAhead.Set ();
+ busy = false;
if (sendNext)
SendNext ();
}
Modified: trunk/mcs/class/System/System.Net/WebConnectionStream.cs
===================================================================
--- trunk/mcs/class/System/System.Net/WebConnectionStream.cs 2005-05-03
07:24:27 UTC (rev 43915)
+++ trunk/mcs/class/System/System.Net/WebConnectionStream.cs 2005-05-03
09:41:51 UTC (rev 43916)
@@ -59,6 +59,7 @@
bool headersSent;
object locker = new object ();
bool initRead;
+ bool read_eof;
public WebConnectionStream (WebConnection cnc)
{
@@ -133,8 +134,8 @@
internal void ReadAll ()
{
- if (!isRead || totalRead >= contentLength ||
nextReadCalled) {
- if (!nextReadCalled) {
+ if (!isRead || read_eof || totalRead >= contentLength
|| nextReadCalled) {
+ if (isRead && !nextReadCalled) {
nextReadCalled = true;
cnc.NextRead ();
}
@@ -233,6 +234,7 @@
AsyncCallback cb = new AsyncCallback
(ReadCallbackWrapper);
WebAsyncResult res = (WebAsyncResult) BeginRead
(buffer, offset, size, cb, null);
if (!res.IsCompleted && !res.WaitUntilComplete
(request.ReadWriteTimeout, false)) {
+ nextReadCalled = true;
cnc.Close (true);
throw new IOException ("Read timed out.");
}
@@ -287,7 +289,12 @@
if (contentLength != Int32.MaxValue && contentLength -
totalRead < size)
size = contentLength - totalRead;
- result.InnerAsyncResult = cnc.BeginRead (buffer,
offset, size, cb, result);
+ if (!read_eof) {
+ result.InnerAsyncResult = cnc.BeginRead
(buffer, offset, size, cb, result);
+ } else {
+ result.SetCompleted (true, result.NBytes);
+ result.DoCallback ();
+ }
return result;
}
@@ -302,15 +309,24 @@
result.EndCalled = true;
if (!result.IsCompleted) {
- int nbytes = cnc.EndRead (result);
- bool finished = (nbytes == -1);
- if (finished && result.NBytes > 0)
+ int nbytes = -1;
+ try {
+ nbytes = cnc.EndRead (result);
+ } catch (Exception) {
+ nextReadCalled = true;
+ cnc.Close (true);
+ throw;
+ }
+
+ if (nbytes < 0) {
nbytes = 0;
+ read_eof = true;
+ }
totalRead += nbytes;
result.SetCompleted (false, nbytes +
result.NBytes);
result.DoCallback ();
- if (finished || nbytes == 0)
+ if (nbytes == 0)
contentLength = totalRead;
}
@@ -425,6 +441,7 @@
AsyncCallback cb = new AsyncCallback
(WriteCallbackWrapper);
WebAsyncResult res = (WebAsyncResult) BeginWrite
(buffer, offset, size, cb, null);
if (!res.IsCompleted && !res.WaitUntilComplete
(request.ReadWriteTimeout, false)) {
+ nextReadCalled = true;
cnc.Close (true);
throw new IOException ("Write timed out.");
}
@@ -514,8 +531,10 @@
if (!nextReadCalled) {
CheckComplete ();
// If we have not read all the contents
- if (!nextReadCalled)
+ if (!nextReadCalled) {
+ nextReadCalled = true;
cnc.Close (true);
+ }
}
return;
} else if (!allowBuffering) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches