From 69c167a134bacba2da697099813a45013fa53bcf Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Wed, 21 Oct 2020 15:13:37 -0700 Subject: native messaging test file. --- fs/test-native.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 fs/test-native.c (limited to 'fs') 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 +#include +#include +#include + +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; +} -- cgit v1.2.3