summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal_binding/udp_wrap.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-01-04 08:51:39 +0530
committerGitHub <noreply@github.com>2024-01-04 08:51:39 +0530
commitad65440092ed2e5f85d1c7cadb6f59bef0c7be75 (patch)
treef31acce3ce9246315859b1e4ad777157260011c3 /ext/node/polyfills/internal_binding/udp_wrap.ts
parenta0b687235907ce91358677353c00f575548313b4 (diff)
fix(ext/node): UdpSocket ref and unref (#21777)
Diffstat (limited to 'ext/node/polyfills/internal_binding/udp_wrap.ts')
-rw-r--r--ext/node/polyfills/internal_binding/udp_wrap.ts11
1 files changed, 9 insertions, 2 deletions
diff --git a/ext/node/polyfills/internal_binding/udp_wrap.ts b/ext/node/polyfills/internal_binding/udp_wrap.ts
index 619950997..209c84a23 100644
--- a/ext/node/polyfills/internal_binding/udp_wrap.ts
+++ b/ext/node/polyfills/internal_binding/udp_wrap.ts
@@ -78,6 +78,7 @@ export class UDP extends HandleWrap {
#listener?: Deno.DatagramConn;
#receiving = false;
+ #unrefed = false;
#recvBufferSize = UDP_DGRAM_MAXSIZE;
#sendBufferSize = UDP_DGRAM_MAXSIZE;
@@ -273,7 +274,8 @@ export class UDP extends HandleWrap {
}
override ref() {
- notImplemented("udp.UDP.prototype.ref");
+ this.#listener?.ref();
+ this.#unrefed = false;
}
send(
@@ -315,7 +317,8 @@ export class UDP extends HandleWrap {
}
override unref() {
- notImplemented("udp.UDP.prototype.unref");
+ this.#listener?.unref();
+ this.#unrefed = true;
}
#doBind(ip: string, port: number, _flags: number, family: number): number {
@@ -443,6 +446,10 @@ export class UDP extends HandleWrap {
let remoteAddr: Deno.NetAddr | null;
let nread: number | null;
+ if (this.#unrefed) {
+ this.#listener!.unref();
+ }
+
try {
[buf, remoteAddr] = (await this.#listener!.receive(p)) as [
Uint8Array,