summaryrefslogtreecommitdiff
path: root/core/examples
diff options
context:
space:
mode:
Diffstat (limited to 'core/examples')
-rw-r--r--core/examples/http_bench.js8
-rw-r--r--core/examples/http_bench.rs30
2 files changed, 21 insertions, 17 deletions
diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js
index d9878cbe7..a893dab40 100644
--- a/core/examples/http_bench.js
+++ b/core/examples/http_bench.js
@@ -36,18 +36,18 @@ const scratchBytes = new Uint8Array(
);
assert(scratchBytes.byteLength === 3 * 4);
-function send(promiseId, opId, rid, zeroCopy = null) {
+function send(promiseId, opId, rid, ...zeroCopy) {
scratch32[0] = promiseId;
scratch32[1] = rid;
scratch32[2] = -1;
- return Deno.core.dispatch(opId, scratchBytes, zeroCopy);
+ return Deno.core.dispatch(opId, scratchBytes, ...zeroCopy);
}
/** Returns Promise<number> */
-function sendAsync(opId, rid, zeroCopy = null) {
+function sendAsync(opId, rid, ...zeroCopy) {
const promiseId = nextPromiseId++;
const p = createResolvable();
- const buf = send(promiseId, opId, rid, zeroCopy);
+ const buf = send(promiseId, opId, rid, ...zeroCopy);
if (buf) {
const record = recordFromBuf(buf);
// Sync result.
diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs
index a52f69fcb..233864fac 100644
--- a/core/examples/http_bench.rs
+++ b/core/examples/http_bench.rs
@@ -113,19 +113,19 @@ impl Isolate {
fn register_sync_op<F>(&mut self, name: &'static str, handler: F)
where
- F: 'static + Fn(State, u32, Option<ZeroCopyBuf>) -> Result<u32, Error>,
+ F: 'static + Fn(State, u32, &mut [ZeroCopyBuf]) -> Result<u32, Error>,
{
let state = self.state.clone();
let core_handler = move |_isolate_state: &mut CoreIsolateState,
control_buf: &[u8],
- zero_copy_buf: Option<ZeroCopyBuf>|
+ zero_copy_bufs: &mut [ZeroCopyBuf]|
-> Op {
let state = state.clone();
let record = Record::from(control_buf);
let is_sync = record.promise_id == 0;
assert!(is_sync);
- let result: i32 = match handler(state, record.rid, zero_copy_buf) {
+ let result: i32 = match handler(state, record.rid, zero_copy_bufs) {
Ok(r) => r as i32,
Err(_) => -1,
};
@@ -139,7 +139,7 @@ impl Isolate {
fn register_op<F>(
&mut self,
name: &'static str,
- handler: impl Fn(State, u32, Option<ZeroCopyBuf>) -> F + Copy + 'static,
+ handler: impl Fn(State, u32, &mut [ZeroCopyBuf]) -> F + Copy + 'static,
) where
F: TryFuture,
F::Ok: TryInto<i32>,
@@ -148,15 +148,16 @@ impl Isolate {
let state = self.state.clone();
let core_handler = move |_isolate_state: &mut CoreIsolateState,
control_buf: &[u8],
- zero_copy_buf: Option<ZeroCopyBuf>|
+ zero_copy_bufs: &mut [ZeroCopyBuf]|
-> Op {
let state = state.clone();
let record = Record::from(control_buf);
let is_sync = record.promise_id == 0;
assert!(!is_sync);
+ let mut zero_copy = zero_copy_bufs.to_vec();
let fut = async move {
- let op = handler(state, record.rid, zero_copy_buf);
+ let op = handler(state, record.rid, &mut zero_copy);
let result = op
.map_ok(|r| r.try_into().expect("op result does not fit in i32"))
.unwrap_or_else(|_| -1)
@@ -182,7 +183,7 @@ impl Future for Isolate {
fn op_close(
state: State,
rid: u32,
- _buf: Option<ZeroCopyBuf>,
+ _buf: &mut [ZeroCopyBuf],
) -> Result<u32, Error> {
debug!("close rid={}", rid);
let resource_table = &mut state.borrow_mut().resource_table;
@@ -195,7 +196,7 @@ fn op_close(
fn op_listen(
state: State,
_rid: u32,
- _buf: Option<ZeroCopyBuf>,
+ _buf: &mut [ZeroCopyBuf],
) -> Result<u32, Error> {
debug!("listen");
let addr = "127.0.0.1:4544".parse::<SocketAddr>().unwrap();
@@ -209,7 +210,7 @@ fn op_listen(
fn op_accept(
state: State,
rid: u32,
- _buf: Option<ZeroCopyBuf>,
+ _buf: &mut [ZeroCopyBuf],
) -> impl TryFuture<Ok = u32, Error = Error> {
debug!("accept rid={}", rid);
@@ -227,9 +228,11 @@ fn op_accept(
fn op_read(
state: State,
rid: u32,
- buf: Option<ZeroCopyBuf>,
+ bufs: &mut [ZeroCopyBuf],
) -> impl TryFuture<Ok = usize, Error = Error> {
- let mut buf = buf.unwrap();
+ assert_eq!(bufs.len(), 1, "Invalid number of arguments");
+ let mut buf = bufs[0].clone();
+
debug!("read rid={}", rid);
poll_fn(move |cx| {
@@ -244,9 +247,10 @@ fn op_read(
fn op_write(
state: State,
rid: u32,
- buf: Option<ZeroCopyBuf>,
+ bufs: &mut [ZeroCopyBuf],
) -> impl TryFuture<Ok = usize, Error = Error> {
- let buf = buf.unwrap();
+ assert_eq!(bufs.len(), 1, "Invalid number of arguments");
+ let buf = bufs[0].clone();
debug!("write rid={}", rid);
poll_fn(move |cx| {