protected override void BeginSend(IWriteRequest request, IoBuffer buf)
 {
     EndPoint destination = request.Destination;
     if (destination == null)
         destination = this.RemoteEndPoint;
     BeginSend(buf, destination);
 }
Example #2
0
 /// <inheritdoc/>
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     if (IsBlocked(session))
         BlockSession(session);
     else
         // forward if not blocked
         base.MessageSent(nextFilter, session, writeRequest);
 }
 private static IList<IWriteRequest> AsRequestList(IWriteRequest request)
 {
     if (request == null)
         throw new ArgumentNullException("request");
     List<IWriteRequest> requests = new List<IWriteRequest>(1);
     requests.Add(request);
     return requests.AsReadOnly();
 }
 /// <inheritdoc/>
 public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     IoBuffer buf = writeRequest.Message as IoBuffer;
     if (buf == null)
         throw new ArgumentException("This filter should only buffer IoBuffer objects");
     else
         Write(session, buf);
 }
Example #5
0
        /// <inheritdoc/>
        protected override void BeginSend(IWriteRequest request, IoBuffer buf)
        {
            _writeBuffer.Clear();

            SocketAsyncEventArgs saea;
            SocketAsyncEventArgsBuffer saeaBuf = buf as SocketAsyncEventArgsBuffer;
            if (saeaBuf == null)
            {
                if (_writeBuffer.Remaining < buf.Remaining)
                {
                    Int32 oldLimit = buf.Limit;
                    buf.Limit = buf.Position + _writeBuffer.Remaining;
                    _writeBuffer.Put(buf);
                    buf.Limit = oldLimit;
                }
                else
                {
                    _writeBuffer.Put(buf);
                }
                _writeBuffer.Flip();
                saea = _writeBuffer.SocketAsyncEventArgs;
                saea.SetBuffer(saea.Offset + _writeBuffer.Position, _writeBuffer.Limit);
            }
            else
            {
                saea = saeaBuf.SocketAsyncEventArgs;
                saea.Completed += _completeHandler;
            }

            Boolean willRaiseEvent;
            try
            {
                willRaiseEvent = Socket.SendAsync(saea);
            }
            catch (ObjectDisposedException)
            {
                // do nothing
                return;
            }
            catch (Exception ex)
            {
                EndSend(ex);
                return;
            }
            if (!willRaiseEvent)
            {
                ProcessSend(saea);
            }
        }
 /// <inheritdoc/>
 protected override void BeginSendFile(IWriteRequest request, IFileRegion file)
 {
     try
     {
         Socket.BeginSendFile(file.FullName, SendFileCallback, new SendingContext(Socket, file));
     }
     catch (ObjectDisposedException)
     {
         // ignore
     }
     catch (Exception ex)
     {
         EndSend(ex);
     }
 }
Example #7
0
        /// <inheritdoc/>
        public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            IoEvent ioe = new IoEvent(IoEventType.Write, session, writeRequest);
            if (_queueHandler.Accept(this, ioe))
            {
                nextFilter.FilterWrite(session, writeRequest);
                IWriteFuture writeFuture = writeRequest.Future;
                if (writeFuture == null)
                    return;

                // We can track the write request only when it has a future.
                _queueHandler.Offered(this, ioe);
                writeFuture.Complete += (s, e) => _queueHandler.Polled(this, ioe);
            }
        }
 /// <inheritdoc/>
 protected override void BeginSend(IWriteRequest request, IoBuffer buf)
 {
     ArraySegment<Byte> array = buf.GetRemaining();
     try
     {
         Socket.BeginSend(array.Array, array.Offset, array.Count, SocketFlags.None, SendCallback, new SendingContext(Socket, buf));
     }
     catch (ObjectDisposedException)
     {
         // ignore
     }
     catch (Exception ex)
     {
         EndSend(ex);
     }
 }
            public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
            {
                _counter++;

                IoBuffer buf = writeRequest.Message as IoBuffer;
                if (buf == null)
                    throw new AssertFailedException("Wrong message type");
                if (_counter == 3)
                {
                    Assert.AreEqual(1, buf.Limit);
                    Assert.AreEqual(0, buf.Get());
                }
                else
                {
                    Assert.AreEqual(10, buf.Limit);
                }
            }
        public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
        {
            var buf = writeRequest.Message as IoBuffer;
            if (buf != null && buf.Remaining != 0)
            {
                var length = buf.Remaining + Magic.Length;
                if (length < 0)
                    throw new ArgumentOutOfRangeException("length", "length is less than zero");

                var @out = IoBuffer.Allocate(length);
                Magic.WriteMagic(@out);
                @out.Put(buf);
                @out.Flip();
                base.FilterWrite(
                    nextFilter, session, new ProtocolCodecFilter.EncodedWriteRequest(@out, null, writeRequest.Destination));
            }
            else
                base.FilterWrite(nextFilter, session, writeRequest);
        }
        /// <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);
        }
