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 #if HAVE_SYS_TYPES_H
00024 #include <sys/types.h>
00025 #endif
00026
00027 #if HAVE_NETINET_IN_H
00028 #include <netinet/in.h>
00029 #endif
00030
00031
00032
00033
00034 #if HAVE_SYS_TIME_H
00035 #include <sys/time.h>
00036 #endif
00037
00038 #include "tds.h"
00039
00040 TDS_RCSID(pool_h, "$Id: pool.h,v 1.15 2006/06/12 19:45:59 freddy77 Exp $");
00041
00042
00043 #define PGSIZ 2048
00044 #define BLOCKSIZ 512
00045 #define MAX_POOL_USERS 1024
00046
00047
00048 typedef enum
00049 {
00050 TDS_SRV_LOGIN,
00051 TDS_SRV_IDLE,
00052 TDS_SRV_QUERY,
00053 TDS_SRV_WAIT,
00054 TDS_SRV_CANCEL,
00055 TDS_SRV_DEAD
00056 } TDS_USER_STATE;
00057
00058
00059 typedef struct tds_pool_member TDS_POOL_MEMBER;
00060
00061
00062 typedef struct tds_pool_user
00063 {
00064 TDSSOCKET *tds;
00065 TDS_USER_STATE user_state;
00066 TDS_POOL_MEMBER *assigned_member;
00067 }
00068 TDS_POOL_USER;
00069
00070 struct tds_pool_member
00071 {
00072 TDSSOCKET *tds;
00073
00074 int need_more;
00075 int state;
00076 time_t last_used_tm;
00077 TDS_POOL_USER *current_user;
00078
00079
00080
00081
00082 int num_bytes_left;
00083 unsigned char fragment[PGSIZ];
00084 };
00085
00086 typedef struct tds_pool
00087 {
00088 char *name;
00089 char *user;
00090 char *password;
00091 char *server;
00092 char *database;
00093 int port;
00094 int max_member_age;
00095 int min_open_conn;
00096 int max_open_conn;
00097 int num_members;
00098 TDS_POOL_MEMBER *members;
00099 int max_users;
00100 TDS_POOL_USER *users;
00101 }
00102 TDS_POOL;
00103
00104
00105
00106
00107 int pool_process_members(TDS_POOL * pool, fd_set * fds);
00108 TDS_POOL_MEMBER *pool_find_idle_member(TDS_POOL * pool);
00109 void pool_mbr_init(TDS_POOL * pool);
00110 void pool_free_member(TDS_POOL_MEMBER * pmbr);
00111 void pool_assign_member(TDS_POOL_MEMBER * pmbr, TDS_POOL_USER *puser);
00112 void pool_deassign_member(TDS_POOL_MEMBER * pmbr);
00113 void pool_reset_member(TDS_POOL_MEMBER * pmbr);
00114
00115
00116 int pool_process_users(TDS_POOL * pool, fd_set * fds);
00117 void pool_user_init(TDS_POOL * pool);
00118 TDS_POOL_USER *pool_user_create(TDS_POOL * pool, TDS_SYS_SOCKET s, struct sockaddr_in *sin);
00119 void pool_free_user(TDS_POOL_USER * puser);
00120 void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser);
00121
00122
00123 void dump_buf(const void *buf, int length);
00124 void dump_login(TDSLOGIN * login);
00125 void die_if(int expr, const char *msg);
00126
00127
00128 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
00129
00130
00131 #endif