FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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 "tds.h"
39 
40 TDS_RCSID(pool_h, "$Id: pool.h,v 1.15 2006-06-12 19:45:59 freddy77 Exp $");
41 
42 /* defines */
43 #define PGSIZ 2048
44 #define BLOCKSIZ 512
45 #define MAX_POOL_USERS 1024
46 
47 /* enums and typedefs */
48 typedef enum
49 {
50  TDS_SRV_LOGIN,
51  TDS_SRV_IDLE,
52  TDS_SRV_QUERY,
53  TDS_SRV_WAIT, /* if no members are free wait */
54  TDS_SRV_CANCEL,
55  TDS_SRV_DEAD
56 } TDS_USER_STATE;
57 
58 /* forward declaration */
59 typedef struct tds_pool_member TDS_POOL_MEMBER;
60 
61 
62 typedef struct tds_pool_user
63 {
64  TDSSOCKET *tds;
65  TDS_USER_STATE user_state;
66  TDS_POOL_MEMBER *assigned_member;
67 }
69 
71 {
72  TDSSOCKET *tds;
73  /* sometimes we get a partial packet */
74  int need_more;
75  int state;
76  time_t last_used_tm;
77  TDS_POOL_USER *current_user;
78  /*
79  * these variables are used for tracking the state of the TDS protocol
80  * so we know when to return the state to TDS_IDLE.
81  */
82  int num_bytes_left;
83  unsigned char fragment[PGSIZ];
84 };
85 
86 typedef struct tds_pool
87 {
88  char *name;
89  char *user;
90  char *password;
91  char *server;
92  char *database;
93  int port;
94  int max_member_age; /* in seconds */
95  int min_open_conn;
96  int max_open_conn;
97  int num_members;
98  TDS_POOL_MEMBER *members;
99  int max_users;
100  TDS_POOL_USER *users;
101 }
102 TDS_POOL;
103 
104 /* prototypes */
105 
106 /* member.c */
107 int pool_process_members(TDS_POOL * pool, fd_set * fds);
108 TDS_POOL_MEMBER *pool_find_idle_member(TDS_POOL * pool);
109 void pool_mbr_init(TDS_POOL * pool);
110 void pool_free_member(TDS_POOL_MEMBER * pmbr);
111 void pool_assign_member(TDS_POOL_MEMBER * pmbr, TDS_POOL_USER *puser);
112 void pool_deassign_member(TDS_POOL_MEMBER * pmbr);
113 void pool_reset_member(TDS_POOL_MEMBER * pmbr);
114 
115 /* user.c */
116 int pool_process_users(TDS_POOL * pool, fd_set * fds);
117 void pool_user_init(TDS_POOL * pool);
118 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, TDS_SYS_SOCKET s, struct sockaddr_in *sin);
119 void pool_free_user(TDS_POOL_USER * puser);
120 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
121 
122 /* util.c */
123 void dump_buf(const void *buf, int length);
124 void dump_login(TDSLOGIN * login);
125 void die_if(int expr, const char *msg);
126 
127 /* config.c */
128 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
129 
130 
131 #endif