/// <summary> /// Closes this session with the specified reason. /// Notifies the recipient connection the reason for the session's closure. /// </summary> /// <param name="reason">Reason for closing this session.</param> public override void Close(SocketCloseReason reason) { if (CurrentState == State.Closed) { return; } MqFrame closeFrame = null; if (CurrentState == State.Connected) { CurrentState = State.Closing; closeFrame = CreateFrame(new byte[2], MqFrameType.Command); closeFrame.Write(0, (byte)0); closeFrame.Write(1, (byte)reason); } // If we are passed a closing frame, then send it to the other connection. if (closeFrame != null) { MqMessage msg; if (_outbox.IsEmpty == false) { while (_outbox.TryDequeue(out msg)) { } } msg = new MqMessage(closeFrame); _outbox.Enqueue(msg); // Process the last bit of data. ProcessOutbox(); } base.Close(reason); }
/// <summary> /// Writes a boolean value. /// 1 Byte. /// </summary> /// <param name="value">Value to write to the message.</param> public override void Write(bool value) { EnsureSpace(1); _builderFrame.Write(_position, value); _position += 1; }