feat: support linux vsock (#28725)

impl support for vsock
https://man7.org/linux/man-pages/man7/vsock.7.html
This commit is contained in:
snek 2025-04-11 07:35:05 +02:00 committed by GitHub
parent 7218113d24
commit 9da231dc7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 680 additions and 28 deletions

View file

@ -4045,6 +4045,58 @@ Deno.test(
},
);
Deno.test(
{
ignore: Deno.build.os !== "linux",
permissions: { run: true, net: true },
},
async function httpServerVsockSocket() {
const { promise, resolve } = Promise.withResolvers<Deno.VsockAddr>();
const ac = new AbortController();
await using server = Deno.serve(
{
signal: ac.signal,
cid: -1,
port: 8000,
onListen(info) {
resolve(info);
},
onError: createOnErrorCb(ac),
},
(_req, { remoteAddr }) => {
assertEquals(remoteAddr.transport, "vsock");
assertEquals(remoteAddr.cid, 1);
assertEquals(remoteAddr.port, conn.localAddr.port);
return new Response("hello world!");
},
);
assertEquals((await promise).cid, 4294967295);
assertEquals((await promise).port, 8000);
const conn = await Deno.connect({
transport: "vsock",
cid: 1,
port: 8000,
});
await conn.write(
new TextEncoder().encode("GET / HTTP/1.1\r\nhost: example.com\r\n\r\n"),
);
const data = new Uint8Array(512);
const n = await conn.read(data);
const body = new TextDecoder().decode(data.subarray(0, n!));
assertEquals(
"hello world!",
body.split("\r\n").at(-1),
);
await conn.close();
ac.abort();
await server.finished;
},
);
// serve Handler must return Response class or promise that resolves Response class
Deno.test(
{ permissions: { net: true, run: true } },