void Discard(Exception cause = null) { for (;;) { PendingWrite current = this.currentWrite; if (this.currentWrite == null) { current = this.queue.Count > 0 ? this.queue.Dequeue() : null; } else { this.currentWrite = null; } if (current == null) { break; } object message = current.Message; var chunks = message as IChunkedInput <T>; if (chunks != null) { try { if (!chunks.IsEndOfInput) { if (cause == null) { cause = new ClosedChannelException(); } current.Fail(cause); } else { current.Success(); } } catch (Exception exception) { current.Fail(exception); Logger.Warn($"{StringUtil.SimpleClassName(typeof(ChunkedWriteHandler<T>))}.IsEndOfInput failed", exception); } finally { CloseInput(chunks); } } else { if (cause == null) { cause = new ClosedChannelException(); } current.Fail(cause); } } }
private static void HandleEndOfInputFuture(Task task, PendingWrite currentWrite) { if (task.IsSuccess()) { var chunks = (IChunkedInput <T>)currentWrite.Message; // read state of the input in local variables before closing it long inputProgress = chunks.Progress; long inputLength = chunks.Length; CloseInput(chunks); currentWrite.Progress(inputProgress, inputLength); currentWrite.Success(inputLength); } else { CloseInput((IChunkedInput <T>)currentWrite.Message); currentWrite.Fail(task.Exception); } }