public static bool End(IAsyncResult result, out RequestContext context) { MultipleReceiveAsyncResult thisPtr = AsyncResult.End <MultipleReceiveAsyncResult>(result); context = thisPtr.RequestContext; return(thisPtr.Valid); }
void HandleReceiveRequestComplete(IAsyncResult innerResult, bool completedSynchronously) { MultipleReceiveAsyncResult receiveResult = this.outstanding; Exception completionException = null; try { Fx.AssertAndThrow(receiveResult != null, "HandleReceive invoked without an outstanding result"); // Cleanup states this.outstanding = null; // set the context on the outer result for the ChannelHandler. RequestContext context; receiveResult.Valid = this.channelBinder.EndTryReceive(innerResult, out context); receiveResult.RequestContext = context; } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } completionException = ex; } receiveResult.Complete(completedSynchronously, completionException); }
public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult result2; Fx.AssertAndThrow(this.outstanding == null, "BeginTryReceive should not have a pending result."); MultipleReceiveAsyncResult result = new MultipleReceiveAsyncResult(callback, state); this.outstanding = result; this.EnsurePump(timeout); if (this.pendingResults.TryDequeueHead(out result2)) { this.HandleReceiveRequestComplete(result2, true); } return(result); }
public IAsyncResult BeginTryReceive(TimeSpan timeout, AsyncCallback callback, object state) { // At anytime there can be only one thread in BeginTryReceive and the // outstanding AsyncResult should have completed before the next one. // There should be no pending oustanding result here. Fx.AssertAndThrow(this.outstanding == null, "BeginTryReceive should not have a pending result."); MultipleReceiveAsyncResult multipleReceiveResult = new MultipleReceiveAsyncResult(callback, state); this.outstanding = multipleReceiveResult; EnsurePump(timeout); IAsyncResult innerResult; if (this.pendingResults.TryDequeueHead(out innerResult)) { HandleReceiveRequestComplete(innerResult, true); } return multipleReceiveResult; }
private void HandleReceiveRequestComplete(IAsyncResult innerResult, bool completedSynchronously) { MultipleReceiveAsyncResult outstanding = this.outstanding; Exception completionException = null; try { RequestContext context; Fx.AssertAndThrow(outstanding != null, "HandleReceive invoked without an outstanding result"); this.outstanding = null; outstanding.Valid = this.channelBinder.EndTryReceive(innerResult, out context); outstanding.RequestContext = context; } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } completionException = exception2; } outstanding.Complete(completedSynchronously, completionException); }
public bool EndTryReceive(IAsyncResult result, out RequestContext requestContext) { return(MultipleReceiveAsyncResult.End(result, out requestContext)); }