Skip to content

Commit

Permalink
Fix #185
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv committed Jun 6, 2024
1 parent df64a4d commit 8ee1d99
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/shim-deno/src/deno/internal/Conn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
///<reference path="../stable/lib.deno.d.ts" />

import { Socket } from "net";
import { once } from "events";

import { FsFile } from "../stable/classes/FsFile.js";

Expand Down Expand Up @@ -40,6 +41,38 @@ export class Conn extends FsFile implements Deno.Conn {
unref(): void {
this.#socket.unref();
}

async read(p: Uint8Array): Promise<number | null> {
let wait = false;
while (true) {
if (wait) {
try {
await once(this.#socket, "readable", {
signal: AbortSignal.timeout(5),
});
} catch (error) {
if (
!(error != null && typeof error === "object" && "name" in error &&
error.name == "AbortError")
) {
throw error;
}
}
wait = false;
}
try {
return await super.read(p);
} catch (error) {
if (
!(error != null && typeof error === "object" && "code" in error &&
error.code == "EAGAIN")
) {
throw error;
}
wait = true;
}
}
}
}

export class TlsConn extends Conn implements Deno.TlsConn {
Expand Down

0 comments on commit 8ee1d99

Please sign in to comment.