diff options
Diffstat (limited to 'core/examples/http_bench_json_ops.rs')
-rw-r--r-- | core/examples/http_bench_json_ops.rs | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 7c895f326..6d61d35ec 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -10,7 +10,6 @@ use deno_core::OpState; use deno_core::RcRef; use deno_core::Resource; use deno_core::ResourceId; -use deno_core::ZeroCopyBuf; use std::cell::RefCell; use std::env; use std::net::SocketAddr; @@ -83,37 +82,23 @@ struct TcpStream { } impl TcpStream { - async fn read( - self: Rc<Self>, - mut buf: ZeroCopyBuf, - ) -> Result<(usize, ZeroCopyBuf), Error> { + async fn read(self: Rc<Self>, data: &mut [u8]) -> Result<usize, Error> { let mut rd = RcRef::map(&self, |r| &r.rd).borrow_mut().await; let cancel = RcRef::map(self, |r| &r.cancel); - let nread = rd - .read(&mut buf) - .try_or_cancel(cancel) - .await - .map_err(Error::from)?; - Ok((nread, buf)) + let nread = rd.read(data).try_or_cancel(cancel).await?; + Ok(nread) } - async fn write(self: Rc<Self>, buf: ZeroCopyBuf) -> Result<usize, Error> { + async fn write(self: Rc<Self>, data: &[u8]) -> Result<usize, Error> { let mut wr = RcRef::map(self, |r| &r.wr).borrow_mut().await; - wr.write(&buf).await.map_err(Error::from) + let nwritten = wr.write(data).await?; + Ok(nwritten) } } impl Resource for TcpStream { - fn read_return( - self: Rc<Self>, - buf: ZeroCopyBuf, - ) -> AsyncResult<(usize, ZeroCopyBuf)> { - Box::pin(self.read(buf)) - } - - fn write(self: Rc<Self>, buf: ZeroCopyBuf) -> AsyncResult<usize> { - Box::pin(self.write(buf)) - } + deno_core::impl_readable_byob!(); + deno_core::impl_writable!(); fn close(self: Rc<Self>) { self.cancel.cancel() |