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.9 2003/12/22 08:32:14 freddy77 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 /* HAVE_SYS_TYPES_H */
00029 
00030 #if HAVE_NETINET_IN_H
00031 #include <netinet/in.h>
00032 #endif /* HAVE_NETINET_IN_H */
00033 
00034 #include "tds.h"
00035 
00036 /* defines */
00037 #define PGSIZ 2048
00038 #define BLOCKSIZ 512
00039 #define MAX_POOL_USERS 1024
00040 
00041 /* enums and typedefs */
00042 enum
00043 {
00044         TDS_SRV_LOGIN,
00045         TDS_SRV_IDLE,
00046         TDS_SRV_QUERY,
00047         TDS_SRV_WAIT,           /* if no members are free wait */
00048         TDS_SRV_CANCEL,
00049         TDS_SRV_DEAD
00050 };
00051 
00052 typedef struct tds_pool_user
00053 {
00054         TDSSOCKET *tds;
00055         int user_state;
00056 }
00057 TDS_POOL_USER;
00058 
00059 typedef struct tds_pool_member
00060 {
00061         TDSSOCKET *tds;
00062         /* sometimes we get a partial packet */
00063         int need_more;
00064         int state;
00065         time_t last_used_tm;
00066         TDS_POOL_USER *current_user;
00067         /* 
00068          * ** these variables are used for tracking the state of the TDS protocol 
00069          * ** so we know when to return the state to TDS_IDLE.
00070          */
00071         int num_bytes_left;
00072         unsigned char fragment[PGSIZ];
00073 }
00074 TDS_POOL_MEMBER;
00075 
00076 typedef struct tds_pool
00077 {
00078         char *name;
00079         char *user;
00080         char *password;
00081         char *server;
00082         char *database;
00083         int port;
00084         int max_member_age;     /* in seconds */
00085         int min_open_conn;
00086         int max_open_conn;
00087         int num_members;
00088         TDS_POOL_MEMBER *members;
00089         int max_users;
00090         TDS_POOL_USER *users;
00091 }
00092 TDS_POOL;
00093 
00094 /* prototypes */
00095 /* main.c */
00096 TDS_POOL *pool_init(char *name);
00097 void pool_main_loop(TDS_POOL * pool);
00098 
00099 /* member.c */
00100 int pool_process_members(TDS_POOL * pool, fd_set * fds);
00101 TDSSOCKET *pool_mbr_login(TDS_POOL * pool);
00102 TDS_POOL_MEMBER *pool_find_idle_member(TDS_POOL * pool);
00103 void pool_mbr_init(TDS_POOL * pool);
00104 
00105 /* user.c */
00106 int pool_process_users(TDS_POOL * pool, fd_set * fds);
00107 void pool_user_init(TDS_POOL * pool);
00108 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, int s, struct sockaddr_in *sin);
00109 void pool_free_user(TDS_POOL_USER * puser);
00110 void pool_user_read(TDS_POOL * pool, TDS_POOL_USER * puser);
00111 int pool_user_login(TDS_POOL * pool, TDS_POOL_USER * puser);
00112 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
00113 
00114 /* util.c */
00115 void dump_buf(const void *buf, int length);
00116 void dump_login(TDSLOGIN * login);
00117 void die_if(int expr, const char *msg);
00118 
00119 /* stream.c */
00120 int pool_find_end_token(TDS_POOL_MEMBER * pmbr, const unsigned char *buf, int len);
00121 
00122 /* config.c */
00123 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
00124 
00125 
00126 #endif

Generated on Tue Jan 13 20:54:53 2004 for FreeTDS API by doxygen1.2.18