aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2020-10-21 15:13:37 -0700
committerOmar Rizwan <omar.rizwan@gmail.com>2020-10-21 15:14:00 -0700
commit69c167a134bacba2da697099813a45013fa53bcf (patch)
tree9d7abd1efad8a2ca2118635874286b633a65aea1 /fs
parentc78377d46442739e48ffd1e418b950b78608e509 (diff)
native messaging test file.
Diffstat (limited to 'fs')
-rw-r--r--fs/test-native.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/fs/test-native.c b/fs/test-native.c
new file mode 100644
index 0000000..c53df29
--- /dev/null
+++ b/fs/test-native.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main() {
+ FILE *log = fopen("log.txt", "w");
+ fprintf(log, "hello\n"); fflush(log);
+
+ for (;;) {
+ char *outMsg = "{\"text\":\"This is a response message\"}";
+ unsigned int outLen = strlen(outMsg);
+ char *bOutLen = (char *)&outLen;
+ write(1, bOutLen, 4); // 1 is stdout
+ write(1, outMsg, outLen);
+ fflush(stdout);
+ fprintf(log, "wrote msg\n"); fflush(log);
+
+ char bInLen[4];
+ read(0, bInLen, 4); // 0 is stdin
+ unsigned int inLen = *(unsigned int *)bInLen;
+ char *inMsg = (char *)malloc(inLen);
+ read(0, inMsg, inLen);
+ inMsg[inLen] = '\0';
+ fprintf(log, "msg: [%s]\n", inMsg); fflush(log);
+ free(inMsg);
+
+ }
+ return 0;
+}