Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
            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?
            }
Ejemplo n.º 3
0
            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;
                }
            }
Ejemplo n.º 4
0
        protected FABSocketChannelAsyncOperation PrepareWriteOperation(IList <ArraySegment <byte> > buffers)
        {
            FABSocketChannelAsyncOperation operation = this.WriteOperation;

            operation.BufferList = buffers;
            return(operation);
        }
Ejemplo n.º 5
0
        protected FABSocketChannelAsyncOperation PrepareWriteOperation(ArraySegment <byte> buffer)
        {
            FABSocketChannelAsyncOperation operation = this.WriteOperation;

            operation.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
            return(operation);
        }
Ejemplo n.º 6
0
        protected void ResetWriteOperation()
        {
            FABSocketChannelAsyncOperation operation = this.writeOperation;

            Contract.Assert(operation != null);
            if (operation.BufferList == null)
            {
                operation.SetBuffer(null, 0, 0);
            }
            else
            {
                operation.BufferList = null;
            }
        }
Ejemplo n.º 7
0
 protected abstract void DoFinishConnect(FABSocketChannelAsyncOperation operation);
Ejemplo n.º 8
0
 public abstract void FinishRead(FABSocketChannelAsyncOperation operation);