# 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 #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  * POSIX says fd_set type may be defined in either sys/select.h or sys/time.h.
    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.14 2005/07/30 09:01:22 freddy77 Exp $");
    00041
    00042 /* defines */
    00043 #define PGSIZ 2048
    00044 #define BLOCKSIZ 512
    00045 #define MAX_POOL_USERS 1024
    00046
    00047 /* enums and typedefs */
    00048 typedef enum
    00049 {
    00050         TDS_SRV_LOGIN,
    00051         TDS_SRV_IDLE,
    00052         TDS_SRV_QUERY,
    00053         TDS_SRV_WAIT,           /* if no members are free wait */
    00054         TDS_SRV_CANCEL,
    00055         TDS_SRV_DEAD
    00056 } TDS_USER_STATE;
    00057
    00058 /* forward declaration */
    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         /* sometimes we get a partial packet */
    00074         int need_more;
    00075         int state;
    00076         time_t last_used_tm;
    00077         TDS_POOL_USER *current_user;
    00078         /*
    00079          * these variables are used for tracking the state of the TDS protocol
    00080          * so we know when to return the state to TDS_IDLE.
    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;     /* in seconds */
    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 /* prototypes */
    00105
    00106 /* member.c */
    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 /* user.c */
    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, int 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 /* util.c */
    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 /* config.c */
    00128 int pool_read_conf_file(char *poolname, TDS_POOL * pool);
    00129
    00130
    00131 #endif