Function release [src]

Tries to release a connection back to the connection pool. This function is threadsafe. If the connection is marked as closing, it will be closed instead. The allocator must be the owner of all nodes in this pool. The allocator must be the owner of all resources associated with the connection.

Prototype

pub fn release(pool: *ConnectionPool, allocator: Allocator, connection: *Connection) void

Parameters

pool: *ConnectionPoolallocator: Allocatorconnection: *Connection

Source

pub fn release(pool: *ConnectionPool, allocator: Allocator, connection: *Connection) void { pool.mutex.lock(); defer pool.mutex.unlock(); const node: *Node = @fieldParentPtr("data", connection); pool.used.remove(node); if (node.data.closing or pool.free_size == 0) { node.data.close(allocator); return allocator.destroy(node); } if (pool.free_len >= pool.free_size) { const popped = pool.free.popFirst() orelse unreachable; pool.free_len -= 1; popped.data.close(allocator); allocator.destroy(popped); } if (node.data.proxied) { pool.free.prepend(node); // proxied connections go to the end of the queue, always try direct connections first } else { pool.free.append(node); } pool.free_len += 1; }