summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-01-13 01:17:31 +0100
committerGitHub <noreply@github.com>2021-01-12 16:17:31 -0800
commit8142496c571e7a5e42f2a2886fe005c27d96f616 (patch)
treea4e9a1d152f4738f4667995ddc735309be74deb2
parent8d5af6ca5264201be1cb04b0bb1a0b88ce5166da (diff)
feat: stabilize Deno.shutdown() and Conn#closeWrite()
Closes: #9099
-rw-r--r--cli/diagnostics.rs1
-rw-r--r--cli/dts/lib.deno.ns.d.ts18
-rw-r--r--cli/dts/lib.deno.unstable.d.ts26
-rw-r--r--runtime/js/30_net.js19
-rw-r--r--runtime/js/90_deno_ns.js1
-rw-r--r--runtime/ops/net.rs10
6 files changed, 16 insertions, 59 deletions
diff --git a/cli/diagnostics.rs b/cli/diagnostics.rs
index 648d18f35..4f1ae0c96 100644
--- a/cli/diagnostics.rs
+++ b/cli/diagnostics.rs
@@ -34,7 +34,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"PluginPermissionDescriptor",
"ReadPermissionDescriptor",
"RunPermissionDescriptor",
- "ShutdownMode",
"Signal",
"SignalStream",
"StartTlsOptions",
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index 736f99f0d..8026d934a 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -1711,11 +1711,7 @@ declare namespace Deno {
/** The resource ID of the connection. */
readonly rid: number;
/** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
- * callers should just use `close()`.
- *
- * **Unstable** because of lack of testing and because Deno.shutdown is also
- * unstable.
- * */
+ * callers should just use `close()`. */
closeWrite(): void;
}
@@ -1809,6 +1805,18 @@ declare namespace Deno {
*/
export function connectTls(options: ConnectTlsOptions): Promise<Conn>;
+ /** Shutdown socket send operations.
+ *
+ * Matches behavior of POSIX shutdown(3).
+ *
+ * ```ts
+ * const listener = Deno.listen({ port: 80 });
+ * const conn = await listener.accept();
+ * Deno.shutdown(conn.rid);
+ * ```
+ */
+ export function shutdown(rid: number): Promise<void>;
+
export interface Metrics {
opsDispatched: number;
opsDispatchedSync: number;
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index 0eaed73ba..1de7ed8cc 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -835,32 +835,6 @@ declare namespace Deno {
mtime: number | Date,
): Promise<void>;
- /** **UNSTABLE**: Under consideration to remove `ShutdownMode` entirely.
- *
- * Corresponds to `SHUT_RD`, `SHUT_WR`, `SHUT_RDWR` on POSIX-like systems.
- *
- * See: http://man7.org/linux/man-pages/man2/shutdown.2.html */
- export enum ShutdownMode {
- Read = 0,
- Write,
- ReadWrite, // TODO(ry) panics on ReadWrite.
- }
-
- /** **UNSTABLE**: Both the `how` parameter and `ShutdownMode` enum are under
- * consideration for removal.
- *
- * Shutdown socket send and receive operations.
- *
- * Matches behavior of POSIX shutdown(3).
- *
- * ```ts
- * const listener = Deno.listen({ port: 80 });
- * const conn = await listener.accept();
- * Deno.shutdown(conn.rid, Deno.ShutdownMode.Write);
- * ```
- */
- export function shutdown(rid: number, how: ShutdownMode): Promise<void>;
-
/** **UNSTABLE**: new API, yet to be vetted.
*
* A generic transport listener for message-oriented protocols. */
diff --git a/runtime/js/30_net.js b/runtime/js/30_net.js
index 1a5f5116d..db00f5a2b 100644
--- a/runtime/js/30_net.js
+++ b/runtime/js/30_net.js
@@ -5,19 +5,8 @@
const { errors } = window.__bootstrap.errors;
const { read, write } = window.__bootstrap.io;
- const ShutdownMode = {
- // See http://man7.org/linux/man-pages/man2/shutdown.2.html
- // Corresponding to SHUT_RD, SHUT_WR, SHUT_RDWR
- 0: "Read",
- 1: "Write",
- 2: "ReadWrite",
- Read: 0, // TODO: nonsense, remove me.
- Write: 1,
- ReadWrite: 2, // unused
- };
-
- function shutdown(rid, how) {
- return core.jsonOpAsync("op_shutdown", { rid, how });
+ function shutdown(rid) {
+ return core.jsonOpAsync("op_shutdown", { rid });
}
function opAccept(rid, transport) {
@@ -78,9 +67,8 @@
core.close(this.rid);
}
- // TODO(lucacasonato): make this unavailable in stable
closeWrite() {
- shutdown(this.rid, ShutdownMode.Write);
+ shutdown(this.rid);
}
}
@@ -221,7 +209,6 @@
opListen,
Listener,
shutdown,
- ShutdownMode,
Datagram,
};
})(this);
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index 7cc7b543b..c4205a1a9 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -111,7 +111,6 @@
applySourceMap: __bootstrap.errorStack.opApplySourceMap,
formatDiagnostics: __bootstrap.errorStack.opFormatDiagnostics,
shutdown: __bootstrap.net.shutdown,
- ShutdownMode: __bootstrap.net.ShutdownMode,
listen: __bootstrap.netUnstable.listen,
connect: __bootstrap.netUnstable.connect,
listenDatagram: __bootstrap.netUnstable.listenDatagram,
diff --git a/runtime/ops/net.rs b/runtime/ops/net.rs
index dea7ffe51..caf1ef0d3 100644
--- a/runtime/ops/net.rs
+++ b/runtime/ops/net.rs
@@ -24,7 +24,6 @@ use deno_core::ZeroCopyBuf;
use serde::Deserialize;
use std::borrow::Cow;
use std::cell::RefCell;
-use std::net::Shutdown;
use std::net::SocketAddr;
use std::rc::Rc;
use tokio::io::AsyncWriteExt;
@@ -331,7 +330,6 @@ async fn op_connect(
#[derive(Deserialize)]
struct ShutdownArgs {
rid: i32,
- how: i32,
}
async fn op_shutdown(
@@ -344,14 +342,6 @@ async fn op_shutdown(
let args: ShutdownArgs = serde_json::from_value(args)?;
let rid = args.rid as u32;
- let how = args.how;
-
- // TODO(bartlomieju): no longer needed after Tokio 1.0 upgrade
- let _shutdown_mode = match how {
- 0 => Shutdown::Read, // TODO: nonsense, remove me.
- 1 => Shutdown::Write,
- _ => unimplemented!(),
- };
let resource = state
.borrow()