2015-08-12 16:48:24 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2015-08-12 16:48:24 +08:00
|
|
|
|
#include <map>
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
|
|
|
|
#include "../connpool/connect_manager.hpp"
|
2015-08-12 16:48:24 +08:00
|
|
|
|
|
2019-05-18 21:19:21 +08:00
|
|
|
|
#ifndef ACL_CLIENT_ONLY
|
|
|
|
|
|
2015-08-12 16:48:24 +08:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
/**
|
2015-10-25 14:15:07 +08:00
|
|
|
|
* <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 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>)
|
2015-10-25 14:15:07 +08:00
|
|
|
|
* @param charset {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
2015-08-12 16:48:24 +08:00
|
|
|
|
* @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,
|
2015-10-25 14:15:07 +08:00
|
|
|
|
int rw_timeout = 60, const char* charset = "utf8");
|
2015-08-12 16:48:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-10-25 14:15:07 +08:00
|
|
|
|
* <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 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
|
2019-05-18 21:19:21 +08:00
|
|
|
|
|
|
|
|
|
#endif // ACL_CLIENT_ONLY
|