From 60e12907d2bc8908c77754573b8a3364a6bfee68 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Thu, 16 Apr 2020 20:34:26 +0200 Subject: [System.Net.Http]: Disable exception filters on watchOS. (#398) --- .../src/System/Net/Http/HttpContent.cs | 33 ++++++++++++++++++++++ .../ChunkedEncodingReadStream.cs | 22 +++++++++++++++ .../ConnectionCloseReadStream.cs | 22 +++++++++++++++ .../SocketsHttpHandler/ContentLengthReadStream.cs | 22 +++++++++++++++ .../Net/Http/SocketsHttpHandler/HttpConnection.cs | 12 ++++++++ .../Http/SocketsHttpHandler/HttpConnectionPool.cs | 14 +++++++++ .../Http/SocketsHttpHandler/RawConnectionStream.cs | 33 ++++++++++++++++++++++ 7 files changed, 158 insertions(+) diff --git a/src/System.Net.Http/src/System/Net/Http/HttpContent.cs b/src/System.Net.Http/src/System/Net/Http/HttpContent.cs index 740347a083..fe424798d4 100644 --- a/src/System.Net.Http/src/System/Net/Http/HttpContent.cs +++ b/src/System.Net.Http/src/System/Net/Http/HttpContent.cs @@ -337,10 +337,21 @@ namespace System.Net.Http return CopyToAsyncCore(new ValueTask(task)); } } +#if MONOTOUCH_WATCH + catch (Exception e) + { + if (StreamCopyExceptionNeedsWrapping(e)) + { + return Task.FromException(GetStreamCopyException(e)); + } + throw; + } +#else catch (Exception e) when (StreamCopyExceptionNeedsWrapping(e)) { return Task.FromException(GetStreamCopyException(e)); } +#endif } private static async Task CopyToAsyncCore(ValueTask copyTask) @@ -349,10 +360,21 @@ namespace System.Net.Http { await copyTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception e) + { + if (StreamCopyExceptionNeedsWrapping(e)) + { + throw GetStreamCopyException(e); + } + throw; + } +#else catch (Exception e) when (StreamCopyExceptionNeedsWrapping(e)) { throw GetStreamCopyException(e); } +#endif } public Task CopyToAsync(Stream stream) @@ -403,10 +425,21 @@ namespace System.Net.Http CheckTaskNotNull(task); return LoadIntoBufferAsyncCore(task, tempBuffer); } +#if MONOTOUCH_WATCH + catch (Exception e) + { + if (StreamCopyExceptionNeedsWrapping(e)) + { + return Task.FromException(GetStreamCopyException(e)); + } + throw; + } +#else catch (Exception e) when (StreamCopyExceptionNeedsWrapping(e)) { return Task.FromException(GetStreamCopyException(e)); } +#endif // other synchronous exceptions from SerializeToStreamAsync/CheckTaskNotNull will propagate } diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingReadStream.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingReadStream.cs index fdf7d48e56..d10a2233dc 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingReadStream.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ChunkedEncodingReadStream.cs @@ -115,10 +115,21 @@ namespace System.Net.Http } } } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); @@ -161,10 +172,21 @@ namespace System.Net.Http await _connection.FillAsync().ConfigureAwait(false); } } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionCloseReadStream.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionCloseReadStream.cs index 1506cdf2b8..7471a07ce4 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionCloseReadStream.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectionCloseReadStream.cs @@ -39,10 +39,21 @@ namespace System.Net.Http { bytesRead = await readTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); @@ -100,10 +111,21 @@ namespace System.Net.Http { await copyTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ContentLengthReadStream.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ContentLengthReadStream.cs index cbf51b0424..9c90a419f4 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ContentLengthReadStream.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ContentLengthReadStream.cs @@ -51,10 +51,21 @@ namespace System.Net.Http { bytesRead = await readTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); @@ -115,10 +126,21 @@ namespace System.Net.Http { await copyTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); 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 e7ffaef7bc..6374d98241 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 @@ -158,11 +158,23 @@ namespace System.Net.Http { return _socket.Poll(0, SelectMode.SelectRead); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (e is SocketException || e is ObjectDisposedException) + { + // Poll can throw when used on a closed socket. + return true; + } + throw; + } +#else catch (Exception e) when (e is SocketException || e is ObjectDisposedException) { // Poll can throw when used on a closed socket. return true; } +#endif } else { diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs index 13bcd87f19..c2df0a38e4 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs @@ -295,10 +295,24 @@ namespace System.Net.Http { return await SendWithNtConnectionAuthAsync((HttpConnection)connection, request, doRequestAuth, cancellationToken).ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (HttpRequestException e) + { + if (!isNewConnection && e.InnerException is IOException && connection.CanRetry) + { + // Eat exception and try again. + } + else + { + throw; + } + } +#else catch (HttpRequestException e) when (!isNewConnection && e.InnerException is IOException && connection.CanRetry) { // Eat exception and try again. } +#endif finally { connection.Release(); diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs index 6eba9babd3..b32ae62834 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RawConnectionStream.cs @@ -39,10 +39,21 @@ namespace System.Net.Http { bytesRead = await readTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); @@ -95,10 +106,21 @@ namespace System.Net.Http { await copyTask.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); @@ -168,10 +190,21 @@ namespace System.Net.Http { await task.ConfigureAwait(false); } +#if MONOTOUCH_WATCH + catch (Exception exc) + { + if (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) + { + throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); + } + throw; + } +#else catch (Exception exc) when (CancellationHelper.ShouldWrapInOperationCanceledException(exc, cancellationToken)) { throw CancellationHelper.CreateOperationCanceledException(exc, cancellationToken); } +#endif finally { ctr.Dispose(); -- cgit v1.2.3