mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
fix(ext/node): implement dgram setBroadcast (#29195)
This commit is contained in:
parent
d67da9d4e7
commit
802826e54e
7 changed files with 71 additions and 4 deletions
|
@ -27,6 +27,7 @@ import {
|
||||||
op_net_recv_unixpacket,
|
op_net_recv_unixpacket,
|
||||||
op_net_send_udp,
|
op_net_send_udp,
|
||||||
op_net_send_unixpacket,
|
op_net_send_unixpacket,
|
||||||
|
op_net_set_broadcast_udp,
|
||||||
op_net_set_multi_loopback_udp,
|
op_net_set_multi_loopback_udp,
|
||||||
op_net_set_multi_ttl_udp,
|
op_net_set_multi_ttl_udp,
|
||||||
op_set_keepalive,
|
op_set_keepalive,
|
||||||
|
@ -377,6 +378,12 @@ class Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _setBroadcast = Symbol("setBroadcast");
|
||||||
|
|
||||||
|
function setDatagramBroadcast(conn, broadcast) {
|
||||||
|
return conn[_setBroadcast](broadcast);
|
||||||
|
}
|
||||||
|
|
||||||
class DatagramConn {
|
class DatagramConn {
|
||||||
#rid = 0;
|
#rid = 0;
|
||||||
#addr = null;
|
#addr = null;
|
||||||
|
@ -393,6 +400,10 @@ class DatagramConn {
|
||||||
return this.#addr;
|
return this.#addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[_setBroadcast](broadcast) {
|
||||||
|
op_net_set_broadcast_udp(this.#rid, broadcast);
|
||||||
|
}
|
||||||
|
|
||||||
async joinMulticastV4(addr, multiInterface) {
|
async joinMulticastV4(addr, multiInterface) {
|
||||||
await op_net_join_multi_v4_udp(
|
await op_net_join_multi_v4_udp(
|
||||||
this.#rid,
|
this.#rid,
|
||||||
|
@ -688,6 +699,7 @@ export {
|
||||||
Listener,
|
Listener,
|
||||||
listenOptionApiName,
|
listenOptionApiName,
|
||||||
resolveDns,
|
resolveDns,
|
||||||
|
setDatagramBroadcast,
|
||||||
TcpConn,
|
TcpConn,
|
||||||
UnixConn,
|
UnixConn,
|
||||||
UpgradedConn,
|
UpgradedConn,
|
||||||
|
|
|
@ -156,6 +156,7 @@ deno_core::extension!(deno_net,
|
||||||
ops::op_net_leave_multi_v6_udp,
|
ops::op_net_leave_multi_v6_udp,
|
||||||
ops::op_net_set_multi_loopback_udp,
|
ops::op_net_set_multi_loopback_udp,
|
||||||
ops::op_net_set_multi_ttl_udp,
|
ops::op_net_set_multi_ttl_udp,
|
||||||
|
ops::op_net_set_broadcast_udp,
|
||||||
ops::op_dns_resolve<P>,
|
ops::op_dns_resolve<P>,
|
||||||
ops::op_set_nodelay,
|
ops::op_set_nodelay,
|
||||||
ops::op_set_keepalive,
|
ops::op_set_keepalive,
|
||||||
|
|
|
@ -390,6 +390,23 @@ pub async fn op_net_set_multi_ttl_udp(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[op2(async)]
|
||||||
|
pub async fn op_net_set_broadcast_udp(
|
||||||
|
state: Rc<RefCell<OpState>>,
|
||||||
|
#[smi] rid: ResourceId,
|
||||||
|
broadcast: bool,
|
||||||
|
) -> Result<(), NetError> {
|
||||||
|
let resource = state
|
||||||
|
.borrow_mut()
|
||||||
|
.resource_table
|
||||||
|
.get::<UdpSocketResource>(rid)
|
||||||
|
.map_err(|_| NetError::SocketClosed)?;
|
||||||
|
let socket = RcRef::map(&resource, |r| &r.socket).borrow().await;
|
||||||
|
socket.set_broadcast(broadcast)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// If this token is present in op_net_connect_tcp call and
|
/// If this token is present in op_net_connect_tcp call and
|
||||||
/// the hostname matches with one of the resolved IPs, then
|
/// the hostname matches with one of the resolved IPs, then
|
||||||
/// the permission check is performed against the original hostname.
|
/// the permission check is performed against the original hostname.
|
||||||
|
|
|
@ -300,8 +300,13 @@ export class UDP extends HandleWrap {
|
||||||
return this.#doSend(req, bufs, count, args, AF_INET6);
|
return this.#doSend(req, bufs, count, args, AF_INET6);
|
||||||
}
|
}
|
||||||
|
|
||||||
setBroadcast(_bool: 0 | 1): number {
|
setBroadcast(bool: 0 | 1): number {
|
||||||
notImplemented("udp.UDP.prototype.setBroadcast");
|
if (!this.#listener) {
|
||||||
|
return codeMap.get("EBADF")!;
|
||||||
|
}
|
||||||
|
|
||||||
|
net.setDatagramBroadcast(this.#listener, bool === 1);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMulticastInterface(_interfaceAddress: string): number {
|
setMulticastInterface(_interfaceAddress: string): number {
|
||||||
|
|
|
@ -448,6 +448,7 @@
|
||||||
"test-dgram-send-invalid-msg-type.js",
|
"test-dgram-send-invalid-msg-type.js",
|
||||||
"test-dgram-send-multi-buffer-copy.js",
|
"test-dgram-send-multi-buffer-copy.js",
|
||||||
"test-dgram-send-multi-string-array.js",
|
"test-dgram-send-multi-string-array.js",
|
||||||
|
"test-dgram-setBroadcast.js",
|
||||||
"test-dgram-udp4.js",
|
"test-dgram-udp4.js",
|
||||||
"test-dgram-udp6-send-default-host.js",
|
"test-dgram-udp6-send-default-host.js",
|
||||||
"test-dgram-unref.js",
|
"test-dgram-unref.js",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!-- deno-fmt-ignore-file -->
|
<!-- deno-fmt-ignore-file -->
|
||||||
# Remaining Node Tests
|
# Remaining Node Tests
|
||||||
|
|
||||||
1163 tests out of 3993 have been ported from Node 23.9.0 (29.13% ported, 71.40% remaining).
|
1164 tests out of 3993 have been ported from Node 23.9.0 (29.15% ported, 71.37% remaining).
|
||||||
|
|
||||||
NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tests/node_compat/runner` dir instead.
|
NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tests/node_compat/runner` dir instead.
|
||||||
|
|
||||||
|
@ -626,7 +626,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co
|
||||||
- [parallel/test-dgram-send-empty-packet.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-send-empty-packet.js)
|
- [parallel/test-dgram-send-empty-packet.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-send-empty-packet.js)
|
||||||
- [parallel/test-dgram-send-queue-info.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-send-queue-info.js)
|
- [parallel/test-dgram-send-queue-info.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-send-queue-info.js)
|
||||||
- [parallel/test-dgram-sendto.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-sendto.js)
|
- [parallel/test-dgram-sendto.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-sendto.js)
|
||||||
- [parallel/test-dgram-setBroadcast.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-setBroadcast.js)
|
|
||||||
- [parallel/test-dgram-setTTL.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-setTTL.js)
|
- [parallel/test-dgram-setTTL.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-setTTL.js)
|
||||||
- [parallel/test-dgram-udp6-link-local-address.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-udp6-link-local-address.js)
|
- [parallel/test-dgram-udp6-link-local-address.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-udp6-link-local-address.js)
|
||||||
- [parallel/test-dgram-unref-in-cluster.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-unref-in-cluster.js)
|
- [parallel/test-dgram-unref-in-cluster.js](https://github.com/nodejs/node/tree/v23.9.0/test/parallel/test-dgram-unref-in-cluster.js)
|
||||||
|
|
32
tests/node_compat/test/parallel/test-dgram-setBroadcast.js
Normal file
32
tests/node_compat/test/parallel/test-dgram-setBroadcast.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
// deno-fmt-ignore-file
|
||||||
|
// deno-lint-ignore-file
|
||||||
|
|
||||||
|
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
|
||||||
|
// Taken from Node 23.9.0
|
||||||
|
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const dgram = require('dgram');
|
||||||
|
|
||||||
|
{
|
||||||
|
// Should throw EBADF if the socket is never bound.
|
||||||
|
const socket = dgram.createSocket('udp4');
|
||||||
|
|
||||||
|
assert.throws(() => {
|
||||||
|
socket.setBroadcast(true);
|
||||||
|
}, /^Error: setBroadcast EBADF$/);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Can call setBroadcast() after binding the socket.
|
||||||
|
const socket = dgram.createSocket('udp4');
|
||||||
|
|
||||||
|
socket.bind(0, common.mustCall(() => {
|
||||||
|
socket.setBroadcast(true);
|
||||||
|
socket.setBroadcast(false);
|
||||||
|
socket.close();
|
||||||
|
}));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue