fr_connection_alive_t a,
char const *prefix);
-fr_connection_pool_t *fr_connection_pool_init(CONF_SECTION *parent,
+fr_connection_pool_t *fr_connection_pool_init(TALLOC_CTX *ctx,
CONF_SECTION *cs,
void *opaque,
fr_connection_create_t c,
fr_connection_alive_t a,
char const *log_prefix,
char const *trigger_prefix);
+
+fr_connection_pool_t *fr_connection_pool_copy(TALLOC_CTX *ctx, fr_connection_pool_t *pool, void *opaque);
+
void fr_connection_pool_free(fr_connection_pool_t *pool);
void *fr_connection_get(fr_connection_pool_t *pool);
int fr_connection_get_num(fr_connection_pool_t *pool);
+void *fr_connection_get_opaque(fr_connection_pool_t *pool);
void fr_connection_release(fr_connection_pool_t *pool, void *conn);
void *fr_connection_reconnect(fr_connection_pool_t *pool, void *conn);
int fr_connection_del(fr_connection_pool_t *pool, void *conn);
pool = cf_data_find(cs, CONNECTION_POOL_CF_KEY);
if (!pool) {
DEBUG4("%s: No pool reference found for config item \"%s.pool\"", log_prefix, parent_name(cs));
- pool = fr_connection_pool_init(module, cs, opaque, c, a, log_prefix, trigger_prefix);
+ pool = fr_connection_pool_init(cs, cs, opaque, c, a, log_prefix, trigger_prefix);
if (!pool) return NULL;
DEBUG4("%s: Adding pool reference %p to config item \"%s.pool\"", log_prefix, pool, parent_name(cs));
return 0;
}
-
/** Create a new connection pool
*
* Allocates structures used by the connection pool, initialises the various
*
* @note Will call the 'start' trigger.
*
- * @param[in] parent section.
+ * @param[in] ctx Context to link pool's destruction to.
* @param[in] cs pool section.
* @param[in] opaque data pointer to pass to callbacks.
* @param[in] c Callback to create new connections.
* @param[in] trigger_prefix prefix to prepend to all trigger names.
* @return A new connection pool or NULL on error.
*/
-fr_connection_pool_t *fr_connection_pool_init(CONF_SECTION *parent,
+fr_connection_pool_t *fr_connection_pool_init(TALLOC_CTX *ctx,
CONF_SECTION *cs,
void *opaque,
fr_connection_create_t c,
fr_connection_t *this;
time_t now;
- if (!parent || !cs || !opaque || !c) return NULL;
+ if (!cs || !opaque || !c) return NULL;
now = time(NULL);
* Ensure the pool is freed at the same time
* as its parent.
*/
- if (fr_link_talloc_ctx_free(cs, pool) < 0) {
+ if (fr_link_talloc_ctx_free(ctx, pool) < 0) {
talloc_free(pool);
return NULL;
return pool;
}
+/** Allocate a new pool using an existing one as a template
+ *
+ * @param ctx to allocate new pool in.
+ * @param pool to copy.
+ * @param opaque data to pass to connection function.
+ * @return
+ * - New connection pool.
+ * - NULL on error.
+ */
+fr_connection_pool_t *fr_connection_pool_copy(TALLOC_CTX *ctx, fr_connection_pool_t *pool, void *opaque)
+{
+ return fr_connection_pool_init(ctx, pool->cs, opaque, pool->create,
+ pool->alive, pool->log_prefix, pool->trigger_prefix);
+}
/** Check whether a connection needs to be removed from the pool
*
return pool->num;
}
+/** Get the opaque data associated with a pool
+ *
+ * @param pool to retrieve opaque data for.
+ * @return the opaque data for the pool.
+ */
+void *fr_connection_get_opaque(fr_connection_pool_t *pool)
+{
+ return pool->opaque;
+}
+
/** Release a connection
*
* Will mark a connection as unused and decrement the number of active