예제 #1
0
        /// <inheritdoc/>
        public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            if (_manipulateWrites)
            {
                // manipulate bytes
                IoBuffer buf = writeRequest.Message as IoBuffer;
                if (buf != null)
                {
                    ManipulateIoBuffer(session, buf);
                    IoBuffer buffer = InsertBytesToNewIoBuffer(session, buf);
                    if (buffer != null)
                    {
                        writeRequest = new DefaultWriteRequest(buffer, writeRequest.Future);
                    }
                    // manipulate PDU
                }
                else
                {
                    if (_duplicatePduProbability > _rng.Next())
                    {
                        nextFilter.FilterWrite(session, writeRequest);
                    }

                    if (_resendPduLasterProbability > _rng.Next())
                    {
                        // store it somewhere and trigger a write execution for
                        // later
                        // TODO
                    }
                    if (_removePduProbability > _rng.Next())
                    {
                        return;
                    }
                }
            }

            base.FilterWrite(nextFilter, session, writeRequest);
        }
예제 #2
0
 private void WriteBuffer(IoBuffer buf)
 {
     IWriteRequest writeRequest;
     if (_authenticated)
         writeRequest = new SslFilter.EncryptedWriteRequest(_currentWriteRequest, buf);
     else
         writeRequest = new DefaultWriteRequest(buf);
     _currentNextFilter.FilterWrite(_session, writeRequest);
 }
예제 #3
0
            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;
            }