Esempio n. 1
0
        /// <summary>子消息读取</summary>
        /// <param name="stream">数据流</param>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        protected override Boolean OnRead(Stream stream, Object context)
        {
            SessionPresent = stream.ReadByte() > 0;
            ReturnCode     = (ConnectReturnCode)stream.ReadByte();

            return(true);
        }
Esempio n. 2
0
        public override void Decode(IByteBuffer buffer)
        {
            int remainingLength = RemaingLength;
            int ackData         = buffer.ReadUnsignedShort(ref remainingLength);

            SessionPresent            = ((ackData >> 8) & 0x1) != 0;
            ConnectReturnCode         = (ConnectReturnCode)(ackData & 0xFF);
            FixedHeader.RemaingLength = remainingLength;
        }
Esempio n. 3
0
        public void TestConnAckMessage(bool sessionPresent, ConnectReturnCode returnCode)
        {
            var packet = new ConnAckPacket();

            packet.SessionPresent = sessionPresent;
            packet.ReturnCode     = returnCode;

            ConnAckPacket recoded = this.RecodePacket(packet, false, true);

            this.contextMock.Verify(x => x.FireChannelRead(It.IsAny <ConnAckPacket>()), Times.Once);
            Assert.Equal(packet.SessionPresent, recoded.SessionPresent);
            Assert.Equal(packet.ReturnCode, recoded.ReturnCode);
        }
Esempio n. 4
0
        public void ConnAckMessageTest(bool sessionPresent, ConnectReturnCode returnCode)
        {
            var packet = new ConnAckPacket();

            packet.VariableHeader.SessionPresent    = sessionPresent;
            packet.VariableHeader.ConnectReturnCode = returnCode;

            var recoded = RecodePacket(packet, false, false);

            contextMock.Verify(x => x.FireChannelRead(It.IsAny <ConnAckPacket>()), Times.Once);
            Assert.Equal(packet.VariableHeader.SessionPresent, recoded.VariableHeader.SessionPresent);
            Assert.Equal(packet.VariableHeader.ConnectReturnCode, recoded.VariableHeader.ConnectReturnCode);
        }
Esempio n. 5
0
        private int ReadVariableHeader()
        {
            // Variable header could potentially be read by more than one thread but we're OK with that.
            // Just trying to guard against multiple threads reading in the variables at the same time.
            lock (_msg.SyncLock)
            {
                int pos;
                _msg.ReadRemainingLength(out pos);
                byte b1 = _msg.MsgBuffer[pos++];    // Skip past reserved header byte
                byte b2 = _msg.MsgBuffer[pos++];

                if (b2 < (byte)ConnectReturnCode.Unknown)
                {
                    _connectReturnCode = (ConnectReturnCode)b2;
                }
                else
                {
                    _connectReturnCode = ConnectReturnCode.Unknown;
                }

                _msg.VariableHeaderRead = true;
                return(pos);
            }
        }
Esempio n. 6
0
 public MqttConnectResult(ConnectReturnCode connectReturn)
 {
     ConnectReturn = connectReturn;
 }
Esempio n. 7
0
 /// <summary>
 /// Instantiate a new <see cref="ConnectResult"/> where the client got connected.
 /// <see cref="ConnectError"/> will be <see cref="ConnectError.Ok"/>.
 /// </summary>
 /// <param name="sessionState">The session state.</param>
 /// <param name="connectReturnCode">The connection return code.</param>
 public ConnectResult(SessionState sessionState, ConnectReturnCode connectReturnCode)
 {
     ConnectError      = ConnectError.Ok;
     SessionState      = sessionState;
     ConnectReturnCode = connectReturnCode;
 }
Esempio n. 8
0
 /// <summary>
 /// Instantiate a new <see cref="ConnectResult"/> where the result is an error.
 /// <see cref="SessionState"/> will be <see cref="SessionState.Unknown"/>.
 /// <see cref="ConnectReturnCode"/> will be <see cref="ConnectReturnCode.Unknown"/>.
 /// </summary>
 /// <param name="connectError">The reason the client could not connect.</param>
 public ConnectResult(ConnectError connectError)
 {
     ConnectError      = connectError;
     SessionState      = SessionState.Unknown;
     ConnectReturnCode = ConnectReturnCode.Unknown;
 }
Esempio n. 9
0
 public ConnAckPacket(bool sessionPresent, ConnectReturnCode returnCode)
     : base(new ConnAckVariableHeader(sessionPresent, returnCode), new PayloadNone())
 {
     FixedHeader = FixedHeader.CreateStandardHeader(ControlPacketType.CONNACK, (UInt16)(VariableHeader.Encode().Count() + Payload.Encode().Count()));
 }
Esempio n. 10
0
 public override void Decode(IByteBuffer buffer)
 {
     SessionPresent    = (buffer.ReadByte() & 0x01) == 1;
     ConnectReturnCode = (ConnectReturnCode)buffer.ReadByte();
 }
Esempio n. 11
0
 private static void Connected(ConnectReturnCode connectResponse)
 {
     Console.WriteLine("Connected Ssuccessful!, ConnectReturnCode: " + connectResponse);
 }
Esempio n. 12
0
 public ConnectResult(bool success, ConnectReturnCode returnCode, Task closeFuture)
 {
     Success     = success;
     ReturnCode  = returnCode;
     CloseFuture = closeFuture;
 }
        private int ReadVariableHeader()
        {
            // Variable header could potentially be read by more than one thread but we're OK with that.
            // Just trying to guard against multiple threads reading in the variables at the same time.
            lock (_msg.SyncLock)
            {
                int pos;
                _msg.ReadRemainingLength(out pos);
                byte b1 = _msg.MsgBuffer[pos++];    // Skip past reserved header byte
                byte b2 = _msg.MsgBuffer[pos++];

                if (b2 < (byte)ConnectReturnCode.Unknown)
                {
                    _connectReturnCode = (ConnectReturnCode)b2;
                }
                else
                {
                    _connectReturnCode = ConnectReturnCode.Unknown;
                }

                _msg.VariableHeaderRead = true;
                return pos;
            }
        }
Esempio n. 14
0
 public ConnAckVariableHeader(bool sessionPresent, ConnectReturnCode returnCode)
 {
     SessionPresent = sessionPresent;
     ReturnCode     = returnCode;
 }