1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

net: expose shutdown() and ShutdownMode (#3558)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2019-12-29 07:20:23 -08:00 committed by Ry Dahl
parent 4d4908dde3
commit 176d1ff12e
2 changed files with 19 additions and 3 deletions

View file

@ -77,7 +77,15 @@ export {
export { truncateSync, truncate } from "./truncate.ts";
export { FileInfo } from "./file_info.ts";
export { openPlugin } from "./plugins.ts";
export { connect, dial, listen, Listener, Conn } from "./net.ts";
export {
connect,
dial,
listen,
Listener,
Conn,
ShutdownMode,
shutdown
} from "./net.ts";
export { dialTLS, listenTLS } from "./tls.ts";
export { metrics, Metrics } from "./metrics.ts";
export { resources } from "./resources.ts";

View file

@ -32,7 +32,7 @@ export interface Listener extends AsyncIterator<Conn> {
[Symbol.asyncIterator](): AsyncIterator<Conn>;
}
enum ShutdownMode {
export enum ShutdownMode {
// See http://man7.org/linux/man-pages/man2/shutdown.2.html
// Corresponding to SHUT_RD, SHUT_WR, SHUT_RDWR
Read = 0,
@ -40,7 +40,15 @@ enum ShutdownMode {
ReadWrite // unused
}
function shutdown(rid: number, how: ShutdownMode): void {
/** Shut down socket send and receive operations.
*
* Matches behavior of POSIX shutdown(3).
*
* 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): void {
sendSync(dispatch.OP_SHUTDOWN, { rid, how });
}