font opened PR #5624 from sockets-c-api to main:
This adds support for WASI sockets to the C API by adding a new API to handle preopening sockets for clients. This uses
HashMapinstead ofVecfor preopened sockets to identify if the caller has called in more than once with the same FD number. If so, then we return false so caller is at least given a hint that they may be misusing the API e.g. attempting to overwrite an already existing socket FD.I stuck with the same
boolreturn value because it was already being done for the other APIs e.g.wasi_config_preopen_dir. I think it would be beneficial to have a more specific error type, if possible, but not something to address in this PR.I don't think there are any tests for these APIs so none were added. Of course I was personally testing this with the
cruncontainer runtime that is using these APIs.I don't know who could review this so any help identifying the right people would be greatly appreciated!
Fixes #5071
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
font updated PR #5624 from sockets-c-api to main.
peterhuene submitted PR review.
peterhuene submitted PR review.
peterhuene created PR review comment:
* "127.0.0.1:8080") requested to listen on.
peterhuene created PR review comment:
* \brief Configures a "preopened" listen socket to be available to WASI APIs.
peterhuene created PR review comment:
Cast seems unnecessary?
builder = builder.preopened_socket(fd_num, listener)?;
peterhuene created PR review comment:
I think this might be better represented with:
unsafe fn cstr_to_str<'a>(s: *const c_char) -> Option<&'a str> { CStr::from_ptr(s).to_str().ok() }Which we can then also call from
cstr_to_path.
peterhuene created PR review comment:
host_port: *const c_char,
peterhuene created PR review comment:
Nit: we don't need to call it
stdlisteneras we're directly using thewasmtime_wasi::TcpListenertype.Perhaps simply
listenerwould be a better name to use here?
peterhuene created PR review comment:
If we change to
cstr_to_strabove:let address = match cstr_to_str(host_port) { Some(s) => s, None => return false, };
font updated PR #5624 from sockets-c-api to main.
font updated PR #5624 from sockets-c-api to main.
font submitted PR review.
font submitted PR review.
font created PR review comment:
Ah yes, thanks! Left over from using a different type previously.
peterhuene submitted PR review.
peterhuene has enabled auto merge for PR #5624.
peterhuene merged PR #5624.
Last updated: Dec 06 2025 at 06:05 UTC