From e734173e6f5df2fc9df39dc8b98a03e8b83d889f Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sat, 24 Nov 2018 10:58:33 -0800 Subject: [PATCH] URL and title kind of work. direct_io option makes it reliably change. Big speedup from... removing prints. Did I even need multithreading? --- extension/background.js | 40 ++++++++++++++++++++---------------- fs/Makefile | 4 +--- fs/hello.c | 45 +++++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/extension/background.js b/extension/background.js index 1b2b5cc..25575ca 100644 --- a/extension/background.js +++ b/extension/background.js @@ -88,25 +88,31 @@ const router = { }; }, async open(path) { - return fhManager.allocate(await getTab(parseInt(pathComponent(path, -2)))); + return 0; }, async read(path, fh, size, offset) { - const tab = fhManager.ref(fh); - return tab.url.substr(offset, size); + const tab = await getTab(parseInt(pathComponent(path, -2))); + return (tab.url + "\n").substr(offset, size); }, - async release(path, fh) { - fhManager.free(fh); - } + async release(path, fh) {} + }, + "title": { + async getattr() { + return { + st_mode: unix.S_IFREG | 0444, + st_nlink: 1, + st_size: 1000 // FIXME + }; + }, + async open(path) { + return 0; + }, + async read(path, fh, size, offset) { + const tab = await getTab(parseInt(pathComponent(path, -2))); + return (tab.title + "\n").substr(offset, size); + }, + async release(path, fh) {} }, - /* "title": fileFromProperty('title'), - * "sources": folderFromResource( - * (tab, path) => new Promise(resolve => chrome.debugger.attach( - * { tabId: tab.id }, "1-3", resolve)), - * { - * readdir() { - - * } - * }*/ } } } @@ -160,7 +166,7 @@ ws.onmessage = async function(event) { const req = JSON.parse(event.data); let response = { op: req.op, error: unix.EIO }; - console.time(req.op + ':' + req.path); + /* console.time(req.op + ':' + req.path);*/ try { if (req.op === 'getattr') { response = { @@ -202,7 +208,7 @@ ws.onmessage = async function(event) { error: e instanceof UnixError ? e.error : unix.EIO } } - console.timeEnd(req.op + ':' + req.path); + /* console.timeEnd(req.op + ':' + req.path);*/ response.id = req.id; ws.send(JSON.stringify(response)); diff --git a/fs/Makefile b/fs/Makefile index 806daa8..0a85261 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -29,11 +29,9 @@ clean: rm -f $(TARGETS) *.o rm -rf *.dSYM -remount: unmount mount - unmount: killall -9 hello || true diskutil unmount force mnt || true mount: hello - ./hello -s -f mnt + ./hello -odirect_io -f mnt diff --git a/fs/hello.c b/fs/hello.c index 1609c6e..f86ae59 100644 --- a/fs/hello.c +++ b/fs/hello.c @@ -29,8 +29,11 @@ enum request_response_state { struct request_response { enum request_response_state state; + char *request; cJSON *response; + + clock_t start; }; #define REQUEST_RESPONSE_QUEUE_SIZE 128 @@ -54,8 +57,9 @@ static request_id enqueue_request(cJSON *req) { queue[id].state = SEND_REQUEST; queue[id].request = cJSON_Print(req); queue[id].response = NULL; + queue[id].start = clock(); - printf("%s\n", queue[id].request); + /* printf("%s\n", queue[id].request); */ pthread_mutex_unlock(&queue_mutex); @@ -96,6 +100,8 @@ static cJSON *await_response(request_id id) { queue[id].state = EMPTY; queue[id].response = NULL; + /* printf("Elapsed: %f seconds\n", (double)(clock() - queue[id].start) / CLOCKS_PER_SEC); */ + pthread_mutex_unlock(&queue_mutex); return resp; @@ -143,7 +149,6 @@ static int hello_getattr(const char *path, struct stat *stbuf) { memset(stbuf, 0, sizeof(struct stat)); - printf("\n\ngetattr(%s)\n", path); MAKE_REQ("getattr", { cJSON_AddStringToObject(req, "path", path); @@ -151,7 +156,6 @@ hello_getattr(const char *path, struct stat *stbuf) JSON_GET_PROP_INT(stbuf->st_mode, "st_mode"); JSON_GET_PROP_INT(stbuf->st_nlink, "st_nlink"); JSON_GET_PROP_INT(stbuf->st_size, "st_size"); - printf("returning re getattr(%s)\n", path); ret = 0; }); @@ -175,8 +179,6 @@ static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { - printf("\n\nreaddir(%s)\n", path); - // send {op: "readdir", path} to the websocket handler MAKE_REQ("readdir", { cJSON_AddStringToObject(req, "path", path); @@ -185,7 +187,6 @@ hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler, cJSON *entry; cJSON_ArrayForEach(entry, entries) { filler(buf, cJSON_GetStringValue(entry), NULL, 0); - printf("entry: [%s]\n", cJSON_GetStringValue(entry)); } ret = 0; @@ -265,11 +266,11 @@ websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void unsigned char data[131072] = {0}; int i = 0; - printf("WebSocket frame incoming\n"); - printf(" Frame OpCode: %d\n", frame->opcode); - printf(" Final frame?: %s\n", (frame->flags & WBY_WSF_FIN) ? "yes" : "no"); - printf(" Masked? : %s\n", (frame->flags & WBY_WSF_MASKED) ? "yes" : "no"); - printf(" Data Length : %d\n", (int) frame->payload_length); + /* printf("WebSocket frame incoming\n"); */ + /* printf(" Frame OpCode: %d\n", frame->opcode); */ + /* printf(" Final frame?: %s\n", (frame->flags & WBY_WSF_FIN) ? "yes" : "no"); */ + /* printf(" Masked? : %s\n", (frame->flags & WBY_WSF_MASKED) ? "yes" : "no"); */ + /* printf(" Data Length : %d\n", (int) frame->payload_length); */ if ((unsigned long) frame->payload_length > sizeof(data)) { printf("Data too long!\n"); @@ -282,17 +283,17 @@ websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void size_t read_size = remain > (int) sizeof buffer ? sizeof buffer : (size_t) remain; size_t k; - printf("%08x ", (int) i); + /* printf("%08x ", (int) i); */ if (0 != wby_read(connection, buffer, read_size)) break; - for (k = 0; k < read_size; ++k) - printf("%02x ", buffer[k]); - for (k = read_size; k < 16; ++k) - printf(" "); - printf(" | "); - for (k = 0; k < read_size; ++k) - printf("%c", isprint(buffer[k]) ? buffer[k] : '?'); - printf("\n"); + /* for (k = 0; k < read_size; ++k) */ + /* printf("%02x ", buffer[k]); */ + /* for (k = read_size; k < 16; ++k) */ + /* printf(" "); */ + /* printf(" | "); */ + /* for (k = 0; k < read_size; ++k) */ + /* printf("%c", isprint(buffer[k]) ? buffer[k] : '?'); */ + /* printf("\n"); */ for (k = 0; k < read_size; ++k) data[i + k] = buffer[k]; i += (int)read_size; @@ -313,7 +314,7 @@ websocket_frame(struct wby_con *connection, const struct wby_frame *frame, void request_id id = id_item->valueint; pthread_mutex_lock(&queue_mutex); - printf("got resp"); + if (queue[id].state != RECEIVE_RESPONSE) { printf("Got response to request in wrong state!\n"); exit(1); @@ -337,7 +338,7 @@ websocket_closed(struct wby_con *connection, void *userdata) static void test_log(const char* text) { - printf("[debug] %s\n", text); + /* printf("[debug] %s\n", text); */ } void *websocket_main(void *threadid)