summaryrefslogtreecommitdiff
path: root/c/sources/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/sources/server.c')
-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"