Skip to content
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

Add CLI options for preopened listen sockets #3729

Merged
merged 1 commit into from
Feb 7, 2022

Conversation

haraldh
Copy link
Contributor

@haraldh haraldh commented Jan 27, 2022

As a follow up for #3711, this implements CLI options to insert pre-opened sockets.

--listenfd : Inherit environment variables and file descriptors following the systemd listen fd specification (UNIX only)

--tcplisten <SOCKET ADDRESS>: Grant access to the given TCP listen socket

TODO

  • Write test cases

EXAMPLES

$ git clone --branch wasi https://github.com/haraldh/mio.git
$ cd mio
$ cargo +nightly build --target wasm32-wasi --example tcp_server --features="os-poll net" 
$ wasmtime run --tcplisten 127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/debug/examples/tcp_server.wasm 
Using preopened socket FD 3
You can connect to the server using `nc`:
 $ nc <IP> <PORT>
You'll see our welcome message and anything you type will be printed here.
^Z
[1]+  Stopped                 wasmtime run --tcplisten 127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/debug/examples/tcp_server.wasm
$ bg
$ echo Hello | nc 127.0.0.1 9000
Accepted connection from: 0.0.0.0:0
Hello world!
Received data: Hello
Connection closed
$ fg
$ ^C

@github-actions
Copy link

Subscribe to Label Action

cc @kubkon

This issue or pull request has been labeled: "wasi"

Thus the following users have been cc'd because of the following labels:

  • kubkon: wasi

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@haraldh haraldh force-pushed the wasmtime_listen_cli branch 5 times, most recently from d921e8e to 6ba0c26 Compare January 28, 2022 13:56
@haraldh haraldh changed the title DRAFT: Add CLI options for preopened listen sockets Add CLI options for preopened listen sockets Jan 28, 2022
@haraldh haraldh force-pushed the wasmtime_listen_cli branch from 6ba0c26 to 877f4fb Compare February 1, 2022 07:46
This patch  implements CLI options to insert pre-opened sockets.

`--listenfd` : Inherit environment variables and file descriptors following
               the systemd listen fd specification (UNIX only).

`--tcplisten <SOCKET ADDRESS>`: Grant access to the given TCP listen socket.

Signed-off-by: Harald Hoyer <harald@profian.com>
@haraldh haraldh force-pushed the wasmtime_listen_cli branch from 877f4fb to 6be5273 Compare February 4, 2022 10:36
@haraldh
Copy link
Contributor Author

haraldh commented Feb 4, 2022

rebased

@haraldh
Copy link
Contributor Author

haraldh commented Feb 4, 2022

added mio for wasi example to first comment

@sunfishcode
Copy link
Member

This looks like it will be a good way to enable experimentation with the new WASI accept functionality.

Looking forward, the convention of having applications implicitly assume they can get environment variables like LISTEN_FDS is problematic for WASI. To make WASI programs modular and statically analyzable, we want to make API contracts explicit in imports and exports, rather than in dynamic environment-variable conventions. I expect what we'll want in the future is for this to use the Typed Main feature, and then to have WASI libc on the inside translate that back into making getenv("LISTEN_FDS") return this information for compatibility.

However, we can address that as the pieces needed to use Typed Main come online. For now, this looks good.

@sunfishcode sunfishcode merged commit fa889b4 into bytecodealliance:main Feb 7, 2022
mpardesh pushed a commit to avanhatt/wasmtime that referenced this pull request Mar 17, 2022
…alliance#3729)

This patch  implements CLI options to insert pre-opened sockets.

`--listenfd` : Inherit environment variables and file descriptors following
               the systemd listen fd specification (UNIX only).

`--tcplisten <SOCKET ADDRESS>`: Grant access to the given TCP listen socket.

Signed-off-by: Harald Hoyer <harald@profian.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants