core: Miniscule incremental progress on websocket message handling in C.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 10m36s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 10m36s
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "ssb.db.h"
|
#include "ssb.db.h"
|
||||||
#include "ssb.h"
|
#include "ssb.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
#include "taskstub.js.h"
|
||||||
#include "util.js.h"
|
#include "util.js.h"
|
||||||
|
|
||||||
#include "picohttpparser.h"
|
#include "picohttpparser.h"
|
||||||
@@ -219,6 +220,8 @@ typedef struct _app_t
|
|||||||
tf_http_request_t* request;
|
tf_http_request_t* request;
|
||||||
const char* settings;
|
const char* settings;
|
||||||
JSValue credentials;
|
JSValue credentials;
|
||||||
|
|
||||||
|
tf_taskstub_t* taskstub;
|
||||||
} app_t;
|
} app_t;
|
||||||
|
|
||||||
static void _httpd_auth_query_work(tf_ssb_t* ssb, void* user_data)
|
static void _httpd_auth_query_work(tf_ssb_t* ssb, void* user_data)
|
||||||
@@ -230,11 +233,37 @@ static void _httpd_auth_query_work(tf_ssb_t* ssb, void* user_data)
|
|||||||
static void _httpd_app_on_message(tf_http_request_t* request, int op_code, const void* data, size_t size)
|
static void _httpd_app_on_message(tf_http_request_t* request, int op_code, const void* data, size_t size)
|
||||||
{
|
{
|
||||||
tf_printf("REQUEST MESSAGE %.*s\n", (int)size, (const char*)data);
|
tf_printf("REQUEST MESSAGE %.*s\n", (int)size, (const char*)data);
|
||||||
|
app_t* work = request->user_data;
|
||||||
|
JSContext* context = request->context;
|
||||||
|
switch (op_code)
|
||||||
|
{
|
||||||
|
case 0x1:
|
||||||
|
case 0x2:
|
||||||
|
break;
|
||||||
|
/* CLOSE */
|
||||||
|
case 0x8:
|
||||||
|
if (work->taskstub)
|
||||||
|
{
|
||||||
|
JSValue result = tf_taskstub_kill(work->taskstub);
|
||||||
|
tf_util_report_error(context, result);
|
||||||
|
JS_FreeValue(context, result);
|
||||||
|
work->taskstub = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* PONG */
|
||||||
|
case 0xa:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _httpd_app_on_close(tf_http_request_t* request)
|
static void _httpd_app_on_close(tf_http_request_t* request)
|
||||||
{
|
{
|
||||||
tf_printf("REQUEST CLOSE\n");
|
tf_printf("REQUEST CLOSE\n");
|
||||||
|
JSContext* context = request->context;
|
||||||
|
app_t* work = request->user_data;
|
||||||
|
JS_FreeValue(context, work->credentials);
|
||||||
|
tf_free(work);
|
||||||
|
|
||||||
tf_http_request_unref(request);
|
tf_http_request_unref(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,12 +352,12 @@ static void _httpd_auth_query_after_work(tf_ssb_t* ssb, int status, void* user_d
|
|||||||
/* What now? */
|
/* What now? */
|
||||||
tf_free((void*)cookie);
|
tf_free((void*)cookie);
|
||||||
JS_FreeCString(context, name_string);
|
JS_FreeCString(context, name_string);
|
||||||
JS_FreeValue(context, work->credentials);
|
|
||||||
tf_free(work);
|
|
||||||
|
|
||||||
// tf_http_request_unref(request);
|
// tf_http_request_unref(request);
|
||||||
request->on_message = _httpd_app_on_message;
|
request->on_message = _httpd_app_on_message;
|
||||||
request->on_close = _httpd_app_on_close;
|
request->on_close = _httpd_app_on_close;
|
||||||
|
request->context = context;
|
||||||
|
request->user_data = work;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tf_httpd_endpoint_app_socket_c(tf_http_request_t* request)
|
static void _tf_httpd_endpoint_app_socket_c(tf_http_request_t* request)
|
||||||
|
|||||||
@@ -1761,8 +1761,6 @@ static void _tf_task_on_handle_close(uv_handle_t* handle)
|
|||||||
handle->data = NULL;
|
handle->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue tf_taskstub_kill(tf_taskstub_t* stub);
|
|
||||||
|
|
||||||
void tf_task_destroy(tf_task_t* task)
|
void tf_task_destroy(tf_task_t* task)
|
||||||
{
|
{
|
||||||
if (!task->_shutting_down)
|
if (!task->_shutting_down)
|
||||||
|
|||||||
@@ -82,4 +82,11 @@ void tf_taskstub_on_error(tf_taskstub_t* stub, JSValue error);
|
|||||||
*/
|
*/
|
||||||
void tf_taskstub_on_print(tf_taskstub_t* stub, JSValue arguments);
|
void tf_taskstub_on_print(tf_taskstub_t* stub, JSValue arguments);
|
||||||
|
|
||||||
|
/**
|
||||||
|
** Terminate a task stub.
|
||||||
|
** @param stub The task stub to kill.
|
||||||
|
** @return A promise if it is happening asynchronously.
|
||||||
|
*/
|
||||||
|
JSValue tf_taskstub_kill(tf_taskstub_t* stub);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|||||||
Reference in New Issue
Block a user