Skip to content

Full posix sockets linux fixes#2

Closed
jakogut wants to merge 14 commits intojuj:full_posix_socketsfrom
jakogut:full_posix_sockets_linux_fixes
Closed

Full posix sockets linux fixes#2
jakogut wants to merge 14 commits intojuj:full_posix_socketsfrom
jakogut:full_posix_sockets_linux_fixes

Conversation

@jakogut
Copy link

@jakogut jakogut commented Feb 26, 2019

Fixes issues with missing headers and symbols when building websocket_to_posix_proxy on Linux.

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". That is, POSIX sockets proxying builds on top of the Emscripten WebSockets library, and requires multithreading and proxying the application main() to a pthread.
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".
Copy link
Owner

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=1 with sockets proxying - any code in the SYSCALLS.* 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?

#include <errno.h>
#include <assert.h>
#include <netdb.h>
#include <arpa/inet.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this behind #if defined(__APPLE__) || defined(__linux__)

return val.s_addr;
return INADDR_NONE;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks odd, why implement inet_addr here? It looks like it is provided by sockets library, declared in that <arpa/inet.h>

with PythonTcpEchoServerProcess('7777'):
# Build and run the TCP echo client program with Emscripten
self.btest(path_from_root('tests', 'websocket', 'tcp_echo_client.cpp'), expected='101', args=['-lwebsocket', '-s', 'PROXY_POSIX_SOCKETS=1', '-s', 'USE_PTHREADS=1', '-s', 'PROXY_TO_PTHREAD=1'])
self.btest(path_from_root('tests', 'websocket', 'tcp_echo_client.cpp'), expected='101', args=['-lwebsocket', '-s', 'PROXY_POSIX_SOCKETS=1', '-s', 'USE_PTHREADS=1', '-s', 'PROXY_TO_PTHREAD=1', '-s', 'FORCE_FILESYSTEM=1'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this change?

add_executable(websocket_to_posix_proxy ${sourceFiles})

find_package(Threads)
target_link_libraries(websocket_to_posix_proxy ${CMAKE_THREAD_LIBS_INIT})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#if defined(__APPLE__) || defined(__linux__)

#include <sys/socket.h>
#include <signal.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@juj juj force-pushed the full_posix_sockets branch 3 times, most recently from 7aa34e4 to 1d220c5 Compare June 14, 2019 06:43
@juj juj force-pushed the full_posix_sockets branch from 1d220c5 to c694a10 Compare June 20, 2019 12:05
@juj juj force-pushed the full_posix_sockets branch 2 times, most recently from f52e26e to aaee189 Compare July 11, 2019 10:49
@juj juj force-pushed the full_posix_sockets branch 2 times, most recently from 0761158 to 9ac2540 Compare July 29, 2019 14:13
@jakogut jakogut closed this Aug 26, 2019
juj pushed a commit that referenced this pull request May 18, 2020
* Updated WebGPU

* Updated AUTHORS

* Updated WebGPU

* Updated AUTHORS

* Fixed review issues

- Changed 'const * nextInChain' to 'chain' for chained descriptors
- Removed unnecessary structs/enums for web
- Changed wgpuDeviceGetDefaultQueue so it returns the same queue
     when called multiple times with the same device
- Changed makeCheckDescriptor to also work with 'chain' member (hacky)

* Fixed review #2 issues

* Updated shader module creation

* Fixed struct_info.json

* Shader module descriptor chaining

* Apply suggestions from code review

* Adapt to Dawn webgpu.h

* Remove some unused and deprecated bits

Co-authored-by: Kai Ninomiya <kainino@chromium.org>
Co-authored-by: Hugo Amiard <hugo.amiard@laposte.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants