summaryrefslogtreecommitdiff
path: root/ext/net/01_net.js
diff options
context:
space:
mode:
authorSam Gwilym <sam@gwil.garden>2023-03-20 21:27:00 +0000
committerGitHub <noreply@github.com>2023-03-20 22:27:00 +0100
commit4c34a2f2df595fa43b3eb06722c3ad742450d8bd (patch)
tree8eb320918a6f71b631db0f8d58d5aa8e917146f1 /ext/net/01_net.js
parentcd53ab5427811bddbed1c30d3733e1df87bb23f9 (diff)
feat(ext/net): Add multicasting APIs to DatagramConn (#10706) (#17811)
Diffstat (limited to 'ext/net/01_net.js')
-rw-r--r--ext/net/01_net.js59
1 files changed, 59 insertions, 0 deletions
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);