Skip to content

Comments

add support to bind to port 0 in emrun#18775

Merged
kripken merged 3 commits intoemscripten-core:mainfrom
arsnyder16:asnyder/dynamic-port
Feb 18, 2023
Merged

add support to bind to port 0 in emrun#18775
kripken merged 3 commits intoemscripten-core:mainfrom
arsnyder16:asnyder/dynamic-port

Conversation

@arsnyder16
Copy link
Contributor

Allowing port 0 binding will find an available port automatically.

This is useful in situations where you want run emrun multiple times with something like GNU parallel

Example output

# ./emrun --verbose --no_browser a
Web server root directory: /root/arsnyder16-emscripten
Starting web server: http://0.0.0.0:6931/
Now listening at http://0.0.0.0:6931/
Entering web server loop.
^CClosed web server.
emrun quitting with process exit code None
# ./emrun --verbose --no_browser --port 0 a
Web server root directory: /root/arsnyder16-emscripten
Starting web server: http://0.0.0.0:0/
Now listening at http://0.0.0.0:41261/
Entering web server loop.
^CClosed web server.
emrun quitting with process exit code None

logi('Web server root directory: ' + os.path.abspath('.'))
logv('Starting web server: http://%s:%i/' % (options.hostname, options.port))
httpd = HTTPWebServer((options.hostname, options.port), HTTPHandler)
options.port = httpd.socket.getsockname()[1]
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a comment here? otherwise it is a little odd to see port passed in and then read back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Added.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

@kripken kripken enabled auto-merge (squash) February 17, 2023 23:37
@kripken
Copy link
Member

kripken commented Feb 17, 2023

I wonder if we could use this to parallelize our browser test suite here... (edit: not this specifically, as we don't use emrun for most tests, but we could spawn in parallel using port 0)

@arsnyder16
Copy link
Contributor Author

I wonder if we could use this to parallelize our browser test suite here... (edit: not this specifically, as we don't use emrun for most tests, but we could spawn in parallel using port 0)

This will certainly open the door, our native tests are all with gtest so we are able to leverage the sharding it can do.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 17, 2023

I wonder if we could use this to parallelize our browser test suite here... (edit: not this specifically, as we don't use emrun for most tests, but we could spawn in parallel using port 0)

I don't think the browser test suite uses emrun. I'm also not sure lack of port numbers would be blocking factor there.

@kripken kripken merged commit dbac5e8 into emscripten-core:main Feb 18, 2023
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.

3 participants