From 47c2f034e95696a47770d60aec1362501e7f330d Mon Sep 17 00:00:00 2001 From: Ali Hasani Date: Tue, 28 Apr 2020 21:07:59 +0430 Subject: [PATCH] BREAKING: address renamed to path in UnixAddr UnixConnectOptions UnixListenOptions (#4959) --- cli/js/lib.deno.ns.d.ts | 12 ++++++------ cli/js/net.ts | 4 ++-- cli/js/ops/net.ts | 2 +- cli/js/tests/net_test.ts | 34 +++++++++++++++++----------------- cli/ops/net.rs | 16 ++++++++-------- cli/ops/net_unix.rs | 8 ++++---- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 0c6f8ab187..4626f6214b 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -1829,7 +1829,7 @@ declare namespace Deno { export interface UnixAddr { transport: "unix" | "unixpacket"; - address: string; + path: string; } export type Addr = NetAddr | UnixAddr; @@ -1917,7 +1917,7 @@ declare namespace Deno { export interface UnixListenOptions { /** A Path to the Unix Socket. */ - address: string; + path: string; } /** **UNSTABLE**: new API, yet to be vetted. * @@ -1936,7 +1936,7 @@ declare namespace Deno { * * Listen announces on the local transport address. * - * const listener = Deno.listen({ address: "/foo/bar.sock", transport: "unix" }) + * const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unix" }) * * Requires `allow-read` and `allow-write` permission. */ export function listen( @@ -1957,7 +1957,7 @@ declare namespace Deno { * * Listen announces on the local transport address. * - * const listener = Deno.listen({ address: "/foo/bar.sock", transport: "unixpacket" }) + * const listener = Deno.listen({ path: "/foo/bar.sock", transport: "unixpacket" }) * * Requires `allow-read` and `allow-write` permission. */ export function listen( @@ -1992,7 +1992,7 @@ declare namespace Deno { export interface UnixConnectOptions { transport: "unix"; - address: string; + path: string; } /** @@ -2003,7 +2003,7 @@ declare namespace Deno { * const conn2 = await Deno.connect({ hostname: "192.0.2.1", port: 80 }); * const conn3 = await Deno.connect({ hostname: "[2001:db8::1]", port: 80 }); * const conn4 = await Deno.connect({ hostname: "golang.org", port: 80, transport: "tcp" }); - * const conn5 = await Deno.connect({ address: "/foo/bar.sock", transport: "unix" }); + * const conn5 = await Deno.connect({ path: "/foo/bar.sock", transport: "unix" }); * * Requires `allow-net` permission for "tcp" and `allow-read` for unix. */ export function connect( diff --git a/cli/js/net.ts b/cli/js/net.ts index 92fdfe3aca..6f6736ee22 100644 --- a/cli/js/net.ts +++ b/cli/js/net.ts @@ -142,7 +142,7 @@ export interface ListenOptions { export interface UnixListenOptions { transport: "unix" | "unixpacket"; - address: string; + path: string; } export function listen( @@ -190,7 +190,7 @@ export interface ConnectOptions { } export interface UnixConnectOptions { transport: "unix"; - address: string; + path: string; } export async function connect(options: UnixConnectOptions): Promise; export async function connect(options: ConnectOptions): Promise; diff --git a/cli/js/ops/net.ts b/cli/js/ops/net.ts index d04c7ba8ff..f2d272fe9b 100644 --- a/cli/js/ops/net.ts +++ b/cli/js/ops/net.ts @@ -9,7 +9,7 @@ export interface NetAddr { export interface UnixAddr { transport: "unix" | "unixpacket"; - address: string; + path: string; } export type Addr = NetAddr | UnixAddr; diff --git a/cli/js/tests/net_test.ts b/cli/js/tests/net_test.ts index c8c9a893a2..8840730a8b 100644 --- a/cli/js/tests/net_test.ts +++ b/cli/js/tests/net_test.ts @@ -38,11 +38,11 @@ unitTest( function netUnixListenClose(): void { const filePath = Deno.makeTempFileSync(); const socket = Deno.listen({ - address: filePath, + path: filePath, transport: "unix", }); assert(socket.addr.transport === "unix"); - assertEquals(socket.addr.address, filePath); + assertEquals(socket.addr.path, filePath); socket.close(); } ); @@ -52,11 +52,11 @@ unitTest( function netUnixPacketListenClose(): void { const filePath = Deno.makeTempFileSync(); const socket = Deno.listen({ - address: filePath, + path: filePath, transport: "unixpacket", }); assert(socket.addr.transport === "unixpacket"); - assertEquals(socket.addr.address, filePath); + assertEquals(socket.addr.path, filePath); socket.close(); } ); @@ -86,7 +86,7 @@ unitTest( async function netUnixCloseWhileAccept(): Promise { const filePath = await Deno.makeTempFile(); const listener = Deno.listen({ - address: filePath, + path: filePath, transport: "unix", }); const p = listener.accept(); @@ -131,7 +131,7 @@ unitTest( { ignore: true, perms: { read: true, write: true } }, async function netUnixConcurrentAccept(): Promise { const filePath = await Deno.makeTempFile(); - const listener = Deno.listen({ transport: "unix", address: filePath }); + const listener = Deno.listen({ transport: "unix", path: filePath }); let acceptErrCount = 0; const checkErr = (e: Error): void => { if (e.message === "Listener has been closed") { @@ -192,19 +192,19 @@ unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, async function netUnixDialListen(): Promise { const filePath = await Deno.makeTempFile(); - const listener = Deno.listen({ address: filePath, transport: "unix" }); + const listener = Deno.listen({ path: filePath, transport: "unix" }); listener.accept().then( async (conn): Promise => { assert(conn.remoteAddr != null); assert(conn.localAddr.transport === "unix"); - assertEquals(conn.localAddr.address, filePath); + assertEquals(conn.localAddr.path, filePath); await conn.write(new Uint8Array([1, 2, 3])); conn.close(); } ); - const conn = await Deno.connect({ address: filePath, transport: "unix" }); + const conn = await Deno.connect({ path: filePath, transport: "unix" }); assert(conn.remoteAddr.transport === "unix"); - assertEquals(conn.remoteAddr.address, filePath); + assertEquals(conn.remoteAddr.path, filePath); assert(conn.remoteAddr != null); const buf = new Uint8Array(1024); const readResult = await conn.read(buf); @@ -256,20 +256,20 @@ unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, async function netUnixPacketSendReceive(): Promise { const filePath = await Deno.makeTempFile(); - const alice = Deno.listen({ address: filePath, transport: "unixpacket" }); + const alice = Deno.listen({ path: filePath, transport: "unixpacket" }); assert(alice.addr.transport === "unixpacket"); - assertEquals(alice.addr.address, filePath); + assertEquals(alice.addr.path, filePath); - const bob = Deno.listen({ address: filePath, transport: "unixpacket" }); + const bob = Deno.listen({ path: filePath, transport: "unixpacket" }); assert(bob.addr.transport === "unixpacket"); - assertEquals(bob.addr.address, filePath); + assertEquals(bob.addr.path, filePath); const sent = new Uint8Array([1, 2, 3]); await alice.send(sent, bob.addr); const [recvd, remote] = await bob.receive(); assert(remote.transport === "unixpacket"); - assertEquals(remote.address, filePath); + assertEquals(remote.path, filePath); assertEquals(recvd.length, 3); assertEquals(1, recvd[0]); assertEquals(2, recvd[1]); @@ -309,7 +309,7 @@ unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, async function netUnixListenCloseWhileIterating(): Promise { const filePath = Deno.makeTempFileSync(); - const socket = Deno.listen({ address: filePath, transport: "unix" }); + const socket = Deno.listen({ path: filePath, transport: "unix" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); socket.close(); assertEquals(await nextWhileClosing, { value: undefined, done: true }); @@ -323,7 +323,7 @@ unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, async function netUnixPacketListenCloseWhileIterating(): Promise { const filePath = Deno.makeTempFileSync(); - const socket = Deno.listen({ address: filePath, transport: "unixpacket" }); + const socket = Deno.listen({ path: filePath, transport: "unixpacket" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); socket.close(); assertEquals(await nextWhileClosing, { value: undefined, done: true }); diff --git a/cli/ops/net.rs b/cli/ops/net.rs index b46eedc682..123c61f354 100644 --- a/cli/ops/net.rs +++ b/cli/ops/net.rs @@ -224,7 +224,7 @@ fn op_send( transport, transport_args: ArgsEnum::Unix(args), } if transport == "unixpacket" => { - let address_path = net_unix::Path::new(&args.address); + let address_path = net_unix::Path::new(&args.path); state.check_read(&address_path)?; let op = async move { let mut resource_table = resource_table.borrow_mut(); @@ -301,12 +301,12 @@ fn op_connect( transport, transport_args: ArgsEnum::Unix(args), } if transport == "unix" => { - let address_path = net_unix::Path::new(&args.address); + let address_path = net_unix::Path::new(&args.path); state.check_read(&address_path)?; let op = async move { - let address = args.address; + let path = args.path; let unix_stream = - net_unix::UnixStream::connect(net_unix::Path::new(&address)).await?; + net_unix::UnixStream::connect(net_unix::Path::new(&path)).await?; let local_addr = unix_stream.local_addr()?; let remote_addr = unix_stream.peer_addr()?; let mut resource_table = resource_table.borrow_mut(); @@ -319,11 +319,11 @@ fn op_connect( Ok(json!({ "rid": rid, "localAddr": { - "address": local_addr.as_pathname(), + "path": local_addr.as_pathname(), "transport": transport, }, "remoteAddr": { - "address": remote_addr.as_pathname(), + "path": remote_addr.as_pathname(), "transport": transport, } })) @@ -521,7 +521,7 @@ fn op_listen( transport, transport_args: ArgsEnum::Unix(args), } if transport == "unix" || transport == "unixpacket" => { - let address_path = net_unix::Path::new(&args.address); + let address_path = net_unix::Path::new(&args.path); state.check_read(&address_path)?; state.check_write(&address_path)?; let (rid, local_addr) = if transport == "unix" { @@ -537,7 +537,7 @@ fn op_listen( Ok(JsonOp::Sync(json!({ "rid": rid, "localAddr": { - "address": local_addr.as_pathname(), + "path": local_addr.as_pathname(), "transport": transport, }, }))) diff --git a/cli/ops/net_unix.rs b/cli/ops/net_unix.rs index 28b895b2c0..4b09c2fdb2 100644 --- a/cli/ops/net_unix.rs +++ b/cli/ops/net_unix.rs @@ -23,7 +23,7 @@ pub struct UnixDatagramResource { #[derive(Deserialize)] pub struct UnixListenArgs { - pub address: String, + pub path: String, } pub fn accept_unix( @@ -64,11 +64,11 @@ pub fn accept_unix( Ok(json!({ "rid": rid, "localAddr": { - "address": local_addr.as_pathname(), + "path": local_addr.as_pathname(), "transport": "unix", }, "remoteAddr": { - "address": remote_addr.as_pathname(), + "path": remote_addr.as_pathname(), "transport": "unix", } })) @@ -96,7 +96,7 @@ pub fn receive_unix_packet( Ok(json!({ "size": size, "remoteAddr": { - "address": remote_addr.as_pathname(), + "path": remote_addr.as_pathname(), "transport": "unixpacket", } }))