From ec3064e0a106db9797e940fe258af82c712da19d Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sun, 30 Nov 2025 21:59:37 -0500 Subject: [PATCH] core: Make a place to implement the server-side websocket handling in C, conditionally. --- src/httpd.app.c | 31 ++++++++++++++++++++++++++++++- src/ssb.c | 1 - 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/httpd.app.c b/src/httpd.app.c index fe5cc09e..df71f27f 100644 --- a/src/httpd.app.c +++ b/src/httpd.app.c @@ -1,6 +1,7 @@ #include "httpd.js.h" #include "http.h" +#include "log.h" #include "mem.h" #include "ssb.db.h" #include "ssb.h" @@ -8,6 +9,7 @@ #include "util.js.h" #include "picohttpparser.h" +#include "uv.h" #include @@ -211,7 +213,12 @@ void tf_httpd_endpoint_app(tf_http_request_t* request) tf_ssb_run_work(ssb, _httpd_endpoint_app_blob_work, _httpd_endpoint_app_blob_after_work, data); } -void tf_httpd_endpoint_app_socket(tf_http_request_t* request) +static void _tf_httpd_endpoint_app_socket_c(tf_http_request_t* request) +{ + tf_printf("Unimplemented.\n"); +} + +static void _tf_httpd_endpoint_app_socket_js(tf_http_request_t* request) { tf_task_t* task = request->user_data; tf_ssb_t* ssb = tf_task_get_ssb(task); @@ -250,3 +257,25 @@ void tf_httpd_endpoint_app_socket(tf_http_request_t* request) JS_FreeValue(context, exports); JS_FreeValue(context, global); } + +void tf_httpd_endpoint_app_socket(tf_http_request_t* request) +{ + static bool checked_env; + static bool use_c; + if (!checked_env) + { + char buffer[8] = { 0 }; + size_t buffer_size = sizeof(buffer); + use_c = uv_os_getenv("TF_APP_C", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0; + checked_env = true; + } + + if (use_c) + { + _tf_httpd_endpoint_app_socket_c(request); + } + else + { + _tf_httpd_endpoint_app_socket_js(request); + } +} diff --git a/src/ssb.c b/src/ssb.c index cad08f95..21387fb4 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -2402,7 +2402,6 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path char buffer[8] = { 0 }; size_t buffer_size = sizeof(buffer); - buffer_size = sizeof(buffer); ssb->verbose = uv_os_getenv("TF_SSB_VERBOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0; if (context)