mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat(net): add Deno.UnixConn interface (#13787)
This commit is contained in:
parent
d1db500cda
commit
060dabee4c
3 changed files with 19 additions and 11 deletions
2
cli/dts/lib.deno.unstable.d.ts
vendored
2
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -1053,7 +1053,7 @@ declare namespace Deno {
|
||||||
): Promise<TcpConn>;
|
): Promise<TcpConn>;
|
||||||
export function connect(
|
export function connect(
|
||||||
options: UnixConnectOptions,
|
options: UnixConnectOptions,
|
||||||
): Promise<Conn>;
|
): Promise<UnixConn>;
|
||||||
|
|
||||||
export interface ConnectTlsOptions {
|
export interface ConnectTlsOptions {
|
||||||
/** PEM formatted client certificate chain. */
|
/** PEM formatted client certificate chain. */
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
ObjectPrototypeIsPrototypeOf,
|
ObjectPrototypeIsPrototypeOf,
|
||||||
PromiseResolve,
|
PromiseResolve,
|
||||||
SymbolAsyncIterator,
|
SymbolAsyncIterator,
|
||||||
|
Error,
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
TypedArrayPrototypeSubarray,
|
TypedArrayPrototypeSubarray,
|
||||||
} = window.__bootstrap.primordials;
|
} = window.__bootstrap.primordials;
|
||||||
|
@ -188,6 +189,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UnixConn extends Conn {}
|
||||||
|
|
||||||
class Listener {
|
class Listener {
|
||||||
#rid = 0;
|
#rid = 0;
|
||||||
#addr = null;
|
#addr = null;
|
||||||
|
@ -209,8 +212,11 @@
|
||||||
const res = await opAccept(this.rid, this.addr.transport);
|
const res = await opAccept(this.rid, this.addr.transport);
|
||||||
if (this.addr.transport == "tcp") {
|
if (this.addr.transport == "tcp") {
|
||||||
return new TcpConn(res.rid, res.remoteAddr, res.localAddr);
|
return new TcpConn(res.rid, res.remoteAddr, res.localAddr);
|
||||||
|
} else if (this.addr.transport == "unix") {
|
||||||
|
return new UnixConn(res.rid, res.remoteAddr, res.localAddr);
|
||||||
|
} else {
|
||||||
|
throw new Error("unreachable");
|
||||||
}
|
}
|
||||||
return new Conn(res.rid, res.remoteAddr, res.localAddr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async next() {
|
async next() {
|
||||||
|
@ -311,18 +317,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function connect(options) {
|
async function connect(options) {
|
||||||
let res;
|
|
||||||
|
|
||||||
if (options.transport === "unix") {
|
if (options.transport === "unix") {
|
||||||
res = await opConnect(options);
|
const res = await opConnect(options);
|
||||||
} else {
|
return new UnixConn(res.rid, res.remoteAddr, res.localAddr);
|
||||||
res = await opConnect({
|
}
|
||||||
|
|
||||||
|
const res = await opConnect({
|
||||||
transport: "tcp",
|
transport: "tcp",
|
||||||
hostname: "127.0.0.1",
|
hostname: "127.0.0.1",
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return new TcpConn(res.rid, res.remoteAddr, res.localAddr);
|
return new TcpConn(res.rid, res.remoteAddr, res.localAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,6 +334,7 @@
|
||||||
connect,
|
connect,
|
||||||
Conn,
|
Conn,
|
||||||
TcpConn,
|
TcpConn,
|
||||||
|
UnixConn,
|
||||||
opConnect,
|
opConnect,
|
||||||
listen,
|
listen,
|
||||||
opListen,
|
opListen,
|
||||||
|
|
3
ext/net/lib.deno_net.d.ts
vendored
3
ext/net/lib.deno_net.d.ts
vendored
|
@ -160,6 +160,9 @@ declare namespace Deno {
|
||||||
setKeepAlive(keepalive?: boolean): void;
|
setKeepAlive(keepalive?: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deno-lint-ignore no-empty-interface
|
||||||
|
export interface UnixConn extends Conn {}
|
||||||
|
|
||||||
export interface ConnectTlsOptions {
|
export interface ConnectTlsOptions {
|
||||||
/** The port to connect to. */
|
/** The port to connect to. */
|
||||||
port: number;
|
port: number;
|
||||||
|
|
Loading…
Add table
Reference in a new issue