Пример #1
0
        public override void HandleFrame(InboundFrame frame)
        {
            lock (_closingLock)
            {
                if (!_closing)
                {
                    base.HandleFrame(frame);
                    return;
                }
            }

            if (!_closeServerInitiated && frame.IsMethod())
            {
                MethodBase method = Connection.Protocol.DecodeMethodFrom(frame.Payload);
                if ((method.ProtocolClassId == _closeClassId) &&
                    (method.ProtocolMethodId == _closeMethodId))
                {
                    base.HandleFrame(frame);
                    return;
                }

                if ((method.ProtocolClassId == _closeOkClassId) &&
                    (method.ProtocolMethodId == _closeOkMethodId))
                {
                    // This is the reply (CloseOk) we were looking for
                    // Call any listener attached to this session
                    Handler();
                }
            }

            // Either a non-method frame, or not what we were looking
            // for. Ignore it - we're quiescing.
        }
        public override Task HandleFrame(InboundFrame frame)
        {
            if (!m_closing)
            {
                return(base.HandleFrame(frame));
            }

            if (!m_closeServerInitiated && (frame.IsMethod()))
            {
                MethodBase method = Connection.Protocol.DecodeMethodFrom(frame.GetReader());
                if ((method.ProtocolClassId == m_closeClassId) &&
                    (method.ProtocolMethodId == m_closeMethodId))
                {
                    return(base.HandleFrame(frame));
                }

                if ((method.ProtocolClassId == m_closeOkClassId) &&
                    (method.ProtocolMethodId == m_closeOkMethodId))
                {
                    // This is the reply (CloseOk) we were looking for
                    // Call any listener attached to this session
                    Handler();
                }
            }

            // Either a non-method frame, or not what we were looking
            // for. Ignore it - we're quiescing.
            return(Task.CompletedTask);
        }
Пример #3
0
        public override void HandleFrame(InboundFrame frame)
        {
            if (frame.IsMethod())
            {
                MethodBase method = Connection.Protocol.DecodeMethodFrom(frame.GetReader());
                if ((method.ProtocolClassId == ChannelCloseOk.ClassId) &&
                    (method.ProtocolMethodId == ChannelCloseOk.MethodId))
                {
                    // This is the reply we were looking for. Release
                    // the channel with the reason we were passed in
                    // our constructor.
                    Close(m_reason);
                }
                else if ((method.ProtocolClassId == ChannelClose.ClassId) &&
                         (method.ProtocolMethodId == ChannelClose.MethodId))
                {
                    // We're already shutting down the channel, so
                    // just send back an ok.
                    Transmit(CreateChannelCloseOk());
                }
            }

            // Either a non-method frame, or not what we were looking
            // for. Ignore it - we're quiescing.
        }
Пример #4
0
        public Command HandleFrame(InboundFrame f)
        {
            switch (m_state)
            {
            case AssemblyState.ExpectingMethod:
            {
                if (!f.IsMethod())
                {
                    throw new UnexpectedFrameException(f);
                }
                m_command.Method = m_protocol.DecodeMethodFrom(f.GetReader());
                m_state          = m_command.Method.HasContent
                        ? AssemblyState.ExpectingContentHeader
                        : AssemblyState.Complete;
                return(CompletedCommand());
            }

            case AssemblyState.ExpectingContentHeader:
            {
                if (!f.IsHeader())
                {
                    throw new UnexpectedFrameException(f);
                }
                NetworkBinaryReader reader = f.GetReader();
                m_command.Header     = m_protocol.DecodeContentHeaderFrom(reader);
                m_remainingBodyBytes = m_command.Header.ReadFrom(reader);
                UpdateContentBodyState();
                return(CompletedCommand());
            }

            case AssemblyState.ExpectingContentBody:
            {
                if (!f.IsBody())
                {
                    throw new UnexpectedFrameException(f);
                }
                m_command.AppendBodyFragment(f.Payload);
                if ((ulong)f.Payload.Length > m_remainingBodyBytes)
                {
                    throw new MalformedFrameException
                              (string.Format("Overlong content body received - {0} bytes remaining, {1} bytes received",
                                             m_remainingBodyBytes,
                                             f.Payload.Length));
                }
                m_remainingBodyBytes -= (ulong)f.Payload.Length;
                UpdateContentBodyState();
                return(CompletedCommand());
            }

            case AssemblyState.Complete:
            default:
#if NETFX_CORE
                Debug.WriteLine("Received frame in invalid state {0}; {1}", m_state, f);
#else
                //Trace.Fail(string.Format("Received frame in invalid state {0}; {1}", m_state, f));
#endif
                return(null);
            }
        }
Пример #5
0
 public override void HandleFrame(InboundFrame frame)
 {
     using Command cmd = _assembler.HandleFrame(frame);
     if (cmd != null)
     {
         OnCommandReceived(cmd);
     }
 }
