mirror of
https://github.com/osnr/TabFS.git
synced 2024-06-15 20:25:18 +02:00
fs: Some comments.
This commit is contained in:
parent
a8ce61d9a1
commit
cca53bc199
|
@ -16,6 +16,10 @@ void common_init() {
|
||||||
if (pipe(ws_to_tabfs)) exit(1);
|
if (pipe(ws_to_tabfs)) exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: we probably need memory fences here?? especially on
|
||||||
|
// non-x86?? idk
|
||||||
|
// see https://stackoverflow.com/questions/35837539/does-the-use-of-an-anonymous-pipe-introduce-a-memory-barrier-for-interthread-com
|
||||||
|
|
||||||
void common_send_tabfs_to_ws(char *request_data) {
|
void common_send_tabfs_to_ws(char *request_data) {
|
||||||
write(tabfs_to_ws[1], &request_data, sizeof(request_data));
|
write(tabfs_to_ws[1], &request_data, sizeof(request_data));
|
||||||
}
|
}
|
||||||
|
|
16
fs/common.h
16
fs/common.h
|
@ -1,3 +1,6 @@
|
||||||
|
// common provides an interface for tabfs.c (which talks to FUSE) to
|
||||||
|
// talk to ws.c (which talks to the browser over WebSocket).
|
||||||
|
|
||||||
#ifndef COMMON_H
|
#ifndef COMMON_H
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
|
@ -9,7 +12,20 @@ void common_init();
|
||||||
|
|
||||||
typedef int (*fd_set_filler_fn_t)(fd_set*, fd_set*, fd_set*);
|
typedef int (*fd_set_filler_fn_t)(fd_set*, fd_set*, fd_set*);
|
||||||
|
|
||||||
|
// All send and receive calls are blocking!
|
||||||
|
|
||||||
void common_send_tabfs_to_ws(char *request_data);
|
void common_send_tabfs_to_ws(char *request_data);
|
||||||
|
// This function is called by the ws thread; it blocks waiting for
|
||||||
|
// tabfs thread to send a request _from FUSE_, which means that the ws
|
||||||
|
// thread wouldn't be able to hear about events _from the browser_
|
||||||
|
// while blocked here (including important ones, like 'the browser
|
||||||
|
// wants to connect to us!').
|
||||||
|
//
|
||||||
|
// The hack solution is that ws passes a function `filler` to add the
|
||||||
|
// WebSocket file descriptors to the set that
|
||||||
|
// `common_receive_tabfs_to_ws` polls, so it _also_ waits on
|
||||||
|
// _browser-side_ events from the WebSocket file descriptors, not just
|
||||||
|
// FUSE-side events.
|
||||||
char *common_receive_tabfs_to_ws(fd_set_filler_fn_t filler);
|
char *common_receive_tabfs_to_ws(fd_set_filler_fn_t filler);
|
||||||
|
|
||||||
void common_send_ws_to_tabfs(char *response_data);
|
void common_send_ws_to_tabfs(char *response_data);
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
#include "ws.h"
|
#include "ws.h"
|
||||||
|
|
||||||
static cJSON *send_request_then_await_response(cJSON *req) {
|
static cJSON *send_request_then_await_response(cJSON *req) {
|
||||||
char *request_data = cJSON_Print(req); // Will be freed on ws side.
|
// 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);
|
common_send_tabfs_to_ws(request_data);
|
||||||
|
|
||||||
char *response_data = common_receive_ws_to_tabfs();
|
char *response_data = common_receive_ws_to_tabfs();
|
||||||
|
@ -22,6 +23,7 @@ static cJSON *send_request_then_await_response(cJSON *req) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *resp = cJSON_Parse((const char *) response_data);
|
cJSON *resp = cJSON_Parse((const char *) response_data);
|
||||||
|
// Was allocated by sender (ws.c, websocket_frame).
|
||||||
free(response_data);
|
free(response_data);
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
|
|
8
fs/ws.c
8
fs/ws.c
|
@ -37,20 +37,22 @@ static int fill_fd_set_with_ws_sockets(fd_set *read_fds, fd_set *write_fds, fd_s
|
||||||
static void receive_tabfs_request_then_send_to_browser() {
|
static void receive_tabfs_request_then_send_to_browser() {
|
||||||
char *request_data = common_receive_tabfs_to_ws(fill_fd_set_with_ws_sockets);
|
char *request_data = common_receive_tabfs_to_ws(fill_fd_set_with_ws_sockets);
|
||||||
if (request_data == NULL) {
|
if (request_data == NULL) {
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (con == NULL) {
|
if (con == NULL) {
|
||||||
common_send_ws_to_tabfs(NULL);
|
common_send_ws_to_tabfs(NULL);
|
||||||
return;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
wby_frame_begin(con, WBY_WSOP_TEXT_FRAME);
|
wby_frame_begin(con, WBY_WSOP_TEXT_FRAME);
|
||||||
wby_write(con, request_data, strlen(request_data));
|
wby_write(con, request_data, strlen(request_data));
|
||||||
wby_frame_end(con);
|
wby_frame_end(con);
|
||||||
|
|
||||||
|
done:
|
||||||
// Was allocated by sender (tabfs.c, send_request_then_await_response).
|
// Was allocated by sender (tabfs.c, send_request_then_await_response).
|
||||||
free(request_data);
|
if (request_data != NULL) { free(request_data); }
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in a new issue