net retry struct adjust
parent
b02dae19be
commit
f18626b229
|
|
@ -23,40 +23,40 @@ int sf_load_net_retry_config(SFNetRetryConfig *net_retry_cfg,
|
||||||
retry_interval_mode = iniGetStrValue(ini_ctx->section_name,
|
retry_interval_mode = iniGetStrValue(ini_ctx->section_name,
|
||||||
"retry_interval_mode", ini_ctx->context);
|
"retry_interval_mode", ini_ctx->context);
|
||||||
if (retry_interval_mode == NULL || *retry_interval_mode == '\0') {
|
if (retry_interval_mode == NULL || *retry_interval_mode == '\0') {
|
||||||
net_retry_cfg->retry_interval_mode =
|
net_retry_cfg->interval_mm.mode =
|
||||||
sf_net_retry_interval_mode_multiple;
|
sf_net_retry_interval_mode_multiple;
|
||||||
} else if (strncasecmp(retry_interval_mode, "fixed", 5) == 0) {
|
} else if (strncasecmp(retry_interval_mode, "fixed", 5) == 0) {
|
||||||
net_retry_cfg->retry_interval_mode =
|
net_retry_cfg->interval_mm.mode =
|
||||||
sf_net_retry_interval_mode_fixed;
|
sf_net_retry_interval_mode_fixed;
|
||||||
} else if (strncasecmp(retry_interval_mode, "multi", 5) == 0) {
|
} else if (strncasecmp(retry_interval_mode, "multi", 5) == 0) {
|
||||||
net_retry_cfg->retry_interval_mode =
|
net_retry_cfg->interval_mm.mode =
|
||||||
sf_net_retry_interval_mode_multiple;
|
sf_net_retry_interval_mode_multiple;
|
||||||
} else {
|
} else {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"config file: %s, unkown retry_interval_mode: %s, "
|
"config file: %s, unkown retry_interval_mode: %s, "
|
||||||
"set to multiple", __LINE__, ini_ctx->filename,
|
"set to multiple", __LINE__, ini_ctx->filename,
|
||||||
retry_interval_mode);
|
retry_interval_mode);
|
||||||
net_retry_cfg->retry_interval_mode =
|
net_retry_cfg->interval_mm.mode =
|
||||||
sf_net_retry_interval_mode_multiple;
|
sf_net_retry_interval_mode_multiple;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_retry_cfg->retry_max_interval_ms = iniGetIntValue(
|
net_retry_cfg->interval_mm.max_interval_ms = iniGetIntValue(
|
||||||
ini_ctx->section_name, "retry_max_interval_ms",
|
ini_ctx->section_name, "retry_max_interval_ms",
|
||||||
ini_ctx->context, DEFAULT_RETRY_MAX_INTERVAL_MS);
|
ini_ctx->context, DEFAULT_RETRY_MAX_INTERVAL_MS);
|
||||||
|
|
||||||
net_retry_cfg->connect_retry_times = iniGetIntValue(
|
net_retry_cfg->connect.times = iniGetIntValue(
|
||||||
ini_ctx->section_name, "connect_retry_times",
|
ini_ctx->section_name, "connect_retry_times",
|
||||||
ini_ctx->context, DEFAULT_CONNECT_RETRY_TIMES);
|
ini_ctx->context, DEFAULT_CONNECT_RETRY_TIMES);
|
||||||
|
|
||||||
net_retry_cfg->connect_retry_interval_ms = iniGetIntValue(
|
net_retry_cfg->connect.interval_ms = iniGetIntValue(
|
||||||
ini_ctx->section_name, "connect_retry_interval_ms",
|
ini_ctx->section_name, "connect_retry_interval_ms",
|
||||||
ini_ctx->context, DEFAULT_CONNECT_RETRY_INTERVAL_MS);
|
ini_ctx->context, DEFAULT_CONNECT_RETRY_INTERVAL_MS);
|
||||||
|
|
||||||
net_retry_cfg->network_retry_times = iniGetIntValue(
|
net_retry_cfg->network.times = iniGetIntValue(
|
||||||
ini_ctx->section_name, "network_retry_times",
|
ini_ctx->section_name, "network_retry_times",
|
||||||
ini_ctx->context, DEFAULT_NETWORK_RETRY_TIMES);
|
ini_ctx->context, DEFAULT_NETWORK_RETRY_TIMES);
|
||||||
|
|
||||||
net_retry_cfg->network_retry_interval_ms = iniGetIntValue(
|
net_retry_cfg->network.interval_ms = iniGetIntValue(
|
||||||
ini_ctx->section_name, "network_retry_interval_ms",
|
ini_ctx->section_name, "network_retry_interval_ms",
|
||||||
ini_ctx->context, DEFAULT_NETWORK_RETRY_INTERVAL_MS);
|
ini_ctx->context, DEFAULT_NETWORK_RETRY_INTERVAL_MS);
|
||||||
|
|
||||||
|
|
@ -70,13 +70,13 @@ void sf_net_retry_config_to_string(SFNetRetryConfig *net_retry_cfg,
|
||||||
"retry_max_interval_ms=%d ms, connect_retry_times=%d, "
|
"retry_max_interval_ms=%d ms, connect_retry_times=%d, "
|
||||||
"connect_retry_interval_ms=%d ms, network_retry_times=%d, "
|
"connect_retry_interval_ms=%d ms, network_retry_times=%d, "
|
||||||
"network_retry_interval_ms=%d ms",
|
"network_retry_interval_ms=%d ms",
|
||||||
(net_retry_cfg->retry_interval_mode ==
|
(net_retry_cfg->interval_mm.mode ==
|
||||||
sf_net_retry_interval_mode_fixed ? "fixed" : "multipl"),
|
sf_net_retry_interval_mode_fixed ? "fixed" : "multipl"),
|
||||||
net_retry_cfg->retry_max_interval_ms,
|
net_retry_cfg->interval_mm.max_interval_ms,
|
||||||
net_retry_cfg->connect_retry_times,
|
net_retry_cfg->connect.times,
|
||||||
net_retry_cfg->connect_retry_interval_ms,
|
net_retry_cfg->connect.interval_ms,
|
||||||
net_retry_cfg->network_retry_times,
|
net_retry_cfg->network.times,
|
||||||
net_retry_cfg->network_retry_interval_ms);
|
net_retry_cfg->network.interval_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sf_load_read_rule_config(SFDataReadRule *rule, IniFullContext *ini_ctx)
|
void sf_load_read_rule_config(SFDataReadRule *rule, IniFullContext *ini_ctx)
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,28 @@ typedef enum sf_net_retry_interval_mode {
|
||||||
sf_net_retry_interval_mode_multiple
|
sf_net_retry_interval_mode_multiple
|
||||||
} SFNetRetryIntervalMode;
|
} SFNetRetryIntervalMode;
|
||||||
|
|
||||||
|
typedef struct sf_net_retry_interval_mode_max_pair {
|
||||||
|
SFNetRetryIntervalMode mode;
|
||||||
|
int max_interval_ms;
|
||||||
|
} SFNetRetryIntervalModeMaxPair;
|
||||||
|
|
||||||
|
typedef struct sf_net_retry_times_interval_pair {
|
||||||
|
int times;
|
||||||
|
int interval_ms;
|
||||||
|
} SFNetRetryTimesIntervalPair;
|
||||||
|
|
||||||
typedef struct sf_net_retry_config {
|
typedef struct sf_net_retry_config {
|
||||||
SFNetRetryIntervalMode retry_interval_mode;
|
SFNetRetryIntervalModeMaxPair interval_mm;
|
||||||
int retry_max_interval_ms;
|
SFNetRetryTimesIntervalPair connect;
|
||||||
int connect_retry_times;
|
SFNetRetryTimesIntervalPair network;
|
||||||
int connect_retry_interval_ms;
|
|
||||||
int network_retry_times;
|
|
||||||
int network_retry_interval_ms;
|
|
||||||
} SFNetRetryConfig;
|
} SFNetRetryConfig;
|
||||||
|
|
||||||
|
typedef struct sf_net_retry_interval_context {
|
||||||
|
SFNetRetryIntervalModeMaxPair *mm;
|
||||||
|
SFNetRetryTimesIntervalPair *ti;
|
||||||
|
int interval_ms;
|
||||||
|
} SFNetRetryIntervalContext;
|
||||||
|
|
||||||
typedef enum sf_data_read_rule {
|
typedef enum sf_data_read_rule {
|
||||||
sf_data_read_rule_any_available,
|
sf_data_read_rule_any_available,
|
||||||
sf_data_read_rule_slave_first,
|
sf_data_read_rule_slave_first,
|
||||||
|
|
@ -38,6 +51,34 @@ int sf_load_net_retry_config(SFNetRetryConfig *net_retry_cfg,
|
||||||
void sf_net_retry_config_to_string(SFNetRetryConfig *net_retry_cfg,
|
void sf_net_retry_config_to_string(SFNetRetryConfig *net_retry_cfg,
|
||||||
char *output, const int size);
|
char *output, const int size);
|
||||||
|
|
||||||
|
static inline void sf_reset_net_retry_interval(SFNetRetryIntervalContext *ctx)
|
||||||
|
{
|
||||||
|
ctx->interval_ms = FC_MIN(ctx->ti->interval_ms, ctx->mm->max_interval_ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void sf_init_net_retry_interval_context(
|
||||||
|
SFNetRetryIntervalContext *ctx, SFNetRetryIntervalModeMaxPair *mm,
|
||||||
|
SFNetRetryTimesIntervalPair *ti)
|
||||||
|
{
|
||||||
|
ctx->mm = mm;
|
||||||
|
ctx->ti = ti;
|
||||||
|
sf_reset_net_retry_interval(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int sf_calc_next_retry_interval(SFNetRetryIntervalContext *ctx)
|
||||||
|
{
|
||||||
|
if (ctx->mm->mode == sf_net_retry_interval_mode_multiple) {
|
||||||
|
if (ctx->interval_ms < ctx->mm->max_interval_ms) {
|
||||||
|
ctx->interval_ms *= 2;
|
||||||
|
if (ctx->interval_ms > ctx->mm->max_interval_ms) {
|
||||||
|
ctx->interval_ms = ctx->mm->max_interval_ms;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx->interval_ms;
|
||||||
|
}
|
||||||
|
|
||||||
void sf_load_read_rule_config(SFDataReadRule *rule, IniFullContext *ini_ctx);
|
void sf_load_read_rule_config(SFDataReadRule *rule, IniFullContext *ini_ctx);
|
||||||
|
|
||||||
static inline const char *sf_get_read_rule_caption(
|
static inline const char *sf_get_read_rule_caption(
|
||||||
|
|
@ -55,6 +96,11 @@ static inline const char *sf_get_read_rule_caption(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define SF_NET_RETRY_FINISHED(retry_times, counter, result) \
|
||||||
|
!((SF_IS_RETRIABLE_ERROR(result) && ((retry_times > 0 && \
|
||||||
|
counter <= retry_times) || (retry_times < 0))))
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#ifndef _SF_DEFINE_H_
|
#ifndef _SF_DEFINE_H_
|
||||||
#define _SF_DEFINE_H_
|
#define _SF_DEFINE_H_
|
||||||
|
|
||||||
#include "fastcommon/common_define.h"
|
#include "fastcommon/sockopt.h"
|
||||||
|
|
||||||
#define SF_DEF_THREAD_STACK_SIZE (64 * 1024)
|
#define SF_DEF_THREAD_STACK_SIZE (64 * 1024)
|
||||||
#define SF_DEF_MAX_PACKAGE_SIZE (16 * 1024)
|
#define SF_DEF_MAX_PACKAGE_SIZE (16 * 1024)
|
||||||
|
|
@ -30,6 +30,17 @@
|
||||||
#define SF_NIO_STAGE_IS_INPROGRESS(stage) \
|
#define SF_NIO_STAGE_IS_INPROGRESS(stage) \
|
||||||
((stage & SF_NIO_FLAG_INPROGRESS) != 0)
|
((stage & SF_NIO_FLAG_INPROGRESS) != 0)
|
||||||
|
|
||||||
|
#define SF_RETRIABLE_ERROR_MIN 9901
|
||||||
|
#define SF_RETRIABLE_ERROR_MAX 9988
|
||||||
|
#define SF_RETRIABLE_ERROR_NO_SERVER 9901 //no server available
|
||||||
|
#define SF_RETRIABLE_ERROR_NOT_MASTER 9902 //i am not master
|
||||||
|
#define SF_RETRIABLE_ERROR_NOT_ACTIVE 9903 //i am not active
|
||||||
|
#define SF_RETRIABLE_ERROR_CHANNEL_INVALID 9904 //client should re-setup channel
|
||||||
|
|
||||||
|
#define SF_IS_RETRIABLE_ERROR(code) \
|
||||||
|
((code >= SF_RETRIABLE_ERROR_MIN && code <= SF_RETRIABLE_ERROR_MAX) || \
|
||||||
|
(code == EAGAIN) || is_network_error(code))
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue