public void CreateBuffer()
 {
     var bufferPool = new BufferSliceStack(1, 10);
     var buffer = bufferPool.Pop();
     Assert.NotNull(buffer);
     Assert.Equal(10, buffer.Count);
 }
        public void Overflow()
        {
            var bufferPool = new BufferSliceStack(1, 10);

            bufferPool.Pop();
            bufferPool.Pop();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BodyDecoder"/> class.
 /// </summary>
 /// <param name="decoderService">The decoder service.</param>
 /// <param name="bufferSize">Buffer size of each buffer in the pool. Read the remarks at <see cref="BodyDecoder"/></param>
 /// <param name="sizeLimit">Maximum size of the body in bytes. Larger content will generate a <see cref="HttpStatusCode.RequestEntityTooLarge"/> response which will
 /// be sent back to the client.</param>
 public BodyDecoder(IBodyDecoder decoderService, int bufferSize, int sizeLimit)
 {
     if (decoderService == null) throw new ArgumentNullException("decoderService");
     _decoderService = decoderService;
     _bufferSize = bufferSize;
     _sizeLimit = sizeLimit;
     _bufferPool = new BufferSliceStack(1000, bufferSize);
 }
        public void Pop_Return_Pop()
        {
            var bufferPool = new BufferSliceStack(1, 100);

            var slice = bufferPool.Pop();
            Assert.Throws<InvalidOperationException>(() => bufferPool.Pop());
            ((PooledBufferSlice) slice).Dispose();
            var slice2 = bufferPool.Pop();

            Assert.Same(slice, slice2);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Server" /> class.
        /// </summary>
        protected ServerBase(ServerConfiguration configuration)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            configuration.Validate();

            _numConnectedSockets = 0;
            _maxAmountOfConnection = configuration.MaximumNumberOfClients;
            _maxNumberAcceptedClients = new Semaphore(configuration.MaximumNumberOfClients,
                                                      configuration.MaximumNumberOfClients);

            // *2 since we need one for each send/receive pair.
            _bufferSliceStack = new BufferSliceStack(configuration.MaximumNumberOfClients*2, configuration.BufferSize);
        }