Пример #6
0
        public override async Task HandleFrame(InboundFrame frame)
        {
            Command cmd = m_assembler.HandleFrame(frame);

            if (cmd != null)
            {
                await OnCommandReceived(cmd);
            }
        }
Пример #7
0
        public Command HandleFrame(InboundFrame f)
        {
            switch (m_state)
            {
            case AssemblyState.ExpectingMethod:
                if (!f.IsMethod())
                {
                    throw new UnexpectedFrameException(f);
                }
                m_method = m_protocol.DecodeMethodFrom(f.Payload);
                m_state  = m_method.HasContent ? AssemblyState.ExpectingContentHeader : AssemblyState.Complete;
                return(CompletedCommand());

            case AssemblyState.ExpectingContentHeader:
                if (!f.IsHeader())
                {
                    throw new UnexpectedFrameException(f);
                }
                m_header = m_protocol.DecodeContentHeaderFrom(NetworkOrderDeserializer.ReadUInt16(f.Payload));
                ulong totalBodyBytes = m_header.ReadFrom(f.Payload.Slice(2));
                if (totalBodyBytes > MaxArrayOfBytesSize)
                {
                    throw new UnexpectedFrameException(f);
                }

                m_remainingBodyBytes = (int)totalBodyBytes;
                m_body = MemoryPool <byte> .Shared.Rent(m_remainingBodyBytes);

                UpdateContentBodyState();
                return(CompletedCommand());

            case AssemblyState.ExpectingContentBody:
                if (!f.IsBody())
                {
                    throw new UnexpectedFrameException(f);
                }

                if (f.Payload.Length > m_remainingBodyBytes)
                {
                    throw new MalformedFrameException($"Overlong content body received - {m_remainingBodyBytes} bytes remaining, {f.Payload.Length} bytes received");
                }

                f.Payload.CopyTo(m_body.Memory.Slice(_offset));
                m_remainingBodyBytes -= f.Payload.Length;
                _offset += f.Payload.Length;
                UpdateContentBodyState();
                return(CompletedCommand());

            case AssemblyState.Complete:
            default:
                return(null);
            }
        }
Пример #8
0
 public abstract void HandleFrame(InboundFrame frame);
Пример #9
0
 public InboundFrame ReadFrame()
 {
     return(InboundFrame.ReadFrom(_reader, _frameHeaderBuffer));
 }
Пример #10
0
 public InboundFrame ReadFrame()
 {
     return(InboundFrame.ReadFrom(m_reader));
 }
Пример #11
0
 public abstract Task HandleFrame(InboundFrame frame);
        public Command HandleFrame(InboundFrame f)
        {
            switch (m_state)
            {
            case AssemblyState.ExpectingMethod:
            {
                if (!f.IsMethod())
                {
                    throw new UnexpectedFrameException(f);
                }
                m_method = m_protocol.DecodeMethodFrom(f.GetReader());
                m_state  = m_method.HasContent
                        ? AssemblyState.ExpectingContentHeader
                        : AssemblyState.Complete;
                return(CompletedCommand());
            }

            case AssemblyState.ExpectingContentHeader:
            {
                if (!f.IsHeader())
                {
                    throw new UnexpectedFrameException(f);
                }
                NetworkBinaryReader reader = f.GetReader();
                m_header = m_protocol.DecodeContentHeaderFrom(reader);
                var totalBodyBytes = m_header.ReadFrom(reader);
                if (totalBodyBytes > MaxArrayOfBytesSize)
                {
                    throw new UnexpectedFrameException(f);
                }
                m_remainingBodyBytes = (int)totalBodyBytes;
                m_body       = new byte[m_remainingBodyBytes];
                m_bodyStream = new MemoryStream(m_body, true);
                UpdateContentBodyState();
                return(CompletedCommand());
            }

            case AssemblyState.ExpectingContentBody:
            {
                if (!f.IsBody())
                {
                    throw new UnexpectedFrameException(f);
                }
                if (f.Payload.Length > m_remainingBodyBytes)
                {
                    throw new MalformedFrameException
                              (string.Format("Overlong content body received - {0} bytes remaining, {1} bytes received",
                                             m_remainingBodyBytes,
                                             f.Payload.Length));
                }
                m_bodyStream.Write(f.Payload, 0, f.Payload.Length);
                m_remainingBodyBytes -= f.Payload.Length;
                UpdateContentBodyState();
                return(CompletedCommand());
            }

            case AssemblyState.Complete:
            default:
#if NETFX_CORE
                Debug.WriteLine("Received frame in invalid state {0}; {1}", m_state, f);
#else
                //Trace.Fail(string.Format("Received frame in invalid state {0}; {1}", m_state, f));
#endif
                return(null);
            }
        }