Просмотр исходного кода

2005-04-10 Gonzalo Paniagua Javier <[email protected]>

	* WebConnection.cs:
	* HttpWebRequest.cs: now Abort() works properly. Fixes bug #74177.


svn path=/trunk/mcs/; revision=42770
Gonzalo Paniagua Javier 21 лет назад
Родитель
Сommit
e1bb860498

+ 5 - 0
mcs/class/System/System.Net/ChangeLog

@@ -1,3 +1,8 @@
+2005-04-10 Gonzalo Paniagua Javier <[email protected]>
+
+	* WebConnection.cs:
+	* HttpWebRequest.cs: now Abort() works properly. Fixes bug #74177.
+
 2005-04-10 Gonzalo Paniagua Javier <[email protected]>
 
 	* WebConnection.cs: fix some breakage from my last patch.

+ 4 - 8
mcs/class/System/System.Net/HttpWebRequest.cs

@@ -698,7 +698,7 @@ namespace System.Net
 
 			if (result.GotException)
 				throw result.Exception;
-			
+
 			return result.Response;
 		}
 
@@ -734,7 +734,7 @@ namespace System.Net
 			if (abortHandler != null) {
 				try {
 					abortHandler (this, EventArgs.Empty);
-				} catch {}
+				} catch (Exception) {}
 				abortHandler = null;
 			}
 
@@ -988,13 +988,9 @@ namespace System.Net
 
 		internal void SetResponseError (WebExceptionStatus status, Exception e, string where)
 		{
+			if (aborted)
+				return;
 			string msg = String.Format ("Error getting response stream ({0}): {1}", where, status);
-			if (webResponse != null) {
-				if (e is WebException)
-					throw e;
-				throw new WebException (msg, e, status, null);
-			}
-			
 			WebAsyncResult r = asyncRead;
 			if (r == null)
 				r = asyncWrite;

+ 24 - 3
mcs/class/System/System.Net/WebConnection.cs

@@ -51,6 +51,7 @@ namespace System.Net
 		ServicePoint sPoint;
 		Stream nstream;
 		Socket socket;
+		object socketLock = new object ();
 		WebExceptionStatus status;
 		WebConnectionGroup group;
 		bool busy;
@@ -98,7 +99,7 @@ namespace System.Net
 		
 		void Connect ()
 		{
-			lock (this) {
+			lock (socketLock) {
 				if (socket != null && socket.Connected && status == WebExceptionStatus.Success) {
 					// Take the chunked stream to the expected state (State.None)
 					if (CanReuse () && CompleteChunkedRead ()) {
@@ -286,7 +287,8 @@ namespace System.Net
 				req = Data.request;
 
 			Close (true);
-			req.SetResponseError (st, e, where);
+			if (req != null)
+				req.SetResponseError (st, e, where);
 		}
 		
 		static void ReadDone (IAsyncResult result)
@@ -858,7 +860,26 @@ namespace System.Net
 
 		void Abort (object sender, EventArgs args)
 		{
-			HandleError (WebExceptionStatus.RequestCanceled, null, "Abort");
+			lock (this) {
+				if (Data.request == sender) {
+					HandleError (WebExceptionStatus.RequestCanceled, null, "Abort");
+					return;
+				}
+
+				lock (queue) {
+					if (queue.Count > 0 && queue.Peek () == sender) {
+						queue.Dequeue ();
+						return;
+					}
+
+					object [] old = queue.ToArray ();
+					queue.Clear ();
+					for (int i = old.Length - 1; i >= 0; i--) {
+						if (old [i] != sender)
+							queue.Enqueue (old [i]);
+					}
+				}
+			}
 		}
 
 		internal bool Busy {