mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat: deprecate Deno.{Conn,TcpConn,TlsConn,UnixConn}.rid
(#22077)
For removal in Deno v2. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
176118a046
commit
fc176c4dea
4 changed files with 96 additions and 17 deletions
|
@ -1,10 +1,10 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
itest!(workers {
|
itest!(workers {
|
||||||
args: "test --reload --location http://127.0.0.1:4545/ -A --unstable workers/test.ts",
|
args: "test --reload --location http://127.0.0.1:4545/ -A --unstable-worker-options workers/test.ts",
|
||||||
output: "workers/test.ts.out",
|
output: "workers/test.ts.out",
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(worker_error {
|
itest!(worker_error {
|
||||||
args: "run -A workers/worker_error.ts",
|
args: "run -A workers/worker_error.ts",
|
||||||
|
|
|
@ -106,6 +106,11 @@ class Conn {
|
||||||
}
|
}
|
||||||
|
|
||||||
get rid() {
|
get rid() {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.Conn.rid",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `Deno.Conn` instance methods instead.",
|
||||||
|
);
|
||||||
return this.#rid;
|
return this.#rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,14 +123,14 @@ class Conn {
|
||||||
}
|
}
|
||||||
|
|
||||||
write(p) {
|
write(p) {
|
||||||
return write(this.rid, p);
|
return write(this.#rid, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
async read(buffer) {
|
async read(buffer) {
|
||||||
if (buffer.length === 0) {
|
if (buffer.length === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const promise = core.read(this.rid, buffer);
|
const promise = core.read(this.#rid, buffer);
|
||||||
if (this.#unref) core.unrefOpPromise(promise);
|
if (this.#unref) core.unrefOpPromise(promise);
|
||||||
SetPrototypeAdd(this.#pendingReadPromises, promise);
|
SetPrototypeAdd(this.#pendingReadPromises, promise);
|
||||||
let nread;
|
let nread;
|
||||||
|
@ -140,16 +145,16 @@ class Conn {
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
core.close(this.rid);
|
core.close(this.#rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeWrite() {
|
closeWrite() {
|
||||||
return shutdown(this.rid);
|
return shutdown(this.#rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
get readable() {
|
get readable() {
|
||||||
if (this.#readable === undefined) {
|
if (this.#readable === undefined) {
|
||||||
this.#readable = readableStreamForRidUnrefable(this.rid);
|
this.#readable = readableStreamForRidUnrefable(this.#rid);
|
||||||
if (this.#unref) {
|
if (this.#unref) {
|
||||||
readableStreamForRidUnrefableUnref(this.#readable);
|
readableStreamForRidUnrefableUnref(this.#readable);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +164,7 @@ class Conn {
|
||||||
|
|
||||||
get writable() {
|
get writable() {
|
||||||
if (this.#writable === undefined) {
|
if (this.#writable === undefined) {
|
||||||
this.#writable = writableStreamForRid(this.rid);
|
this.#writable = writableStreamForRid(this.#rid);
|
||||||
}
|
}
|
||||||
return this.#writable;
|
return this.#writable;
|
||||||
}
|
}
|
||||||
|
@ -193,16 +198,48 @@ class Conn {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TcpConn extends Conn {
|
class TcpConn extends Conn {
|
||||||
|
#rid = 0;
|
||||||
|
|
||||||
|
constructor(rid, remoteAddr, localAddr) {
|
||||||
|
super(rid, remoteAddr, localAddr);
|
||||||
|
this.#rid = rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
get rid() {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.TcpConn.rid",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `Deno.TcpConn` instance methods instead.",
|
||||||
|
);
|
||||||
|
return this.#rid;
|
||||||
|
}
|
||||||
|
|
||||||
setNoDelay(noDelay = true) {
|
setNoDelay(noDelay = true) {
|
||||||
return op_set_nodelay(this.rid, noDelay);
|
return op_set_nodelay(this.#rid, noDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
setKeepAlive(keepAlive = true) {
|
setKeepAlive(keepAlive = true) {
|
||||||
return op_set_keepalive(this.rid, keepAlive);
|
return op_set_keepalive(this.#rid, keepAlive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnixConn extends Conn {}
|
class UnixConn extends Conn {
|
||||||
|
#rid = 0;
|
||||||
|
|
||||||
|
constructor(rid, remoteAddr, localAddr) {
|
||||||
|
super(rid, remoteAddr, localAddr);
|
||||||
|
this.#rid = rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
get rid() {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.UnixConn.rid",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `Deno.UnixConn` instance methods instead.",
|
||||||
|
);
|
||||||
|
return this.#rid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Listener {
|
class Listener {
|
||||||
#rid = 0;
|
#rid = 0;
|
||||||
|
|
|
@ -24,8 +24,24 @@ function opTlsHandshake(rid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TlsConn extends Conn {
|
class TlsConn extends Conn {
|
||||||
|
#rid = 0;
|
||||||
|
|
||||||
|
constructor(rid, remoteAddr, localAddr) {
|
||||||
|
super(rid, remoteAddr, localAddr);
|
||||||
|
this.#rid = rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
get rid() {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.TlsConn.rid",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `Deno.TlsConn` instance methods instead.",
|
||||||
|
);
|
||||||
|
return this.#rid;
|
||||||
|
}
|
||||||
|
|
||||||
handshake() {
|
handshake() {
|
||||||
return opTlsHandshake(this.rid);
|
return opTlsHandshake(this.#rid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
32
ext/net/lib.deno_net.d.ts
vendored
32
ext/net/lib.deno_net.d.ts
vendored
|
@ -69,7 +69,12 @@ declare namespace Deno {
|
||||||
readonly localAddr: Addr;
|
readonly localAddr: Addr;
|
||||||
/** The remote address of the connection. */
|
/** The remote address of the connection. */
|
||||||
readonly remoteAddr: Addr;
|
readonly remoteAddr: Addr;
|
||||||
/** The resource ID of the connection. */
|
/**
|
||||||
|
* The resource ID of the connection.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@linkcode Deno.Conn} instance methods instead.
|
||||||
|
* {@linkcode Deno.Conn.rid} will be removed in Deno 2.0.
|
||||||
|
*/
|
||||||
readonly rid: number;
|
readonly rid: number;
|
||||||
/** Shuts down (`shutdown(2)`) the write side of the connection. Most
|
/** Shuts down (`shutdown(2)`) the write side of the connection. Most
|
||||||
* callers should just use `close()`. */
|
* callers should just use `close()`. */
|
||||||
|
@ -103,6 +108,13 @@ declare namespace Deno {
|
||||||
* not happened yet. Calling this method is optional; the TLS handshake
|
* not happened yet. Calling this method is optional; the TLS handshake
|
||||||
* will be completed automatically as soon as data is sent or received. */
|
* will be completed automatically as soon as data is sent or received. */
|
||||||
handshake(): Promise<TlsHandshakeInfo>;
|
handshake(): Promise<TlsHandshakeInfo>;
|
||||||
|
/**
|
||||||
|
* The resource ID of the connection.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@linkcode Deno.TlsConn} instance methods instead.
|
||||||
|
* {@linkcode Deno.TlsConn.rid} will be removed in Deno 2.0.
|
||||||
|
*/
|
||||||
|
readonly rid: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @category Network */
|
/** @category Network */
|
||||||
|
@ -260,6 +272,13 @@ declare namespace Deno {
|
||||||
setNoDelay(noDelay?: boolean): void;
|
setNoDelay(noDelay?: boolean): void;
|
||||||
/** Enable/disable keep-alive functionality. */
|
/** Enable/disable keep-alive functionality. */
|
||||||
setKeepAlive(keepAlive?: boolean): void;
|
setKeepAlive(keepAlive?: boolean): void;
|
||||||
|
/**
|
||||||
|
* The resource ID of the connection.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@linkcode Deno.Conn} instance methods instead.
|
||||||
|
* {@linkcode Deno.Conn.rid} will be removed in Deno 2.0.
|
||||||
|
*/
|
||||||
|
readonly rid: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @category Network */
|
/** @category Network */
|
||||||
|
@ -269,8 +288,15 @@ declare namespace Deno {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @category Network */
|
/** @category Network */
|
||||||
// deno-lint-ignore no-empty-interface
|
export interface UnixConn extends Conn {
|
||||||
export interface UnixConn extends Conn {}
|
/**
|
||||||
|
* The resource ID of the connection.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@linkcode Deno.UnixConn} instance methods instead.
|
||||||
|
* {@linkcode Deno.UnixConn.rid} will be removed in Deno 2.0.
|
||||||
|
*/
|
||||||
|
readonly rid: number;
|
||||||
|
}
|
||||||
|
|
||||||
/** Connects to the hostname (default is "127.0.0.1") and port on the named
|
/** Connects to the hostname (default is "127.0.0.1") and port on the named
|
||||||
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
* transport (default is "tcp"), and resolves to the connection (`Conn`).
|
||||||
|
|
Loading…
Add table
Reference in a new issue