summaryrefslogtreecommitdiff
path: root/c/sources/server.c
diff options
context:
space:
mode:
authordweller <dweller@cabin.digital>2024-03-09 00:55:36 +0200
committerdweller <dweller@cabin.digital>2024-03-09 00:55:36 +0200
commit86d3f93ee338b28ab7d40aa83c129cf6b97ef4b7 (patch)
tree507a8d66932e6dea9b121dfcbf980f7925575c9f /c/sources/server.c
Initial commit, 2 years later
Diffstat (limited to '')
-rw-r--r--c/sources/server.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/c/sources/server.c b/c/sources/server.c
new file mode 100644
index 0000000..57c2492
--- /dev/null
+++ b/c/sources/server.c
@@ -0,0 +1,66 @@
+#include "ezipc.h"
+#include "common.h"
+
+
+int main(void)
+{
+ ezi_conn* conn = ezi_create(EZIPC_TEST_PATH);
+ assert(conn);
+
+ msg ok;
+ ok.type = MSG_OK;
+ strcpy((char*)ok.data, "ok");
+
+ msg quit;
+ quit.type = MSG_EXIT;
+ strcpy((char*)quit.data, "exit");
+
+ int counter = 0;
+ bool running = true;
+ while(running)
+ {
+ msg rmsg;
+ size_t rsz = sizeof(rmsg) - 100; // truncate test
+ if(ezi_recv(conn, &rmsg, &rsz))
+ {
+ switch(rmsg.type)
+ {
+ case MSG_TEXT:
+ {
+ printf("got: '%s'\n", (char*)rmsg.data);
+
+ counter++;
+ if(counter >= 10)
+ {
+ if(!ezi_send(conn, &quit, sizeof(quit)))
+ printf("Could not send msg to client\n");
+
+ counter = 0;
+ }
+ else
+ {
+ if(!ezi_send(conn, &ok, sizeof(ok)))
+ printf("Could not send msg to client\n");
+ }
+
+ } break;
+
+ default: break;
+ }
+ }
+ else
+ {
+ printf("Recv error, resetting...\n");
+
+ ezi_destroy(conn);
+ conn = ezi_create(EZIPC_TEST_PATH);
+ assert(conn);
+ }
+ }
+
+ ezi_destroy(conn);
+ return 0;
+}
+
+#define EZIPC_IMPL
+#include "ezipc.h"