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.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
00029
00030 #if HAVE_NETINET_IN_H
00031 #include <netinet/in.h>
00032 #endif
00033
00034 #include "tds.h"
00035
00036
00037 #define PGSIZ 2048
00038 #define BLOCKSIZ 512
00039 #define MAX_POOL_USERS 1024
00040
00041
00042 enum
00043 {
00044 TDS_SRV_LOGIN,
00045 TDS_SRV_IDLE,
00046 TDS_SRV_QUERY,
00047 TDS_SRV_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
00063 int need_more;
00064 int state;
00065 time_t last_used_tm;
00066 TDS_POOL_USER *current_user;
00067
00068
00069
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;
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
00095
00096 TDS_POOL *pool_init(char *name);
00097 void pool_main_loop(TDS_POOL * pool);
00098
00099
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
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
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
00120 int pool_find_end_token(TDS_POOL_MEMBER * pmbr, const unsigned char *buf, int len);
00121
00122
00123 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
00124
00125
00126 #endif