fs: Some comments.

This commit is contained in:
Omar Rizwan 2019-02-25 19:57:07 -08:00
parent a8ce61d9a1
commit cca53bc199
4 changed files with 28 additions and 4 deletions

View file

@ -16,6 +16,10 @@ void common_init() {
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) {
write(tabfs_to_ws[1], &request_data, sizeof(request_data));
}

View file

@ -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
#define COMMON_H
@ -9,7 +12,20 @@ void common_init();
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);
// 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);
void common_send_ws_to_tabfs(char *response_data);

View file

@ -12,7 +12,8 @@
#include "ws.h"
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);
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);
// Was allocated by sender (ws.c, websocket_frame).
free(response_data);
return resp;

View file

@ -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() {
char *request_data = common_receive_tabfs_to_ws(fill_fd_set_with_ws_sockets);
if (request_data == NULL) {
return;
goto done;
}
if (con == NULL) {
common_send_ws_to_tabfs(NULL);
return;
goto done;
}
wby_frame_begin(con, WBY_WSOP_TEXT_FRAME);
wby_write(con, request_data, strlen(request_data));
wby_frame_end(con);
done:
// Was allocated by sender (tabfs.c, send_request_then_await_response).
free(request_data);
if (request_data != NULL) { free(request_data); }
return;
}
static int