diff options
author | Martin Baulig <mabaul@microsoft.com> | 2020-01-08 16:54:10 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2020-01-08 16:54:10 +0300 |
commit | 040fc1343f38e54ee16aef83728162ff87775b7a (patch) | |
tree | 24e66df5e9b28c60470925ffcdfacb154f786d91 | |
parent | 94e8ec61f6c9b30834d5a868e7dcdf4ff3321d10 (diff) |
Add workaround for mono/mono#17710. (#387)
Mono-specific workaround of https://github.com/mono/mono/issues/17710.
-rw-r--r-- | src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs | 13 | ||||
-rw-r--r-- | src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ConnectionReuse.cs | 65 |
2 files changed, 78 insertions, 0 deletions
diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs index 9701716f1a..e7ffaef7bc 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnection.cs @@ -193,6 +193,19 @@ namespace System.Net.Http _readAheadTask = new ValueTask<int>(0); } +#if MONO + if (!_readAheadTask.Value.IsCompleted && _socket != null) + { + try + { + return _socket.Poll(0, SelectMode.SelectRead); + } + catch + { + return false; + } + } +#endif return _readAheadTask.Value.IsCompleted; // equivalent to polling } diff --git a/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ConnectionReuse.cs b/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ConnectionReuse.cs new file mode 100644 index 0000000000..b17839048b --- /dev/null +++ b/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ConnectionReuse.cs @@ -0,0 +1,65 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Net.Sockets; +using System.Net.Test.Common; +using System.Text; +using System.Threading.Tasks; + +#if !MONO +using Microsoft.DotNet.XUnitExtensions; +using Microsoft.DotNet.RemoteExecutor; +#endif + +using Xunit; +using Xunit.Abstractions; + +namespace System.Net.Http.Functional.Tests +{ + using Configuration = System.Net.Test.Common.Configuration; + + public class HttpClientHandler_ConnectionReuse_Test : HttpClientTestBase + { + [Fact] + public async Task Test17710() + { + using (HttpClient client = CreateHttpClient()) + { + const string text = "THE POST CONTENT"; + var data = new StringContent(text); + await LoopbackServer.CreateServerAsync(async (server, url) => + { + Task serverTask1 = server.AcceptConnectionAsync(async connection1 => + { + await connection1.ReadRequestHeaderAsync(); + var buffer = new char[text.Length]; + var ret = await connection1.Reader.ReadBlockAsync(buffer, 0, buffer.Length); + Assert.Equal(text.Length, ret); + await connection1.SendResponseAsync(HttpStatusCode.OK, null, "hello"); + await Task.Delay(500); + connection1.Dispose(); + }); + + await client.PostAsync(url, data); + + await serverTask1; + + Task serverTask2 = server.AcceptConnectionAsync(async connection2 => + { + await connection2.ReadRequestHeaderAsync(); + var buffer = new char[text.Length]; + var ret = await connection2.Reader.ReadBlockAsync(buffer, 0, buffer.Length); + Assert.Equal(text.Length, ret); + await connection2.SendResponseAsync(HttpStatusCode.OK, null, "hello"); + await Task.Delay(500); + connection2.Dispose(); + }); + + await client.PostAsync(url, data); + }); + } + } + } +} |