Adjust how handle_read handle_write function.
Use tokio_io::io::read() and tokio_io::io::write_all()
instead of poll_fn() as suggested in the Tokio gitter.
@@ -30,8 +30,7 @@ use std::time::UNIX_EPOCH;
use std::time::{Duration, Instant};
use tokio;
use tokio::timer::Delay;
-use tokio_io::AsyncRead;
-use tokio_io::AsyncWrite;
+use tokio_io;
use tokio_threadpool;
type OpResult = DenoResult<Buf>;
@@ -611,12 +610,10 @@ fn handle_read(
errors::ErrorKind::BadFileDescriptor,
String::from("Bad File Descriptor"),
)),
- Some(mut resource) => {
- let op = futures::future::poll_fn(move || {
- let poll = resource.poll_read(data);
- poll
- }).map_err(|err| DenoError::from(err))
- .and_then(move |nread: usize| {
+ Some(resource) => {
+ let op = tokio_io::io::read(resource, data)
+ .map_err(|err| DenoError::from(err))
+ .and_then(move |(_resource, _buf, nread)| {
let builder = &mut FlatBufferBuilder::new();
let msg = msg::ReadRes::create(
builder,
@@ -655,17 +652,16 @@ fn handle_write(
errors::ErrorKind::BadFileDescriptor,
String::from("Bad File Descriptor"),
)),
- Some(mut resource) => {
- let op = futures::future::poll_fn(move || {
- let poll = resource.poll_write(data);
- poll
- }).map_err(|err| DenoError::from(err))
- .and_then(move |bytes_written: usize| {
+ Some(resource) => {
+ let len = data.len();
+ let op = tokio_io::io::write_all(resource, data)
+ .map_err(|err| DenoError::from(err))
+ .and_then(move |(_resource, _buf)| {
let builder = &mut FlatBufferBuilder::new();
let msg = msg::WriteRes::create(
builder,
&msg::WriteResArgs {
- nbyte: bytes_written as u32,
+ nbyte: len as u32,
..Default::default()
},
);
