diff options
author | Ludovic Henry <ludovic@xamarin.com> | 2016-01-28 13:50:34 +0300 |
---|---|---|
committer | Ludovic Henry <ludovic@xamarin.com> | 2016-01-28 14:10:53 +0300 |
commit | 83c7edc70e732cd0416a84284e3435ccc448c489 (patch) | |
tree | e34553f9a6a13f5fbdbc9f41ae39b91e8a4386a7 /mcs | |
parent | 7f0b7cf0221f9ebc1cd736f361fe814a1c31cdf9 (diff) |
[SocketResponder] Start in constructor and Stop on Dispose
In conjuction with `using` we ensure that we Start and Stop the SocketResponder correctly, and everytime
Diffstat (limited to 'mcs')
6 files changed, 21 insertions, 269 deletions
diff --git a/mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/SoapHttpClientProtocolTest.cs b/mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/SoapHttpClientProtocolTest.cs index 62fae0ddfbe..0019e05c278 100755 --- a/mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/SoapHttpClientProtocolTest.cs +++ b/mcs/class/System.Web.Services/Test/System.Web.Services.Protocols/SoapHttpClientProtocolTest.cs @@ -52,8 +52,6 @@ namespace MonoTests.System.Web.Services.Protocols { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder (localEP, s => OutParametersResponse (s))) { - sr.Start (); - FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; @@ -64,8 +62,6 @@ namespace MonoTests.System.Web.Services.Protocols Assert.AreEqual (0, a, "#A2"); Assert.IsFalse (b, "#A3"); service.Dispose (); - - sr.Stop (); } } @@ -75,8 +71,6 @@ namespace MonoTests.System.Web.Services.Protocols { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder (localEP, s => FaultResponse_Qualified (s))) { - sr.Start (); - FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; try { @@ -99,13 +93,9 @@ namespace MonoTests.System.Web.Services.Protocols Assert.AreEqual ("Failure processing request.", ex.Message, "#A9"); } service.Dispose (); - - sr.Stop (); } using (SocketResponder sr = new SocketResponder (localEP, s => FaultResponse_Unqualified (s))) { - sr.Start (); - FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; try { @@ -128,8 +118,6 @@ namespace MonoTests.System.Web.Services.Protocols Assert.AreEqual ("Failure processing request.", ex.Message, "#B9"); } service.Dispose (); - - sr.Stop (); } } diff --git a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs index 7eddf3a8ef1..fb9025b2310 100644 --- a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs @@ -79,8 +79,6 @@ namespace MonoTests.System.Net.Sockets { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8765); using (SocketResponder sr = new SocketResponder (localEP, s => CloseRequestHandler (s))) { - sr.Start (); - TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765); NetworkStream ns = tcpClient.GetStream (); Assert.IsNotNull (ns, "#A1"); @@ -106,8 +104,6 @@ namespace MonoTests.System.Net.Sockets } using (SocketResponder sr = new SocketResponder (localEP, s => CloseRequestHandler (s))) { - sr.Start (); - TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765); Assert.AreEqual (0, tcpClient.Available, "#B1"); Assert.IsTrue (tcpClient.Connected, "#B2"); diff --git a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs index 83d291d8f75..ea928e50b30 100644 --- a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs +++ b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs @@ -101,8 +101,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -119,8 +117,6 @@ namespace MonoTests.System.Net response.Close (); rs.Close (); - - responder.Stop (); } } @@ -251,8 +247,6 @@ namespace MonoTests.System.Net foreach (DictionaryEntry de in methods) { using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = (string) de.Key; req.Timeout = 2000; @@ -280,8 +274,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest request; request = (HttpWebRequest) WebRequest.Create (url); @@ -319,8 +311,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; Stream rs; IAsyncResult ar; @@ -375,8 +365,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; req = (HttpWebRequest) WebRequest.Create (url); @@ -472,8 +460,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Abort (); @@ -499,8 +485,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Abort (); @@ -526,8 +510,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.BeginGetRequestStream (null, null); @@ -554,8 +536,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; IAsyncResult ar = req.BeginGetRequestStream (null, null); @@ -584,8 +564,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -610,8 +588,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Timeout = 2000; req.ReadWriteTimeout = 2000; @@ -643,8 +619,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -667,8 +641,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Abort (); @@ -695,8 +667,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; Stream rs; @@ -764,8 +734,6 @@ namespace MonoTests.System.Net // buffered, non-chunked using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; Stream rs; byte [] buffer; @@ -816,8 +784,6 @@ namespace MonoTests.System.Net // buffered, chunked using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; Stream rs; byte [] buffer; @@ -854,8 +820,6 @@ namespace MonoTests.System.Net // non-buffered, non-chunked using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; Stream rs; byte [] buffer; @@ -908,8 +872,6 @@ namespace MonoTests.System.Net // non-buffered, chunked using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req; Stream rs; byte [] buffer; @@ -974,8 +936,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Abort (); @@ -1002,8 +962,6 @@ namespace MonoTests.System.Net string url = "http://" + localEP.ToString () + "/original/"; using (SocketResponder responder = new SocketResponder (localEP, s => RedirectRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.AllowAutoRedirect = false; @@ -1024,7 +982,6 @@ namespace MonoTests.System.Net Assert.AreEqual (WebExceptionStatus.Timeout, ex.Status, "#5"); } } - responder.Stop (); } } @@ -1036,8 +993,6 @@ namespace MonoTests.System.Net // allow autoredirect using (SocketResponder responder = new SocketResponder (localEP, s => RedirectRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -1056,13 +1011,10 @@ namespace MonoTests.System.Net Assert.AreEqual ("GET", resp.Method, "#A3"); Assert.AreEqual ("LOOKS OK", body, "#A4"); } - responder.Stop (); } // do not allow autoredirect using (SocketResponder responder = new SocketResponder (localEP, s => RedirectRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.AllowAutoRedirect = false; @@ -1076,7 +1028,6 @@ namespace MonoTests.System.Net Assert.AreEqual (url, resp.ResponseUri.ToString (), "#B2"); Assert.AreEqual ("POST", resp.Method, "#B3"); } - responder.Stop (); } } @@ -1087,8 +1038,6 @@ namespace MonoTests.System.Net string url = "http://" + localEP.ToString () + "/original/"; using (SocketResponder responder = new SocketResponder (localEP, s => RedirectRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -1107,7 +1056,6 @@ namespace MonoTests.System.Net Assert.AreEqual ("GET", resp.Method, "#A3"); Assert.AreEqual ("LOOKS OK", body, "#A4"); } - responder.Stop (); } } @@ -1118,8 +1066,6 @@ namespace MonoTests.System.Net string url = "http://" + localEP.ToString () + "/original/"; using (SocketResponder responder = new SocketResponder (localEP, s => RedirectRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -1138,7 +1084,6 @@ namespace MonoTests.System.Net Assert.AreEqual ("GET", resp.Method, "#A3"); Assert.AreEqual ("LOOKS OK", body, "#A4"); } - responder.Stop (); } } @@ -1149,8 +1094,6 @@ namespace MonoTests.System.Net string url = "http://" + localEP.ToString () + "/original/"; using (SocketResponder responder = new SocketResponder (localEP, s => RedirectRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -1169,7 +1112,6 @@ namespace MonoTests.System.Net Assert.AreEqual ("GET", resp.Method, "#A3"); Assert.AreEqual ("LOOKS OK", body, "#A4"); } - responder.Stop (); } } @@ -1182,8 +1124,6 @@ namespace MonoTests.System.Net // POST using (SocketResponder responder = new SocketResponder (localEP, s => InternalErrorHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -1206,14 +1146,10 @@ namespace MonoTests.System.Net Assert.AreEqual ("POST", webResponse.Method, "#A7"); webResponse.Close (); } - - responder.Stop (); } // GET using (SocketResponder responder = new SocketResponder (localEP, s => InternalErrorHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -1233,8 +1169,6 @@ namespace MonoTests.System.Net Assert.AreEqual ("GET", webResponse.Method, "#B6"); webResponse.Close (); } - - responder.Stop (); } } @@ -1247,8 +1181,6 @@ namespace MonoTests.System.Net // POST using (SocketResponder responder = new SocketResponder (localEP, s => NoContentLengthHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; req.Timeout = 2000; @@ -1288,14 +1220,10 @@ namespace MonoTests.System.Net HttpWebResponse webResponse = ex.Response as HttpWebResponse; Assert.IsNull (webResponse, "#A11"); } - - responder.Stop (); } // GET using (SocketResponder responder = new SocketResponder (localEP, s => NoContentLengthHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -1317,8 +1245,6 @@ namespace MonoTests.System.Net Assert.AreEqual ("GET", webResponse.Method, "#B6"); webResponse.Close (); } - - responder.Stop (); } } @@ -1329,8 +1255,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/moved/"; using (SocketResponder responder = new SocketResponder (ep, s => VerbEchoHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "WhatEver"; req.KeepAlive = false; @@ -1351,8 +1275,6 @@ namespace MonoTests.System.Net Assert.AreEqual ("WhatEver", resp.Method, "#3"); Assert.AreEqual ("WhatEver", body, "#4"); } - - responder.Stop (); } } @@ -1364,8 +1286,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => NotModifiedSinceHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.KeepAlive = false; @@ -1393,8 +1313,6 @@ namespace MonoTests.System.Net TimeSpan elapsed = DateTime.Now - start; Assert.IsTrue (elapsed.TotalMilliseconds < 2000, "#4"); - - responder.Stop (); } } @@ -1504,11 +1422,7 @@ namespace MonoTests.System.Net using (var responder = new SocketResponder (ep, TimeOutHandler)) { - responder.Start (); - TestTimeOut (url, WebExceptionStatus.Timeout); - - responder.Stop (); } } @@ -2772,8 +2686,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString (); using (SocketResponder responder = new SocketResponder (ep, s => CookieRequestHandler (s))) { - responder.Start (); - CookieContainer container = new CookieContainer (); container.Add(new Uri (url), new Cookie ("foo", "bar")); HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); @@ -2791,8 +2703,6 @@ namespace MonoTests.System.Net } using (SocketResponder responder = new SocketResponder (ep, s => CookieRequestHandler (s))) { - responder.Start (); - CookieContainer container = new CookieContainer (); HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); request.CookieContainer = container; @@ -2860,8 +2770,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -2890,8 +2798,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -2919,8 +2825,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -2943,8 +2847,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -2967,8 +2869,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -2991,8 +2891,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3015,8 +2913,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3044,8 +2940,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3072,8 +2966,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3096,8 +2988,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3124,8 +3014,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3152,8 +3040,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3182,8 +3068,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3212,8 +3096,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3242,8 +3124,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3272,8 +3152,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3302,8 +3180,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3331,8 +3207,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; @@ -3360,8 +3234,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebRequestTest.EchoRequestHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "POST"; diff --git a/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs b/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs index 64136de648a..580c5488907 100644 --- a/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs +++ b/mcs/class/System/Test/System.Net/HttpWebResponseTest.cs @@ -30,8 +30,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -60,8 +58,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -81,8 +77,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -111,8 +105,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -133,8 +125,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -163,8 +153,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -203,8 +191,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -233,8 +219,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -263,8 +247,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -292,8 +274,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -322,8 +302,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -352,8 +330,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -382,8 +358,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -412,8 +386,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -442,8 +414,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -464,8 +434,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -517,8 +485,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -568,8 +534,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -603,8 +567,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -632,8 +594,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -661,8 +621,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -690,8 +648,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -719,8 +675,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -758,8 +712,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -809,8 +761,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -861,8 +811,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -913,8 +861,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -965,8 +911,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -1018,8 +962,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req; req = (HttpWebRequest) WebRequest.Create (url); @@ -1083,8 +1025,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -1112,8 +1052,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; @@ -1146,8 +1084,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) { - responder.Start (); - HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); req.Method = "GET"; req.Timeout = 2000; diff --git a/mcs/class/System/Test/System.Net/WebClientTest.cs b/mcs/class/System/Test/System.Net/WebClientTest.cs index 7f7fad9c467..af3dcff673a 100644 --- a/mcs/class/System/Test/System.Net/WebClientTest.cs +++ b/mcs/class/System/Test/System.Net/WebClientTest.cs @@ -1424,8 +1424,6 @@ namespace MonoTests.System.Net string url = "http://" + ep.ToString () + "/test/"; using (SocketResponder responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - WebClient wc = new WebClient (); wc.Encoding = Encoding.ASCII; @@ -1882,8 +1880,6 @@ namespace MonoTests.System.Net using (var responder = new SocketResponder (ep, s => EchoRequestHandler (s))) { - responder.Start (); - var webClient = new WebClient (); var cancellationTokenSource = new CancellationTokenSource (); diff --git a/mcs/class/test-helpers/SocketResponder.cs b/mcs/class/test-helpers/SocketResponder.cs index 40c9a372473..686aaa0feff 100644 --- a/mcs/class/test-helpers/SocketResponder.cs +++ b/mcs/class/test-helpers/SocketResponder.cs @@ -41,82 +41,47 @@ namespace MonoTests.Helpers public class SocketResponder : IDisposable { private TcpListener tcpListener; - private readonly IPEndPoint _localEndPoint; private Thread listenThread; private Socket listenSocket; - private SocketRequestHandler _requestHandler; - private int _state = 0; - private readonly object _syncRoot = new object (); + private SocketRequestHandler requestHandler; + private bool disposed; private const int SOCKET_CLOSED = 10004; private const int SOCKET_INVALID_ARGS = 10022; - private const int STATE_UNINITIALIZED = 0; - private const int STATE_RUNNING = 1; - private const int STATE_STOPPED = 2; - - public SocketResponder (IPEndPoint localEP, SocketRequestHandler requestHandler) + public SocketResponder (IPEndPoint ep, SocketRequestHandler rh) { - _localEndPoint = localEP; - _requestHandler = requestHandler; - } + requestHandler = rh; - public IPEndPoint LocalEndPoint - { - get { return _localEndPoint; } + tcpListener = new TcpListener (ep); + tcpListener.Start (); + + listenThread = new Thread (new ThreadStart (Listen)); + listenThread.Start (); } public void Dispose () { - Stop (); - } + if (disposed) + return; - public bool IsStopped - { - get - { - lock (_syncRoot) { - return _state != STATE_RUNNING; - } - } - } + disposed = true; - public void Start () - { - lock (_syncRoot) { - if (_state != STATE_UNINITIALIZED) - throw new InvalidOperationException ("cannot restart SocketResponder"); - _state = STATE_RUNNING; - tcpListener = new TcpListener (LocalEndPoint); - tcpListener.Start (); - listenThread = new Thread (new ThreadStart (Listen)); - listenThread.Start (); - } - } + tcpListener.Stop (); - public void Stop () - { - lock (_syncRoot) { - if (_state != STATE_RUNNING) - return; - _state = STATE_STOPPED; - if (tcpListener != null) { - tcpListener.Stop (); - tcpListener = null; - if (listenSocket != null) - listenSocket.Close (); - Thread.Sleep (50); - } - } + if (listenSocket != null) + listenSocket.Close (); + + Thread.Sleep (50); } private void Listen () { - while (_state == STATE_RUNNING) { + while (!disposed) { listenSocket = null; try { listenSocket = tcpListener.AcceptSocket (); - listenSocket.Send (_requestHandler (listenSocket)); + listenSocket.Send (requestHandler (listenSocket)); try { listenSocket.Shutdown (SocketShutdown.Receive); listenSocket.Shutdown (SocketShutdown.Send); @@ -124,11 +89,10 @@ namespace MonoTests.Helpers } } catch (SocketException ex) { // ignore interruption of blocking call - if (ex.ErrorCode != SOCKET_CLOSED && ex.ErrorCode != SOCKET_INVALID_ARGS && _state != STATE_STOPPED) + if (ex.ErrorCode != SOCKET_CLOSED && ex.ErrorCode != SOCKET_INVALID_ARGS && !disposed) throw; } catch (ObjectDisposedException ex) { - Console.WriteLine (ex); - if (_state != STATE_STOPPED) + if (!disposed) throw; #if MOBILE } catch (InvalidOperationException ex) { |