From 0e59042ba78abeae0ff0d66a8e4d24df24c59c71 Mon Sep 17 00:00:00 2001 From: Passw Date: Sat, 20 Dec 2025 01:51:58 +0800 Subject: [PATCH] fix issue https://github.com/RetroShare/RetroShare/issues/2964 --- src/jsonapi/async-method-wrapper-template.cpp.tmpl | 3 ++- src/jsonapi/jsonapi-generator.py | 13 +++++++------ src/jsonapi/jsonapi.cpp | 5 +++-- src/jsonapi/p3webui.cc | 5 ++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/jsonapi/async-method-wrapper-template.cpp.tmpl b/src/jsonapi/async-method-wrapper-template.cpp.tmpl index 29f53ad48a..324bc083f3 100644 --- a/src/jsonapi/async-method-wrapper-template.cpp.tmpl +++ b/src/jsonapi/async-method-wrapper-template.cpp.tmpl @@ -58,7 +58,8 @@ $%callbackParamsSerialization%$ sStream << "data: " << compactJSON << ctx.mJson << "\n\n"; const std::string message = sStream.str(); - lService->schedule( [weakSession, message]() + auto io_context = lService->get_io_context(); + asio::post(*io_context, [weakSession, message]() { auto session = weakSession.lock(); if(!session || session->is_closed()) return; diff --git a/src/jsonapi/jsonapi-generator.py b/src/jsonapi/jsonapi-generator.py index 1795469999..468ccd25a4 100755 --- a/src/jsonapi/jsonapi-generator.py +++ b/src/jsonapi/jsonapi-generator.py @@ -177,7 +177,7 @@ def processFile(file): callbackParams = pType else: pType = pType.replace('&', '').replace(' ', '') - + # Apparently some xml declarations include new lines ('\n') and/or multiple spaces # Strip them using python magic pType = ' '.join(pType.split()) @@ -224,8 +224,8 @@ def processFile(file): inputParamsDeserialization = '' if hasInput: - inputParamsDeserialization += '\t\t{\n' - inputParamsDeserialization += '\t\t\tRsGenericSerializer::SerializeContext& ctx(cReq);\n' + inputParamsDeserialization += '\t\t{\n' + inputParamsDeserialization += '\t\t\tRsGenericSerializer::SerializeContext& ctx(cReq);\n' inputParamsDeserialization += '\t\t\tRsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON);\n'; outputParamsSerialization = '' @@ -248,9 +248,9 @@ def processFile(file): outputParamsSerialization += '\t\t\tRS_SERIAL_PROCESS(' outputParamsSerialization += mp._name + ');\n' - if hasInput: + if hasInput: inputParamsDeserialization += '\t\t}\n' - if retvalType != 'void': + if retvalType != 'void': outputParamsSerialization += '\t\t\tRS_SERIAL_PROCESS(retval);\n' if hasOutput: outputParamsSerialization += '\t\t}\n' @@ -270,7 +270,8 @@ def processFile(file): std::chrono::seconds(maxWait+120) ); auto lService = weakService.lock(); if(!lService || lService->is_down()) return; - lService->schedule( [=]() + auto io_context = lService->get_io_context(); + asio::post(*io_context, [=]() { auto session = weakSession.lock(); if(session && session->is_open()) diff --git a/src/jsonapi/jsonapi.cpp b/src/jsonapi/jsonapi.cpp index 7cb074d47e..db67db64b2 100644 --- a/src/jsonapi/jsonapi.cpp +++ b/src/jsonapi/jsonapi.cpp @@ -28,6 +28,7 @@ #include #include +#include #include "jsonapi.h" @@ -403,8 +404,8 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), return; } - lService->schedule( [weakSession, hId, event]() - { + auto io_context = lService->get_io_context(); + asio::post(*io_context, [weakSession, hId, event]() { auto session = weakSession.lock(); if(!session || session->is_closed()) { diff --git a/src/jsonapi/p3webui.cc b/src/jsonapi/p3webui.cc index b31c3a5d44..14218ba00c 100644 --- a/src/jsonapi/p3webui.cc +++ b/src/jsonapi/p3webui.cc @@ -96,7 +96,10 @@ template class handler { "Content-Length", std::to_string(body.size()) } }; - session->close(restbed::OK, body, headers); + session->close(restbed::OK, restbed::Bytes( + reinterpret_cast(body.data()), + reinterpret_cast(body.data() + body.size())), + headers); } else {