Open btkhoi2001 opened 7 months ago
That seems very odd. Can you uncommenting the POSIX_SOCKET_DEBUG
line in system/lib/websocket/websocket_to_posix_socket.c
and then rebuilding the library using ./embuilder build libsockets_proxy-mt --force
Is this something to do with the way the C++ lambda capture works for the bridgeUrl pointer? I would have though it would capture by simply copying the pointer.. but maybe not? @tlively ?
The lambda here is capturing bridgeURL
by reference because of the [&]
binder. Since the proxying is async, the function returns on the calling thread before the lambda is executed on the thread it was sent to, so when the lambda is eventually executed, the reference to bridgeURL
is dangling.
To fix it, you could either make the lambda capture the argument by value or you can switch to synchronous proxying to keep the parameters and local variables on the calling thread alive until the work is complete.
You also don't need the queue.execute()
call on the calling thread, since it isn't performing any proxied work. The work will automatically execute on the worker thread as soon as it returns to its event loop.
Please include the following in your bug report:
Version of emscripten/emsdk:
Full link command
I am trying to port my socket application to WebAssembly which uses Full POSIX Sockets over WebSocket Proxy Server. I want to initialize the bridge only in certain case, not when the main function is loaded. So I wrap it in a function with EMSCRIPTEN_KEEPALIVE and call it in the javascript module. I made some changes based on this example test code tcp_echo_client.c
Then initialize a bridge when a user clicks the button.
Problem: First, the task is still executed even without this line:
Second, I want to make sure the bridgeUrl successfully passed into the lambda expression, so I use
printf
to check it. When I place it beforeemscripten_init_websocket_to_posix_socket_bridge
, It still prints the correct URL, but it gets "flushed" and becomes empty when passing intoemscripten_init_websocket_to_posix_socket_bridge
The same error happens when I change the order, I place
printf
after. It successfully initiated the bridge, butprintf
prints empty URL.bridgeUrl
is messed up whenever passed into a function.