Esempio n. 1
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);
            }
        }
Esempio n. 2
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.GetReader());
                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.
        }
Esempio n. 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.
        }
        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);
            }
        }