diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-04-22 16:19:08 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 16:19:08 +0530 |
commit | 57f7e07c13a1a692602022af4fc32c6ac352bb72 (patch) | |
tree | e2b6bf271ebda2aecf158b25c9d6c466461549dd /core/examples | |
parent | 2724235ec798f1fbf8fb5bd291615987ac4b919e (diff) |
Reland "perf(http): optimize ReadableStreams backed by a resource" (#14346)
Diffstat (limited to 'core/examples')
-rw-r--r-- | core/examples/http_bench_json_ops.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 2068c3b85..7c895f326 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -83,13 +83,18 @@ struct TcpStream { } impl TcpStream { - async fn read(self: Rc<Self>, mut buf: ZeroCopyBuf) -> Result<usize, Error> { + async fn read( + self: Rc<Self>, + mut buf: ZeroCopyBuf, + ) -> Result<(usize, ZeroCopyBuf), Error> { let mut rd = RcRef::map(&self, |r| &r.rd).borrow_mut().await; let cancel = RcRef::map(self, |r| &r.cancel); - rd.read(&mut buf) + let nread = rd + .read(&mut buf) .try_or_cancel(cancel) .await - .map_err(Error::from) + .map_err(Error::from)?; + Ok((nread, buf)) } async fn write(self: Rc<Self>, buf: ZeroCopyBuf) -> Result<usize, Error> { @@ -99,7 +104,10 @@ impl TcpStream { } impl Resource for TcpStream { - fn read(self: Rc<Self>, buf: ZeroCopyBuf) -> AsyncResult<usize> { + fn read_return( + self: Rc<Self>, + buf: ZeroCopyBuf, + ) -> AsyncResult<(usize, ZeroCopyBuf)> { Box::pin(self.read(buf)) } |