From 7d4e357bac40a3ef792bb9fc25c9340c5b0131d6 Mon Sep 17 00:00:00 2001 From: mrfoxygmfr Date: Wed, 21 May 2025 02:36:23 +0300 Subject: feat: add controller and worker examples --- controller.c | 19 +++++++++++++++++++ worker.c | 16 ++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 controller.c create mode 100644 worker.c diff --git a/controller.c b/controller.c new file mode 100644 index 0000000..6efcb7e --- /dev/null +++ b/controller.c @@ -0,0 +1,19 @@ +#include "lib/controller.h" + +int32_t main() { + controller_init("127.0.0.1", "33554", 1, 4); + controller_start(); + + printf("%d\n", controller_yield_task("test", 4)); + printf("%d\n", controller_yield_task("task", 4)); + + controller_wait(); + + const char* c; + size_t sz; + printf("%d\n", controller_get_result(&c, &sz)); + printf("%d\n", controller_get_result(&c, &sz)); + + controller_finish(); + printf("OK\n"); +} diff --git a/worker.c b/worker.c new file mode 100644 index 0000000..c6698d9 --- /dev/null +++ b/worker.c @@ -0,0 +1,16 @@ +#include "./lib/worker.h" + +void func(const char* task, size_t task_size, char** resp, size_t* resp_size) { + printf("HERE %*s\n", (int) task_size, task); + + task = task; + task_size = task_size; + *resp = malloc(10); + *resp_size = 10; + sleep(1); +} + +int32_t main() { + worker_init("127.0.0.1", "33554", 2, func); + worker_exec(); +} -- cgit mrf-deployment