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_LOGIN,
49  TDS_SRV_IDLE,
50  TDS_SRV_QUERY,
51  TDS_SRV_WAIT, /* if no members are free wait */
52  TDS_SRV_CANCEL,
53  TDS_SRV_DEAD
54 } TDS_USER_STATE;
55 
56 /* forward declaration */
57 typedef struct tds_pool_member TDS_POOL_MEMBER;
58 
59 
60 typedef struct tds_pool_user
61 {
62  TDSSOCKET *tds;
63  TDS_USER_STATE user_state;
64  TDS_POOL_MEMBER *assigned_member;
65 }
67 
69 {
70  TDSSOCKET *tds;
71  /* sometimes we get a partial packet */
72  int need_more;
73  int state;
74  time_t last_used_tm;
75  TDS_POOL_USER *current_user;
76  /*
77  * these variables are used for tracking the state of the TDS protocol
78  * so we know when to return the state to TDS_IDLE.
79  */
80  int num_bytes_left;
81  unsigned char fragment[PGSIZ];
82 };
83 
84 typedef struct tds_pool
85 {
86  char *name;
87  char *user;
88  char *password;
89  char *server;
90  char *database;
91  int port;
92  int max_member_age; /* in seconds */
93  int min_open_conn;
94  int max_open_conn;
95  int num_members;
96  TDS_POOL_MEMBER *members;
97  int max_users;
98  TDS_POOL_USER *users;
99 }
100 TDS_POOL;
101 
102 /* prototypes */
103 
104 /* member.c */
105 int pool_process_members(TDS_POOL * pool, fd_set * fds);
106 TDS_POOL_MEMBER *pool_find_idle_member(TDS_POOL * pool);
107 void pool_mbr_init(TDS_POOL * pool);
108 void pool_free_member(TDS_POOL_MEMBER * pmbr);
109 void pool_assign_member(TDS_POOL_MEMBER * pmbr, TDS_POOL_USER *puser);
110 void pool_deassign_member(TDS_POOL_MEMBER * pmbr);
111 void pool_reset_member(TDS_POOL_MEMBER * pmbr);
112 
113 /* user.c */
114 int pool_process_users(TDS_POOL * pool, fd_set * fds);
115 void pool_user_init(TDS_POOL * pool);
116 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, TDS_SYS_SOCKET s, struct sockaddr_in *sin);
117 void pool_free_user(TDS_POOL_USER * puser);
118 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
119 
120 /* util.c */
121 void dump_buf(const void *buf, int length);
122 void dump_login(TDSLOGIN * login);
123 void die_if(int expr, const char *msg);
124 
125 /* config.c */
126 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
127 
128 
129 #endif
Definition: pool.h:60
Definition: pool.h:68
Definition: tds.h:531
Definition: pool.h:84
Main include file for libtds.
Information for a server connection.
Definition: tds.h:1131