00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
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 
00036 
00037 #if HAVE_SYS_TIME_H
00038 #include <sys/time.h>
00039 #endif
00040 
00041 #include "tds.h"
00042 
00043 
00044 #define PGSIZ 2048
00045 #define BLOCKSIZ 512
00046 #define MAX_POOL_USERS 1024
00047 
00048 
00049 enum
00050 {
00051         TDS_SRV_LOGIN,
00052         TDS_SRV_IDLE,
00053         TDS_SRV_QUERY,
00054         TDS_SRV_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         
00070         int need_more;
00071         int state;
00072         time_t last_used_tm;
00073         TDS_POOL_USER *current_user;
00074         
00075 
00076 
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;     
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 
00102 
00103 TDS_POOL *pool_init(char *name);
00104 void pool_main_loop(TDS_POOL * pool);
00105 
00106 
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 
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 
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 
00127 int pool_find_end_token(TDS_POOL_MEMBER * pmbr, const unsigned char *buf, int len);
00128 
00129 
00130 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
00131 
00132 
00133 #endif