From 5a2c2b5d037a93734cb69b98ae768a6c5fd00dd2 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 25 Jul 2019 12:52:48 +0200 Subject: [PATCH] add simple way of messaging numbers and return code --- fuse-native.c | 28 ++++++++++++---------------- index.js | 9 +++++++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/fuse-native.c b/fuse-native.c index 86c4d6f..c9a1955 100644 --- a/fuse-native.c +++ b/fuse-native.c @@ -28,7 +28,8 @@ typedef struct { } fuse_thread_t; typedef struct { - int hello; + uint32_t ints[32]; + int32_t res; fuse_thread_t *fuse; fuse_native_semaphore_t sem; uv_async_t async; @@ -39,18 +40,6 @@ typedef struct { static pthread_key_t thread_locals_key; -// static fuse_thread_locals_t * thread_local_map[1024]; -// static int thread_local_map_length = 0; - -// static int get_free_thread_id () { -// for (int i = 0; i < thread_local_map_length; i++) { -// if (thread_local_map[i] == NULL) return i; -// } - -// return thread_local_map_length++; -// } - - static void fin (napi_env env, void *fin_data, void* fin_hint) { printf("finaliser is run\n"); // exit(0); @@ -91,8 +80,6 @@ static fuse_thread_locals_t* get_thread_locals () { fuse_thread_locals_t* l = (fuse_thread_locals_t *) malloc(sizeof(fuse_thread_locals_t)); - l->hello = 42; - // TODO: mutex me?? int err = uv_async_init(uv_default_loop(), &(l->async), (uv_async_cb) fuse_native_dispatch); @@ -138,14 +125,23 @@ static int fuse_native_getattr (const char *path, struct stat *stat) { uv_async_send(&(l->async)); fuse_native_semaphore_wait(&(l->sem)); + printf("l->res: %i\n", l->res); + printf("l->ints[0]: %u\n", l->ints[0]); + printf("l->ints[1]: %u\n", l->ints[1]); + printf("l->ints[2]: %u\n", l->ints[2]); + return -1; } NAPI_METHOD(fuse_native_signal) { - NAPI_ARGV(5) + NAPI_ARGV(2) NAPI_ARGV_BUFFER_CAST(fuse_thread_locals_t *, l, 0); + NAPI_ARGV_INT32(res, 1) + l->res = res; fuse_native_semaphore_signal(&(l->sem)); + + return NULL; } NAPI_METHOD(fuse_native_mount) { diff --git a/index.js b/index.js index dd1cada..e0b7185 100644 --- a/index.js +++ b/index.js @@ -12,9 +12,14 @@ class Fuse { } onop (handle) { - console.log('on_op is called', handle) + const ints = new Uint32Array(handle.buffer, handle.byteOffset, 32) + + ints[0] = 1 + ints[1] = 42 + ints[2] = 10 + process.nextTick(function () { - binding.fuse_native_signal(handle) + binding.fuse_native_signal(handle, -1) }) } }