public static IWriteFuture NewNotWrittenFuture(IoSession session, Exception cause)
 {
     DefaultWriteFuture unwrittenFuture = new DefaultWriteFuture(session);
     unwrittenFuture.Exception = cause;
     return unwrittenFuture;
 }
 public static IWriteFuture NewWrittenFuture(IoSession session)
 {
     DefaultWriteFuture writtenFuture = new DefaultWriteFuture(session);
     writtenFuture.Written = true;
     return writtenFuture;
 }
            public override IWriteFuture Flush()
            {
                IQueue<Object> bufferQueue = MessageQueue;
                IWriteFuture future = null;

                while (!bufferQueue.IsEmpty)
                {
                    Object encodedMessage = bufferQueue.Dequeue();

                    if (encodedMessage == null)
                        break;

                    // Flush only when the buffer has remaining.
                    IoBuffer buf = encodedMessage as IoBuffer;
                    if (buf == null || buf.HasRemaining)
                    {
                        future = new DefaultWriteFuture(_session);
                        _nextFilter.FilterWrite(_session, new EncodedWriteRequest(encodedMessage, future, _destination));
                    }
                }

                if (future == null)
                {
                    // Creates an empty writeRequest containing the destination
                    IWriteRequest writeRequest = new DefaultWriteRequest(DefaultWriteRequest.EmptyMessage, null, _destination);
                    future = DefaultWriteFuture.NewNotWrittenFuture(_session, new NothingWrittenException(writeRequest));
                }

                return future;
            }