-
Notifications
You must be signed in to change notification settings - Fork 3.5k
emrun: fix interactive programs become unresponsive #25998
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
base: main
Are you sure you want to change the base?
Conversation
This commit adds the --interactive flag which forwards emrun's stdin to the client program. The client program's "emrun_postjs.js" connects to emrun's "/in" endpoint before starting the program. All stdin input received by emrun are forwarded to the client as server-side events. The client program can access this input via `TTY.default_tty_ops.get_char`. This commit also adds an implementation of `TTY.stream_ops.poll` implementation so that the client can check whether the input is ready using the `select` syscall. To avoid blocking the browser's main loop, --interactive flag enables only non-blocking stdin. The client program can check input readiness using the select syscall then perform the read when the input becomes available. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
Currently, emrun receives client output line by line separated by newline characters. However, interactive programs often needs to display output without a trailing newline char, such as the prompt characters (e.g. "$" and "#"). And the current emrun implementation can't display such output correctly. This commit fixes this issue by sending the client program's output to emrun character by character when --interactive is enabled. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
|
I'm curious about the use of stdin for programs running on the web. Emscripten doesn't really have good support for stdin on the web right now, but maybe its something we could improbe. Would it perhaps make sense to instead run these kind of tests under node where stdin and stdout and much better supported? |
|
I've been running an emscripten-compiled QEMU targetting browser (https://github.com/ktock/qemu-wasm-sample/tree/tcidev ). I'm using xterm-pty as the terminal layer on browser. |
|
I'm somewhat hesitant to add more features and complexity to emrun. Right now we have very pretty limited testing of it, and we also don't use it internally do testing of emscripten itself (the test runner has it own builtin webserver). I wonder if this is the kind of functionality that is best built in top of emscripten rather then within it? I don't feel super strongly here, but just want to push back at least little bit. At least we should improve our emrun testing before we start making it more complicated. It looks like we disabled a bunch of the tests back in #14434 and we should probably fix that first .. |
|
BTW, have to tried doing some of your testing under node? It makes the debug test cycle a lot faster when the browser is not in the loop :) I'm not suggesting you remove all browser testing, but do some large fraction under node (this is what we do internally in emscripten testing). |
|
Thanks for the suggestion. I currently rely on manually running the |
|
Yes, file packager output should work just fine under node. |
Emrun is a convenient tool for showcasing emscripten-compiled program to other developers on the CLI without requiring manual HTTP server setup.
However, interactive programs don't work because emrun doesn't forward stdin to the client program.
This PR fixes this issue by introducing a new emrun flag
--interactivewhich forwards emrun's stdin to the client program. In this mode, the program's output is sent to emrun character by character to support output without a trailing newline char, such as the prompt characters.It focuses on the interactive programs that use non-blocking stdin (e.g. select/poll with nonblocking reads) so that the browser's main loop isn't blocked when using this flag.
Example
I've used FireFox 146:
This prints "hi" to the terminal.