diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-03-04 20:33:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-04 20:33:13 +0100 |
commit | 060dabee4c0411015f60867f3efd933c25a19a2c (patch) | |
tree | 2abe3fc5209f46b7a9ebeeedcfa95b9bccad889a /ext/net | |
parent | d1db500cdaab0864a8b118dec89738e858ce0724 (diff) |
feat(net): add Deno.UnixConn interface (#13787)
Diffstat (limited to 'ext/net')
-rw-r--r-- | ext/net/01_net.js | 25 | ||||
-rw-r--r-- | ext/net/lib.deno_net.d.ts | 3 |
2 files changed, 18 insertions, 10 deletions
diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 8c17942da..803205319 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -9,6 +9,7 @@ ObjectPrototypeIsPrototypeOf, PromiseResolve, SymbolAsyncIterator, + Error, Uint8Array, TypedArrayPrototypeSubarray, } = window.__bootstrap.primordials; @@ -188,6 +189,8 @@ } } + class UnixConn extends Conn {} + class Listener { #rid = 0; #addr = null; @@ -209,8 +212,11 @@ const res = await opAccept(this.rid, this.addr.transport); if (this.addr.transport == "tcp") { 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() { @@ -311,18 +317,16 @@ } async function connect(options) { - let res; - if (options.transport === "unix") { - res = await opConnect(options); - } else { - res = await opConnect({ - transport: "tcp", - hostname: "127.0.0.1", - ...options, - }); + const res = await opConnect(options); + return new UnixConn(res.rid, res.remoteAddr, res.localAddr); } + const res = await opConnect({ + transport: "tcp", + hostname: "127.0.0.1", + ...options, + }); return new TcpConn(res.rid, res.remoteAddr, res.localAddr); } @@ -330,6 +334,7 @@ connect, Conn, TcpConn, + UnixConn, opConnect, listen, opListen, diff --git a/ext/net/lib.deno_net.d.ts b/ext/net/lib.deno_net.d.ts index ab779a1ff..bb031f60d 100644 --- a/ext/net/lib.deno_net.d.ts +++ b/ext/net/lib.deno_net.d.ts @@ -160,6 +160,9 @@ declare namespace Deno { setKeepAlive(keepalive?: boolean): void; } + // deno-lint-ignore no-empty-interface + export interface UnixConn extends Conn {} + export interface ConnectTlsOptions { /** The port to connect to. */ port: number; |