summaryrefslogtreecommitdiff
path: root/ext/net
diff options
context:
space:
mode:
Diffstat (limited to 'ext/net')
-rw-r--r--ext/net/01_net.js24
-rw-r--r--ext/net/lib.deno_net.d.ts17
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. */