Skip to content

Commit 8ab3cf8

Browse files
committed
* NEW [conf] Support to read ms.
Signed-off-by: wangha <wanghamax@gmail.com>
1 parent 7a5b5ab commit 8ab3cf8

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

include/nng/supplemental/nanolib/conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ webhook_event get_webhook_event(const char *hook_type, const char *hook_name);
683683

684684
NNG_DECL int get_size(const char *str, uint64_t *size);
685685
NNG_DECL int get_time(const char *str, uint64_t *second);
686+
NNG_DECL int get_time_ms(const char *str, uint64_t *second);
686687
NNG_DECL void conf_parse(conf *nanomq_conf);
687688
NNG_DECL void conf_parse_ver2(conf *nanomq_conf);
688689
NNG_DECL void conf_parse_cipher(conf *nanomq_conf, const char *key, const char *key2);

src/supplemental/nanolib/conf.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,6 +4095,27 @@ get_size(const char *str, uint64_t *size)
40954095
return 0;
40964096
}
40974097

4098+
int
4099+
get_time_ms(const char *str, uint64_t *msec)
4100+
{
4101+
char unit[3] = { 0 };
4102+
uint64_t ms = 0;
4103+
if (2 == sscanf(str, "%lu%02s", &ms, unit)) {
4104+
if (0 == strncmp(unit, "ms", 2)) {
4105+
*msec = ms;
4106+
return 0;
4107+
} else if (unit[0] == ' ') {
4108+
*msec = ms;
4109+
return 0;
4110+
} else if (unit[0] == 's') {
4111+
*msec = 1000 * ms;
4112+
return 0;
4113+
}
4114+
return -2;
4115+
}
4116+
return -1;
4117+
}
4118+
40984119
int
40994120
get_time(const char *str, uint64_t *second)
41004121
{

src/supplemental/nanolib/conf_ver2.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ compose_url(char *head, char *address)
127127
} \
128128
} while (0);
129129

130+
#define hocon_read_time_ms(structure, field, key, jso) \
131+
do { \
132+
cJSON *jso_key = cJSON_GetObjectItem(jso, key); \
133+
if (NULL == jso_key) { \
134+
log_debug("Config %s is not set, use default!", key); \
135+
break; \
136+
} \
137+
if (cJSON_IsString(jso_key)) { \
138+
if (NULL != jso_key->valuestring) { \
139+
uint64_t msec = 0; \
140+
get_time_ms(jso_key->valuestring, &msec); \
141+
(structure)->field = msec; \
142+
} \
143+
} \
144+
} while (0);
145+
130146
#define hocon_read_size_base(structure, field, key, jso) \
131147
do { \
132148
cJSON *jso_key = cJSON_GetObjectItem(jso, key); \
@@ -1201,9 +1217,9 @@ conf_bridge_quic_parse_ver2(conf_bridge_node *node, cJSON *jso_bridge_node)
12011217
node, qdiscon_timeout, "quic_discon_timeout", jso_bridge_node);
12021218
hocon_read_time_base(node, qsend_idle_timeout,
12031219
"quic_send_idle_timeout", jso_bridge_node);
1204-
hocon_read_time_base(
1220+
hocon_read_time_ms(
12051221
node, qinitial_rtt_ms, "quic_initial_rtt_ms", jso_bridge_node);
1206-
hocon_read_time_base(
1222+
hocon_read_time_ms(
12071223
node, qmax_ack_delay_ms, "quic_max_ack_delay_ms", jso_bridge_node);
12081224
hocon_read_time_base(
12091225
node, qconnect_timeout, "quic_handshake_timeout", jso_bridge_node);

0 commit comments

Comments
 (0)