public PooledBuffer GetBuffer() { PooledBuffer buffer = null; if (!_queues.TryPop(out buffer)) { //no pooled buffer = new PooledBuffer(this, new byte[4096], 0, 4096, false); } Interlocked.Increment(ref _activeCount); return buffer; }
internal ConnectStream(Connection connection, ArraySegment<byte> buffer, int offset, int bufferCount, long readCount, bool chunked, HttpRequest request) { _connection = connection; _readBytes = readCount; _chunked = chunked; if (_chunked) { _chunkParser = new ChunkParser(connection, buffer, offset, bufferCount); } else { _readBuffer = buffer; _readOffset = offset; _readBufferSize = bufferCount; } _request = request; _pooledBuffer = connection.Buffer; }
public Connection(ServicePoint servicePoint) { _state = 0; _servicePoint = servicePoint; _saea = SaeaPool.Default.GetSaea(); _buffer = BufferPool.Default.GetBuffer(); _socket = new Socket(servicePoint.HostEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _socket.NoDelay = !servicePoint.UseNagleAlgorithm; if (_servicePoint.IsSecured) { _asyncReadWrite = new SslAsyncReadWrite(servicePoint.Address.Host, _socket, _saea, servicePoint.ClientCertificate, ValidateServerCertificate); } else { _asyncReadWrite = new AsyncReadWrite(_socket, _saea); } }
public void FreeBuffer(PooledBuffer buffer) { _queues.Push(buffer); Interlocked.Decrement(ref _activeCount); }