mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
BREAKING: address renamed to path in UnixAddr UnixConnectOptions UnixListenOptions (#4959)
This commit is contained in:
parent
e0ca60e770
commit
47c2f034e9
6 changed files with 38 additions and 38 deletions
12
cli/js/lib.deno.ns.d.ts
vendored
12
cli/js/lib.deno.ns.d.ts
vendored
|
@ -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(
|
||||
|
|
|
@ -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<Conn>;
|
||||
export async function connect(options: ConnectOptions): Promise<Conn>;
|
||||
|
|
|
@ -9,7 +9,7 @@ export interface NetAddr {
|
|||
|
||||
export interface UnixAddr {
|
||||
transport: "unix" | "unixpacket";
|
||||
address: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export type Addr = NetAddr | UnixAddr;
|
||||
|
|
|
@ -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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> => {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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 });
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
})))
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}))
|
||||
|
|
Loading…
Reference in a new issue