Example #12
0
 /// <summary>
 /// </summary>
 public WriteRequestWrapper(IWriteRequest request)
 {
     if (request == null)
         throw new ArgumentNullException("request");
     _inner = request;
 }
Example #13
0
 /// <inheritdoc/>
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     Profile(_profileMessageSent, _messageSentTimerWorker, () => nextFilter.MessageSent(session, writeRequest));
 }
Example #14
0
 public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     test.testResult += id + "FW";
     nextFilter.FilterWrite(session, writeRequest);
 }
Example #15
0
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     test.testResult += id + "MS";
     nextFilter.MessageSent(session, writeRequest);
 }
Example #16
0
        public void ScheduleFilterWrite(INextFilter nextFilter, IWriteRequest writeRequest)
        {
            if (!_authenticated)
            {
                if (_session.Connected)
                {
                    // Handshake not complete yet.
                    _preHandshakeEventQueue.Enqueue(new IoFilterEvent(nextFilter, IoEventType.Write, _session, writeRequest));
                }
                return;
            }

            IoBuffer buf = (IoBuffer)writeRequest.Message;
            lock (this)
            {
                ArraySegment<Byte> array = buf.GetRemaining();
                _currentNextFilter = nextFilter;
                _currentWriteRequest = writeRequest;
                // SSL encrypt
                _sslStream.Write(array.Array, array.Offset, array.Count);
            }
        }
 public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     _filter.FilterWrite(nextFilter, session, writeRequest);
 }
Example #18
0
 /// <inheritdoc/>
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     Filter(new IoFilterEvent(nextFilter, IoEventType.MessageSent, session, writeRequest));
 }
Example #19
0
 /// <inheritdoc/>
 public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     Filter(new IoFilterEvent(nextFilter, IoEventType.Write, session, writeRequest));
 }
Example #20
0
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     EncryptedWriteRequest encryptedWriteRequest = writeRequest as EncryptedWriteRequest;
     if (encryptedWriteRequest == null)
     {
         // ignore extra buffers used for handshaking
     }
     else
     {
         base.MessageSent(nextFilter, session, encryptedWriteRequest.InnerRequest);
     }
 }
Example #21
0
 private void FireMessageSent(IWriteRequest req)
 {
     CurrentWriteRequest = null;
     try
     {
         this.FilterChain.FireMessageSent(req);
     }
     catch (Exception ex)
     {
         this.FilterChain.FireExceptionCaught(ex);
     }
 }
Example #22
0
 /// <inheritdoc/>
 public virtual void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     nextFilter.MessageSent(session, writeRequest);
 }
Example #23
0
 public override void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     SslHandler handler = GetSslSessionHandler(session);
     handler.ScheduleFilterWrite(nextFilter, writeRequest);
 }
Example #24
0
        /// <inheritdoc/>
        protected override void BeginSendFile(IWriteRequest request, IFileRegion file)
        {
            SocketAsyncEventArgs saea = _writeBuffer.SocketAsyncEventArgs;
            saea.SendPacketsElements = new SendPacketsElement[] {
                new SendPacketsElement(file.FullName)
            };

            Boolean willRaiseEvent;
            try
            {
                willRaiseEvent = Socket.SendPacketsAsync(saea);
            }
            catch (ObjectDisposedException)
            {
                // do nothing
                return;
            }
            catch (Exception ex)
            {
                EndSend(ex);
                return;
            }
            if (!willRaiseEvent)
            {
                ProcessSend(saea);
            }
        }
Example #25
0
 /// <inheritdoc/>
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     Object message = writeRequest.Message;
     if (!IsKeepAliveMessage(session, message))
         nextFilter.MessageSent(session, writeRequest);
 }
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     _filter.MessageSent(nextFilter, session, writeRequest);
 }
Example #27
0
 protected abstract void BeginSend(IWriteRequest request, IoBuffer buf);
Example #28
0
 public EncryptedWriteRequest(IWriteRequest writeRequest, IoBuffer encryptedMessage)
     : base(writeRequest)
 {
     _encryptedMessage = encryptedMessage;
 }
Example #29
0
 /// <inheritdoc/>
 public virtual void FilterWrite(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     nextFilter.FilterWrite(session, writeRequest);
 }
Example #30
0
 protected abstract void BeginSendFile(IWriteRequest request, IFileRegion file);