Support C++14 and remove dependency on future standard 2a
Former-commit-id: 18496b62853738bf7bd48f65fe34aafcba8bbe0b
This commit is contained in:
parent
3de971b10c
commit
47f98259f9
@ -21,7 +21,7 @@ NODEPS:=clean distclean
|
|||||||
|
|
||||||
# Default settings
|
# Default settings
|
||||||
STD=-std=c11 -pedantic -DREDIS_STATIC=''
|
STD=-std=c11 -pedantic -DREDIS_STATIC=''
|
||||||
CXX_STD=-std=c++2a -pedantic -fno-rtti -D__STDC_FORMAT_MACROS
|
CXX_STD=-std=c++14 -pedantic -fno-rtti -D__STDC_FORMAT_MACROS
|
||||||
ifneq (,$(findstring clang,$(CC)))
|
ifneq (,$(findstring clang,$(CC)))
|
||||||
ifneq (,$(findstring FreeBSD,$(uname_S)))
|
ifneq (,$(findstring FreeBSD,$(uname_S)))
|
||||||
STD+=-Wno-c11-extensions
|
STD+=-Wno-c11-extensions
|
||||||
|
200
src/config.cpp
200
src/config.cpp
@ -123,7 +123,7 @@ clientBufferLimitsConfig clientBufferLimitsDefaults[CLIENT_TYPE_OBUF_COUNT] = {
|
|||||||
* rewrite. */
|
* rewrite. */
|
||||||
typedef struct boolConfigData {
|
typedef struct boolConfigData {
|
||||||
int *config; /* The pointer to the server config this value is stored in */
|
int *config; /* The pointer to the server config this value is stored in */
|
||||||
const int default_value; /* The default value of the config on rewrite */
|
int default_value; /* The default value of the config on rewrite */
|
||||||
int (*is_valid_fn)(int val, const char **err); /* Optional function to check validity of new value (generic doc above) */
|
int (*is_valid_fn)(int val, const char **err); /* Optional function to check validity of new value (generic doc above) */
|
||||||
int (*update_fn)(int val, int prev, const char **err); /* Optional function to apply new value at runtime (generic doc above) */
|
int (*update_fn)(int val, int prev, const char **err); /* Optional function to apply new value at runtime (generic doc above) */
|
||||||
} boolConfigData;
|
} boolConfigData;
|
||||||
@ -140,7 +140,7 @@ typedef struct stringConfigData {
|
|||||||
typedef struct enumConfigData {
|
typedef struct enumConfigData {
|
||||||
int *config; /* The pointer to the server config this value is stored in */
|
int *config; /* The pointer to the server config this value is stored in */
|
||||||
configEnum *enum_value; /* The underlying enum type this data represents */
|
configEnum *enum_value; /* The underlying enum type this data represents */
|
||||||
const int default_value; /* The default value of the config on rewrite */
|
int default_value; /* The default value of the config on rewrite */
|
||||||
int (*is_valid_fn)(int val, const char **err); /* Optional function to check validity of new value (generic doc above) */
|
int (*is_valid_fn)(int val, const char **err); /* Optional function to check validity of new value (generic doc above) */
|
||||||
int (*update_fn)(int val, int prev, const char **err); /* Optional function to apply new value at runtime (generic doc above) */
|
int (*update_fn)(int val, int prev, const char **err); /* Optional function to apply new value at runtime (generic doc above) */
|
||||||
} enumConfigData;
|
} enumConfigData;
|
||||||
@ -162,7 +162,7 @@ typedef struct numericConfigData {
|
|||||||
int is_memory; /* Indicates if this value can be loaded as a memory value */
|
int is_memory; /* Indicates if this value can be loaded as a memory value */
|
||||||
long long lower_bound; /* The lower bound of this numeric value */
|
long long lower_bound; /* The lower bound of this numeric value */
|
||||||
long long upper_bound; /* The upper bound of this numeric value */
|
long long upper_bound; /* The upper bound of this numeric value */
|
||||||
const long long default_value; /* The default value of the config on rewrite */
|
long long default_value; /* The default value of the config on rewrite */
|
||||||
int (*is_valid_fn)(long long val, const char **err); /* Optional function to check validity of new value (generic doc above) */
|
int (*is_valid_fn)(long long val, const char **err); /* Optional function to check validity of new value (generic doc above) */
|
||||||
int (*update_fn)(long long val, long long prev, const char **err); /* Optional function to apply new value at runtime (generic doc above) */
|
int (*update_fn)(long long val, long long prev, const char **err); /* Optional function to apply new value at runtime (generic doc above) */
|
||||||
numericType numeric_type; /* An enum indicating the type of this value */
|
numericType numeric_type; /* An enum indicating the type of this value */
|
||||||
@ -1669,15 +1669,17 @@ static void boolConfigRewrite(typeData data, const char *name, struct rewriteCon
|
|||||||
rewriteConfigYesNoOption(state, name,*(data.yesno.config), data.yesno.default_value);
|
rewriteConfigYesNoOption(state, name,*(data.yesno.config), data.yesno.default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createBoolConfig(name, alias, modifiable, config_addr, default, is_valid, update) { \
|
constexpr standardConfig createBoolConfig(const char *name, const char *alias, int modifiable, int &config_addr, int defaultValue, int (*is_valid)(int val, const char **err), int (*update)(int val, int prev, const char **err))
|
||||||
embedCommonConfig(name, alias, modifiable) \
|
{
|
||||||
{boolConfigInit, boolConfigLoad, boolConfigSet, boolConfigGet, boolConfigRewrite}, \
|
standardConfig conf = {
|
||||||
{ { /* .data.yesno */ \
|
embedCommonConfig(name, alias, modifiable)
|
||||||
&(config_addr), \
|
{ boolConfigInit, boolConfigLoad, boolConfigSet, boolConfigGet, boolConfigRewrite }
|
||||||
(default), \
|
};
|
||||||
(is_valid), \
|
conf.data.yesno.config = &config_addr;
|
||||||
(update), \
|
conf.data.yesno.default_value = defaultValue;
|
||||||
} } \
|
conf.data.yesno.is_valid_fn = is_valid;
|
||||||
|
conf.data.yesno.update_fn = update;
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String Configs */
|
/* String Configs */
|
||||||
@ -1734,16 +1736,19 @@ static void stringConfigRewrite(typeData data, const char *name, struct rewriteC
|
|||||||
#define ALLOW_EMPTY_STRING 0
|
#define ALLOW_EMPTY_STRING 0
|
||||||
#define EMPTY_STRING_IS_NULL 1
|
#define EMPTY_STRING_IS_NULL 1
|
||||||
|
|
||||||
#define createStringConfig(name, alias, modifiable, empty_to_null, config_addr, default, is_valid, update) { \
|
constexpr standardConfig createStringConfig(const char *name, const char *alias, int modifiable, int empty_to_null, char *&config_addr, const char *defaultValue, int (*is_valid)(char*,const char**), int (*update)(char*,char*,const char**)) {
|
||||||
embedCommonConfig(name, alias, modifiable) \
|
standardConfig conf = {
|
||||||
embedConfigInterface(stringConfigInit, stringConfigLoad, stringConfigSet, stringConfigGet, stringConfigRewrite) \
|
embedCommonConfig(name, alias, modifiable)
|
||||||
{ .string = { \
|
embedConfigInterface(stringConfigInit, stringConfigLoad, stringConfigSet, stringConfigGet, stringConfigRewrite)
|
||||||
&(config_addr), \
|
};
|
||||||
(default), \
|
conf.data.string = {
|
||||||
(is_valid), \
|
&(config_addr),
|
||||||
(update), \
|
(defaultValue),
|
||||||
(empty_to_null), \
|
(is_valid),
|
||||||
} } \
|
(update),
|
||||||
|
(empty_to_null),
|
||||||
|
};
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enum configs */
|
/* Enum configs */
|
||||||
@ -1805,16 +1810,20 @@ static void configEnumRewrite(typeData data, const char *name, struct rewriteCon
|
|||||||
rewriteConfigEnumOption(state, name,*(data.enumd.config), data.enumd.enum_value, data.enumd.default_value);
|
rewriteConfigEnumOption(state, name,*(data.enumd.config), data.enumd.enum_value, data.enumd.default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createEnumConfig(name, alias, modifiable, enum, config_addr, default, is_valid, update) { \
|
constexpr standardConfig createEnumConfig(const char *name, const char *alias, int modifiable, configEnum *enumVal, int &config_addr, int defaultValue, int (*is_valid)(int,const char**), int (*update)(int,int,const char**)) {
|
||||||
embedCommonConfig(name, alias, modifiable) \
|
standardConfig c = {
|
||||||
embedConfigInterface(configEnumInit, configEnumLoad, configEnumSet, configEnumGet, configEnumRewrite) \
|
embedCommonConfig(name, alias, modifiable)
|
||||||
{ .enumd = { \
|
embedConfigInterface(configEnumInit, configEnumLoad, configEnumSet, configEnumGet, configEnumRewrite)
|
||||||
&(config_addr), \
|
};
|
||||||
(enum), \
|
c.data.enumd = {
|
||||||
(default), \
|
&(config_addr),
|
||||||
(is_valid), \
|
(enumVal),
|
||||||
(update), \
|
(defaultValue),
|
||||||
} } \
|
(is_valid),
|
||||||
|
(update),
|
||||||
|
};
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gets a 'long long val' and sets it into the union, using a macro to get
|
/* Gets a 'long long val' and sets it into the union, using a macro to get
|
||||||
@ -1986,85 +1995,90 @@ static void numericConfigRewrite(typeData data, const char *name, struct rewrite
|
|||||||
#define INTEGER_CONFIG 0
|
#define INTEGER_CONFIG 0
|
||||||
#define MEMORY_CONFIG 1
|
#define MEMORY_CONFIG 1
|
||||||
|
|
||||||
#define embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) { \
|
constexpr standardConfig embedCommonNumericalConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonConfig(name, alias, modifiable) \
|
standardConfig conf = {
|
||||||
embedConfigInterface(numericConfigInit, numericConfigLoad, numericConfigSet, numericConfigGet, numericConfigRewrite) \
|
embedCommonConfig(name, alias, modifiable)
|
||||||
{ .numeric = { \
|
embedConfigInterface(numericConfigInit, numericConfigLoad, numericConfigSet, numericConfigGet, numericConfigRewrite)
|
||||||
.is_memory = (memory), \
|
};
|
||||||
.lower_bound = (lower), \
|
conf.data.numeric.is_memory = (memory);
|
||||||
.upper_bound = (upper), \
|
conf.data.numeric.lower_bound = (lower);
|
||||||
.default_value = (default), \
|
conf.data.numeric.upper_bound = (upper);
|
||||||
.is_valid_fn = (is_valid), \
|
conf.data.numeric.default_value = (defaultValue);
|
||||||
.update_fn = (update),
|
conf.data.numeric.is_valid_fn = (is_valid);
|
||||||
|
conf.data.numeric.update_fn = (update);
|
||||||
#define createIntConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
return conf;
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
|
||||||
.numeric_type = NUMERIC_TYPE_INT, \
|
|
||||||
.config { .i = &(config_addr) } \
|
|
||||||
} } \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createUIntConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createIntConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, int &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**))
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
{
|
||||||
.numeric_type = NUMERIC_TYPE_UINT, \
|
standardConfig conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.config { .ui = &(config_addr) } \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_INT;
|
||||||
} } \
|
conf.data.numeric.config.i = &config_addr;
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createLongConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createUIntConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, unsigned int &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**))
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
{
|
||||||
.numeric_type = NUMERIC_TYPE_LONG, \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.config { .l = &(config_addr) } \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_UINT;
|
||||||
} } \
|
conf.data.numeric.config.ui = &(config_addr);
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createULongConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createLongConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, long &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_ULONG, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_LONG;
|
||||||
.config { .ul = &(config_addr) } \
|
conf.data.numeric.config.l = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createLongLongConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createULongConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, unsigned long &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_LONG_LONG, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_ULONG;
|
||||||
.config { .ll = &(config_addr) } \
|
conf.data.numeric.config.ul = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createULongLongConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createLongLongConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, long long &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_ULONG_LONG, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_LONG_LONG;
|
||||||
.config { .ull = &(config_addr) } \
|
conf.data.numeric.config.ll = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createSizeTConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createULongLongConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, unsigned long long &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_SIZE_T, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_ULONG_LONG;
|
||||||
.config { .st = &(config_addr) } \
|
conf.data.numeric.config.ull = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createSSizeTConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createSizeTConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, size_t &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_SSIZE_T, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_SIZE_T;
|
||||||
.config { .sst = &(config_addr) } \
|
conf.data.numeric.config.st = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createTimeTConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createSSizeTConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, ssize_t &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_TIME_T, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_SSIZE_T;
|
||||||
.config { .tt = &(config_addr) } \
|
conf.data.numeric.config.sst = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define createOffTConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
constexpr standardConfig createTimeTConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, time_t &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
embedCommonNumericalConfig(name, alias, modifiable, lower, upper, config_addr, default, memory, is_valid, update) \
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
.numeric_type = NUMERIC_TYPE_OFF_T, \
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_TIME_T;
|
||||||
.config { .ot = &(config_addr) } \
|
conf.data.numeric.config.tt = &(config_addr);
|
||||||
} } \
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr standardConfig createOffTConfig(const char *name, const char *alias, int modifiable, long long lower, long long upper, off_t &config_addr, long long defaultValue, int memory, int (*is_valid)(long long, const char**), int (*update)(long long, long long, const char**)) {
|
||||||
|
auto conf = embedCommonNumericalConfig(name, alias, modifiable, lower, upper, defaultValue, memory, is_valid, update);
|
||||||
|
conf.data.numeric.numeric_type = NUMERIC_TYPE_OFF_T;
|
||||||
|
conf.data.numeric.config.ot = &(config_addr);
|
||||||
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int isValidActiveDefrag(int val, const char **err) {
|
static int isValidActiveDefrag(int val, const char **err) {
|
||||||
|
@ -330,19 +330,19 @@ static ssize_t connSocketSyncReadLine(connection *conn, char *ptr, ssize_t size,
|
|||||||
|
|
||||||
|
|
||||||
ConnectionType CT_Socket = {
|
ConnectionType CT_Socket = {
|
||||||
.ae_handler = connSocketEventHandler,
|
connSocketEventHandler,
|
||||||
.connect = connSocketConnect,
|
connSocketConnect,
|
||||||
.write = connSocketWrite,
|
connSocketWrite,
|
||||||
.read = connSocketRead,
|
connSocketRead,
|
||||||
.close = connSocketClose,
|
connSocketClose,
|
||||||
.accept = connSocketAccept,
|
connSocketAccept,
|
||||||
.set_write_handler = connSocketSetWriteHandler,
|
connSocketSetWriteHandler,
|
||||||
.set_read_handler = connSocketSetReadHandler,
|
connSocketSetReadHandler,
|
||||||
.get_last_error = connSocketGetLastError,
|
connSocketGetLastError,
|
||||||
.blocking_connect = connSocketBlockingConnect,
|
connSocketBlockingConnect,
|
||||||
.sync_write = connSocketSyncWrite,
|
connSocketSyncWrite,
|
||||||
.sync_read = connSocketSyncRead,
|
connSocketSyncRead,
|
||||||
.sync_readline = connSocketSyncReadLine
|
connSocketSyncReadLine
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ public:
|
|||||||
#define C_ERR -1
|
#define C_ERR -1
|
||||||
|
|
||||||
/* Static server configuration */
|
/* Static server configuration */
|
||||||
#define CONFIG_DEFAULT_HZ 20 /* Time interrupt calls/sec. */
|
#define CONFIG_DEFAULT_HZ 10 /* Time interrupt calls/sec. */
|
||||||
#define CONFIG_MIN_HZ 1
|
#define CONFIG_MIN_HZ 1
|
||||||
#define CONFIG_MAX_HZ 500
|
#define CONFIG_MAX_HZ 500
|
||||||
#define MAX_CLIENTS_PER_CLOCK_TICK 200 /* HZ is adapted based on that. */
|
#define MAX_CLIENTS_PER_CLOCK_TICK 200 /* HZ is adapted based on that. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user