mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
feat: support linux vsock (#28725)
impl support for vsock https://man7.org/linux/man-pages/man7/vsock.7.html
This commit is contained in:
parent
7218113d24
commit
9da231dc7a
17 changed files with 680 additions and 28 deletions
95
cli/tsc/dts/lib.deno.ns.d.ts
vendored
95
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -5160,6 +5160,23 @@ declare namespace Deno {
|
|||
path: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options that can be passed to `Deno.serve` to create a server listening on
|
||||
* a vsock socket.
|
||||
*
|
||||
* @category HTTP Server
|
||||
*/
|
||||
export interface ServeVsockOptions extends ServeOptions<Deno.VsockAddr> {
|
||||
/** The transport to use. */
|
||||
transport?: "vsock";
|
||||
|
||||
/** The context identifier to use. */
|
||||
cid: number;
|
||||
|
||||
/** The port to use. */
|
||||
port: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @category HTTP Server
|
||||
*/
|
||||
|
@ -5261,6 +5278,56 @@ declare namespace Deno {
|
|||
options: ServeUnixOptions,
|
||||
handler: ServeHandler<Deno.UnixAddr>,
|
||||
): HttpServer<Deno.UnixAddr>;
|
||||
/** Serves HTTP requests with the given option bag and handler.
|
||||
*
|
||||
* You can specify the socket path with `path` option.
|
||||
*
|
||||
* ```ts
|
||||
* Deno.serve(
|
||||
* { cid: -1, port: 3000 },
|
||||
* (_req) => new Response("Hello, world")
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* You can stop the server with an {@linkcode AbortSignal}. The abort signal
|
||||
* needs to be passed as the `signal` option in the options bag. The server
|
||||
* aborts when the abort signal is aborted. To wait for the server to close,
|
||||
* await the promise returned from the `Deno.serve` API.
|
||||
*
|
||||
* ```ts
|
||||
* const ac = new AbortController();
|
||||
*
|
||||
* const server = Deno.serve(
|
||||
* { signal: ac.signal, cid: -1, port: 3000 },
|
||||
* (_req) => new Response("Hello, world")
|
||||
* );
|
||||
* server.finished.then(() => console.log("Server closed"));
|
||||
*
|
||||
* console.log("Closing server...");
|
||||
* 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.
|
||||
*
|
||||
* ```ts
|
||||
* Deno.serve({
|
||||
* onListen({ cid, port }) {
|
||||
* console.log(`Server started at ${cid}:${port}`);
|
||||
* // ... more info specific to your server ..
|
||||
* },
|
||||
* cid: -1,
|
||||
* port: 3000,
|
||||
* }, (_req) => new Response("Hello, world"));
|
||||
* ```
|
||||
*
|
||||
* @category HTTP Server
|
||||
*/
|
||||
export function serve(
|
||||
options: ServeVsockOptions,
|
||||
handler: ServeHandler<Deno.VsockAddr>,
|
||||
): HttpServer<Deno.VsockAddr>;
|
||||
/** Serves HTTP requests with the given option bag and handler.
|
||||
*
|
||||
* You can specify an object with a port and hostname option, which is the
|
||||
|
@ -5348,6 +5415,34 @@ declare namespace Deno {
|
|||
export function serve(
|
||||
options: ServeUnixOptions & ServeInit<Deno.UnixAddr>,
|
||||
): 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.
|
||||
*
|
||||
* ```ts
|
||||
* const ac = new AbortController();
|
||||
*
|
||||
* const server = Deno.serve({
|
||||
* cid: -1,
|
||||
* port: 3000,
|
||||
* handler: (_req) => new Response("Hello, world"),
|
||||
* signal: ac.signal,
|
||||
* onListen({ cid, port }) {
|
||||
* console.log(`Server started at ${cid}:${port}`);
|
||||
* },
|
||||
* });
|
||||
* server.finished.then(() => console.log("Server closed"));
|
||||
*
|
||||
* console.log("Closing server...");
|
||||
* ac.abort();
|
||||
* ```
|
||||
*
|
||||
* @category HTTP Server
|
||||
*/
|
||||
export function serve(
|
||||
options: ServeVsockOptions & ServeInit<Deno.VsockAddr>,
|
||||
): HttpServer<Deno.VsockAddr>;
|
||||
/** Serves HTTP requests with the given option bag.
|
||||
*
|
||||
* You can specify an object with a port and hostname option, which is the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue