1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

feat: stabilize Deno.shutdown() and Conn#closeWrite()

Closes: #9099
This commit is contained in:
Bartek Iwańczuk 2021-01-13 01:17:31 +01:00 committed by GitHub
parent 8d5af6ca52
commit 8142496c57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 59 deletions

View file

@ -34,7 +34,6 @@ const UNSTABLE_DENO_PROPS: &[&str] = &[
"PluginPermissionDescriptor", "PluginPermissionDescriptor",
"ReadPermissionDescriptor", "ReadPermissionDescriptor",
"RunPermissionDescriptor", "RunPermissionDescriptor",
"ShutdownMode",
"Signal", "Signal",
"SignalStream", "SignalStream",
"StartTlsOptions", "StartTlsOptions",

View file

@ -1711,11 +1711,7 @@ declare namespace Deno {
/** The resource ID of the connection. */ /** The resource ID of the connection. */
readonly rid: number; readonly rid: number;
/** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most /** Shuts down (`shutdown(2)`) the writing side of the TCP connection. Most
* callers should just use `close()`. * callers should just use `close()`. */
*
* **Unstable** because of lack of testing and because Deno.shutdown is also
* unstable.
* */
closeWrite(): void; closeWrite(): void;
} }
@ -1809,6 +1805,18 @@ declare namespace Deno {
*/ */
export function connectTls(options: ConnectTlsOptions): Promise<Conn>; 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 { export interface Metrics {
opsDispatched: number; opsDispatched: number;
opsDispatchedSync: number; opsDispatchedSync: number;

View file

@ -835,32 +835,6 @@ declare namespace Deno {
mtime: number | Date, mtime: number | Date,
): Promise<void>; ): 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. /** **UNSTABLE**: new API, yet to be vetted.
* *
* A generic transport listener for message-oriented protocols. */ * A generic transport listener for message-oriented protocols. */

View file

@ -5,19 +5,8 @@
const { errors } = window.__bootstrap.errors; const { errors } = window.__bootstrap.errors;
const { read, write } = window.__bootstrap.io; const { read, write } = window.__bootstrap.io;
const ShutdownMode = { function shutdown(rid) {
// See http://man7.org/linux/man-pages/man2/shutdown.2.html return core.jsonOpAsync("op_shutdown", { rid });
// 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 opAccept(rid, transport) { function opAccept(rid, transport) {
@ -78,9 +67,8 @@
core.close(this.rid); core.close(this.rid);
} }
// TODO(lucacasonato): make this unavailable in stable
closeWrite() { closeWrite() {
shutdown(this.rid, ShutdownMode.Write); shutdown(this.rid);
} }
} }
@ -221,7 +209,6 @@
opListen, opListen,
Listener, Listener,
shutdown, shutdown,
ShutdownMode,
Datagram, Datagram,
}; };
})(this); })(this);

View file

@ -111,7 +111,6 @@
applySourceMap: __bootstrap.errorStack.opApplySourceMap, applySourceMap: __bootstrap.errorStack.opApplySourceMap,
formatDiagnostics: __bootstrap.errorStack.opFormatDiagnostics, formatDiagnostics: __bootstrap.errorStack.opFormatDiagnostics,
shutdown: __bootstrap.net.shutdown, shutdown: __bootstrap.net.shutdown,
ShutdownMode: __bootstrap.net.ShutdownMode,
listen: __bootstrap.netUnstable.listen, listen: __bootstrap.netUnstable.listen,
connect: __bootstrap.netUnstable.connect, connect: __bootstrap.netUnstable.connect,
listenDatagram: __bootstrap.netUnstable.listenDatagram, listenDatagram: __bootstrap.netUnstable.listenDatagram,

View file

@ -24,7 +24,6 @@ use deno_core::ZeroCopyBuf;
use serde::Deserialize; use serde::Deserialize;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
use std::net::Shutdown;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::rc::Rc; use std::rc::Rc;
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
@ -331,7 +330,6 @@ async fn op_connect(
#[derive(Deserialize)] #[derive(Deserialize)]
struct ShutdownArgs { struct ShutdownArgs {
rid: i32, rid: i32,
how: i32,
} }
async fn op_shutdown( async fn op_shutdown(
@ -344,14 +342,6 @@ async fn op_shutdown(
let args: ShutdownArgs = serde_json::from_value(args)?; let args: ShutdownArgs = serde_json::from_value(args)?;
let rid = args.rid as u32; 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 let resource = state
.borrow() .borrow()