Example #1
0
        public void Overflow()
        {
            var bufferPool = new BufferSliceStack(1, 10);

            bufferPool.Pop();
            bufferPool.Pop();
        }
Example #2
0
        public void CreateBuffer()
        {
            var bufferPool = new BufferSliceStack(1, 10);
            var buffer     = bufferPool.Pop();

            Assert.NotNull(buffer);
            Assert.Equal(10, buffer.Count);
        }
        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);
        }
        /// <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);

            _listenerArgs            = new SocketAsyncEventArgs();
            _listenerArgs.Completed += OnAccept;

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