Beispiel #1
0
        protected virtual void Dispose(bool disposing)
        {
            // close all active handles
            foreach (var kvp in handles)
            {
                var handle = kvp.Value;
                if (!handle.IsClosing)
                {
                    handle.Dispose();
                }
            }

            // make sure the callbacks of close are called
            RunOnce();

            if (disposing)
            {
                if (ByteBufferAllocator != null)
                {
                    ByteBufferAllocator.Dispose();
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
                    ByteBufferAllocator = null;
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
                }
            }

            int r = uv_loop_close(NativeHandle);
            Ensure.Success(r);
        }
        public void ReadDisconnectPayloadTest()
        {
            var buffer = ByteBufferAllocator.NewBuffer(DataSerializer.Endian);

            var detailMessage = "Invalid CommandType";
            var srcDetail     = Encoding.UTF8.GetBytes(detailMessage);

            buffer.WriteInt((int)DisconnectReason.InvalidDataFormat);
            buffer.WriteInt(srcDetail.Length);
            buffer.WriteBytes(srcDetail);

            byte[] payload = buffer.ToArray();
            int    offset  = 0;

            DisconnectReason disconnectType = (DisconnectReason)ByteRead.GetInt(payload, ref offset);

            int detailLength = ByteRead.GetInt(payload, ref offset);

            byte[] dstDetail = new byte[detailLength];
            ByteRead.ReadBytes(payload, dstDetail, offset, 0, detailLength);

            Assert.AreEqual(DisconnectReason.InvalidDataFormat, disconnectType);
            Assert.AreEqual(srcDetail.Length, detailLength);
            Assert.AreEqual(detailMessage, Encoding.UTF8.GetString(dstDetail));
        }
Beispiel #3
0
        protected virtual void Dispose(bool disposing)
        {
            // close all active handles
            foreach (var kvp in handles)
            {
                var handle = kvp.Value;
                if (!handle.IsClosing)
                {
                    handle.Dispose();
                }
            }

            // make sure the callbacks of close are called
            RunOnce();

            if (disposing)
            {
                if (ByteBufferAllocator != null)
                {
                    ByteBufferAllocator.Dispose();
                    ByteBufferAllocator = null;
                }
            }

            int r = uv_loop_close(NativeHandle);

            Ensure.Success(r);
        }
Beispiel #4
0
        internal Udp(LoopContext loop, ByteBufferAllocator allocator)
            : base(loop, uv_handle_type.UV_UDP)
        {
            Contract.Requires(allocator != null);

            this.allocator   = allocator;
            this.bufferQueue = new BufferQueue();
        }
        public void GetTest()
        {
            var bigEndianBuffer = ByteBufferAllocator.NewBuffer(Endian.BigEndian);

            bigEndianBuffer.WriteInt(10);

            var littleEndianBuffer = ByteBufferAllocator.NewReadOnlyBuffer(Endian.LittleEndian, bigEndianBuffer.ToArray());

            Assert.AreEqual(10.Reverse(), littleEndianBuffer.ReadInt());
        }
Beispiel #6
0
        public void DataObjectSerializeTest()
        {
            DataObject dataObject = new DataObject();

            dataObject.SetByte(0, 119);
            var buffer = ByteBufferAllocator.NewBuffer(Endian.BigEndian);

            DataSerializer.Write(buffer, dataObject);
            _output.WriteLine(TestUtil.ToString(buffer.ToArray()));
        }
Beispiel #7
0
        internal Pipeline(StreamHandle streamHandle, ByteBufferAllocator allocator)
        {
            Contract.Requires(streamHandle != null);
            Contract.Requires(allocator != null);

            this.streamHandle = streamHandle;
            this.allocator    = allocator;
            this.receiveBufferSizeEstimate = new ReceiveBufferSizeEstimate();
            this.bufferQueue = new BufferQueue();
        }
        public void WritableBufferTest()
        {
            var buffer = ByteBufferAllocator.NewBuffer(Endian.BigEndian, new byte[1] {
                1
            });

            buffer.WriteByte(2);

            Assert.AreEqual(1, buffer.ReadByte());
            Assert.AreEqual(2, buffer.ReadByte());
        }
Beispiel #9
0
        public IoBuffer GetBuffer()
        {
            var buf = new ByteBufferAllocator().Allocate(Length);

            buf.AutoExpand = false;
            buf.Put(Symbol);
            buf.Put(Symbol);
            buf.Put(destinationAddr);
            this.Fill(buf);
            buf.Put(ComputeChecksum(buf));
            return(buf);
        }
        public void ReadStringTest()
        {
            var buffer = ByteBufferAllocator.NewBuffer(DataSerializer.Endian);

            var detailMessage = "Hello,World!!!";
            var detailBytes   = Encoding.UTF8.GetBytes(detailMessage);

            buffer.WriteInt(detailBytes.Length);
            buffer.WriteBytes(detailBytes);

            int offset = 0;
            var result = ByteRead.GetString <int>(buffer.ToArray(), ref offset, Encoding.UTF8);

            Assert.AreEqual(detailMessage, result);
            Assert.AreEqual(sizeof(int) + detailMessage.Length, offset);
        }
Beispiel #11
0
        protected void Dispose(bool disposing)
        {
            if (disposing)
            {
                GC.SuppressFinalize(this);
            }

            if (NativeHandle != Default.NativeHandle)
            {
                uv_loop_delete(NativeHandle);
            }

            if (ByteBufferAllocator != null)
            {
                ByteBufferAllocator.Dispose();
                ByteBufferAllocator = null;
            }
        }
        private void EndianTest(Endian endian)
        {
            var buffer = ByteBufferAllocator.NewBuffer(endian);

            buffer.WriteBool(true);
            buffer.WriteByte(byte.MaxValue);
            buffer.WriteShort(short.MaxValue);
            buffer.WriteInt(int.MaxValue);
            buffer.WriteLong(long.MaxValue);
            buffer.WriteFloat(float.MaxValue);
            buffer.WriteDouble(double.MaxValue);

            Assert.AreEqual(true, buffer.ReadBool());
            Assert.AreEqual(byte.MaxValue, buffer.ReadByte());
            Assert.AreEqual(short.MaxValue, buffer.ReadShort());
            Assert.AreEqual(int.MaxValue, buffer.ReadInt());
            Assert.AreEqual(long.MaxValue, buffer.ReadLong());
            Assert.AreEqual(float.MaxValue, buffer.ReadFloat());
            Assert.AreEqual(double.MaxValue, buffer.ReadDouble());
        }
 public static IByteBuffer NewBuffer(int capacity)
 {
     return(ByteBufferAllocator.NewBuffer(DataSerializer.Endian, capacity));
 }
Beispiel #14
0
 public ByteBuffer(byte[] buffer, int pos)
 {
     _buffer = new ByteArrayAllocator(buffer);
     _pos    = pos;
 }
        public void ReadonlyBufferTest()
        {
            var buffer = ByteBufferAllocator.NewReadOnlyBuffer(Endian.BigEndian, new byte[8]);

            buffer.WriteByte(0);
        }
Beispiel #16
0
            private int _pos; // Must track start of the buffer.

            public ByteBuffer(ByteBufferAllocator allocator, int position)
            {
                _buffer = allocator;
                _pos    = position;
            }
 public static IByteBuffer NewBuffer(byte[] data)
 {
     return(ByteBufferAllocator.NewBuffer(DataSerializer.Endian, data));
 }
 public static IByteBuffer NewBuffer()
 {
     return(ByteBufferAllocator.NewBuffer(DataSerializer.Endian));
 }