HTTP module

ConnectionPool

LIFO connection pool for reusing [ServerConnection]({#ref classicy_1_1http_1_1ServerConnection #}) objects.

ConnectionPool

#include <icy/http/server.h>

LIFO connection pool for reusing ServerConnection objects. Avoids per-request heap allocation by resetting and reusing connections instead of destroying and recreating them.

Public Methods

ReturnNameDescription
ServerConnection::Ptracquire inlineTakes a connection from the pool for reuse.
boolrelease inlineReturns a connection to the pool after use.
voidsetMaxSize inlineSets the maximum number of connections the pool will hold.
size_tsize const inlineReturns the current number of connections held in the pool.

acquire

inline

inline ServerConnection::Ptr acquire()

Takes a connection from the pool for reuse.

Returns

A pooled connection, or nullptr if the pool is empty.


release

inline

inline bool release(ServerConnection::Ptr & conn)

Returns a connection to the pool after use.

Parameters

  • conn The connection to return.

Returns

true if accepted into the pool; false if the pool is full.


setMaxSize

inline

inline void setMaxSize(size_t n)

Sets the maximum number of connections the pool will hold.

Parameters

  • n Maximum pool capacity.

size

const inline

inline size_t size() const

Returns the current number of connections held in the pool.

Private Attributes

ReturnNameDescription
std::vector< ServerConnection::Ptr >_pool
size_t_maxSize

_pool

std::vector< ServerConnection::Ptr > _pool

_maxSize

size_t _maxSize = 128