2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 #ifndef FR_CONNECTION_H
17 #define FR_CONNECTION_H
22 * @brief Structures, prototypes and global variables for server connection pools.
24 * @copyright 2012 The FreeRADIUS server project
25 * @copyright 2012 Alan DeKok <aland@deployingradius.com>
28 RCSIDH(connection_h, "$Id$")
30 #include <freeradius-devel/conffile.h>
36 typedef struct fr_connection_pool_t fr_connection_pool_t;
38 /** Create a new connection handle
40 * This function will be called whenever the connection pool manager needs
41 * to spawn a new connection, and on reconnect.
43 * Memory should be talloced in the parent context to hold the module's
44 * connection structure. The parent context is allocated in the NULL
45 * context, but will be freed when fr_connection_t is freed.
47 * There is no delete callback, so operations such as closing sockets and
48 * freeing library connection handles should be done by a destructor attached
49 * to memory allocated beneath ctx.
51 * @note A function pointer matching this prototype must be passed
52 * to fr_connection_pool_init.
54 * @param[in,out] ctx to allocate memory in.
55 * @param[in] opaque pointer passed to fr_connection_pool_init.
56 * @return NULL on error, else a connection handle.
58 typedef void *(*fr_connection_create_t)(TALLOC_CTX *ctx, void *opaque);
60 /** Check a connection handle is still viable
62 * Should check the state of a connection handle.
64 * @note NULL may be passed to fr_connection_init, if there is no way to check
65 * the state of a connection handle.
66 * @note Not currently use by connection pool manager.
67 * @param[in] opaque pointer passed to fr_connection_pool_init.
68 * @param[in] connection handle returned by fr_connection_create_t.
69 * @return < 0 on error or if the connection is unusable, else 0.
71 typedef int (*fr_connection_alive_t)(void *opaque, void *connection);
73 fr_connection_pool_t *fr_connection_pool_init(CONF_SECTION *cs,
75 fr_connection_create_t c,
76 fr_connection_alive_t a,
78 void fr_connection_pool_delete(fr_connection_pool_t *pool);
80 void *fr_connection_get(fr_connection_pool_t *pool);
81 int fr_connection_get_num(fr_connection_pool_t *pool);
82 void fr_connection_release(fr_connection_pool_t *pool, void *conn);
83 void *fr_connection_reconnect(fr_connection_pool_t *pool, void *conn);
84 int fr_connection_del(fr_connection_pool_t *pool, void *conn);
90 #endif /* FR_CONNECTION_H*/