diff options
author | Manuel de la Pena <mandel@microsoft.com> | 2017-04-24 23:46:14 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-04-26 15:46:37 +0300 |
commit | 8b35ee723765921debc55ca71fe087c7dc58ae02 (patch) | |
tree | 789b15a8a6855dcf5a2343e5f65c5c419e947500 /mcs/class/System.Net.Http | |
parent | 390e75170b803fbb8c1d0255fb8152762b0a31b6 (diff) |
Make changes as per review to make the code more thread safe.
Diffstat (limited to 'mcs/class/System.Net.Http')
-rw-r--r-- | mcs/class/System.Net.Http/CFContentStream.cs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/mcs/class/System.Net.Http/CFContentStream.cs b/mcs/class/System.Net.Http/CFContentStream.cs index d639ae2a29f..a5d237d1530 100644 --- a/mcs/class/System.Net.Http/CFContentStream.cs +++ b/mcs/class/System.Net.Http/CFContentStream.cs @@ -30,6 +30,7 @@ using System.Threading; using System.Threading.Tasks; using System.IO; using System.Net; +using System.Runtime.ExceptionServices; #if XAMCORE_4_0 using CFNetwork; @@ -57,7 +58,7 @@ namespace System.Net.Http Mutex data_mutex; AutoResetEvent data_event; AutoResetEvent data_read_event; - Exception http_exception = null; + ExceptionDispatchInfo http_exception; // The requirements are: // * We must read at least one byte from the stream every time @@ -96,7 +97,7 @@ namespace System.Net.Http if (gotMutex) { var stream = (CFHTTPStream)sender; if (e.EventType == CFStreamEventType.ErrorOccurred) - http_exception = stream.GetError (); + Volatile.Write (http_exception, ExceptionDispatchInfo.Capture (stream.GetError ())); data_mutex.ReleaseMutex (); } } @@ -118,6 +119,7 @@ namespace System.Net.Http data_mutex.WaitOne (); data = null; + this.http_stream.ErrorEvent -= HandleErrorEvent; data_mutex.ReleaseMutex (); data_event.Set (); @@ -128,8 +130,9 @@ namespace System.Net.Http while (data_event.WaitOne ()) { data_mutex.WaitOne (); if (http_exception != null) { + http_exception.Throw (); data_mutex.ReleaseMutex (); - throw http_exception; + break; } if (data == null || data.Length <= 0) { data_mutex.ReleaseMutex (); |