diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-02-27 15:18:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-27 15:18:30 +0100 |
commit | 7e3d9084b69d12119b2ad6ef7ac2681e66e36aa0 (patch) | |
tree | 623cc4785c7fc18f91cf9a51763e5517a2aca640 /ext/net | |
parent | a65ce33fabb44bb2d9ed04773f7f334ed9c9a6b5 (diff) |
feat: Add Deno.TcpConn class, change return type from Deno.connect (#13714)
Diffstat (limited to 'ext/net')
-rw-r--r-- | ext/net/01_net.js | 24 | ||||
-rw-r--r-- | ext/net/lib.deno_net.d.ts | 17 |
2 files changed, 31 insertions, 10 deletions
diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 2970dd817..8c17942da 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -163,14 +163,6 @@ return shutdown(this.rid); } - setNoDelay(nodelay = true) { - return core.opSync("op_set_nodelay", this.rid, nodelay); - } - - setKeepAlive(keepalive = true) { - return core.opSync("op_set_keepalive", this.rid, keepalive); - } - get readable() { if (this.#readable === undefined) { this.#readable = readableStreamForRid(this.rid); @@ -186,6 +178,16 @@ } } + class TcpConn extends Conn { + setNoDelay(nodelay = true) { + return core.opSync("op_set_nodelay", this.rid, nodelay); + } + + setKeepAlive(keepalive = true) { + return core.opSync("op_set_keepalive", this.rid, keepalive); + } + } + class Listener { #rid = 0; #addr = null; @@ -205,6 +207,9 @@ async accept() { const res = await opAccept(this.rid, this.addr.transport); + if (this.addr.transport == "tcp") { + return new TcpConn(res.rid, res.remoteAddr, res.localAddr); + } return new Conn(res.rid, res.remoteAddr, res.localAddr); } @@ -318,12 +323,13 @@ }); } - return new Conn(res.rid, res.remoteAddr, res.localAddr); + return new TcpConn(res.rid, res.remoteAddr, res.localAddr); } window.__bootstrap.net = { connect, Conn, + TcpConn, opConnect, listen, opListen, diff --git a/ext/net/lib.deno_net.d.ts b/ext/net/lib.deno_net.d.ts index 038452055..ab779a1ff 100644 --- a/ext/net/lib.deno_net.d.ts +++ b/ext/net/lib.deno_net.d.ts @@ -143,7 +143,22 @@ declare namespace Deno { * ``` * * Requires `allow-net` permission for "tcp". */ - export function connect(options: ConnectOptions): Promise<Conn>; + export function connect(options: ConnectOptions): Promise<TcpConn>; + + export interface TcpConn extends Conn { + /** + * **UNSTABLE**: new API, see https://github.com/denoland/deno/issues/13617. + * + * Enable/disable the use of Nagle's algorithm. Defaults to true. + */ + setNoDelay(nodelay?: boolean): void; + /** + * **UNSTABLE**: new API, see https://github.com/denoland/deno/issues/13617. + * + * Enable/disable keep-alive functionality. + */ + setKeepAlive(keepalive?: boolean): void; + } export interface ConnectTlsOptions { /** The port to connect to. */ |