2015-08-12 16:48:24 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "acl_cpp/acl_cpp_define.hpp"
|
|
|
|
|
#include <map>
|
|
|
|
|
#include "acl_cpp/stdlib/string.hpp"
|
|
|
|
|
#include "acl_cpp/connpool/connect_manager.hpp"
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class mysql_conf;
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API mysql_manager : public connect_manager
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-08-12 17:22:52 +08:00
|
|
|
|
mysql_manager(time_t idle_ttl = 120);
|
2015-08-12 16:48:24 +08:00
|
|
|
|
~mysql_manager();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʵ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbaddr {const char*} mysql <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>IP:PORT<EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD> UNIX ƽ̨<EFBFBD>¿<EFBFBD><EFBFBD><EFBFBD>Ϊ UNIX <EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
* @param dbname {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dbuser {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>û<EFBFBD>
|
|
|
|
|
* @param dbpass {const char*} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-08-14 17:28:30 +08:00
|
|
|
|
* @param dblimit {size_t} <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-08-12 16:48:24 +08:00
|
|
|
|
* @param dbflags {unsigned long} mysql <EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
|
|
|
|
|
* @param auto_commit {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ύ
|
|
|
|
|
* @param conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿⳬʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
|
|
|
|
* @param rw_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ͨ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>IOʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>)
|
|
|
|
|
* @return {mysql_manager&}
|
|
|
|
|
*/
|
|
|
|
|
mysql_manager& add(const char* dbaddr, const char* dbname,
|
|
|
|
|
const char* dbuser, const char* dbpass,
|
2015-08-14 17:28:30 +08:00
|
|
|
|
size_t dblimit = 64, unsigned long dbflags = 0,
|
2015-08-12 16:48:24 +08:00
|
|
|
|
bool auto_commit = true, int conn_timeout = 60,
|
|
|
|
|
int rw_timeout = 60);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʵ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param conf {const mysql_conf&}
|
|
|
|
|
* @return {mysql_manager&}
|
|
|
|
|
*/
|
|
|
|
|
mysql_manager& add(const mysql_conf& conf);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> connect_manager <EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ip:port
|
2015-09-27 20:59:21 +08:00
|
|
|
|
* @param count {size_t} <EFBFBD><EFBFBD><EFBFBD>ӳصĴ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><EFBFBD><EFBFBD>ֵΪ 0 ʱ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-08-12 16:48:24 +08:00
|
|
|
|
* @param idx {size_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳض<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>±<EFBFBD>λ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD> 0 <EFBFBD><EFBFBD>ʼ)
|
|
|
|
|
* @return {connect_pool*} <EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳض<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2015-08-14 17:28:30 +08:00
|
|
|
|
connect_pool* create_pool(const char* addr, size_t count, size_t idx);
|
2015-08-12 16:48:24 +08:00
|
|
|
|
|
|
|
|
|
private:
|
2015-08-12 17:22:52 +08:00
|
|
|
|
time_t idle_ttl_; // <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ӵĿ<D3B5><C4BF>й<EFBFBD><D0B9><EFBFBD>ʱ<EFBFBD><CAB1>
|
2015-08-12 16:48:24 +08:00
|
|
|
|
std::map<string, mysql_conf*> dbs_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|