Main Page   Modules   Compound List   File List   Compound Members   File Members   Related Pages  

pool.h

00001 /* TDSPool - Connection pooling for TDS based databases
00002  * Copyright (C) 2001 Brian Bruns
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  */
00019 
00020 #ifndef _pool_h_
00021 #define _pool_h_
00022 
00023 static char rcsid_pool_h[] = "$Id: pool.h,v 1.10 2004/04/14 00:32:00 jklowden Exp $";
00024 static void *no_unused_var_warn_pool_h[] = { rcsid_pool_h, no_unused_var_warn_pool_h };
00025 
00026 #if HAVE_SYS_TYPES_H
00027 #include <sys/types.h>
00028 #endif
00029 
00030 #if HAVE_NETINET_IN_H
00031 #include <netinet/in.h>
00032 #endif
00033 
00034 /* 
00035  * POSIX says fd_set type may be defined in either sys/select.h or sys/time.h. 
00036  */
00037 #if HAVE_SYS_TIME_H
00038 #include <sys/time.h>
00039 #endif
00040 
00041 #include "tds.h"
00042 
00043 /* defines */
00044 #define PGSIZ 2048
00045 #define BLOCKSIZ 512
00046 #define MAX_POOL_USERS 1024
00047 
00048 /* enums and typedefs */
00049 enum
00050 {
00051         TDS_SRV_LOGIN,
00052         TDS_SRV_IDLE,
00053         TDS_SRV_QUERY,
00054         TDS_SRV_WAIT,           /* if no members are free wait */
00055         TDS_SRV_CANCEL,
00056         TDS_SRV_DEAD
00057 };
00058 
00059 typedef struct tds_pool_user
00060 {
00061         TDSSOCKET *tds;
00062         int user_state;
00063 }
00064 TDS_POOL_USER;
00065 
00066 typedef struct tds_pool_member
00067 {
00068         TDSSOCKET *tds;
00069         /* sometimes we get a partial packet */
00070         int need_more;
00071         int state;
00072         time_t last_used_tm;
00073         TDS_POOL_USER *current_user;
00074         /* 
00075          * ** these variables are used for tracking the state of the TDS protocol 
00076          * ** so we know when to return the state to TDS_IDLE.
00077          */
00078         int num_bytes_left;
00079         unsigned char fragment[PGSIZ];
00080 }
00081 TDS_POOL_MEMBER;
00082 
00083 typedef struct tds_pool
00084 {
00085         char *name;
00086         char *user;
00087         char *password;
00088         char *server;
00089         char *database;
00090         int port;
00091         int max_member_age;     /* in seconds */
00092         int min_open_conn;
00093         int max_open_conn;
00094         int num_members;
00095         TDS_POOL_MEMBER *members;
00096         int max_users;
00097         TDS_POOL_USER *users;
00098 }
00099 TDS_POOL;
00100 
00101 /* prototypes */
00102 /* main.c */
00103 TDS_POOL *pool_init(char *name);
00104 void pool_main_loop(TDS_POOL * pool);
00105 
00106 /* member.c */
00107 int pool_process_members(TDS_POOL * pool, fd_set * fds);
00108 TDSSOCKET *pool_mbr_login(TDS_POOL * pool);
00109 TDS_POOL_MEMBER *pool_find_idle_member(TDS_POOL * pool);
00110 void pool_mbr_init(TDS_POOL * pool);
00111 
00112 /* user.c */
00113 int pool_process_users(TDS_POOL * pool, fd_set * fds);
00114 void pool_user_init(TDS_POOL * pool);
00115 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, int s, struct sockaddr_in *sin);
00116 void pool_free_user(TDS_POOL_USER * puser);
00117 void pool_user_read(TDS_POOL * pool, TDS_POOL_USER * puser);
00118 int pool_user_login(TDS_POOL * pool, TDS_POOL_USER * puser);
00119 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
00120 
00121 /* util.c */
00122 void dump_buf(const void *buf, int length);
00123 void dump_login(TDSLOGIN * login);
00124 void die_if(int expr, const char *msg);
00125 
00126 /* stream.c */
00127 int pool_find_end_token(TDS_POOL_MEMBER * pmbr, const unsigned char *buf, int len);
00128 
00129 /* config.c */
00130 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
00131 
00132 
00133 #endif

Generated on Tue Mar 29 19:52:35 2005 for FreeTDS API by doxygen1.3