forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 3
Full posix sockets linux fixes #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jakogut
wants to merge
14
commits into
juj:full_posix_sockets
from
jakogut:full_posix_sockets_linux_fixes
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7f53211
-s PROXY_POSIX_SOCKETS option: Allows POSIX sockets support via proxy…
juj 6ef8f30
Fix libc library to depend on libc-sockets library
juj bd04975
Update docs with linker settings
juj cbfb0bf
Use lib name libc-sockets-proxy instead of libposix-sockets-proxy
juj f5462e7
Fix build error
juj 12a8b13
Update libc and libc-sockets symbols
juj db29521
Update wasm-libc symbols
juj f265f4d
Flake
juj 503c788
Fix wasm libc build
juj 551164b
tools: websocket_to_posix_proxy: fix undefined reference to pthread_c…
jakogut a6ad746
tools: websocket_to_posix_proxy: fix missing signal header
jakogut c3138f8
libc-sockets-proxy: define inet_addr
jakogut 3463aad
docs: porting: networking: document filesystem necessity with posix p…
jakogut 62080bc
tests: posix_proxy_sockets: enable FORCE_FILESYSTEM=1
jakogut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| .. Networking: | ||
|
|
||
| ============================== | ||
| Networking | ||
| ============================== | ||
|
|
||
| Emscripten compiled applications have a number of ways to connect with online servers. Check the subtopics here to learn about the different strategies that are available. | ||
|
|
||
| If you are familiar with networking concepts provided by different web APIs, such as XmlHttpRequest, Fetch, WebSockets and WebRTC, you can quickly get started by leveraging what you already know: by calling out from C/C++ code to JavaScript (see the "Connecting C++ and JavaScript" section), you can establish networked connections by writing regular JavaScript. For C/C++ developers, Emscripten provides a few approaches, described here. | ||
|
|
||
| Emscripten WebSockets API | ||
| ========================= | ||
|
|
||
| WebSockets API provides connection-oriented message-framed bidirectional asynchronous networking communication to the browser. It is the closest to TCP on the web that web sites can access, direct access to TCP sockets is not possible from web browsers. | ||
|
|
||
| Emscripten provides a passthrough API for accessing the WebSockets API from C/C++ code. This is useful for developers who would prefer not to write any JavaScript code, or deal with the C/C++ and JavaScript language interop. See the system include file <emscripten/websocket.h> for details. One benefit that the Emscripten WebSockets API provides over manual WebSockets access in JavaScript is the ability to share access to a WebSocket handle across multiple threads, something that can be time consuming to develop from scratch. | ||
|
|
||
| To target Emscripten WebSockets API, you must link it in with a "-lwebsocket.js" linker directive. | ||
|
|
||
| Emulated POSIX TCP Sockets over WebSockets | ||
| ========================================== | ||
|
|
||
| If you have existing TCP networking code written in C/C++ that utilizes the Posix Sockets API, by default Emscripten attempts to emulate such connections to take place over the WebSocket protocol instead. For this to work, you will need to use something like WebSockify on the server side to enable the TCP server stack to receive incoming WebSocket connections. This emulation is not very complete at the moment, it is likely that you will run into problems out of the box and need to adapt the code to work within the limitations that this emulation provides. | ||
|
|
||
| This is the default build mode for POSIX sockets, no linker flags or option settings are needed to enable it. | ||
|
|
||
| Full POSIX Sockets over WebSocket Proxy Server | ||
| ============================================== | ||
|
|
||
| Emscripten provides a native POSIX Sockets proxy server program, located in directory tools/websocket_to_posix_proxy/, that allows full POSIX Sockets API access from a web browser. This support works by proxying all POSIX Sockets API calls from the browser to the Emscripten POSIX Sockets proxy server (via transparent use of WebSockets API), and the proxy server then performs the native TCP/UDP calls on behalf of the page. This allows a web browser page to run full TCP & UDP connections, act as a server to accept incoming connections, and perform host name lookups and reverse lookups. Because all API calls are individually proxied, this support can be slow. This support is mostly useful for developing testing infrastructure and debugging. | ||
|
|
||
| To use POSIX sockets proxying, link the application with flags "-lwebsocket.js -s PROXY_POSIX_SOCKETS=1 -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1 -s FORCE_FILESYSTEM=1". That is, POSIX sockets proxying builds on top of the Emscripten WebSockets library, and requires multithreading and proxying the application main() to a pthread. Without FORCE_FILESYSTEM=1, required syscalls may be optimized out, giving the runtime error "SYSCALLS.getStreamFromFD is not a function". | ||
|
|
||
| For an example of how the POSIX Sockets proxy server works in an Emscripten client program, see the file tests/websocket/tcp_echo_client.cpp. | ||
|
|
||
| XmlHttpRequests and Fetch API | ||
| ============================= | ||
|
|
||
| For HTTP transfers, one can use the browser built-in XmlHttpRequest (XHR) API and the newer Fetch API. These can be accessed directly from JavaScript. Emscripten also provides passthrough APIs to perform HTTP requests. For more information, see the emscripten_async_wget*() C API and the Emscripten Fetch API. | ||
|
|
||
| WebRTC and UDP | ||
| ============== | ||
|
|
||
| Direct UDP communication is not available in browsers, but as a close alternative, the WebRTC specification provides a mechanism to perform UDP-like communication with WebRTC Data Channels. Currently Emscripten does not provide a C/C++ API for interacting with WebRTC. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
|
|
||
| #include "websocket.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| extern EMSCRIPTEN_RESULT emscripten_init_websocket_to_posix_socket_bridge(const char *bridgeUrl); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| U __errno_location | ||
| U __syscall102 | ||
| U __syscall221 | ||
| U __syscall_ret | ||
| U free | ||
| -------- T accept | ||
| -------- T bind | ||
| -------- T connect | ||
| -------- T freeaddrinfo | ||
| -------- T getpeername | ||
| -------- T getsockname | ||
| -------- T getsockopt | ||
| -------- T listen | ||
| -------- T recv | ||
| -------- T recvfrom | ||
| -------- T recvmsg | ||
| -------- T send | ||
| -------- T sendmsg | ||
| -------- T sendto | ||
| -------- T setsockopt | ||
| -------- T shutdown | ||
| -------- T socket | ||
| -------- T socketpair |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it is not intended to use
-s FORCE_FILESYSTEM=1with sockets proxying - any code in theSYSCALLS.*will not be compatible with sockets proxying, but rather if you are getting such an error, I think it's due to some bits missing in the sockets proxying PR. Let's revert this doc piece back and look at the runtime error in more detail?