Jacek Sieka 7b7f790cfa
interop: chronos example, NimMain calling and other fixes (#15)
* add end-to-end example for running chronos in a thread
* `NimMain` must be called once to init runtime
* shared memory updates
2023-06-23 12:11:00 +02:00

25 lines
648 B
C

#include <stdio.h>
#include <stdlib.h>
/* Import functions from Nim */
void* startNode(const char* url, void (*onHeader)(void*, const char*, size_t), void* user);
void stopNode(void** ctx);
void onHeader(void* user, const char* headers, size_t len) {
printf("Received headers! %lu\n", len);
printf("%.*s\n\n", (int)len, headers);
}
int main(int argc, char** argv) {
printf("Starting node\n");
void* ctx = startNode("127.0.0.1:60000", onHeader, 0);
printf("Node is listening on http://127.0.0.1:60000\nType `q` and press enter to stop\n");
int stop = 0;
while (getchar() != 'q');
printf("Stopping node\n");
stopNode(&ctx);
}