at work
This commit is contained in:
78
cworker.c
78
cworker.c
@@ -94,7 +94,7 @@ static int cworker_readopts(const cworker_t* worker, char** argv, int argc) {
|
||||
log_error("Args parsing error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
clparser_destroy(&parser);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -269,53 +269,55 @@ int cworker_run(const cworker_t* worker) {
|
||||
int cworker_handler(const cworker_t* worker, int socket) {
|
||||
int err = 0;
|
||||
|
||||
rcache_t cache;
|
||||
jlexer_t lexer;
|
||||
jparser_t parser;
|
||||
//rcache_t cache;
|
||||
//jlexer_t lexer;
|
||||
//jparser_t parser;
|
||||
|
||||
rcache_init(&cache, socket);
|
||||
jlexer_init(&lexer, &cache);
|
||||
jparser_init(&parser, &lexer);
|
||||
//rcache_init(&cache, socket);
|
||||
//jlexer_init(&lexer, &cache);
|
||||
//jparser_init(&parser, &lexer);
|
||||
|
||||
if (jparser_parse(&parser) < 0) {
|
||||
log_error("Cannot parse json");
|
||||
err = -1;
|
||||
goto exit;
|
||||
}
|
||||
//if (jparser_parse(&parser) < 0) {
|
||||
//log_error("Cannot parse json");
|
||||
//err = -1;
|
||||
//goto exit;
|
||||
//}
|
||||
|
||||
int64_t id = 0;
|
||||
char* name = "none";
|
||||
//int64_t id = 0;
|
||||
//char* name = "none";
|
||||
|
||||
if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
||||
log_error("Cannot bind id");
|
||||
}
|
||||
if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
||||
log_error("Cannot bind name");
|
||||
}
|
||||
//if (jparser_bind(&parser, JVALTYPE_NUM, "id", (void *)&id) < 0) {
|
||||
//log_error("Cannot bind id");
|
||||
//}
|
||||
//if (jparser_bind(&parser, JVALTYPE_STR, "name", (void *)&name) < 0) {
|
||||
//log_error("Cannot bind name");
|
||||
//}
|
||||
|
||||
|
||||
char* msg = NULL;
|
||||
asprintf(&msg, "hello, %s!", name);
|
||||
//char* msg = NULL;
|
||||
//asprintf(&msg, "hello, %s!", name);
|
||||
|
||||
jblock_t jb;
|
||||
jblock_init(&jb);
|
||||
jblock_addstr(&jb, "message", msg);
|
||||
jblock_addbool(&jb, "error", false);
|
||||
//jblock_t jb;
|
||||
//jblock_init(&jb);
|
||||
//jblock_addstr(&jb, "message", msg);
|
||||
//jblock_addbool(&jb, "error", false);
|
||||
|
||||
char* jsonstr = NULL;
|
||||
jblock_outjson(&jb, &jsonstr);
|
||||
jblock_destroy(&jb);
|
||||
//char* jsonstr = NULL;
|
||||
//jblock_outjson(&jb, &jsonstr);
|
||||
//jblock_destroy(&jb);
|
||||
|
||||
write(socket, jsonstr, strlen(jsonstr));
|
||||
free(jsonstr);
|
||||
free(name);
|
||||
free(msg);
|
||||
//write(socket, jsonstr, strlen(jsonstr));
|
||||
//free(jsonstr);
|
||||
//free(name);
|
||||
//free(msg);
|
||||
|
||||
exit:
|
||||
jparser_destroy(&parser);
|
||||
jlexer_destroy(&lexer);
|
||||
rcache_destroy(&cache);
|
||||
return err;
|
||||
//exit:
|
||||
//jparser_destroy(&parser);
|
||||
//jlexer_destroy(&lexer);
|
||||
//rcache_destroy(&cache);
|
||||
|
||||
close(socket);
|
||||
return err;
|
||||
}
|
||||
|
||||
void cworker_shutdown(cworker_t* worker) {
|
||||
|
||||
Reference in New Issue
Block a user