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 * @note A function pointer matching this prototype must be passed
44 * to fr_connection_pool.
45 * @param[in] ctx pointer passed to fr_connection_pool_init.
46 * @return NULL on error, else a connection handle.
48 typedef void *(*fr_connection_create_t)(void *ctx);
50 /** Check a connection handle is still viable
52 * Should check the state of a connection handle.
54 * @note NULL may be passed to fr_connection_init, if there is no way to check
55 * the state of a connection handle.
56 * @note Not currently use by connection pool manager.
57 * @param[in] ctx pointer passed to fr_connection_pool_init.
58 * @param[in] connection handle returned by fr_connection_create_t.
59 * @return < 0 on error or if the connection is unusable, else 0.
61 typedef int (*fr_connection_alive_t)(void *ctx, void *connection);
63 /** Delete a connection and free allocated memory
65 * Should close any sockets associated with the passed connection handle,
66 * and free any memory allocated to it.
68 * @param[in] ctx pointer passed to fr_connection_pool_init.
69 * @param[in,out] connection handle returned by fr_connection_create_t.
70 * @return < 0 on error else 0 if connection was closed successfully.
72 typedef int (*fr_connection_delete_t)(void *ctx, void *connection);
74 fr_connection_pool_t *fr_connection_pool_init(CONF_SECTION *cs,
76 fr_connection_create_t c,
77 fr_connection_alive_t a,
78 fr_connection_delete_t d,
80 void fr_connection_pool_delete(fr_connection_pool_t *pool);
82 void *fr_connection_get(fr_connection_pool_t *pool);
83 int fr_connection_get_num(fr_connection_pool_t *pool);
84 void fr_connection_release(fr_connection_pool_t *pool, void *conn);
85 void *fr_connection_reconnect(fr_connection_pool_t *pool, void *conn);
86 int fr_connection_del(fr_connection_pool_t *pool, void *conn);
92 #endif /* FR_CONNECTION_H*/