Ejemplo n.º 1
0
        private void Shutdown()
        {
            _packetBuilder.Reset();

            lock (lockObj)
            {
                try
                {
                    if (clientSocket != null)
                    {
                        clientSocket.Shutdown(SocketShutdown.Both);
                        clientSocket.Close();
                        clientSocket = null;
                    }
                }
                catch (Exception ce)
                {
                    com.QH.QPGame.GameUtils.Logger.Net.Log(ce.Message);
                }
                finally
                {
                    clientSocket = null;
                }
            }
        }
Ejemplo n.º 2
0
        public void Reset()
        {
            // Arrange
            string result = null;

            m_mockBinaryWriter.Setup(writer => writer.Write(It.IsAny <byte[]>(), 0, It.IsAny <int>()))
            .Callback <byte[], int, int>((b, i, c) =>
                                         result = Encoding.ASCII.GetString(b, i, c - 2)).Returns(0);

            // Act
            m_builder.Reset();

            // Assert
            m_builder.WriteTo(m_mockBinaryWriter.Object);
            Assert.Equal(string.Empty, result);
        }
Ejemplo n.º 3
0
        public void Store(StorePacket packet, bool noreply)
        {
            m_builder
            .Reset()
            .WriteOperation((RequestOperation)packet.Operation)
            .WriteKey(packet.Key)
            .WriteFlags(packet.Flags)
            .WriteExpires(packet.Expires)
            .WriteLength(packet.Value.Count)
            .WriteVersion(packet.Version);

            if (noreply)
            {
                m_builder.WriteNoReply();
            }

            m_builder.WriteValue(packet.Value);
        }
Ejemplo n.º 4
0
        public void WriteFlags()
        {
            // Arrange
            int extra  = -1;
            int result = -1;

            m_mockBinaryWriter.Setup(writer => writer.Write(It.IsAny <byte[]>(), 0, It.IsAny <int>()))
            .Callback <byte[], int, int>((b, i, c) =>
            {
                extra  = b[4];
                result = BigEndianConverter.GetInt32(b, 24);
            }).Returns(0);
            m_builder.Reset();
            m_builder.WriteOperation(RequestOperation.Set);

            // Act
            m_builder.WriteFlags(123456789);

            // Assert
            m_builder.WriteTo(m_mockBinaryWriter.Object);
            Assert.Equal(8, extra);
            Assert.Equal(123456789, result);
        }