Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
85354b6e
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
85354b6e
编写于
12月 02, 2020
作者:
Y
YuQing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add functions: iniGetByteValueEx and iniGetIntCorrectValueEx
上级
5a04c1c6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
197 addition
and
12 deletion
+197
-12
src/fast_timer.c
src/fast_timer.c
+1
-5
src/ini_file_reader.c
src/ini_file_reader.c
+100
-0
src/ini_file_reader.h
src/ini_file_reader.h
+95
-2
src/locked_timer.c
src/locked_timer.c
+1
-5
未找到文件。
src/fast_timer.c
浏览文件 @
85354b6e
...
...
@@ -85,7 +85,7 @@ void fast_timer_add_ex(FastTimer *timer, FastTimerEntry *entry,
new_expires
=
expires
;
new_set_expires
=
set_expires
;
}
else
{
new_expires
=
timer
->
current_time
;
new_expires
=
timer
->
current_time
+
1
;
//plus 1 for rare case
new_set_expires
=
true
;
}
slot
=
TIMER_GET_SLOT_POINTER
(
timer
,
new_expires
);
...
...
@@ -97,10 +97,6 @@ int fast_timer_modify(FastTimer *timer, FastTimerEntry *entry,
{
int
result
;
if
(
new_expires
<=
timer
->
current_time
)
{
return
ETIMEDOUT
;
}
if
(
new_expires
>
entry
->
expires
)
{
entry
->
rehash
=
TIMER_GET_SLOT_INDEX
(
timer
,
new_expires
)
!=
TIMER_GET_SLOT_INDEX
(
timer
,
entry
->
expires
);
...
...
src/ini_file_reader.c
浏览文件 @
85354b6e
...
...
@@ -2854,6 +2854,44 @@ char *iniGetStrValueEx(const char *szSectionName, const char *szItemName,
return
pFound
->
value
;
}
#define INI_FILL_SECTION_PROMPT(prompt, size, section_name) \
do { \
if (section_name != NULL && *(section_name) != '\0') { \
snprintf(prompt, size, "section: %s, ", section_name); \
} else { \
*prompt = '\0'; \
} \
} while (0)
int64_t
iniCheckAndCorrectIntValue
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int64_t
nValue
,
const
int64_t
nMinValue
,
const
int64_t
nMaxValue
)
{
char
section_prompt
[
128
];
if
(
nValue
<
nMinValue
)
{
INI_FILL_SECTION_PROMPT
(
section_prompt
,
sizeof
(
section_prompt
),
pIniContext
->
section_name
);
logWarning
(
"file: "
__FILE__
", line: %d, "
"config file: %s, %sitem name: %s, item value: %"
PRId64
" < min value: %"
PRId64
", set to min value: %"
PRId64
,
__LINE__
,
pIniContext
->
filename
,
section_prompt
,
szItemName
,
nValue
,
nMinValue
,
nMinValue
);
return
nMinValue
;
}
else
if
(
nValue
>
nMaxValue
)
{
INI_FILL_SECTION_PROMPT
(
section_prompt
,
sizeof
(
section_prompt
),
pIniContext
->
section_name
);
logWarning
(
"file: "
__FILE__
", line: %d, "
"config file: %s, %sitem name: %s, item value: %"
PRId64
" > max value: %"
PRId64
", set to max value: %"
PRId64
,
__LINE__
,
pIniContext
->
filename
,
section_prompt
,
szItemName
,
nValue
,
nMaxValue
,
nMaxValue
);
return
nMaxValue
;
}
return
nValue
;
}
int64_t
iniGetInt64ValueEx
(
const
char
*
szSectionName
,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
int64_t
nDefaultValue
,
const
bool
bRetryGlobal
)
...
...
@@ -2872,6 +2910,56 @@ int64_t iniGetInt64ValueEx(const char *szSectionName,
}
}
int64_t
iniGetInt64CorrectValueEx
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int64_t
nDefaultValue
,
const
int64_t
nMinValue
,
const
int64_t
nMaxValue
,
const
bool
bRetryGlobal
)
{
int64_t
value
;
value
=
iniGetInt64ValueEx
(
pIniContext
->
section_name
,
szItemName
,
pIniContext
->
context
,
nDefaultValue
,
bRetryGlobal
);
return
iniCheckAndCorrectIntValue
(
pIniContext
,
szItemName
,
value
,
nMinValue
,
nMaxValue
);
}
int64_t
iniGetByteValueEx
(
const
char
*
szSectionName
,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
int64_t
nDefaultValue
,
const
int
nDefaultUnitBytes
,
const
bool
bRetryGlobal
)
{
char
*
pValue
;
int64_t
nValue
;
pValue
=
iniGetStrValueEx
(
szSectionName
,
szItemName
,
pContext
,
bRetryGlobal
);
if
(
pValue
==
NULL
)
{
return
nDefaultValue
;
}
if
(
parse_bytes
(
pValue
,
nDefaultUnitBytes
,
&
nValue
)
!=
0
)
{
return
nDefaultValue
;
}
return
nValue
;
}
int64_t
iniGetByteCorrectValueEx
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int64_t
nDefaultValue
,
const
int
nDefaultUnitBytes
,
const
int64_t
nMinValue
,
const
int64_t
nMaxValue
,
const
bool
bRetryGlobal
)
{
int64_t
nValue
;
nValue
=
iniGetByteValueEx
(
pIniContext
->
section_name
,
szItemName
,
pIniContext
->
context
,
nDefaultValue
,
nDefaultUnitBytes
,
bRetryGlobal
);
return
iniCheckAndCorrectIntValue
(
pIniContext
,
szItemName
,
nValue
,
nMinValue
,
nMaxValue
);
}
int
iniGetIntValueEx
(
const
char
*
szSectionName
,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
int
nDefaultValue
,
const
bool
bRetryGlobal
)
...
...
@@ -2890,6 +2978,18 @@ int iniGetIntValueEx(const char *szSectionName,
}
}
int
iniGetIntCorrectValueEx
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int
nDefaultValue
,
const
int
nMinValue
,
const
int
nMaxValue
,
const
bool
bRetryGlobal
)
{
int
value
;
value
=
iniGetIntValueEx
(
pIniContext
->
section_name
,
szItemName
,
pIniContext
->
context
,
nDefaultValue
,
bRetryGlobal
);
return
iniCheckAndCorrectIntValue
(
pIniContext
,
szItemName
,
value
,
nMinValue
,
nMaxValue
);
}
double
iniGetDoubleValueEx
(
const
char
*
szSectionName
,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
double
dbDefaultValue
,
const
bool
bRetryGlobal
)
...
...
src/ini_file_reader.h
浏览文件 @
85354b6e
...
...
@@ -136,6 +136,25 @@ extern "C" {
#define iniGetPercentValue(ini_ctx, item_name, item_value, default_value) \
iniGetPercentValueEx(ini_ctx, item_name, item_value, default_value, false)
#define iniGetByteValue(szSectionName, szItemName, pContext, nDefaultValue) \
iniGetByteValueEx(szSectionName, szItemName, pContext, \
nDefaultValue, 1, false)
#define iniGetIntCorrectValue(ini_ctx, item_name, \
default_value, min_value, max_value) \
iniGetIntCorrectValueEx(ini_ctx, item_name, \
default_value, min_value, max_value, false)
#define iniGetInt64CorrectValue(ini_ctx, item_name, \
default_value, min_value, max_value) \
iniGetInt64CorrectValueEx(ini_ctx, item_name, \
default_value, min_value, max_value, false)
#define iniGetByteCorrectValue(ini_ctx, item_name, \
default_value, min_value, max_value) \
iniGetByteCorrectValueEx(ini_ctx, item_name, \
default_value, 1, min_value, max_value, false)
int
iniSetAnnotationCallBack
(
AnnotationEntry
*
annotations
,
int
count
);
void
iniDestroyAnnotationCallBack
();
...
...
@@ -232,6 +251,33 @@ int iniGetIntValueEx(const char *szSectionName,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
int
nDefaultValue
,
const
bool
bRetryGlobal
);
/** check and correct item value
* parameters:
* pIniContext: the full ini context
* szItemName: the item name
* nValue: the item value
* nMinValue: the min value to check (including)
* nMaxValue: the max value to check (including)
* return: corrected value
*/
int64_t
iniCheckAndCorrectIntValue
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int64_t
nValue
,
const
int64_t
nMinValue
,
const
int64_t
nMaxValue
);
/** get item correct value (32 bits integer)
* parameters:
* pIniContext: the full ini context
* szItemName: the item name
* nDefaultValue: the default value
* nMinValue: the min value to check (including)
* nMaxValue: the max value to check (including)
* bRetryGlobal: if fetch from global section when the item not exist
* return: item value, return nDefaultValue when the item not exist
*/
int
iniGetIntCorrectValueEx
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int
nDefaultValue
,
const
int
nMinValue
,
const
int
nMaxValue
,
const
bool
bRetryGlobal
);
/** get item string value array
* parameters:
* szSectionName: the section name, NULL or empty string for
...
...
@@ -244,9 +290,9 @@ int iniGetIntValueEx(const char *szSectionName,
IniItem
*
iniGetValuesEx
(
const
char
*
szSectionName
,
const
char
*
szItemName
,
IniContext
*
pContext
,
int
*
nTargetCount
);
/** get item
int64 value (64 bits
)
/** get item
value (64 bits integer
)
* parameters:
* szSectionName: the section name, NULL or empty string for
* szSectionName: the section name, NULL or empty string for
* global section
* szItemName: the item name
* pContext: the ini context
...
...
@@ -258,6 +304,53 @@ int64_t iniGetInt64ValueEx(const char *szSectionName,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
int64_t
nDefaultValue
,
const
bool
bRetryGlobal
);
/** get item correct value (64 bits integer)
* parameters:
* pIniContext: the full ini context
* szItemName: the item name
* nDefaultValue: the default value
* nMinValue: the min value to check (including)
* nMaxValue: the max value to check (including)
* bRetryGlobal: if fetch from global section when the item not exist
* return: int64 value, return nDefaultValue when the item not exist
*/
int64_t
iniGetInt64CorrectValueEx
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int64_t
nDefaultValue
,
const
int64_t
nMinValue
,
const
int64_t
nMaxValue
,
const
bool
bRetryGlobal
);
/** get item byte value (64 bits integer)
* parameters:
* szSectionName: the section name, NULL or empty string for
* global section
* szItemName: the item name
* pContext: the ini context
* nDefaultValue: the default value
* nDefaultUnitBytes: the default byte unit, such as 1 for byte, 1024 for KB
* bRetryGlobal: if fetch from global section when the item not exist
* return: int64 value, return nDefaultValue when the item not exist
*/
int64_t
iniGetByteValueEx
(
const
char
*
szSectionName
,
const
char
*
szItemName
,
IniContext
*
pContext
,
const
int64_t
nDefaultValue
,
const
int
nDefaultUnitBytes
,
const
bool
bRetryGlobal
);
/** get item correct byte value (64 bits integer)
* parameters:
* pIniContext: the full ini context
* szItemName: the item name
* nDefaultValue: the default value
* nDefaultUnitBytes: the default byte unit, such as 1 for byte, 1024 for KB
* nMinValue: the min value to check (including)
* nMaxValue: the max value to check (including)
* bRetryGlobal: if fetch from global section when the item not exist
* return: int64 value, return nDefaultValue when the item not exist
*/
int64_t
iniGetByteCorrectValueEx
(
IniFullContext
*
pIniContext
,
const
char
*
szItemName
,
const
int64_t
nDefaultValue
,
const
int
nDefaultUnitBytes
,
const
int64_t
nMinValue
,
const
int64_t
nMaxValue
,
const
bool
bRetryGlobal
);
/** get item boolean value
* parameters:
* szSectionName: the section name, NULL or empty string for
...
...
src/locked_timer.c
浏览文件 @
85354b6e
...
...
@@ -227,7 +227,7 @@ void locked_timer_add_ex(LockedTimer *timer, LockedTimerEntry *entry,
new_expires
=
expires
;
new_flags
=
flags
;
}
else
{
new_expires
=
timer
->
current_time
;
new_expires
=
timer
->
current_time
+
1
;
//plus 1 for rare case
new_flags
=
flags
|
FAST_TIMER_FLAGS_SET_EXPIRES
;
}
slot
=
TIMER_GET_SLOT_POINTER
(
timer
,
new_expires
);
...
...
@@ -240,10 +240,6 @@ int locked_timer_modify(LockedTimer *timer, LockedTimerEntry *entry,
int
result
;
int
slot_index
;
if
(
new_expires
<=
timer
->
current_time
)
{
return
ETIMEDOUT
;
}
if
(
new_expires
>
entry
->
expires
)
{
if
((
result
=
check_entry_status
(
timer
,
entry
,
&
slot_index
))
!=
0
)
{
return
result
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录