public void MainLoopIteration() { InboundFrame frame = m_frameHandler.ReadFrame(); NotifyHeartbeatListener(); // We have received an actual frame. if (frame.IsHeartbeat()) { // Ignore it: we've already just reset the heartbeat // latch. return; } if (frame.Channel == 0) { // In theory, we could get non-connection.close-ok // frames here while we're quiescing (m_closeReason != // null). In practice, there's a limited number of // things the server can ask of us on channel 0 - // essentially, just connection.close. That, combined // with the restrictions on pipelining, mean that // we're OK here to handle channel 0 traffic in a // quiescing situation, even though technically we // should be ignoring everything except // connection.close-ok. m_session0.HandleFrame(frame); } else { // If we're still m_running, but have a m_closeReason, // then we must be quiescing, which means any inbound // frames for non-zero channels (and any inbound // commands on channel zero that aren't // Connection.CloseOk) must be discarded. if (m_closeReason == null) { // No close reason, not quiescing the // connection. Handle the frame. (Of course, the // Session itself may be quiescing this particular // channel, but that's none of our concern.) ISession session = m_sessionManager.Lookup(frame.Channel); if (session == null) { throw new ChannelErrorException(frame.Channel); } else { session.HandleFrame(frame); } } } }
private void ReceiveLoop() { while (!_closed) { InboundFrame frame = _frameHandler.ReadFrame(); NotifyHeartbeatListener(); bool shallReturn = true; if (frame.Channel == 0) { if (frame.Type == FrameType.FrameHeartbeat) { // Ignore it: we've already just reset the heartbeat } else { // In theory, we could get non-connection.close-ok // frames here while we're quiescing (m_closeReason != // null). In practice, there's a limited number of // things the server can ask of us on channel 0 - // essentially, just connection.close. That, combined // with the restrictions on pipelining, mean that // we're OK here to handle channel 0 traffic in a // quiescing situation, even though technically we // should be ignoring everything except // connection.close-ok. shallReturn = _session0.HandleFrame(in frame); } } else { // If we're still m_running, but have a m_closeReason, // then we must be quiescing, which means any inbound // frames for non-zero channels (and any inbound // commands on channel zero that aren't // Connection.CloseOk) must be discarded. if (_closeReason is null) { // No close reason, not quiescing the // connection. Handle the frame. (Of course, the // Session itself may be quiescing this particular // channel, but that's none of our concern.) shallReturn = _sessionManager.Lookup(frame.Channel).HandleFrame(in frame); } } if (shallReturn) { frame.ReturnPayload(); } } }