add function sf_load_cluster_config_by_file

iovec_array
YuQing 2021-05-22 17:12:27 +08:00
parent 4d1ef0ba1a
commit 662e2036f6
2 changed files with 35 additions and 20 deletions

View File

@ -68,11 +68,10 @@ static int find_group_indexes_in_cluster_config(SFClusterConfig *cluster,
static int load_server_cfg(SFClusterConfig *cluster, static int load_server_cfg(SFClusterConfig *cluster,
const char *cluster_filename, const int default_port, const char *cluster_filename, const int default_port,
const int size) const bool share_between_groups)
{ {
IniContext ini_context; IniContext ini_context;
const int min_hosts_each_group = 1; const int min_hosts_each_group = 1;
const bool share_between_groups = true;
int result; int result;
if ((result=iniLoadFromFile(cluster_filename, &ini_context)) != 0) { if ((result=iniLoadFromFile(cluster_filename, &ini_context)) != 0) {
@ -90,11 +89,38 @@ static int load_server_cfg(SFClusterConfig *cluster,
return result; return result;
} }
int sf_load_cluster_config_by_file(SFClusterConfig *cluster,
const char *full_cluster_filename, const int default_port,
const bool share_between_groups, const bool calc_sign)
{
int result;
if ((result=load_server_cfg(cluster, full_cluster_filename,
default_port, share_between_groups)) != 0)
{
return result;
}
if ((result=find_group_indexes_in_cluster_config(cluster,
full_cluster_filename)) != 0)
{
return result;
}
if (calc_sign) {
if ((result=calc_cluster_config_sign(cluster)) != 0) {
return result;
}
}
return 0;
}
int sf_load_cluster_config_ex(SFClusterConfig *cluster, IniFullContext int sf_load_cluster_config_ex(SFClusterConfig *cluster, IniFullContext
*ini_ctx, const int default_port, char *full_cluster_filename, *ini_ctx, const int default_port, char *full_cluster_filename,
const int size) const int size)
{ {
int result; const bool share_between_groups = true;
char *cluster_config_filename; char *cluster_config_filename;
cluster_config_filename = iniGetStrValue(ini_ctx->section_name, cluster_config_filename = iniGetStrValue(ini_ctx->section_name,
@ -108,21 +134,6 @@ int sf_load_cluster_config_ex(SFClusterConfig *cluster, IniFullContext
resolve_path(ini_ctx->filename, cluster_config_filename, resolve_path(ini_ctx->filename, cluster_config_filename,
full_cluster_filename, size); full_cluster_filename, size);
if ((result=load_server_cfg(cluster, full_cluster_filename, return sf_load_cluster_config_by_file(cluster, full_cluster_filename,
default_port, size)) != 0) default_port, share_between_groups, true);
{
return result;
}
if ((result=find_group_indexes_in_cluster_config(
cluster, ini_ctx->filename)) != 0)
{
return result;
}
if ((result=calc_cluster_config_sign(cluster)) != 0) {
return result;
}
return 0;
} }

View File

@ -35,6 +35,10 @@ static inline int sf_load_cluster_config(SFClusterConfig *cluster,
full_cluster_filename, PATH_MAX); full_cluster_filename, PATH_MAX);
} }
int sf_load_cluster_config_by_file(SFClusterConfig *cluster,
const char *full_cluster_filename, const int default_port,
const bool share_between_groups, const bool calc_sign);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif