using System.Threading.Tasks;
using System.IO;
using System.Net;
+using System.Runtime.ExceptionServices;
#if XAMCORE_4_0
using CFNetwork;
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
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 ();
}
}
data_mutex.WaitOne ();
data = null;
+ this.http_stream.ErrorEvent -= HandleErrorEvent;
data_mutex.ReleaseMutex ();
data_event.Set ();
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 ();