private void ProcessInput()
        {
            bool disconnection = false;
            int  processed;

            if (m_insize == -1)
            {
                m_insize      = 0;
                disconnection = true;
            }

            if (m_options.RawSocket)
            {
                if (m_insize == 0 || !m_decoder.MessageReadySize(m_insize))
                {
                    processed = 0;
                }
                else
                {
                    processed = m_decoder.ProcessBuffer(m_inpos, m_insize);
                }
            }
            else
            {
                // Push the data to the decoder.
                processed = m_decoder.ProcessBuffer(m_inpos, m_insize);
            }

            if (processed == -1)
            {
                disconnection = true;
            }
            else
            {
                // Stop polling for input if we got stuck.
                if (processed < m_insize)
                {
                    m_receivingState = ReceiveState.Stuck;

                    m_inpos.AdvanceOffset(processed);
                    m_insize -= processed;
                }
                else
                {
                    m_inpos  = null;
                    m_insize = 0;
                }
            }

            // Flush all messages the decoder may have produced.
            m_session.Flush();

            // An input error has occurred. If the last decoded message
            // has already been accepted, we terminate the engine immediately.
            // Otherwise, we stop waiting for socket events and postpone
            // the termination until after the message is accepted.
            if (disconnection)
            {
                if (m_decoder.Stalled())
                {
                    m_ioObject.RemoveSocket(m_handle);
                    m_ioEnabled = false;
                    m_state     = State.Stalled;
                }
                else
                {
                    Error();
                }
            }
            else if (m_receivingState != ReceiveState.Stuck)
            {
                m_decoder.GetBuffer(out m_inpos, out m_insize);
                BeginRead(m_inpos, m_insize);
            }
        }