summaryrefslogtreecommitdiff
path: root/core/examples/http_bench.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-09-30 20:59:44 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-09-30 14:59:44 -0400
commitffbf0c20ccc4e70281958f18ed117f40bdd91397 (patch)
tree602fc442c91186e80a57eca85c5069f4a9be04d3 /core/examples/http_bench.js
parentae26a9c7a22bf3311648a93a3171f087490c6e4d (diff)
feat: op registration in core (#3002)
Diffstat (limited to 'core/examples/http_bench.js')
-rw-r--r--core/examples/http_bench.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js
index 4c68f2be6..a7142b09d 100644
--- a/core/examples/http_bench.js
+++ b/core/examples/http_bench.js
@@ -1,11 +1,6 @@
// 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 OP_LISTEN = 1;
-const OP_ACCEPT = 2;
-const OP_READ = 3;
-const OP_WRITE = 4;
-const OP_CLOSE = 5;
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"
@@ -80,12 +75,12 @@ function handleAsyncMsgFromRust(opId, buf) {
/** Listens on 0.0.0.0:4500, returns rid. */
function listen() {
- return sendSync(OP_LISTEN, -1);
+ return sendSync(ops["listen"], -1);
}
/** Accepts a connection, returns rid. */
async function accept(rid) {
- return await sendAsync(OP_ACCEPT, rid);
+ return await sendAsync(ops["accept"], rid);
}
/**
@@ -93,16 +88,16 @@ async function accept(rid) {
* Returns bytes read.
*/
async function read(rid, data) {
- return await sendAsync(OP_READ, rid, data);
+ return await sendAsync(ops["read"], rid, data);
}
/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */
async function write(rid, data) {
- return await sendAsync(OP_WRITE, rid, data);
+ return await sendAsync(ops["write"], rid, data);
}
function close(rid) {
- return sendSync(OP_CLOSE, rid);
+ return sendSync(ops["close"], rid);
}
async function serve(rid) {
@@ -120,8 +115,11 @@ async function serve(rid) {
close(rid);
}
+let ops;
+
async function main() {
Deno.core.setAsyncHandler(handleAsyncMsgFromRust);
+ ops = Deno.core.ops();
Deno.core.print("http_bench.js start\n");