From 64bd1f3948e2ce57a1fb26196019855727290465 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Wed, 21 Oct 2020 15:53:27 -0700 Subject: fs: Attempt to switch to native messaging. It relays 1 message ok! --- fs/tabfs.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'fs/tabfs.c') diff --git a/fs/tabfs.c b/fs/tabfs.c index da70ff3..424b330 100644 --- a/fs/tabfs.c +++ b/fs/tabfs.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -11,26 +12,26 @@ #include "base64/base64.h" #include "base64/base64.c" -#include "common.h" - static cJSON *send_request_then_await_response(cJSON *req) { - // Will be freed at receiver (ws.c, receive_tabfs_request_then_send_to_browser). char *request_data = cJSON_Print(req); - common_send_tabfs_to_ws(request_data); - - char *response_data = common_receive_ws_to_tabfs(); + unsigned int request_len = strlen(request_data); + write(1, (char *) &request_len, 4); // stdout + write(1, request_data, request_len); + + unsigned int response_len; + read(0, (char *) &response_len, 4); // stdin + char *response_data = malloc(response_len); + read(0, response_data, response_len); if (response_data == NULL) { // Connection is dead. return cJSON_Parse("{ \"error\": 5 }"); } cJSON *resp = cJSON_Parse((const char *) response_data); - // Was allocated by sender (ws.c, websocket_frame). free(response_data); return resp; } - // This helper macro is used to implement all the FUSE fs operations. // // It constructs a JSON object to represent the incoming request, then @@ -229,10 +230,10 @@ static struct fuse_operations tabfs_filesystem_operations = { int main(int argc, char **argv) { - common_init(); - - /* pthread_t websocket_thread; */ - /* pthread_create(&websocket_thread, NULL, websocket_main, NULL); */ - - return fuse_main(argc, argv, &tabfs_filesystem_operations, NULL); + FILE* log = fopen("log.txt", "w"); + for (int i = 0; i < argc; i++) { + fprintf(log, "arg%d: [%s]\n", i, argv[i]); fflush(log); + } + char* fuse_argv[] = {argv[0], "-odirect_io", "-s", "-f", "mnt"}; + return fuse_main(5, fuse_argv, &tabfs_filesystem_operations, NULL); } -- cgit v1.2.3