Ejemplo n.º 1
0
        public void ValidateIndexAndLength()
        {
            // Empty
            ByteBuffer byteBuffer = UnpooledByteBuffer.From(new byte[0]);

            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(0, -1));
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(-1, -1));
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(1, 0));

            // Unpooled
            var bytes = new byte[10];

            byteBuffer = UnpooledByteBuffer.From(bytes, 0, 5);
            byteBuffer.Validate(0, 5);
            byteBuffer.Validate(4, 1);
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(-1));
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(5, 1));

            byteBuffer = UnpooledByteBuffer.From(bytes, 4, 5);
            byteBuffer.Validate(0, 5);
            byteBuffer.Validate(4, 1);
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(-1));
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(5, 1));

            // Pooled
            byteBuffer = ByteBufferAllocator.Default.Buffer(5, 5);
            byteBuffer.Validate(0, 5);
            byteBuffer.Validate(4, 1);
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(-1));
            Assert.Throws <IndexOutOfRangeException>(() => byteBuffer.Validate(5, 1));
        }
Ejemplo n.º 2
0
        protected internal void QueueWriteStream(byte[] array, int offset, int count,
                                                 Action <StreamHandle, Exception> completion)
        {
            Contract.Requires(array != null && array.Length > 0);
            Contract.Requires(offset >= 0 && count > 0);
            Contract.Requires((offset + count) <= array.Length);

            ByteBuffer byteBuffer = UnpooledByteBuffer.From(array, offset, count);
            var        bufferRef  = new BufferRef(byteBuffer, false);

            this.pipeline.QueueWrite(bufferRef, completion);
        }
Ejemplo n.º 3
0
        public void QueueSend(byte[] array, int offset, int count,
                              IPEndPoint remoteEndPoint,
                              Action <Udp, Exception> completion = null)
        {
            Contract.Requires(array != null && array.Length > 0);
            Contract.Requires(offset >= 0 && count > 0);
            Contract.Requires((offset + count) <= array.Length);
            Contract.Requires(remoteEndPoint != null);

            ByteBuffer byteBuffer = UnpooledByteBuffer.From(array, offset, count);
            var        bufferRef  = new BufferRef(byteBuffer, false);

            this.QueueSend(bufferRef, remoteEndPoint, completion);
        }