FreeTDS API
 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 #if HAVE_SYS_TYPES_H
24 #include <sys/types.h>
25 #endif
26 
27 #if HAVE_NETINET_IN_H
28 #include <netinet/in.h>
29 #endif
30 
31 /*
32  * POSIX says fd_set type may be defined in either sys/select.h or sys/time.h.
33  */
34 #if HAVE_SYS_TIME_H
35 #include <sys/time.h>
36 #endif
37 
38 #include <freetds/tds.h>
39 
40 /* defines */
41 #define PGSIZ 2048
42 #define BLOCKSIZ 512
43 #define MAX_POOL_USERS 1024
44 
45 /* enums and typedefs */
46 typedef enum
47 {
48  TDS_SRV_WAIT, /* if no members are free wait */
49  TDS_SRV_QUERY,
50 } TDS_USER_STATE;
51 
52 /* forward declaration */
53 typedef struct tds_pool_event TDS_POOL_EVENT;
54 typedef struct tds_pool_socket TDS_POOL_SOCKET;
55 typedef struct tds_pool_member TDS_POOL_MEMBER;
56 typedef struct tds_pool_user TDS_POOL_USER;
57 typedef struct tds_pool TDS_POOL;
58 
60 {
61  TDS_POOL_EVENT *next;
62  void (*execute)(TDS_POOL_EVENT *event);
63 };
64 
66 {
67  TDSSOCKET *tds;
68  bool poll_recv;
69  bool poll_send;
70 };
71 
73 {
74  TDS_POOL_SOCKET sock;
75  TDSLOGIN *login;
76  TDS_USER_STATE user_state;
77  TDS_POOL_MEMBER *assigned_member;
78 };
79 
81 {
82  TDS_POOL_SOCKET sock;
83  TDS_POOL_MEMBER *next;
84  bool doing_async;
85  time_t last_used_tm;
86  TDS_POOL_USER *current_user;
87 };
88 
89 struct tds_pool
90 {
91  char *name;
92  char *user;
93  char *password;
94  char *server;
95  char *database;
96  int port;
97  int max_member_age; /* in seconds */
98  int min_open_conn;
99  int max_open_conn;
100  tds_mutex events_mtx;
101  TDS_SYS_SOCKET event_fd;
102  TDS_POOL_EVENT *events;
103 
104  int num_members;
105  int num_active_members;
106  TDS_POOL_MEMBER *members;
108  int waiters;
109  int max_users;
110  TDS_POOL_USER *users;
111  TDSCONTEXT *ctx;
112 };
113 
114 /* prototypes */
115 
116 /* member.c */
117 void pool_process_members(TDS_POOL * pool, fd_set * rfds, fd_set * wfds);
118 TDS_POOL_MEMBER *pool_find_idle_member(TDS_POOL * pool, TDS_POOL_USER *user);
119 void pool_mbr_init(TDS_POOL * pool);
120 void pool_mbr_destroy(TDS_POOL * pool);
121 void pool_free_member(TDS_POOL *pool, TDS_POOL_MEMBER * pmbr);
122 void pool_assign_member(TDS_POOL_MEMBER * pmbr, TDS_POOL_USER *puser);
123 void pool_deassign_member(TDS_POOL_MEMBER * pmbr);
124 void pool_reset_member(TDS_POOL *pool, TDS_POOL_MEMBER * pmbr);
125 bool pool_packet_read(TDSSOCKET * tds);
126 
127 /* user.c */
128 void pool_process_users(TDS_POOL * pool, fd_set * rfds, fd_set * wfds);
129 void pool_user_init(TDS_POOL * pool);
130 void pool_user_destroy(TDS_POOL * pool);
131 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, TDS_SYS_SOCKET s);
132 void pool_free_user(TDS_POOL * pool, TDS_POOL_USER * puser);
133 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
134 
135 /* util.c */
136 void dump_login(TDSLOGIN * login);
137 void die_if(int expr, const char *msg);
138 void pool_event_add(TDS_POOL *pool, TDS_POOL_EVENT *ev);
139 bool pool_write_data(TDS_POOL_SOCKET *from, TDS_POOL_SOCKET *to);
140 
141 /* config.c */
142 int pool_read_conf_file(const char *poolname, TDS_POOL * pool);
143 
144 
145 #endif
Definition: tds.h:539
Definition: pool.h:72
Information for a server connection.
Definition: tds.h:1155
Definition: pool.h:65
Definition: pool.h:59
Definition: pool.h:80
Definition: pool.h:89
int waiters
number of users in wait state
Definition: pool.h:108
Definition: tds.h:1050
Main include file for libtds.