summaryrefslogtreecommitdiff
path: root/cli/ops/io.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-08-21 20:42:48 -0400
committerGitHub <noreply@github.com>2019-08-21 20:42:48 -0400
commitbdc97b3976786bb744a27e59b0f4f28554a682df (patch)
treebf4635ad903de542c10620e95adb72eee03d9204 /cli/ops/io.rs
parentb764d1b8ffc4bf5e2ab89bdbd978d708a6da0f24 (diff)
Organize dispatch a bit (#2796)
Just some clean up reorganization around flatbuffer/minimal dispatch code. This is prep for adding a JSON dispatcher.
Diffstat (limited to 'cli/ops/io.rs')
-rw-r--r--cli/ops/io.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/cli/ops/io.rs b/cli/ops/io.rs
new file mode 100644
index 000000000..610238942
--- /dev/null
+++ b/cli/ops/io.rs
@@ -0,0 +1,43 @@
+use super::dispatch_minimal::MinimalOp;
+use crate::deno_error;
+use crate::resources;
+use crate::tokio_write;
+use deno::ErrBox;
+use deno::PinnedBuf;
+use futures::Future;
+
+pub fn op_read(rid: i32, zero_copy: Option<PinnedBuf>) -> Box<MinimalOp> {
+ debug!("read rid={}", rid);
+ let zero_copy = match zero_copy {
+ None => {
+ return Box::new(futures::future::err(deno_error::no_buffer_specified()))
+ }
+ Some(buf) => buf,
+ };
+ match resources::lookup(rid as u32) {
+ None => Box::new(futures::future::err(deno_error::bad_resource())),
+ Some(resource) => Box::new(
+ tokio::io::read(resource, zero_copy)
+ .map_err(ErrBox::from)
+ .and_then(move |(_resource, _buf, nread)| Ok(nread as i32)),
+ ),
+ }
+}
+
+pub fn op_write(rid: i32, zero_copy: Option<PinnedBuf>) -> Box<MinimalOp> {
+ debug!("write rid={}", rid);
+ let zero_copy = match zero_copy {
+ None => {
+ return Box::new(futures::future::err(deno_error::no_buffer_specified()))
+ }
+ Some(buf) => buf,
+ };
+ match resources::lookup(rid as u32) {
+ None => Box::new(futures::future::err(deno_error::bad_resource())),
+ Some(resource) => Box::new(
+ tokio_write::write(resource, zero_copy)
+ .map_err(ErrBox::from)
+ .and_then(move |(_resource, _buf, nwritten)| Ok(nwritten as i32)),
+ ),
+ }
+}