Stream: git-wasmtime

Topic: wasmtime / PR #5624 Add support for WASI sockets to C API


view this post on Zulip Wasmtime GitHub notifications bot (Jan 23 2023 at 22:30):

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 HashMap instead of Vec for 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 bool return 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 crun container 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.

Please ensure all communication adheres to the code of conduct.
-->

view this post on Zulip Wasmtime GitHub notifications bot (Jan 24 2023 at 21:23):

font updated PR #5624 from sockets-c-api to main.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene created PR review comment:

 * "127.0.0.1:8080") requested to listen on.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene created PR review comment:

 * \brief Configures a "preopened" listen socket to be available to WASI APIs.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene created PR review comment:

Cast seems unnecessary?

            builder = builder.preopened_socket(fd_num, listener)?;

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

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.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene created PR review comment:

    host_port: *const c_char,

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene created PR review comment:

Nit: we don't need to call it stdlistener as we're directly using the wasmtime_wasi::TcpListener type.

Perhaps simply listener would be a better name to use here?

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2023 at 22:30):

peterhuene created PR review comment:

If we change to cstr_to_str above:

    let address = match cstr_to_str(host_port) {
        Some(s) => s,
        None => return false,
    };

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2023 at 01:40):

font updated PR #5624 from sockets-c-api to main.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2023 at 01:46):

font updated PR #5624 from sockets-c-api to main.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2023 at 02:03):

font submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2023 at 02:03):

font submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 03 2023 at 02:03):

font created PR review comment:

Ah yes, thanks! Left over from using a different type previously.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2023 at 23:55):

peterhuene submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 09 2023 at 23:56):

peterhuene has enabled auto merge for PR #5624.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2023 at 00:22):

peterhuene merged PR #5624.


Last updated: Oct 23 2024 at 20:03 UTC