예제 #1
0
        /// <summary>
        ///     This method is be called when a message receive operation has been completed.
        /// </summary>
        /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param>
        /// <param name="bytesTransferred">the number of bytes that were transferred</param>
        public void InCompleted(SocketError socketError, int bytesTransferred)
        {
            if (socketError != SocketError.Success || bytesTransferred == 0)
            {
                this.m_joined = false;
                this.Error();
            }
            else
            {
                // Read the offset of the fist message in the current packet.
                Debug.Assert(bytesTransferred >= sizeof(ushort));

                ushort offset = this.m_data.GetUnsignedShort(this.m_options.Endian, 0);
                this.m_data.AdvanceOffset(sizeof(ushort));
                bytesTransferred -= sizeof(ushort);

                // Join the stream if needed.
                if (!this.m_joined)
                {
                    // There is no beginning of the message in current packet.
                    // Ignore the data.
                    if (offset == 0xffff)
                    {
                        this.BeginReceive();
                        return;
                    }

                    Debug.Assert(offset <= bytesTransferred);
                    Debug.Assert(this.m_decoder == null);

                    // We have to move data to the beginning of the first message.
                    this.m_data.AdvanceOffset(offset);
                    bytesTransferred -= offset;

                    // Mark the stream as joined.
                    this.m_joined = true;

                    // Create and connect decoder for the peer.
                    this.m_decoder = new V1Decoder(0, this.m_options.MaxMessageSize, this.m_options.Endian);
                    this.m_decoder.SetMsgSink(this.m_session);
                }

                // Push all the data to the decoder.
                int processed = this.m_decoder.ProcessBuffer(this.m_data, bytesTransferred);
                if (processed < bytesTransferred)
                {
                    // Save some state so we can resume the decoding process later.
                    this.m_pendingBytes = bytesTransferred - processed;
                    this.m_pendingData  = new ByteArraySegment(this.m_data, processed);

                    this.m_state = State.Stuck;
                }
                else
                {
                    this.m_session.Flush();

                    this.BeginReceive();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This method is be called when a message receive operation has been completed.
        /// </summary>
        /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param>
        /// <param name="bytesTransferred">the number of bytes that were transferred</param>
        public void InCompleted(SocketError socketError, int bytesTransferred)
        {
            if (socketError != SocketError.Success || bytesTransferred == 0)
            {
                m_joined = false;
                Error();
            }
            else
            {
                // Read the offset of the fist message in the current packet.
                Debug.Assert(bytesTransferred >= sizeof(ushort));

                ushort offset = m_data.GetUnsignedShort(m_options.Endian, 0);
                m_data.AdvanceOffset(sizeof(ushort));
                bytesTransferred -= sizeof(ushort);

                // Join the stream if needed.
                if (!m_joined)
                {
                    // There is no beginning of the message in current packet.
                    // Ignore the data.
                    if (offset == 0xffff)
                    {
                        BeginReceive();
                        return;
                    }

                    Debug.Assert(offset <= bytesTransferred);
                    Debug.Assert(m_decoder == null);

                    // We have to move data to the beginning of the first message.
                    m_data.AdvanceOffset(offset);
                    bytesTransferred -= offset;

                    // Mark the stream as joined.
                    m_joined = true;

                    // Create and connect decoder for the peer.
                    m_decoder = new V1Decoder(0, m_options.MaxMessageSize, m_options.Endian);
                }

                // Push all the data to the decoder.
                m_pendingBytes = bytesTransferred;
                m_pendingData  = new ByteArraySegment(m_data, 0);
                ProcessInput();
            }
        }
예제 #3
0
파일: PgmSession.cs 프로젝트: awb99/netmq
        /// <summary>
        /// This method is be called when a message receive operation has been completed.
        /// </summary>
        /// <param name="socketError">a SocketError value that indicates whether Success or an error occurred</param>
        /// <param name="bytesTransferred">the number of bytes that were transferred</param>
        public void InCompleted(SocketError socketError, int bytesTransferred)
        {
            if (socketError != SocketError.Success || bytesTransferred == 0)
            {
                m_joined = false;
                Error();
            }
            else
            {
                // Read the offset of the fist message in the current packet.
                Debug.Assert(bytesTransferred >= sizeof(ushort));

                ushort offset = m_data.GetUnsignedShort(m_options.Endian, 0);
                m_data.AdvanceOffset(sizeof(ushort));
                bytesTransferred -= sizeof(ushort);

                // Join the stream if needed.
                if (!m_joined)
                {
                    // There is no beginning of the message in current packet.
                    // Ignore the data.
                    if (offset == 0xffff)
                    {
                        BeginReceive();
                        return;
                    }

                    Debug.Assert(offset <= bytesTransferred);
                    Debug.Assert(m_decoder == null);

                    // We have to move data to the beginning of the first message.
                    m_data.AdvanceOffset(offset);
                    bytesTransferred -= offset;

                    // Mark the stream as joined.
                    m_joined = true;

                    // Create and connect decoder for the peer.
                    m_decoder = new V1Decoder(0, m_options.MaxMessageSize, m_options.Endian);
                    m_decoder.SetMsgSink(m_session);
                }

                // Push all the data to the decoder.
                int processed = m_decoder.ProcessBuffer(m_data, bytesTransferred);
                if (processed < bytesTransferred)
                {
                    // Save some state so we can resume the decoding process later.
                    m_pendingBytes = bytesTransferred - processed;
                    m_pendingData = new ByteArraySegment(m_data, processed);

                    m_state = State.Stuck;
                }
                else
                {
                    m_session.Flush();

                    BeginReceive();
                }
            }
        }