summaryrefslogtreecommitdiff
path: root/cli/ops/io.rs
diff options
context:
space:
mode:
authorValentin Anger <syrupthinker@gryphno.de>2020-06-01 20:20:47 +0200
committerGitHub <noreply@github.com>2020-06-01 14:20:47 -0400
commitbecbb56b19e96e4dd72b861217a855fba953d290 (patch)
treed9e99771c537ef87a4a945f0120775c337ef90aa /cli/ops/io.rs
parent12d741c2fe453625d510313beaa2e1c282784c00 (diff)
feat(core): Ops can take several zero copy buffers (#4788)
Diffstat (limited to 'cli/ops/io.rs')
-rw-r--r--cli/ops/io.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/cli/ops/io.rs b/cli/ops/io.rs
index 5769d74ed..0e007ad1a 100644
--- a/cli/ops/io.rs
+++ b/cli/ops/io.rs
@@ -211,16 +211,16 @@ pub fn op_read(
_state: &State,
is_sync: bool,
rid: i32,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: &mut [ZeroCopyBuf],
) -> MinimalOp {
debug!("read rid={}", rid);
- if zero_copy.is_none() {
- return MinimalOp::Sync(Err(no_buffer_specified()));
+ match zero_copy.len() {
+ 0 => return MinimalOp::Sync(Err(no_buffer_specified())),
+ 1 => {}
+ _ => panic!("Invalid number of arguments"),
}
let resource_table = isolate_state.resource_table.clone();
- let mut buf = zero_copy.unwrap();
-
if is_sync {
MinimalOp::Sync({
// First we look up the rid in the resource table.
@@ -229,7 +229,7 @@ pub fn op_read(
Ok(std_file) => {
use std::io::Read;
std_file
- .read(&mut buf)
+ .read(&mut zero_copy[0])
.map(|n: usize| n as i32)
.map_err(OpError::from)
}
@@ -239,6 +239,7 @@ pub fn op_read(
})
})
} else {
+ let mut zero_copy = zero_copy[0].clone();
MinimalOp::Async(
poll_fn(move |cx| {
let mut resource_table = resource_table.borrow_mut();
@@ -249,7 +250,7 @@ pub fn op_read(
let mut task_tracker_id: Option<usize> = None;
let nread = match resource_holder
.resource
- .poll_read(cx, &mut buf.as_mut()[..])
+ .poll_read(cx, &mut zero_copy)
.map_err(OpError::from)
{
Poll::Ready(t) => {
@@ -335,15 +336,15 @@ pub fn op_write(
_state: &State,
is_sync: bool,
rid: i32,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: &mut [ZeroCopyBuf],
) -> MinimalOp {
debug!("write rid={}", rid);
- if zero_copy.is_none() {
- return MinimalOp::Sync(Err(no_buffer_specified()));
+ match zero_copy.len() {
+ 0 => return MinimalOp::Sync(Err(no_buffer_specified())),
+ 1 => {}
+ _ => panic!("Invalid number of arguments"),
}
- let buf = zero_copy.unwrap();
-
if is_sync {
MinimalOp::Sync({
// First we look up the rid in the resource table.
@@ -352,7 +353,7 @@ pub fn op_write(
Ok(std_file) => {
use std::io::Write;
std_file
- .write(&buf)
+ .write(&zero_copy[0])
.map(|nwritten: usize| nwritten as i32)
.map_err(OpError::from)
}
@@ -362,6 +363,7 @@ pub fn op_write(
})
})
} else {
+ let zero_copy = zero_copy[0].clone();
let resource_table = isolate_state.resource_table.clone();
MinimalOp::Async(
async move {
@@ -370,7 +372,7 @@ pub fn op_write(
let resource_holder = resource_table
.get_mut::<StreamResourceHolder>(rid as u32)
.ok_or_else(OpError::bad_resource_id)?;
- resource_holder.resource.poll_write(cx, &buf.as_ref()[..])
+ resource_holder.resource.poll_write(cx, &zero_copy)
})
.await?;