mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
parent
fe9cee620a
commit
9c7c9a35c1
3 changed files with 23 additions and 12 deletions
10
cli/dts/lib.deno.ns.d.ts
vendored
10
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -1726,19 +1726,21 @@ declare namespace Deno {
|
||||||
* Requires `allow-write` permission. */
|
* Requires `allow-write` permission. */
|
||||||
export function truncate(name: string, len?: number): Promise<void>;
|
export function truncate(name: string, len?: number): Promise<void>;
|
||||||
|
|
||||||
export interface NetAddr {
|
export interface Addr {
|
||||||
|
transport: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NetAddr extends Addr {
|
||||||
transport: "tcp" | "udp";
|
transport: "tcp" | "udp";
|
||||||
hostname: string;
|
hostname: string;
|
||||||
port: number;
|
port: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnixAddr {
|
export interface UnixAddr extends Addr {
|
||||||
transport: "unix" | "unixpacket";
|
transport: "unix" | "unixpacket";
|
||||||
path: string;
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Addr = NetAddr | UnixAddr;
|
|
||||||
|
|
||||||
/** A generic network listener for stream-oriented protocols. */
|
/** A generic network listener for stream-oriented protocols. */
|
||||||
export interface Listener<Address extends Addr = Addr>
|
export interface Listener<Address extends Addr = Addr>
|
||||||
extends AsyncIterable<Conn<Address>> {
|
extends AsyncIterable<Conn<Address>> {
|
||||||
|
|
19
cli/dts/lib.deno.unstable.d.ts
vendored
19
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -874,23 +874,26 @@ declare namespace Deno {
|
||||||
/** **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. */
|
||||||
export interface DatagramConn extends AsyncIterable<[Uint8Array, Addr]> {
|
export interface DatagramConn<Address extends Addr = Addr>
|
||||||
|
extends AsyncIterable<[Uint8Array, Address]> {
|
||||||
/** **UNSTABLE**: new API, yet to be vetted.
|
/** **UNSTABLE**: new API, yet to be vetted.
|
||||||
*
|
*
|
||||||
* Waits for and resolves to the next message to the `UDPConn`. */
|
* Waits for and resolves to the next message to the `UDPConn`. */
|
||||||
receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>;
|
receive(p?: Uint8Array): Promise<[Uint8Array, Address]>;
|
||||||
/** UNSTABLE: new API, yet to be vetted.
|
/** UNSTABLE: new API, yet to be vetted.
|
||||||
*
|
*
|
||||||
* Sends a message to the target. */
|
* Sends a message to the target. */
|
||||||
send(p: Uint8Array, addr: Addr): Promise<number>;
|
send(p: Uint8Array, addr: Address): Promise<number>;
|
||||||
/** UNSTABLE: new API, yet to be vetted.
|
/** UNSTABLE: new API, yet to be vetted.
|
||||||
*
|
*
|
||||||
* Close closes the socket. Any pending message promises will be rejected
|
* Close closes the socket. Any pending message promises will be rejected
|
||||||
* with errors. */
|
* with errors. */
|
||||||
close(): void;
|
close(): void;
|
||||||
/** Return the address of the `UDPConn`. */
|
/** Return the address of the `UDPConn`. */
|
||||||
readonly addr: Addr;
|
readonly addr: Address;
|
||||||
[Symbol.asyncIterator](): AsyncIterableIterator<[Uint8Array, Addr]>;
|
[Symbol.asyncIterator](): AsyncIterableIterator<
|
||||||
|
[Uint8Array, Address]
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnixListenOptions {
|
export interface UnixListenOptions {
|
||||||
|
@ -930,7 +933,7 @@ declare namespace Deno {
|
||||||
* Requires `allow-net` permission. */
|
* Requires `allow-net` permission. */
|
||||||
export function listenDatagram(
|
export function listenDatagram(
|
||||||
options: ListenOptions & { transport: "udp" },
|
options: ListenOptions & { transport: "udp" },
|
||||||
): DatagramConn;
|
): DatagramConn<NetAddr>;
|
||||||
|
|
||||||
/** **UNSTABLE**: new API, yet to be vetted
|
/** **UNSTABLE**: new API, yet to be vetted
|
||||||
*
|
*
|
||||||
|
@ -946,7 +949,7 @@ declare namespace Deno {
|
||||||
* Requires `allow-read` and `allow-write` permission. */
|
* Requires `allow-read` and `allow-write` permission. */
|
||||||
export function listenDatagram(
|
export function listenDatagram(
|
||||||
options: UnixListenOptions & { transport: "unixpacket" },
|
options: UnixListenOptions & { transport: "unixpacket" },
|
||||||
): DatagramConn;
|
): DatagramConn<UnixAddr>;
|
||||||
|
|
||||||
export interface UnixConnectOptions {
|
export interface UnixConnectOptions {
|
||||||
transport: "unix";
|
transport: "unix";
|
||||||
|
@ -1000,7 +1003,7 @@ declare namespace Deno {
|
||||||
* Requires `allow-net` permission.
|
* Requires `allow-net` permission.
|
||||||
*/
|
*/
|
||||||
export function startTls(
|
export function startTls(
|
||||||
conn: Conn<NetAddr>,
|
conn: Conn,
|
||||||
options?: StartTlsOptions,
|
options?: StartTlsOptions,
|
||||||
): Promise<Conn<NetAddr>>;
|
): Promise<Conn<NetAddr>>;
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,12 @@
|
||||||
conn,
|
conn,
|
||||||
{ hostname = "127.0.0.1", certFile } = {},
|
{ hostname = "127.0.0.1", certFile } = {},
|
||||||
) {
|
) {
|
||||||
|
if (
|
||||||
|
!(conn.localAddr.transport === "tcp" ||
|
||||||
|
conn.localAddr.transport === "udp")
|
||||||
|
) {
|
||||||
|
throw new TypeError(`conn is not a valid network connection`);
|
||||||
|
}
|
||||||
const res = await opStartTls({
|
const res = await opStartTls({
|
||||||
rid: conn.rid,
|
rid: conn.rid,
|
||||||
hostname,
|
hostname,
|
||||||
|
|
Loading…
Add table
Reference in a new issue