FreeTDS API

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pool.h
1 /* TDSPool - Connection pooling for TDS based databases
2 * Copyright (C) 2001 Brian Bruns
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20 #ifndef _pool_h_
21 #define _pool_h_
22
23 #include <assert.h>
24
25 #if HAVE_SYS_TYPES_H
26 #include <sys/types.h>
27 #endif
28
29 #if HAVE_NETINET_IN_H
30 #include <netinet/in.h>
31 #endif
32
33 /*
34 * POSIX says fd_set type may be defined in either sys/select.h or sys/time.h.
35 */
36 #if HAVE_SYS_TIME_H
37 #include <sys/time.h>
38 #endif
39
40 #include <freetds/tds.h>
41 #include <freetds/dlist.h>
42
43 /* defines */
44 #define PGSIZ 2048
45 #define BLOCKSIZ 512
46 #define MAX_POOL_USERS 1024
47
48 /* enums and typedefs */
49 typedef enum
50 {
51 TDS_SRV_WAIT, /* if no members are free wait */
52 TDS_SRV_QUERY,
53 } TDS_USER_STATE;
54
55 /* forward declaration */
56 typedef struct tds_pool_event TDS_POOL_EVENT;
57 typedef struct tds_pool_socket TDS_POOL_SOCKET;
58 typedef struct tds_pool_member TDS_POOL_MEMBER;
59 typedef struct tds_pool_user TDS_POOL_USER;
60 typedef struct tds_pool TDS_POOL;
61 typedef void (*TDS_POOL_EXECUTE)(TDS_POOL_EVENT *event);
62
63 struct tds_pool_event
64 {
65 TDS_POOL_EVENT *next;
66 TDS_POOL_EXECUTE execute;
67 };
68
69 struct tds_pool_socket
70 {
71 TDSSOCKET *tds;
72 bool poll_recv;
73 bool poll_send;
74 };
75
76 struct tds_pool_user
77 {
78 TDS_POOL_SOCKET sock;
79 DLIST_FIELDS(dlist_user_item);
80 TDSLOGIN *login;
81 TDS_USER_STATE user_state;
82 TDS_POOL_MEMBER *assigned_member;
83 };
84
85 struct tds_pool_member
86 {
87 TDS_POOL_SOCKET sock;
88 DLIST_FIELDS(dlist_member_item);
89 bool doing_async;
90 time_t last_used_tm;
91 TDS_POOL_USER *current_user;
92 };
93
94 #define DLIST_NAME(suffix) dlist_member_ ## suffix
95 #define DLIST_LIST_TYPE dlist_members
96 #define DLIST_TYPE TDS_POOL_MEMBER
97 #include <freetds/dlist.tmpl.h>
98
99 #define DLIST_NAME(suffix) dlist_user_ ## suffix
100 #define DLIST_LIST_TYPE dlist_users
101 #define DLIST_TYPE TDS_POOL_USER
102 #include <freetds/dlist.tmpl.h>
103
104 struct tds_pool
105 {
106 char *name;
107 char *user;
108 char *password;
109 char *server;
110 char *database;
111 int port;
112 int max_member_age; /* in seconds */
113 int min_open_conn;
114 int max_open_conn;
115 tds_mutex events_mtx;
116 TDS_SYS_SOCKET listen_fd;
117 TDS_SYS_SOCKET wakeup_fd;
118 TDS_SYS_SOCKET event_fd;
119 TDS_POOL_EVENT *events;
120
121 int num_active_members;
122 dlist_members active_members;
123 dlist_members idle_members;
124
126 dlist_users waiters;
127 int num_users;
128 dlist_users users;
129 TDSCONTEXT *ctx;
130
131 unsigned long user_logins;
132 unsigned long member_logins;
133 };
134
135 /* prototypes */
136
137 /* member.c */
138 void pool_process_members(TDS_POOL * pool, fd_set * rfds, fd_set * wfds);
139 TDS_POOL_MEMBER *pool_assign_idle_member(TDS_POOL * pool, TDS_POOL_USER *user);
140 void pool_mbr_init(TDS_POOL * pool);
141 void pool_mbr_destroy(TDS_POOL * pool);
142 void pool_free_member(TDS_POOL *pool, TDS_POOL_MEMBER * pmbr);
143 void pool_assign_member(TDS_POOL *pool, TDS_POOL_MEMBER * pmbr, TDS_POOL_USER *puser);
144 void pool_deassign_member(TDS_POOL *pool, TDS_POOL_MEMBER * pmbr);
145 void pool_reset_member(TDS_POOL *pool, TDS_POOL_MEMBER * pmbr);
146 bool pool_packet_read(TDSSOCKET * tds);
147
148 /* user.c */
149 void pool_process_users(TDS_POOL * pool, fd_set * rfds, fd_set * wfds);
150 void pool_user_init(TDS_POOL * pool);
151 void pool_user_destroy(TDS_POOL * pool);
152 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, TDS_SYS_SOCKET s);
153 void pool_free_user(TDS_POOL * pool, TDS_POOL_USER * puser);
154 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
155 bool pool_user_send_login_ack(TDS_POOL * pool, TDS_POOL_USER * puser);
156 void pool_user_finish_login(TDS_POOL * pool, TDS_POOL_USER * puser);
157
158 /* util.c */
159 void dump_login(TDSLOGIN * login);
160 void pool_event_add(TDS_POOL *pool, TDS_POOL_EVENT *ev, TDS_POOL_EXECUTE execute);
161 int pool_write(TDS_SYS_SOCKET sock, const void *buf, size_t len);
162 bool pool_write_data(TDS_POOL_SOCKET *from, TDS_POOL_SOCKET *to);
163
164 /* config.c */
165 int pool_read_conf_file(const char *poolname, TDS_POOL * pool, char **err);
166
167
168 #endif
tds_socket
Information for a server connection.
Definition: tds.h:1168
tds_pool_event
Definition: pool.h:63
tds_pool_user
Definition: pool.h:76
tds_pool_socket
Definition: pool.h:69
tds_pool
Definition: pool.h:104
tds.h
Main include file for libtds.
tds_context
Definition: tds.h:1058
tds_login
Definition: tds.h:547
tds_pool_member
Definition: pool.h:85
tds_pool::waiters
dlist_users waiters
users in wait state
Definition: pool.h:126