添加mk_env_init1接口

This commit is contained in:
xiongziliang 2019-12-20 11:04:18 +08:00
parent 15fbb3d087
commit 0b8c4e75e1
2 changed files with 44 additions and 9 deletions

View File

@ -71,6 +71,24 @@ typedef struct {
*/ */
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg); API_EXPORT void API_CALL mk_env_init(const mk_config *cfg);
/**
* mk_env_init便
*/
API_EXPORT void API_CALL mk_env_init1( // 线程数
int thread_num,
// 日志级别,支持0~4
int log_level,
// 配置文件是内容还是路径
int ini_is_path,
// 配置文件内容或路径可以为NULL
const char *ini,
// ssl证书是内容还是路径
int ssl_is_path,
// ssl证书内容或路径可以为NULL
const char *ssl,
// 证书密码可以为NULL
const char *ssl_pwd);
/** /**
* *
* @param key * @param key

View File

@ -53,25 +53,42 @@ static TcpServer::Ptr tcpRtpServer(new TcpServer());
//////////////////////////environment init/////////////////////////// //////////////////////////environment init///////////////////////////
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) { API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
assert(cfg); assert(cfg);
mk_env_init1(cfg->thread_num,
cfg->log_level,
cfg->ini_is_path,
cfg->ini,
cfg->ssl_is_path,
cfg->ssl,
cfg->ssl_pwd);
}
API_EXPORT void API_CALL mk_env_init1( int thread_num,
int log_level,
int ini_is_path,
const char *ini,
int ssl_is_path,
const char *ssl,
const char *ssl_pwd) {
static onceToken token([&]() { static onceToken token([&]() {
Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) cfg->log_level)); Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) log_level));
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>()); Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
EventPollerPool::setPoolSize(cfg->thread_num); EventPollerPool::setPoolSize(thread_num);
WorkThreadPool::setPoolSize(cfg->thread_num); WorkThreadPool::setPoolSize(thread_num);
if (cfg->ini) { if (ini && ini[0]) {
//设置配置文件 //设置配置文件
if (cfg->ini_is_path) { if (ini_is_path) {
mINI::Instance().parseFile(cfg->ini); mINI::Instance().parseFile(ini);
} else { } else {
mINI::Instance().parse(cfg->ini); mINI::Instance().parse(ini);
} }
} }
if (cfg->ssl) { if (ssl && ssl[0]) {
//设置ssl证书 //设置ssl证书
SSL_Initor::Instance().loadCertificate(cfg->ssl, true, cfg->ssl_pwd ? cfg->ssl_pwd : "", cfg->ssl_is_path); SSL_Initor::Instance().loadCertificate(ssl, true, ssl_pwd ? ssl_pwd : "", ssl_is_path);
} }
}); });
} }