summaryrefslogtreecommitdiff
path: root/core/examples/http_bench_bin_ops.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-12 21:55:05 +0200
committerGitHub <noreply@github.com>2021-04-12 15:55:05 -0400
commit46b1c653c0c433932908b7610f60b409af134c76 (patch)
tree00d8b59c8c4e9b90538d548ebd828d2b3f94d4fd /core/examples/http_bench_bin_ops.js
parenta20504642d083172f297543f9788b128e9c2e0bc (diff)
refactor(deno): remove concept of bin & json ops (#10145)
Diffstat (limited to 'core/examples/http_bench_bin_ops.js')
-rw-r--r--core/examples/http_bench_bin_ops.js71
1 files changed, 0 insertions, 71 deletions
diff --git a/core/examples/http_bench_bin_ops.js b/core/examples/http_bench_bin_ops.js
deleted file mode 100644
index c3128dbb2..000000000
--- a/core/examples/http_bench_bin_ops.js
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-// This is not a real HTTP server. We read blindly one time into 'requestBuf',
-// then write this fixed 'responseBuf'. The point of this benchmark is to
-// exercise the event loop in a simple yet semi-realistic way.
-const requestBuf = new Uint8Array(64 * 1024);
-const responseBuf = new Uint8Array(
- "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n"
- .split("")
- .map((c) => c.charCodeAt(0)),
-);
-
-/** Listens on 0.0.0.0:4500, returns rid. */
-function listen() {
- return Deno.core.binOpSync("listen", 0);
-}
-
-/** Accepts a connection, returns rid. */
-function accept(rid) {
- return Deno.core.binOpAsync("accept", rid);
-}
-
-/**
- * Reads a packet from the rid, presumably an http request. data is ignored.
- * Returns bytes read.
- */
-function read(rid, data) {
- return Deno.core.binOpAsync("read", rid, data);
-}
-
-/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */
-function write(rid, data) {
- return Deno.core.binOpAsync("write", rid, data);
-}
-
-function close(rid) {
- Deno.core.binOpSync("close", rid);
-}
-
-async function serve(rid) {
- try {
- while (true) {
- await read(rid, requestBuf);
- await write(rid, responseBuf);
- }
- } catch (e) {
- if (
- !e.message.includes("Broken pipe") &&
- !e.message.includes("Connection reset by peer")
- ) {
- throw e;
- }
- }
- close(rid);
-}
-
-async function main() {
- Deno.core.ops();
- Deno.core.registerErrorClass("Error", Error);
-
- const listenerRid = listen();
- Deno.core.print(
- `http_bench_bin_ops listening on http://127.0.0.1:4544/\n`,
- );
-
- while (true) {
- const rid = await accept(listenerRid);
- serve(rid);
- }
-}
-
-main();