示例#1
0
        public void TestAcquire()
        {
            var o = new ObjectStub();

            managerMock.Expect(m => m.GetItem()).Return(o);
            Assert.AreEqual(o, pool.Acquire());
            Assert.AreEqual(PoolSize - 1, pool.Count);
        }
        public SocketAsyncEventArgs AcquireWithBuffer()
        {
            var result = Acquire();
            var buffer = BufferPool.Acquire();

            result.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);

            return(result);
        }
        public RequestUrlBuilder([NotNull] string initialUrl = "")
        {
            if (initialUrl == null)
            {
                throw new ArgumentNullException(nameof(initialUrl));
            }

            builder = builders.Acquire();
            builder.Clear();
            builder.Append(initialUrl);

            hasQueryParameters = initialUrl.IndexOf("?", StringComparison.Ordinal) >= 0;
        }
示例#4
0
        public Task SendDataAsync(Socket socket, byte[] array, int offset, int count)
        {
            var tcs = new TaskCompletionSource <bool>();

            var e = SendArgsPool.Acquire();

            e.SetBuffer(array, offset, count);
            e.UserToken  = tcs;
            e.Completed += OnDataSent;

            SendData(socket, e);

            return(tcs.Task);
        }
        public static void Preallocate <T>(this IPool <T> pool, int count)
            where T : class
        {
            var resources = new List <T>();

            for (int i = 0; i < count; i++)
            {
                resources.Add(pool.Acquire());
            }

            foreach (var resource in resources)
            {
                pool.Release(resource);
            }
        }
 /// <summary>
 /// Acquires a resource from pool and wraps it into a disposable handle which releases resource on disposal.
 /// </summary>
 public static PoolHandle <T> AcquireHandle <T>(this IPool <T> pool)
     where T : class
 {
     return(new PoolHandle <T>(pool, pool.Acquire()));
 }
示例#7
0
 public TSocket Acquire()
 {
     return(socketPool.Acquire());
 }
示例#8
0
 internal PooledObject(IPool <T> pool)
 {
     Object = pool.Acquire();
     _pool  = pool;
 }
示例#9
0
 public EndpointState(IPool <ArraySegment <byte> > bufferPool, IPool <ISocketSender> socketSenderPool)
 {
     BufferPool       = bufferPool;
     SocketSenderPool = socketSenderPool;
     EndPointSendBufferStateFactory = _ => new EndpointSendBufferState(BufferPool.Acquire());
 }