public void Combine_zero_incoming() { var hb1 = new HeartBeatValues("10,0"); var hb2 = new HeartBeatValues("10,5"); var hb3 = hb1.CombineWith(hb2); Assert.AreEqual(10, hb3.Outgoing); Assert.AreEqual(0, hb3.Incoming); }
// ReSharper restore UnusedParameter.Local // ReSharper restore MemberCanBeMadeStatic.Local private void ExpectingConnect(StompFrame frame) { if (frame.Command != StompCommand.Connect && frame.Command != StompCommand.Stomp) { string message = "Expecting " + StompCommand.Connected + " or " + StompCommand.Stomp + " command, received " + frame.Command; Log.Error(_logMessagePrefix + message); var errorFrame = StompFrameUtils.CreateErrorFrame(message); _transport.SendFrame(errorFrame); DisconnectWithoutLocking(); return; } var login = frame.Headers[StompHeader.Login]; var passcode = frame.Headers[StompHeader.Passcode]; if (!Authenticate(login, passcode)) { string message = "Received " + frame.Command + " frame, Access denied"; Log.Warn(_logMessagePrefix + message); var errorFrame = StompFrameUtils.CreateErrorFrame(message); _transport.SendFrame(errorFrame); DisconnectWithoutLocking(); return; } Log.Debug(_logMessagePrefix + "Received " + frame.Command + " frame, authenticated OK"); var sessionId = frame.Headers[StompHeader.Session]; ServerSideSession session = null; if (sessionId != null) { session = _serverData.FindSession(sessionId); if (session == null) { Log.Warn(_logMessagePrefix + "Received " + frame.Command + " frame for non-existent session: " + sessionId); var message = ErrorMessages.SessionDoesNotExistPrefix + sessionId; var errorFrame = StompFrameUtils.CreateErrorFrame(message); _transport.SendFrame(errorFrame); DisconnectWithoutLocking(); return; } if (!session.AddConnection(this)) { var message = frame.Command + " frame requested a session already in use: " + sessionId; Log.Warn(_logMessagePrefix + message); var errorFrame = StompFrameUtils.CreateErrorFrame(message); _transport.SendFrame(errorFrame); DisconnectWithoutLocking(); return; } Log.Debug(_logMessagePrefix + "Reconnected to session " + sessionId); } if (session == null) { session = _serverData.CreateSession(); session.AddConnection(this); Log.Debug(_logMessagePrefix + "Created new session " + session.SessionId); } // helps with debugging if we give the session a more friendly name session.ClientId = frame.Headers[StompHeader.NonStandard.ClientId]; _session = session; var connectedFrame = new StompFrame { Command = StompCommand.Connected, Headers = { {StompHeader.Session, session.SessionId} } }; if (frame.Headers[StompHeader.HeartBeat] == null) { // no heart-beat header received, so we default to 0,0 _negotiatedHeartBeats = new HeartBeatValues(0, 0); } else { var otherHeartBeatValues = new HeartBeatValues(frame.Headers[StompHeader.HeartBeat]); var myHeartBeatValues = new HeartBeatValues(30000, 30000); _negotiatedHeartBeats = myHeartBeatValues.CombineWith(otherHeartBeatValues); connectedFrame.Headers[StompHeader.HeartBeat] = _negotiatedHeartBeats.ToString(); } _transport.SendFrame(connectedFrame); StopConnectTimer(); StartIncomingHeartBeatTimer(); StartOutgoingHeartBeatTimer(); _stateAction = Connected; Log.Debug(_logMessagePrefix + "Session " + session + " connected"); }