1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix deno_core_http_bench (#3364)

This commit is contained in:
Bartek Iwańczuk 2019-11-17 15:44:22 +01:00 committed by Ry Dahl
parent f356b2bd5e
commit a2f5bccad7

View file

@ -13,8 +13,11 @@ extern crate log;
extern crate lazy_static; extern crate lazy_static;
use deno::*; use deno::*;
use futures::compat::AsyncRead01CompatExt;
use futures::compat::AsyncWrite01CompatExt;
use futures::future::FutureExt; use futures::future::FutureExt;
use futures::future::TryFutureExt; use futures::future::TryFutureExt;
use futures::io::{AsyncRead, AsyncWrite};
use futures::stream::StreamExt; use futures::stream::StreamExt;
use std::env; use std::env;
use std::future::Future; use std::future::Future;
@ -26,9 +29,6 @@ use std::sync::Mutex;
use std::sync::MutexGuard; use std::sync::MutexGuard;
use std::task::Poll; use std::task::Poll;
use tokio::net::tcp::Incoming; use tokio::net::tcp::Incoming;
use tokio::prelude::Async;
use tokio::prelude::AsyncRead;
use tokio::prelude::AsyncWrite;
static LOGGER: Logger = Logger; static LOGGER: Logger = Logger;
struct Logger; struct Logger;
@ -273,14 +273,12 @@ fn op_read(
let rid = record.arg as u32; let rid = record.arg as u32;
debug!("read rid={}", rid); debug!("read rid={}", rid);
let mut zero_copy_buf = zero_copy_buf.unwrap(); let mut zero_copy_buf = zero_copy_buf.unwrap();
let fut = futures::future::poll_fn(move |_cx| { let fut = futures::future::poll_fn(move |cx| {
let mut table = lock_resource_table(); let mut table = lock_resource_table();
let stream = table.get_mut::<TcpStream>(rid).ok_or_else(bad_resource)?; let stream = table.get_mut::<TcpStream>(rid).ok_or_else(bad_resource)?;
match stream.0.poll_read(&mut zero_copy_buf) { let mut f: Box<dyn AsyncRead + Unpin> =
Err(e) => Poll::Ready(Err(e)), Box::new(AsyncRead01CompatExt::compat(&stream.0));
Ok(Async::Ready(v)) => Poll::Ready(Ok(v)), AsyncRead::poll_read(Pin::new(&mut f), cx, &mut zero_copy_buf)
Ok(Async::NotReady) => Poll::Pending,
}
}) })
.and_then(move |nread| { .and_then(move |nread| {
debug!("read success {}", nread); debug!("read success {}", nread);
@ -296,14 +294,12 @@ fn op_write(
let rid = record.arg as u32; let rid = record.arg as u32;
debug!("write rid={}", rid); debug!("write rid={}", rid);
let zero_copy_buf = zero_copy_buf.unwrap(); let zero_copy_buf = zero_copy_buf.unwrap();
let fut = futures::future::poll_fn(move |_cx| { let fut = futures::future::poll_fn(move |cx| {
let mut table = lock_resource_table(); let mut table = lock_resource_table();
let stream = table.get_mut::<TcpStream>(rid).ok_or_else(bad_resource)?; let stream = table.get_mut::<TcpStream>(rid).ok_or_else(bad_resource)?;
match stream.0.poll_write(&zero_copy_buf) { let mut f: Box<dyn AsyncWrite + Unpin> =
Err(e) => Poll::Ready(Err(e)), Box::new(AsyncWrite01CompatExt::compat(&stream.0));
Ok(Async::Ready(v)) => Poll::Ready(Ok(v)), AsyncWrite::poll_write(Pin::new(&mut f), cx, &zero_copy_buf)
Ok(Async::NotReady) => Poll::Pending,
}
}) })
.and_then(move |nwritten| { .and_then(move |nwritten| {
debug!("write success {}", nwritten); debug!("write success {}", nwritten);