HTTP module
ConnectionPool
LIFO connection pool for reusing ServerConnection objects. Avoids per-request heap allocation by resetting and reusing connections instead of destroying and recreating them.
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
| Return | Name | Description |
|---|---|---|
ServerConnection::Ptr | acquire inline | Takes a connection from the pool for reuse. |
bool | release inline | Returns a connection to the pool after use. |
void | setMaxSize inline | Sets the maximum number of connections the pool will hold. |
size_t | size const inline | Returns 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
connThe 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
nMaximum pool capacity.
size
const inline
inline size_t size() constReturns the current number of connections held in the pool.
Private Attributes
_pool
std::vector< ServerConnection::Ptr > _pool_maxSize
size_t _maxSize = 128