1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -05:00

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.
This commit is contained in:
Ryan Dahl 2018-10-01 19:43:27 -04:00
parent 42c5b103ec
commit fc1c54dde0

View file

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