This commit is contained in:
root
2026-06-15 21:42:50 +00:00
parent 34a97e2577
commit 99cd92fb4a
126 changed files with 1615 additions and 1057 deletions
+19 -8
View File
@@ -12,7 +12,7 @@
// ---- W3 connector membranes -----------------------------------------------
// sqlite/mysql run host-side (the host links the native connectors and owns the
// connections in per-workspace handle tables). UCEB1-marshalled hostcalls carry
// connections in per-workspace handle tables). UCEB2-marshalled hostcalls carry
// operation requests/responses; `connection` holds the host handle (>0).
static const char* WASM_DB_UNAVAILABLE =
@@ -303,7 +303,7 @@ DValue MySQL::query(String q, StringMap params) { return(query(parse_query_param
DValue MySQL::get_pending_result() { return(DValue()); }
// sqlite runs host-side (the host links libsqlite and owns the connections in
// a per-workspace handle table). One UCEB1-marshalled hostcall carries
// a per-workspace handle table). One UCEB2-marshalled hostcall carries
// {op,handle,path,query,params} in and {handle,result,insert_id,affected,
// error_code,statement_info} out. `connection` holds the host handle (>0).
extern "C" size_t uce_host_sqlite(const char* in, size_t in_len, char* out, size_t cap);
@@ -766,7 +766,7 @@ void uce_wasm_core_reset_request()
wasm_component_slots.clear();
}
// Host pushes the UCEB1-encoded request context into a guest buffer
// Host pushes the UCEB2-encoded request context into a guest buffer
// (uce_alloc) and applies it here; mirrors the native param population.
int uce_wasm_apply_context(const char* buf, size_t len)
{
@@ -800,6 +800,8 @@ int uce_wasm_apply_context(const char* buf, size_t len)
// websocket event context: ws_send()/ws_close() capture into the dispatch
// list (the workspace owns no connections), which collect() carries back to
// the broker. Reset per invocation.
wasm_request.connection = DValue();
wasm_request.resources.websocket_connection_state_before = DValue();
wasm_request.resources.websocket_dispatch_commands = DValue();
wasm_request.resources.websocket_dispatch_capture = false;
DValue* ws = decoded.key("ws");
@@ -817,6 +819,7 @@ int uce_wasm_apply_context(const char* buf, size_t len)
wasm_request.resources.websocket_dispatch_capture = true;
if(DValue* cstate = ws->key("connection_state"))
wasm_request.connection = *cstate;
wasm_request.resources.websocket_connection_state_before = wasm_request.connection;
}
return(0);
}
@@ -829,7 +832,7 @@ Request* uce_wasm_request()
}
// After render: response metadata (status line, headers, cookies, session)
// goes back to the host as UCEB1.
// goes back to the host as UCEB2.
void uce_wasm_finish_response_meta()
{
DValue meta;
@@ -844,14 +847,22 @@ void uce_wasm_finish_response_meta()
}
for(auto& entry : wasm_request.session)
meta["session"][entry.first] = entry.second;
bool ws_has_commands = !wasm_request.resources.websocket_dispatch_commands._map.empty();
bool ws_state_changed = false;
if(wasm_request.resources.websocket_dispatch_capture)
{
String prior_state = ucb_encode(wasm_request.resources.websocket_connection_state_before);
String current_state = ucb_encode(wasm_request.connection);
ws_state_changed = (prior_state != current_state);
}
// Any unit code (not just WS handlers) may call ws_send/ws_close; whenever the
// dispatch list is non-empty, carry it back so the worker can flush it to the
// broker. ws_connection_state rides along for stateful WS handlers.
if(!wasm_request.resources.websocket_dispatch_commands._map.empty())
{
// broker. If only connection state changed, flush a command-less state-only
// batch so the broker can persist the connection mutation.
if(ws_has_commands)
meta["ws_commands"] = wasm_request.resources.websocket_dispatch_commands;
if(ws_state_changed)
meta["ws_connection_state"] = wasm_request.connection;
}
wasm_response_meta = ucb_encode(meta);
}