add sf_configs.[hc]
parent
b60912bfd6
commit
ae72705785
|
|
@ -5,12 +5,16 @@ INC_PATH = -I/usr/include -I/usr/local/include
|
||||||
LIB_PATH = $(LIBS) -lfastcommon
|
LIB_PATH = $(LIBS) -lfastcommon
|
||||||
TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)
|
TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)
|
||||||
|
|
||||||
ALL_HEADERS = sf_types.h sf_global.h sf_define.h sf_nio.h sf_service.h sf_func.h sf_util.h list.h
|
ALL_HEADERS = sf_types.h sf_global.h sf_define.h sf_nio.h sf_service.h \
|
||||||
|
sf_func.h sf_util.h sf_configs.h
|
||||||
|
|
||||||
ALL_LIBS = libserverframe.so
|
ALL_LIBS = libserverframe.so
|
||||||
|
|
||||||
all: $(ALL_LIBS)
|
all: $(ALL_LIBS)
|
||||||
|
|
||||||
libserverframe.so: sf_nio.lo sf_service.lo sf_global.lo sf_func.lo sf_util.lo
|
libserverframe.so: sf_nio.lo sf_service.lo sf_global.lo sf_func.lo sf_util.lo \
|
||||||
|
sf_configs.lo
|
||||||
|
|
||||||
cc -shared -o $@ $^ $(LIB_PATH)
|
cc -shared -o $@ $^ $(LIB_PATH)
|
||||||
|
|
||||||
.lo:
|
.lo:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include "fastcommon/shared_func.h"
|
||||||
|
#include "fastcommon/logger.h"
|
||||||
|
#include "sf_configs.h"
|
||||||
|
|
||||||
|
#define DEFAULT_RETRY_MAX_INTERVAL_MS 5000
|
||||||
|
#define DEFAULT_CONNECT_RETRY_TIMES 10
|
||||||
|
#define DEFAULT_CONNECT_RETRY_INTERVAL_MS 100
|
||||||
|
#define DEFAULT_NETWORK_RETRY_TIMES 10
|
||||||
|
#define DEFAULT_NETWORK_RETRY_INTERVAL_MS 100
|
||||||
|
|
||||||
|
int sf_load_net_retry_config(SFNetRetryConfig *net_retry_cfg,
|
||||||
|
IniFullContext *ini_ctx)
|
||||||
|
{
|
||||||
|
char *retry_interval_mode;
|
||||||
|
retry_interval_mode = iniGetStrValue(ini_ctx->section_name,
|
||||||
|
"retry_interval_mode", ini_ctx->context);
|
||||||
|
if (retry_interval_mode == NULL || *retry_interval_mode == '\0') {
|
||||||
|
net_retry_cfg->retry_interval_mode =
|
||||||
|
sf_net_retry_interval_mode_multiple;
|
||||||
|
} else if (strncasecmp(retry_interval_mode, "fixed", 5) == 0) {
|
||||||
|
net_retry_cfg->retry_interval_mode =
|
||||||
|
sf_net_retry_interval_mode_fixed;
|
||||||
|
} else if (strncasecmp(retry_interval_mode, "multi", 5) == 0) {
|
||||||
|
net_retry_cfg->retry_interval_mode =
|
||||||
|
sf_net_retry_interval_mode_multiple;
|
||||||
|
} else {
|
||||||
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
|
"config file: %s, unkown retry_interval_mode: %s, "
|
||||||
|
"set to multiple", __LINE__, ini_ctx->filename,
|
||||||
|
retry_interval_mode);
|
||||||
|
net_retry_cfg->retry_interval_mode =
|
||||||
|
sf_net_retry_interval_mode_multiple;
|
||||||
|
}
|
||||||
|
|
||||||
|
net_retry_cfg->retry_max_interval_ms = iniGetIntValue(
|
||||||
|
ini_ctx->section_name, "retry_max_interval_ms",
|
||||||
|
ini_ctx->context, DEFAULT_RETRY_MAX_INTERVAL_MS);
|
||||||
|
|
||||||
|
net_retry_cfg->connect_retry_times = iniGetIntValue(
|
||||||
|
ini_ctx->section_name, "connect_retry_times",
|
||||||
|
ini_ctx->context, DEFAULT_CONNECT_RETRY_TIMES);
|
||||||
|
|
||||||
|
net_retry_cfg->connect_retry_interval_ms = iniGetIntValue(
|
||||||
|
ini_ctx->section_name, "connect_retry_interval_ms",
|
||||||
|
ini_ctx->context, DEFAULT_CONNECT_RETRY_INTERVAL_MS);
|
||||||
|
|
||||||
|
net_retry_cfg->network_retry_times = iniGetIntValue(
|
||||||
|
ini_ctx->section_name, "network_retry_times",
|
||||||
|
ini_ctx->context, DEFAULT_NETWORK_RETRY_TIMES);
|
||||||
|
|
||||||
|
net_retry_cfg->network_retry_interval_ms = iniGetIntValue(
|
||||||
|
ini_ctx->section_name, "network_retry_interval_ms",
|
||||||
|
ini_ctx->context, DEFAULT_NETWORK_RETRY_INTERVAL_MS);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sf_net_retry_config_to_string(SFNetRetryConfig *net_retry_cfg,
|
||||||
|
char *output, const int size)
|
||||||
|
{
|
||||||
|
snprintf(output, size, "retry_interval_mode=%s, "
|
||||||
|
"retry_max_interval_ms=%d ms, connect_retry_times=%d, "
|
||||||
|
"connect_retry_interval_ms=%d ms, network_retry_times=%d, "
|
||||||
|
"network_retry_interval_ms=%d ms",
|
||||||
|
(net_retry_cfg->retry_interval_mode ==
|
||||||
|
sf_net_retry_interval_mode_fixed ? "fixed" : "multipl"),
|
||||||
|
net_retry_cfg->retry_max_interval_ms,
|
||||||
|
net_retry_cfg->connect_retry_times,
|
||||||
|
net_retry_cfg->connect_retry_interval_ms,
|
||||||
|
net_retry_cfg->network_retry_times,
|
||||||
|
net_retry_cfg->network_retry_interval_ms);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
//sf_global.h
|
||||||
|
|
||||||
|
#ifndef _SF_GLOBAL_H
|
||||||
|
#define _SF_GLOBAL_H
|
||||||
|
|
||||||
|
#include "fastcommon/common_define.h"
|
||||||
|
#include "fastcommon/ini_file_reader.h"
|
||||||
|
#include "sf_define.h"
|
||||||
|
#include "sf_types.h"
|
||||||
|
|
||||||
|
typedef enum sf_net_retry_interval_mode {
|
||||||
|
sf_net_retry_interval_mode_fixed,
|
||||||
|
sf_net_retry_interval_mode_multiple
|
||||||
|
} SFNetRetryIntervalMode;
|
||||||
|
|
||||||
|
typedef struct sf_net_retry_config {
|
||||||
|
SFNetRetryIntervalMode retry_interval_mode;
|
||||||
|
int retry_max_interval_ms;
|
||||||
|
int connect_retry_times;
|
||||||
|
int connect_retry_interval_ms;
|
||||||
|
int network_retry_times;
|
||||||
|
int network_retry_interval_ms;
|
||||||
|
} SFNetRetryConfig;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int sf_load_net_retry_config(SFNetRetryConfig *net_retry_cfg,
|
||||||
|
IniFullContext *ini_ctx);
|
||||||
|
|
||||||
|
void sf_net_retry_config_to_string(SFNetRetryConfig *net_retry_cfg,
|
||||||
|
char *output, const int size);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#include "fastcommon/common_define.h"
|
#include "fastcommon/common_define.h"
|
||||||
#include "fastcommon/shared_func.h"
|
#include "fastcommon/shared_func.h"
|
||||||
#include "fastcommon/logger.h"
|
#include "fastcommon/logger.h"
|
||||||
#include "sf_define.h"
|
|
||||||
#include "sf_nio.h"
|
#include "sf_nio.h"
|
||||||
#include "sf_global.h"
|
#include "sf_global.h"
|
||||||
|
|
||||||
|
|
|
||||||
11
src/sf_nio.c
11
src/sf_nio.c
|
|
@ -274,7 +274,8 @@ static int sf_nio_deal_task(struct fast_task_info *task)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sf_nio_notify(struct fast_task_info *task, const int new_stage)
|
int sf_nio_notify_ex(struct fast_task_info *task, const int new_stage,
|
||||||
|
const char *file, const int line)
|
||||||
{
|
{
|
||||||
int64_t n;
|
int64_t n;
|
||||||
int result;
|
int result;
|
||||||
|
|
@ -288,9 +289,10 @@ int sf_nio_notify(struct fast_task_info *task, const int new_stage)
|
||||||
{
|
{
|
||||||
if (SF_NIO_STAGE_IS_INPROGRESS(old_stage)) {
|
if (SF_NIO_STAGE_IS_INPROGRESS(old_stage)) {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
|
"from caller {file: %s, line: %d}, "
|
||||||
"client ip: %s, nio stage in progress, "
|
"client ip: %s, nio stage in progress, "
|
||||||
"current stage: %d, skip set to %d", __LINE__,
|
"current stage: %d, skip set to %d", __LINE__,
|
||||||
task->client_ip, old_stage, new_stage);
|
file, line, task->client_ip, old_stage, new_stage);
|
||||||
return EBUSY;
|
return EBUSY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -299,9 +301,10 @@ int sf_nio_notify(struct fast_task_info *task, const int new_stage)
|
||||||
old_stage, new_stage))
|
old_stage, new_stage))
|
||||||
{
|
{
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
|
"from caller {file: %s, line: %d}, "
|
||||||
"client ip: %s, skip set stage to %d because stage "
|
"client ip: %s, skip set stage to %d because stage "
|
||||||
"changed, current stage: %d", __LINE__, task->client_ip,
|
"changed, current stage: %d", __LINE__, file, line,
|
||||||
new_stage, SF_NIO_TASK_STAGE_FETCH(task));
|
task->client_ip, new_stage, SF_NIO_TASK_STAGE_FETCH(task));
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,11 @@ int sf_client_sock_read(int sock, short event, void *arg);
|
||||||
|
|
||||||
void sf_task_finish_clean_up(struct fast_task_info *task);
|
void sf_task_finish_clean_up(struct fast_task_info *task);
|
||||||
|
|
||||||
int sf_nio_notify(struct fast_task_info *task, const int new_stage);
|
int sf_nio_notify_ex(struct fast_task_info *task, const int new_stage,
|
||||||
|
const char *file, const int line);
|
||||||
|
|
||||||
|
#define sf_nio_notify(task, new_stage) \
|
||||||
|
sf_nio_notify_ex(task, new_stage, __FILE__, __LINE__)
|
||||||
|
|
||||||
int sf_set_read_event(struct fast_task_info *task);
|
int sf_set_read_event(struct fast_task_info *task);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue