fix: vsock nits (#28851)

This commit is contained in:
snek 2025-04-11 21:11:03 +02:00 committed by GitHub
parent 5b25eeda57
commit e73ed03373
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 54 additions and 21 deletions

View file

@ -5162,7 +5162,9 @@ declare namespace Deno {
/**
* Options that can be passed to `Deno.serve` to create a server listening on
* a vsock socket.
* a VSOCK socket.
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @category HTTP Server
*/
@ -5280,7 +5282,11 @@ declare namespace Deno {
): HttpServer<Deno.UnixAddr>;
/** Serves HTTP requests with the given option bag and handler.
*
* You can specify the socket path with `path` option.
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* You can specify an object with the cid and port options for the VSOCK interface.
*
* The VSOCK address family facilitates communication between virtual machines and the host they are running on: https://man7.org/linux/man-pages/man7/vsock.7.html
*
* ```ts
* Deno.serve(
@ -5307,9 +5313,9 @@ declare namespace Deno {
* ac.abort();
* ```
*
* By default `Deno.serve` prints the message
* `Listening on path/to/socket` on listening. If you like to
* change this behavior, you can specify a custom `onListen` callback.
* By default `Deno.serve` prints the message `Listening on cid:port`.
* If you want to change this behavior, you can specify a custom `onListen`
* callback.
*
* ```ts
* Deno.serve({
@ -5417,8 +5423,11 @@ declare namespace Deno {
): HttpServer<Deno.UnixAddr>;
/** Serves HTTP requests with the given option bag.
*
* You can specify an object with the path option, which is the
* vsock socket to listen on.
* The VSOCK address family facilitates communication between virtual machines and the host they are running on: https://man7.org/linux/man-pages/man7/vsock.7.html
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* You can specify an object with the cid and port options for the VSOCK interface.
*
* ```ts
* const ac = new AbortController();

View file

@ -18,7 +18,10 @@ declare namespace Deno {
path: string;
}
/** @category Network */
/**
* @experimental **UNSTABLE**: New API, yet to be vetted.
* @category Network
*/
export interface VsockAddr {
transport: "vsock";
cid: number;
@ -74,7 +77,9 @@ declare namespace Deno {
*/
export type UnixListener = Listener<UnixConn, UnixAddr>;
/** Specialized listener that accepts Vsock connections.
/** Specialized listener that accepts VSOCK connections.
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @category Network
*/
@ -236,9 +241,11 @@ declare namespace Deno {
options: UnixListenOptions & { transport: "unix" },
): UnixListener;
/** Options which can be set when opening a vsock listener via
/** Options which can be set when opening a VSOCK listener via
* {@linkcode Deno.listen}.
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @category Network
*/
export interface VsockListenOptions {
@ -247,6 +254,10 @@ declare namespace Deno {
}
/** Listen announces on the local transport address.
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* The VSOCK address family facilitates communication between virtual machines and the host they are running on: https://man7.org/linux/man-pages/man7/vsock.7.html
*
* ```ts
* const listener = Deno.listen({ cid: -1, port: 80, transport: "vsock" })
@ -389,7 +400,10 @@ declare namespace Deno {
// deno-lint-ignore adjacent-overload-signatures
export function connect(options: UnixConnectOptions): Promise<UnixConn>;
/** @category Network */
/**
* @experimental **UNSTABLE**: New API, yet to be vetted.
* @category Network
*/
export interface VsockConnectOptions {
transport: "vsock";
cid: number;
@ -402,6 +416,8 @@ declare namespace Deno {
/** Connects to the hostname (default is "127.0.0.1") and port on the named
* transport (default is "tcp"), and resolves to the connection (`Conn`).
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* ```ts
* const conn1 = await Deno.connect({ port: 80 });
* const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 });

View file

@ -625,10 +625,10 @@ where
use tokio_vsock::VsockAddr;
use tokio_vsock::VsockStream;
super::check_unstable(
&state.borrow(),
r#"Deno.connect({ transport: "vsock" })"#,
);
state
.borrow()
.feature_checker
.check_or_exit("vsock", "Deno.connect");
state.borrow_mut().borrow_mut::<NP>().check_vsock(
cid,
@ -680,7 +680,7 @@ where
use tokio_vsock::VsockAddr;
use tokio_vsock::VsockListener;
super::check_unstable(state, r#"Deno.listen({ transport: "vsock" })"#);
state.feature_checker.check_or_exit("vsock", "Deno.listen");
state
.borrow_mut::<NP>()

View file

@ -164,8 +164,9 @@ const unstableIds = {
process: 11,
temporal: 12,
unsafeProto: 13,
webgpu: 14,
workerOptions: 15,
vsock: 14,
webgpu: 15,
workerOptions: 16,
};
const denoNsUnstableById = { __proto__: null };

View file

@ -62,7 +62,7 @@ pub struct UnstableGranularFlag {
pub id: i32,
}
// NOTE(bartlomieju): keep IDs in sync with `runtime/90_deno_ns.js` (search for `unstableFeatures`)
// NOTE(bartlomieju): keep IDs in sync with `runtime/js/90_deno_ns.js` (search for `unstableFeatures`)
pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[
UnstableGranularFlag {
name: deno_broadcast_channel::UNSTABLE_FEATURE_NAME,
@ -145,17 +145,23 @@ pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[
// for "unstableIds" to see where it's used.
id: 13,
},
UnstableGranularFlag {
name: "vsock",
help_text: "Enable unstable VSOCK APIs",
show_in_help: false,
id: 14,
},
UnstableGranularFlag {
name: deno_webgpu::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable `WebGPU` APIs",
show_in_help: true,
id: 14,
id: 15,
},
UnstableGranularFlag {
name: ops::worker_host::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable Web Worker APIs",
show_in_help: true,
id: 15,
id: 16,
},
];

View file

@ -128,6 +128,7 @@ fn js_unit_test(test: String) {
// flag to particular files, but there's many of them that rely on unstable
// net APIs (`reusePort` in `listen` and `listenTls`; `listenDatagram`)
.arg("--unstable-net")
.arg("--unstable-vsock")
.arg("--location=http://127.0.0.1:4545/")
.arg("--no-prompt");