2 Commits

Author SHA1 Message Date
ec3064e0a1 core: Make a place to implement the server-side websocket handling in C, conditionally.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m18s
2025-12-01 12:28:09 -05:00
af8e60f8c3 cleanup: Stray/stale typedefs. 2025-12-01 12:28:09 -05:00
4 changed files with 30 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
#include "httpd.js.h" #include "httpd.js.h"
#include "http.h" #include "http.h"
#include "log.h"
#include "mem.h" #include "mem.h"
#include "ssb.db.h" #include "ssb.db.h"
#include "ssb.h" #include "ssb.h"
@@ -8,6 +9,7 @@
#include "util.js.h" #include "util.js.h"
#include "picohttpparser.h" #include "picohttpparser.h"
#include "uv.h"
#include <stdlib.h> #include <stdlib.h>
@@ -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); 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_task_t* task = request->user_data;
tf_ssb_t* ssb = tf_task_get_ssb(task); 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, exports);
JS_FreeValue(context, global); 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);
}
}

View File

@@ -2402,7 +2402,6 @@ tf_ssb_t* tf_ssb_create(uv_loop_t* loop, JSContext* context, const char* db_path
char buffer[8] = { 0 }; char buffer[8] = { 0 };
size_t buffer_size = sizeof(buffer); 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; ssb->verbose = uv_os_getenv("TF_SSB_VERBOSE", buffer, &buffer_size) == 0 && strcmp(buffer, "1") == 0;
if (context) if (context)

View File

@@ -15,8 +15,6 @@
/** An event loop. */ /** An event loop. */
typedef struct uv_loop_s uv_loop_t; typedef struct uv_loop_s uv_loop_t;
/** A timer. */
typedef struct uv_timer_s uv_timer_t;
/** A task identifier. */ /** A task identifier. */
typedef int taskid_t; typedef int taskid_t;

View File

@@ -21,9 +21,6 @@ typedef enum _tf_setting_kind_t
k_kind_string, k_kind_string,
} tf_setting_kind_t; } tf_setting_kind_t;
/** An event loop. */
typedef struct uv_loop_s uv_loop_t;
/** /**
** Register utility script functions. ** Register utility script functions.
** @param context The JS context. ** @param context The JS context.