Browse Source

+ csocket-test

master
Alex 'AdUser' Z 4 years ago
parent
commit
b7b624f133
  1. 3
      src/CMakeLists.txt
  2. 33
      src/csocket-test.c

3
src/CMakeLists.txt

@ -30,6 +30,9 @@ add_executable("f2b-filter-test" ${SOURCES})
set(SOURCES "strlcpy.c" "backend-test.c" "log.c" "config.c" "backend.c") set(SOURCES "strlcpy.c" "backend-test.c" "log.c" "config.c" "backend.c")
add_executable("f2b-backend-test" ${SOURCES}) add_executable("f2b-backend-test" ${SOURCES})
set(SOURCES "strlcpy.c" "csocket-test.c" "log.c" "buf.c" "commands.c" "csocket.c")
add_executable("f2b-csocket-test" ${SOURCES})
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries("f2b" "dl") target_link_libraries("f2b" "dl")
target_link_libraries("f2b-source-test" "dl") target_link_libraries("f2b-source-test" "dl")

33
src/csocket-test.c

@ -0,0 +1,33 @@
#include "common.h"
#include "buf.h"
#include "log.h"
#include "commands.h"
#include "csocket.h"
static int run = 1;
void
cmd_handler(const f2b_cmd_t *cmd, f2b_buf_t *res) {
fprintf(stdout, "[handler] received cmd with type %d and %d args:\n", cmd->type, cmd->argc);
for (int i = 0; i < cmd->argc; i++) {
fprintf(stdout, "[handler] arg %d : %s\n", i + 1, cmd->args[i]);
}
UNUSED(res);
return;
}
int main(void) {
f2b_csock_t *csock = NULL;
if ((csock = f2b_csocket_create(DEFAULT_CSOCKET_PATH)) == NULL) {
perror("f2b_csocket_create()");
}
while (run) {
f2b_csocket_poll(csock, cmd_handler);
/* TODO: sleep 0.1s */
}
f2b_csocket_destroy(csock);
return 0;
}
Loading…
Cancel
Save