From 4c34a2f2df595fa43b3eb06722c3ad742450d8bd Mon Sep 17 00:00:00 2001 From: Sam Gwilym Date: Mon, 20 Mar 2023 21:27:00 +0000 Subject: feat(ext/net): Add multicasting APIs to DatagramConn (#10706) (#17811) --- ext/net/01_net.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'ext/net/01_net.js') diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 8d8e34e56..81e13f094 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -277,6 +277,64 @@ class Datagram { return this.#addr; } + async joinMulticastV4(addr, multiInterface) { + await core.opAsync( + "op_net_join_multi_v4_udp", + this.rid, + addr, + multiInterface, + ); + + return { + leave: () => + core.opAsync( + "op_net_leave_multi_v4_udp", + this.rid, + addr, + multiInterface, + ), + setLoopback: (loopback) => + core.opAsync( + "op_net_set_multi_loopback_udp", + this.rid, + true, + loopback, + ), + setTTL: (ttl) => + core.opAsync( + "op_net_set_multi_ttl_udp", + this.rid, + ttl, + ), + }; + } + + async joinMulticastV6(addr, multiInterface) { + await core.opAsync( + "op_net_join_multi_v6_udp", + this.rid, + addr, + multiInterface, + ); + + return { + leave: () => + core.opAsync( + "op_net_leave_multi_v6_udp", + this.rid, + addr, + multiInterface, + ), + setLoopback: (loopback) => + core.opAsync( + "op_net_set_multi_loopback_udp", + this.rid, + false, + loopback, + ), + }; + } + async receive(p) { const buf = p || new Uint8Array(this.bufSize); let nread; @@ -383,6 +441,7 @@ function createListenDatagram(udpOpFn, unixOpFn) { port: args.port, }, args.reuseAddress ?? false, + args.loopback ?? false, ); addr.transport = "udp"; return new Datagram(rid, addr); -- cgit v1.2.3