This commit is contained in:
2023-08-15 08:35:06 +02:00
parent 00bd68d09f
commit 6b110ddc15
14 changed files with 411 additions and 18 deletions

View File

@@ -9,6 +9,8 @@
#include <logger.h>
#include <fcntl.h>
#include <cllexer.h>
#include <clparser.h>
#include <cflexer.h>
#include <cfparser.h>
#include <massert.h>
@@ -31,12 +33,12 @@ int cworker_readconf(cworker_t* worker) {
cflexer_init(&lexer, &cache);
cfparser_init(&parser, &lexer);
if (cfparser_parse(&parser)) {
log_error("parse args error\n");
if (cfparser_parse(&parser) < 0) {
log_error("parse config error\n");
return -1;
}
cfparser_bind(&parser, CFVALTYPE_STR, "port", (void *)&(worker->port));
cfparser_bind(&parser, CFVALTYPE_INT, "port", (void *)&(worker->port));
cfparser_destroy(&parser);
cflexer_destroy(&lexer);
@@ -45,16 +47,45 @@ int cworker_readconf(cworker_t* worker) {
return 0;
}
int cworker_init(cworker_t* worker) {
int cworker_readopts(cworker_t* worker, char** argv, int argc) {
log_debug("reading options");
cllexer_t lexer;
clparser_t parser;
cllexer_init(&lexer);
clparser_init(&parser, &lexer);
clparser_bind(&parser, CLVALTYPE_INT, "port", (void *)&(worker->port));
if (clparser_parse(&parser, &argv[1], argc - 1) < 0) {
log_error("parse args error\n");
return -1;
}
return 0;
}
const int64_t default_port = 9701;
int cworker_init(cworker_t* worker, char** argv, int argc) {
log_debug("init service");
worker->port = 9701;
worker->port = default_port;
if (cworker_readconf(worker) < 0) {
log_error("reading config error\n");
return -1;
}
if (cworker_readopts(worker, argv, argc) < 0) {
log_error("reading config error\n");
return -1;
}
log_debug("port: %d", worker->port);
return 0;
}