public void ActivateIn() { // It is possible that the most recently used decoder // processed the whole buffer but failed to write // the last message into the pipe. if (m_pendingBytes == 0) { if (m_decoder != null) { m_decoder.ProcessBuffer(null, 0); m_session.Flush(); } m_ioObject.SetPollin(m_handle); return; } Debug.Assert(m_decoder != null); Debug.Assert(m_pendingData != null); // Ask the decoder to process remaining data. int n = m_decoder.ProcessBuffer(m_pendingData, m_pendingBytes); m_pendingBytes -= n; m_session.Flush();; if (m_pendingBytes > 0) { return; } // Resume polling. m_ioObject.SetPollin(m_handle); InEvent(); }
public void InEvent() { // If still handshaking, receive and process the greeting message. if (m_handshaking) { if (!Handshake()) { return; } } Debug.Assert(m_decoder != null); bool disconnection = false; int processed; // If there's no data to process in the buffer... if (m_insize == 0) { // Retrieve the buffer and read as much data as possible. // Note that buffer can be arbitrarily large. However, we assume // the underlying TCP layer has fixed buffer size and thus the // number of bytes read will be always limited. m_decoder.GetBuffer(ref m_inpos, ref m_insize); m_insize = Read(m_inpos, m_insize); // Check whether the peer has closed the connection. 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_ioObject.ResetPollin(m_handle); } m_inpos.AdvanceOffset(processed); m_insize -= processed; } // 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.RmFd(m_handle); m_inputError = true; } else { Error(); } } }