diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-08-22 11:49:08 +0200 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-08-22 14:24:35 +0200 |
commit | 2d9f8f45be0c9bc5f56864f66a37c3cc60069fe5 (patch) | |
tree | f2cbf2c9dfdfd035c38be4e48bbdc1d725e0aa9d /desktop/source | |
parent | 0afb4cfc5ed1e926dfd287007c5a35585584daec (diff) |
Emscripten: Experimental -sPROXY_POSIX_SOCKETS support
...see
<https://emscripten.org/docs/porting/networking.html#full-posix-sockets-over-websocket-proxy-server>.
This requires
<https://github.com/stbergmann/emscripten/commit/4aff1f28b88480791236adcc6d5cb2d919ad4bf3>
"-sPROXY_POSIX_SOCKETS: Add websocket_proxy_poll". When configured with
--disable-socketpair (which appears to have no negative consequences),
external/curl appears to only call poll(2) with socket-related file descriptors,
so we can use websocket_proxy_poll instead.
The URL on which the websocket_to_posix_proxy process listens must be specified
as Module.uno_websocket_to_posix_socket_url.
Change-Id: I4ad23098b5bbc0646fa50859c0aeb9870d1cc92a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172243
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Tested-by: Jenkins
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/app/app.cxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx index 2a52f9843f75..a4ce4c965d3a 100644 --- a/desktop/source/app/app.cxx +++ b/desktop/source/app/app.cxx @@ -18,6 +18,7 @@ */ #include <memory> +#include <config_emscripten.h> #include <config_features.h> #include <config_feature_desktop.h> #include <config_feature_opencl.h> @@ -150,6 +151,15 @@ #define GETPID getpid #endif +#if HAVE_EMSCRIPTEN_PROXY_POSIX_SOCKETS +#include <stdexcept> +#include <string> +#include <emscripten/posix_socket.h> +#include <emscripten/threading.h> +#include <emscripten/val.h> +#include <emscripten/websocket.h> +#endif + #include <strings.hxx> using namespace ::com::sun::star::awt; @@ -547,6 +557,35 @@ void Desktop::Init() RequestHandler::Disable(); } pSignalHandler = osl_addSignalHandler(SalMainPipeExchangeSignal_impl, nullptr); + +#if HAVE_EMSCRIPTEN_PROXY_POSIX_SOCKETS + { + auto const val = emscripten::val::module_property("uno_websocket_to_posix_socket_url"); + if (val.isUndefined()) { + throw std::runtime_error("Module.uno_websocket_to_posix_socket_url is undefined"); + } else { + auto const url = val.as<std::string>(); + if (url.find('\0') != std::string::npos) { + throw std::runtime_error( + "Module.uno_websocket_to_posix_socket_url contains embedded NUL"); + } + SAL_INFO("desktop.app", "connecting to <" << url << ">"); + static auto const socket = emscripten_init_websocket_to_posix_socket_bridge( + url.c_str()); + // 0 is CONNECTING, 1 is OPEN, see + // <https://websockets.spec.whatwg.org/#websocket-ready-state>: + unsigned short readyState = 0; + do { + emscripten_websocket_get_ready_state(socket, &readyState); + emscripten_thread_sleep(100); + } while (readyState == 0); + if (readyState != 1) { + throw std::runtime_error("could not connect to <" + url + ">"); + } + SAL_INFO("desktop.app", "connected to <" << url << ">"); + } + } +#endif } void Desktop::InitFinished() |