diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-04-20 22:09:13 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-20 18:39:13 +0200 |
commit | 2612b6f20fc21fb92402aa9086d13a7192ae3814 (patch) | |
tree | 59db7a916a2c8ad55000b152912fd4019f75121d /ext/net/io.rs | |
parent | 57a8fc37fc99491fa2559694f78af52a597bc501 (diff) |
core: introduce `resource.read_return` (#14331)
Diffstat (limited to 'ext/net/io.rs')
-rw-r--r-- | ext/net/io.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ext/net/io.rs b/ext/net/io.rs index 17b86af17..02caf7473 100644 --- a/ext/net/io.rs +++ b/ext/net/io.rs @@ -70,13 +70,13 @@ where pub async fn read( self: Rc<Self>, mut buf: ZeroCopyBuf, - ) -> Result<usize, AnyError> { + ) -> Result<(usize, ZeroCopyBuf), AnyError> { let mut rd = self.rd_borrow_mut().await; let nread = rd .read(&mut buf) .try_or_cancel(self.cancel_handle()) .await?; - Ok(nread) + Ok((nread, buf)) } pub async fn write( @@ -103,7 +103,10 @@ impl Resource for TcpStreamResource { "tcpStream".into() } - 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)) } @@ -160,7 +163,7 @@ impl UnixStreamResource { pub async fn read( self: Rc<Self>, _buf: ZeroCopyBuf, - ) -> Result<usize, AnyError> { + ) -> Result<(usize, ZeroCopyBuf), AnyError> { unreachable!() } pub async fn write( @@ -182,7 +185,10 @@ impl Resource for UnixStreamResource { "unixStream".into() } - 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)) } |