summaryrefslogtreecommitdiff
path: root/cli/js/lib.deno.ns.d.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/lib.deno.ns.d.ts')
-rw-r--r--cli/js/lib.deno.ns.d.ts52
1 files changed, 48 insertions, 4 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index fda2270a8..1839c813a 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -1387,14 +1387,20 @@ declare namespace Deno {
*/
export function openPlugin(filename: string): Plugin;
- type Transport = "tcp";
+ export type Transport = "tcp" | "udp";
- interface Addr {
+ export interface Addr {
transport: Transport;
hostname: string;
port: number;
}
+ export interface UDPAddr {
+ transport?: Transport;
+ hostname?: string;
+ port: number;
+ }
+
/** UNSTABLE: Maybe remove ShutdownMode entirely. */
export enum ShutdownMode {
// See http://man7.org/linux/man-pages/man2/shutdown.2.html
@@ -1417,6 +1423,36 @@ declare namespace Deno {
*/
export function shutdown(rid: number, how: ShutdownMode): void;
+ /** UNSTABLE: new API
+ * Waits for the next message to the passed rid and writes it on the passed buffer.
+ * Returns the number of bytes written and the remote address.
+ */
+ export function recvfrom(rid: number, p: Uint8Array): Promise<[number, Addr]>;
+
+ /** UNSTABLE: new API
+ * A socket is a generic transport listener for message-oriented protocols
+ */
+ export interface UDPConn extends AsyncIterator<[Uint8Array, Addr]> {
+ /** UNSTABLE: new API
+ * Waits for and resolves to the next message to the `Socket`. */
+ receive(p?: Uint8Array): Promise<[Uint8Array, Addr]>;
+
+ /** UNSTABLE: new API
+ * Sends a message to the target. */
+ send(p: Uint8Array, addr: UDPAddr): Promise<void>;
+
+ /** UNSTABLE: new API
+ * Close closes the socket. Any pending message promises will be rejected
+ * with errors.
+ */
+ close(): void;
+
+ /** Return the address of the `Socket`. */
+ addr: Addr;
+
+ [Symbol.asyncIterator](): AsyncIterator<[Uint8Array, Addr]>;
+ }
+
/** A Listener is a generic network listener for stream-oriented protocols. */
export interface Listener extends AsyncIterator<Conn> {
/** Waits for and resolves to the next connection to the `Listener`. */
@@ -1457,7 +1493,9 @@ declare namespace Deno {
transport?: Transport;
}
- /** Listen announces on the local transport address.
+ /** UNSTABLE: new API
+ *
+ * Listen announces on the local transport address.
*
* Requires the allow-net permission.
*
@@ -1476,7 +1514,13 @@ declare namespace Deno {
* listen({ hostname: "[2001:db8::1]", port: 80 });
* listen({ hostname: "golang.org", port: 80, transport: "tcp" })
*/
- export function listen(options: ListenOptions): Listener;
+ export function listen(
+ options: ListenOptions & { transport?: "tcp" }
+ ): Listener;
+ export function listen(
+ options: ListenOptions & { transport: "udp" }
+ ): UDPConn;
+ export function listen(options: ListenOptions): Listener | UDPConn;
export interface ListenTLSOptions {
port: number;