Example #1
0
        public void TestUnsafeBufferAllocate()
        {
            if (!SocketFactory.IsRioSockSupported())
            {
                Assert.Ignore("Omitting due to missing Riosock.dll. It might caused by no VC++ build tool or running on an OS that not supports Windows RIO socket.");
            }

            var byteBuf  = unsafeBufPool.Allocate();
            var bufChunk = byteBuf.ByteBufChunk;

            Assert.AreNotEqual(IntPtr.Zero, bufChunk.UnsafeArray);
            Assert.AreNotEqual(bufChunk.BufId, IntPtr.Zero);
            Assert.AreEqual(bufChunk.FreeBytes, bufChunk.Size - byteBuf.Capacity);

            // Verify GetInputRioBuf()
            var inputRioBuf = byteBuf.GetInputRioBuf();

            Assert.AreNotEqual(null, inputRioBuf);
            Assert.AreEqual(byteBuf.WritableBytes, inputRioBuf.Length);

            // Verify GetOutputRioBuf()
            const string writeStr   = "Write bytes to ByteBuf.";
            var          writeBytes = Encoding.UTF8.GetBytes(writeStr);

            byteBuf.WriteBytes(writeBytes, 0, writeBytes.Length);
            var outputRioBuf = byteBuf.GetOutputRioBuf();

            Assert.AreNotEqual(null, outputRioBuf);
            Assert.AreEqual(byteBuf.ReadableBytes, outputRioBuf.Length);

            byteBuf.Release();
            Assert.AreEqual(bufChunk.FreeBytes, bufChunk.Size);
        }
Example #2
0
        public void TestManagedBufferAllocate()
        {
            var byteBuf  = bufPool.Allocate();
            var bufChunk = byteBuf.ByteBufChunk;

            Assert.AreEqual(bufChunk.FreeBytes, bufChunk.Size - byteBuf.Capacity);
            byteBuf.Release();
            Assert.AreEqual(bufChunk.FreeBytes, bufChunk.Size);
        }
Example #3
0
        public void TestWriteReadUnsafeBuf()
        {
            if (!SocketFactory.IsRioSockSupported())
            {
                Assert.Ignore("Omitting due to missing Riosock.dll. It might caused by no VC++ build tool or running on an OS that not supports Windows RIO socket.");
            }

            var byteBuf = unsafeBufPool.Allocate();

            Assert.AreNotEqual(IntPtr.Zero, byteBuf.UnsafeArray); // Verify the point of UnsafeArray has value on unsafe buffer.
            WriteReadByteBufTest(byteBuf);
            byteBuf.Release();
        }
Example #4
0
        public void TestWriteReadManagedBuf()
        {
            var byteBuf = managedBufPool.Allocate();

            Assert.AreEqual(IntPtr.Zero, byteBuf.UnsafeArray); // Verify the pointer of UnsafeArray is IntPtr.Zero on managed buffer.
            WriteReadByteBufTest(byteBuf);
            byteBuf.Release();
        }