Rename mod_socket_create/delete to mod_conn_create/delete
[freeradius.git] / src / include / connection.h
1 /*
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.
6  *
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.
11  *
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
15  */
16 #ifndef FR_CONNECTION_H
17 #define FR_CONNECTION_H
18 /*
19  * $Id$
20  *
21  * @file connection.h
22  * @brief Structures, prototypes and global variables for server connection pools.
23  *
24  * @copyright 2012  The FreeRADIUS server project
25  * @copyright 2012  Alan DeKok <aland@deployingradius.com>
26  */
27
28 RCSIDH(connection_h, "$Id$")
29
30 #include <freeradius-devel/conffile.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 typedef struct fr_connection_pool_t fr_connection_pool_t;
37
38 /** Create a new connection handle
39  *
40  * This function will be called whenever the connection pool manager needs
41  * to spawn a new connection, and on reconnect.
42  *
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.
47  */
48 typedef void *(*fr_connection_create_t)(void *ctx);
49
50 /** Check a connection handle is still viable
51  *
52  * Should check the state  of a connection handle.
53  *
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.
60  */
61 typedef int (*fr_connection_alive_t)(void *ctx, void *connection);
62
63 /** Delete a connection and free allocated memory
64  *
65  * Should close any sockets associated with the passed connection handle,
66  * and free any memory allocated to it.
67  *
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.
71  */
72 typedef int (*fr_connection_delete_t)(void *ctx, void *connection);
73
74 fr_connection_pool_t *fr_connection_pool_init(CONF_SECTION *cs,
75                                               void *ctx,
76                                               fr_connection_create_t c,
77                                               fr_connection_alive_t a,
78                                               fr_connection_delete_t d,
79                                               char const *prefix);
80 void fr_connection_pool_delete(fr_connection_pool_t *pool);
81
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);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif /* FR_CONNECTION_H*/