Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
    npro  
 Modern all-safe Rust Network Protocol library supporting h1, h2, h3, ws, wt sans-IO and with socket IO + tls
git clone https://npro.rs/repo/npro
 
root / assets / netbsd-iOS.svg
Author[]Andy Green <andy@warmcat.com> 2026-06-29 07:49 UTC
Committer[]Andy Green <andy@warmcat.com> 2026-06-29 08:39 UTC
Tree44cc89d2d6b8638945c2c3974a85bf22124b6c31   Raw Patch
 
windows: use event logging when service
windows: use event logging when service
diff --git a/src/builder/b-sai.c b/src/builder/b-sai.c index 5ff35c8..78a13a3 100644 --- a/src/builder/b-sai.c +++ b/src/builder/b-sai.c @@ -519,6 +519,18 @@ crash_handler(int signum) } #endif +#if defined(WIN32) +static int log_fd = -1; + +static void +lwsl_emit_file(int level, const char *line) +{ + if (log_fd >= 0) { + write(log_fd, line, (unsigned int)strlen(line)); + } +} +#endif + int saib_app_run(int argc, const char **argv) { @@ -593,16 +605,17 @@ saib_app_run(int argc, const char **argv) lws_set_log_level(logs, lwsl_emit_syslog); } else #endif - + { #if defined(__linux__) || defined(__APPLE__) - signal(SIGSEGV, crash_handler); - signal(SIGABRT, crash_handler); - signal(SIGBUS, crash_handler); - signal(SIGILL, crash_handler); - signal(SIGFPE, crash_handler); + signal(SIGSEGV, crash_handler); + signal(SIGABRT, crash_handler); + signal(SIGBUS, crash_handler); + signal(SIGILL, crash_handler); + signal(SIGFPE, crash_handler); #endif - lws_set_log_level(logs, NULL); + lws_set_log_level(logs, NULL); + } #if defined(WIN32) { @@ -623,6 +636,14 @@ saib_app_run(int argc, const char **argv) lws_snprintf(stg_config_dir, sizeof(stg_config_dir), "%s\\sai\\builder", temp); + if (lws_cmdline_option(argc, argv, "--service")) { + char logpath[512]; + lws_snprintf(logpath, sizeof(logpath), "%s\\sai-builder-service.log", stg_config_dir); + log_fd = open(logpath, O_CREAT | O_TRUNC | O_WRONLY, 0600); + if (log_fd >= 0) + lws_set_log_level(logs, lwsl_emit_file); + } + config_dir = stg_config_dir; CoTaskMemFree(wdi); } diff --git a/src/builder/b-ws-server.c b/src/builder/b-ws-server.c index 0fbe627..d371ec3 100644 --- a/src/builder/b-ws-server.c +++ b/src/builder/b-ws-server.c @@ -155,51 +155,49 @@ saib_m_rx(void *userobj, const uint8_t *in, size_t len, int flags) struct sai_plat_server *spm = (struct sai_plat_server *)userobj; sai_plat_t *sp = NULL; sai_resource_t *reso; - struct lejp_ctx ctx; - lws_struct_args_t a; sai_rebuild_t *reb; sai_cancel_t *can; int m; lws_ss_validity_confirmed(spm->ss); - /* - * use the schema name on the incoming JSON to decide what kind of - * structure to instantiate - */ + if (flags & LWSSS_FLAG_SOM) { + memset(&spm->a, 0, sizeof(spm->a)); + spm->a.map_st[0] = lsm_schema_map_m_to_b; + spm->a.map_entries_st[0] = LWS_ARRAY_SIZE(lsm_schema_map_m_to_b); + spm->a.ac_block_size = 512; - memset(&a, 0, sizeof(a)); - a.map_st[0] = lsm_schema_map_m_to_b; - a.map_entries_st[0] = LWS_ARRAY_SIZE(lsm_schema_map_m_to_b); - a.ac_block_size = 512; + lws_struct_json_init_parse(&spm->ctx, NULL, &spm->a); + } -// lwsl_hexdump_warn(in, len); + m = lejp_parse(&spm->ctx, (uint8_t *)in, (int)len); + if (m == LEJP_CONTINUE) + return LWSSSSRET_OK; - lws_struct_json_init_parse(&ctx, NULL, &a); - m = lejp_parse(&ctx, (uint8_t *)in, (int)len); if (m < 0) { lwsl_hexdump_err(in, len); lwsl_err("%s: builder rx JSON decode failed '%s'\n", __func__, lejp_error_to_string(m)); + lwsac_free(&spm->a.ac); return m; } - if (!a.dest) { - lwsac_free(&a.ac); + if (!spm->a.dest) { + lwsac_free(&spm->a.ac); return LWSSSSRET_OK; } - switch (a.top_schema_index) { + switch (spm->a.top_schema_index) { case SAIB_RX_TASK_ALLOCATION: - if (saib_consider_allocating_task(spm, &a, in, len, flags)) + if (saib_consider_allocating_task(spm, &spm->a, in, len, flags)) break; break; case SAIB_RX_TASK_CANCEL: - can = (sai_cancel_t *)a.dest; + can = (sai_cancel_t *)spm->a.dest; lwsl_notice("%s: received task cancel for %s, erase %d\n", __func__, can->task_uuid, can->erase); @@ -260,7 +258,7 @@ saib_m_rx(void *userobj, const uint8_t *in, size_t len, int flags) case SAIB_RX_VIEWERSTATE: { - sai_viewer_state_t *vs = (sai_viewer_state_t *)a.dest; + sai_viewer_state_t *vs = (sai_viewer_state_t *)spm->a.dest; char any_busy = 0; lwsl_notice("Received viewer state update: %u viewers\n", vs->viewers); @@ -306,7 +304,7 @@ saib_m_rx(void *userobj, const uint8_t *in, size_t len, int flags) case SAIB_RX_OPENSHELL: { extern int saib_shell_spawn(struct sai_plat_server *spm, const char *task_uuid); - sai_openshell_t *os = (sai_openshell_t *)a.dest; + sai_openshell_t *os = (sai_openshell_t *)spm->a.dest; lwsl_notice("%s: OPENSHELL received from server for task %s\n", __func__, os->task_uuid); saib_shell_spawn(spm, os->task_uuid); break; @@ -314,7 +312,7 @@ saib_m_rx(void *userobj, const uint8_t *in, size_t len, int flags) case SAIB_RX_PTYDATA: { - sai_ptydata_t *pd = (sai_ptydata_t *)a.dest; + sai_ptydata_t *pd = (sai_ptydata_t *)spm->a.dest; struct sai_shell *sh = NULL; lws_start_foreach_dll(struct lws_dll2 *, d, builder.shell_owner.head) { @@ -361,7 +359,7 @@ saib_m_rx(void *userobj, const uint8_t *in, size_t len, int flags) } case SAIB_RX_RESOURCE_REPLY: - reso = (sai_resource_t *)a.dest; + reso = (sai_resource_t *)spm->a.dest; lwsl_notice("%s: RESOURCE_REPLY: cookie %s\n", __func__, reso->cookie); @@ -370,7 +368,7 @@ saib_m_rx(void *userobj, const uint8_t *in, size_t len, int flags) break; case SAIB_RX_REBUILD: - reb = (sai_rebuild_t *)a.dest; + reb = (sai_rebuild_t *)spm->a.dest; lwsl_notice("%s: REBUILD: %s\n", __func__, reb->builder_name); diff --git a/src/common/include/private.h b/src/common/include/private.h index 5e10bb4..a0f6346 100644 --- a/src/common/include/private.h +++ b/src/common/include/private.h @@ -542,6 +542,9 @@ typedef struct sai_plat_server { char last_msg_start[128]; uint8_t inside_msg; uint8_t tx_corrupted; + + struct lejp_ctx ctx; + lws_struct_args_t a; } sai_plat_server_t; struct sai_env {
Page fetched 0s ago, creation time: 2ms (vhost etag hits: 0%, cache hits: 0%)