protected override void DoClose() { TaskCompletionSource promise = this.connectPromise; if (promise != null) { // Use TrySetException() instead of SetException() to avoid the race against cancellation due to timeout. promise.TrySetException(new ClosedChannelException()); this.connectPromise = null; } IScheduledTask cancellationTask = this.connectCancellationTask; if (cancellationTask != null) { cancellationTask.Cancel(); this.connectCancellationTask = null; } FABSocketChannelAsyncOperation readOp = this.readOperation; if (readOp != null) { readOp.Dispose(); this.readOperation = null; } FABSocketChannelAsyncOperation writeOp = this.writeOperation; if (writeOp != null) { writeOp.Dispose(); this.writeOperation = null; } }
public void FinishWrite(FABSocketChannelAsyncOperation operation) { bool resetWritePending = this.Channel.TryResetState(StateFlags.WriteScheduled); Contract.Assert(resetWritePending); FABChannelOutboundBuffer input = this.OutboundBuffer; try { operation.Validate(); int sent = operation.BytesTransferred; this.Channel.ResetWriteOperation(); if (sent > 0) { input.RemoveBytes(sent); } } catch (Exception ex) { Util.CompleteChannelCloseTaskSafely(this.channel, this.CloseAsync(new ClosedChannelException("Failed to write", ex), false)); } // Double check if there's no pending flush // See https://github.com/Azure/DotNetty/issues/218 this.Flush0(); // todo: does it make sense now that we've actually written out everything that was flushed previously? concurrent flush handling? }
public void FinishConnect(FABSocketChannelAsyncOperation operation) { Contract.Assert(this.channel.EventLoop.InEventLoop); FABSocketChannel ch = this.Channel; try { bool wasActive = ch.Active; ch.DoFinishConnect(operation); this.FulfillConnectPromise(wasActive); } catch (Exception ex) { TaskCompletionSource promise = ch.connectPromise; var remoteAddress = (EndPoint)promise.Task.AsyncState; this.FulfillConnectPromise(this.AnnotateConnectException(ex, remoteAddress)); } finally { // Check for null as the connectTimeoutFuture is only created if a connectTimeoutMillis > 0 is used // See https://github.com/netty/netty/issues/1770 if (ch.connectCancellationTask != null) { ch.connectCancellationTask.Cancel(); } ch.connectPromise = null; } }
protected FABSocketChannelAsyncOperation PrepareWriteOperation(IList <ArraySegment <byte> > buffers) { FABSocketChannelAsyncOperation operation = this.WriteOperation; operation.BufferList = buffers; return(operation); }
protected FABSocketChannelAsyncOperation PrepareWriteOperation(ArraySegment <byte> buffer) { FABSocketChannelAsyncOperation operation = this.WriteOperation; operation.SetBuffer(buffer.Array, buffer.Offset, buffer.Count); return(operation); }
protected void ResetWriteOperation() { FABSocketChannelAsyncOperation operation = this.writeOperation; Contract.Assert(operation != null); if (operation.BufferList == null) { operation.SetBuffer(null, 0, 0); } else { operation.BufferList = null; } }
protected abstract void DoFinishConnect(FABSocketChannelAsyncOperation operation);
public abstract void FinishRead(FABSocketChannelAsyncOperation operation);