public override int EndRead(IAsyncResult asyncResult) { SynchronousReadAsyncResult syncResult = this.syncReadResult; if (ReferenceEquals(asyncResult, syncResult)) { return(syncResult.BytesRead); } Contract.Assert(!((Task <int>)asyncResult).IsCanceled); try { return(((Task <int>)asyncResult).Result); } catch (AggregateException ex) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); throw; // unreachable } finally { this.readCompletionSource = null; this.readCallback = null; this.sslOwnedBuffer = default(ArraySegment <byte>); } }
IAsyncResult PrepareSyncReadResult(int readBytes, object state) { // it is safe to reuse sync result object as it can't lead to leak (no way to attach to it via handle) SynchronousReadAsyncResult result = this.syncReadResult; result.BytesRead = readBytes; result.AsyncState = state; return(result); }
public MediationStream(TlsHandler owner) { this.syncReadResult = new SynchronousReadAsyncResult(); this.owner = owner; }