diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-02-18 15:26:41 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-18 18:26:41 -0500 |
commit | 077af20ceb0869ddff9e08f5db1055138450fe2e (patch) | |
tree | 6bc51ad2112d7828b3dbc641050f1b098d836254 /src/ops.rs | |
parent | 97e29e3dd068c938ec5f8346183f8f523dea23c0 (diff) |
Add `seek` and implement `Seeker` on `File` (#1797)
This patch contains a special hack that circumvents the current tokio
seek problem.
tokio `seek` is implemented to take ownership of the original File and
emit a new one in its future, which conflicts with the design of
ResourceTable.
To avoid the problem, the current hack makes the FsFile resource
an Option which we could `take` the value ownership out of it. We then
convert the tokio File into a Rust std File, perform the seek, and then
put it back into the resource.
This might be able to drop this hack after
https://github.com/tokio-rs/tokio/pull/785 lands.
Diffstat (limited to 'src/ops.rs')
-rw-r--r-- | src/ops.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/ops.rs b/src/ops.rs index a415d7100..c8a005601 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -126,6 +126,7 @@ pub fn dispatch( msg::Any::WriteFile => op_write_file, msg::Any::Now => op_now, msg::Any::IsTTY => op_is_tty, + msg::Any::Seek => op_seek, _ => panic!(format!( "Unhandled message {}", msg::enum_name_any(inner_type) @@ -868,6 +869,28 @@ fn op_write( } } +fn op_seek( + _state: &Arc<IsolateState>, + base: &msg::Base<'_>, + data: libdeno::deno_buf, +) -> Box<Op> { + assert_eq!(data.len(), 0); + let _cmd_id = base.cmd_id(); + let inner = base.inner_as_seek().unwrap(); + let rid = inner.rid(); + let offset = inner.offset(); + let whence = inner.whence(); + + match resources::lookup(rid) { + None => odd_future(errors::bad_resource()), + Some(resource) => { + let op = resources::seek(resource, offset, whence) + .and_then(move |_| Ok(empty_buf())); + Box::new(op) + } + } +} + fn op_remove( state: &Arc<IsolateState>, base: &msg::Base<'_>, |