connectionpool.h
来自「SMS gateway. SMS protocol for CHINA mobi」· C头文件 代码 · 共 72 行
H
72 行
#ifndef __CONNECTION_POOL_H__
#define __CONNECTION_POOL_H__
#include <mysql.h>
#include <time.h>
#include "utils.h"
typedef struct _CONNECTION
{
int nID;
time_t nCreationTime;
time_t nLastQueryTime;
time_t nLastIdleTime;
int nQueryCount;
bool bBusy;
MYSQL *pConn;
} CONNECTION;
class ConnectionPool
{
public:
ConnectionPool(const char *sHost, const char *sUser, const char *sPassword, const char *sDatabase, unsigned int nPort, const char *sUnixSocket, unsigned int nClientFlag, int nCapacity, int nIdleTimeout, int nMaxQuery);
~ConnectionPool();
CONNECTION *GetConnection();
void FreeConnection(CONNECTION *pConn);
int GetIdleCount()
{
return nIdlePoolSize;
}
int GetBusyCount()
{
return nBusyPoolSize;
}
int GetIdleTimeout()
{
return nIdleTimeout;
}
void CheckIdle();
bool bStop;
private:
CONNECTION *CreateConnection();
void CloseConnection(CONNECTION *pConn);
void CloseAllConnections();
pthread_mutex_t mutex;
pthread_t WatcherThread;
// MySQL connection properties
char *sHost, *sUsername, *sPassword, *sDatabase, *sUnixSocket;
unsigned int nPort, nClientFlag;
// Connection pool properties
int nCapacity, nIdleTimeout, nMaxQuery;
FIFO *pIdlePool; // Linked list (FIFO)
int nIdlePoolSize;
HashTable *pBusyPool; // Array (hash map)
int nBusyPoolSize;
int nID;
};
#endif // #ifndef __CONNECTION_POOL_H__
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?