summaryrefslogtreecommitdiff
path: root/core/examples/http_bench_json_ops.js
diff options
context:
space:
mode:
authorInteon <42113979+inteon@users.noreply.github.com>2021-04-08 18:04:02 +0200
committerGitHub <noreply@github.com>2021-04-08 18:04:02 +0200
commitd050b491b10fe37b4461b37c56028a14c8674c95 (patch)
tree47aa768f3027dff90ffd1aacdd267274610bf441 /core/examples/http_bench_json_ops.js
parentc4b21fbff119a8ce006391d8fb7586877759bcef (diff)
fix(core): error handling in examples (#9867)
Diffstat (limited to 'core/examples/http_bench_json_ops.js')
-rw-r--r--core/examples/http_bench_json_ops.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js
index 791fcc499..f8ac05353 100644
--- a/core/examples/http_bench_json_ops.js
+++ b/core/examples/http_bench_json_ops.js
@@ -37,15 +37,17 @@ function close(rid) {
}
async function serve(rid) {
- while (true) {
- const nread = await read(rid, requestBuf);
- if (nread <= 0) {
- break;
+ try {
+ while (true) {
+ await read(rid, requestBuf);
+ await write(rid, responseBuf);
}
-
- const nwritten = await write(rid, responseBuf);
- if (nwritten < 0) {
- break;
+ } catch (e) {
+ if (
+ !e.message.includes("Broken pipe") &&
+ !e.message.includes("Connection reset by peer")
+ ) {
+ throw e;
}
}
close(rid);
@@ -58,12 +60,8 @@ async function main() {
const listenerRid = listen();
Deno.core.print(`http_bench_json_ops listening on http://127.0.0.1:4544/\n`);
- for (;;) {
+ while (true) {
const rid = await accept(listenerRid);
- if (rid < 0) {
- Deno.core.print(`accept error ${rid}`);
- return;
- }
serve(rid);
}
}