逻辑图:
connector_pool头文件
#ifndef __DB_CONNECT_POOL__H
#define __DB_CONNECT_POOL__H
#include <string.h>
#include <mysql/mysql.h>
#include <mutex>
#include <condition_variable>
#include <list>
struct db_config
{
std::string host;
std::string user;
std::string passwd;
std::string db_name;
unsigned short port;
unsigned short conn_num;
};
class db_connector_pool;
class db_connector
{
public:
friend class db_connector_pool;
typedef std::function<void(MYSQL*)> release_connector_cb;
MYSQL* get_conn();
private:
db_connector(MYSQL* conn, release_connector_cb cb);
public:
~db_connector();
private:
MYSQL *m_conn;
std::function<void(MYSQL*)> m_cb;
};
typedef std::shared_ptr<db_connector> db_connector_ptr;
class db_connector_pool
{
public:
db_connector_po