From 2e420a0a40cc3fcc62bcb42ee6a25f4ad4f22dd3 Mon Sep 17 00:00:00 2001 From: wangky <m1561510467@163.com> Date: 星期三, 06 十一月 2024 16:26:04 +0800 Subject: [PATCH] 1 --- Server/王琨元/code/ConnectionPool.h | 58 ++++++++++++++++++++++++++-------------------------------- 1 files changed, 26 insertions(+), 32 deletions(-) diff --git "a/Server/\347\216\213\347\220\250\345\205\203/code/ConnectionPool.h" "b/Server/\347\216\213\347\220\250\345\205\203/code/ConnectionPool.h" index bce6a07..c78a46e 100644 --- "a/Server/\347\216\213\347\220\250\345\205\203/code/ConnectionPool.h" +++ "b/Server/\347\216\213\347\220\250\345\205\203/code/ConnectionPool.h" @@ -1,50 +1,44 @@ #pragma once -#include <queue> -#include <mutex> -#include <condition_variable> -//#include <json/json.h> - #include "MysqlConn.h" - -//using namespace Json; class ConnectionPool { public: - static ConnectionPool* getInstance( ); + static ConnectionPool* getInstance(); - std::shared_ptr<MysqlConn> getMysqlConn(); // 从数据库连接池获取连接 + shared_ptr<MysqlConn> getMysqlConn(); // 从数据库连接池获取连接 - ConnectionPool(const ConnectionPool& other) = delete; - ConnectionPool& operator = (const ConnectionPool & other ) = delete; - - ~ConnectionPool(); + ConnectionPool(const ConnectionPool& other) = delete; + ConnectionPool& operator=(const ConnectionPool& other) = delete; - void description(); + ~ConnectionPool(); + + void description(); protected: - ConnectionPool( ); // 构造函数 + ConnectionPool(); // 构造函数 private: - bool parseJsonFile(); // 解析配置 + // 不再需要解析配置文件的函数 + // bool parseJsonFile(); // 解析配置 - void produce(); - void recycle(); - void addConnection(); // 增加连接数 + void produce(); + void recycle(); + void addConnection(); // 增加连接数 - std::string m_ip; - std::string m_userName; - std::string m_passwd; - std::string m_db; - unsigned short m_port; + // 写死的数据库连接参数 + string m_ip = "127.0.0.1"; + string m_userName = "root"; + string m_passwd = "123456"; + string m_db = "mayi_kunlun"; + unsigned short m_port = 3306; - int m_max_conn; - int m_min_conn; + int m_max_conn; + int m_min_conn; - int m_timeout; // 连接超时时间 - int max_del_time; // 最大删除时间( 连接空闲时间超过这个,就给当前连接关闭 ) - std::queue<MysqlConn*>m_connkQueue ; // 连接队列 - std::mutex m_mutex; // 互斥锁 - std::condition_variable m_cond; // 条件变量 + int m_timeout; // 连接超时时间 + int max_del_time; // 最大删除时间( 连接空闲时间超过这个,就给当前连接关闭 ) + queue<MysqlConn*> m_connkQueue; // 连接队列 + mutex m_mutex; // 互斥锁 + condition_variable m_cond; // 条件变量 }; - -- Gitblit v1.8.0