summaryrefslogtreecommitdiff
path: root/ext/http/lib.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-04-20 22:09:13 +0530
committerGitHub <noreply@github.com>2022-04-20 18:39:13 +0200
commit2612b6f20fc21fb92402aa9086d13a7192ae3814 (patch)
tree59db7a916a2c8ad55000b152912fd4019f75121d /ext/http/lib.rs
parent57a8fc37fc99491fa2559694f78af52a597bc501 (diff)
core: introduce `resource.read_return` (#14331)
Diffstat (limited to 'ext/http/lib.rs')
-rw-r--r--ext/http/lib.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index dff5c14cb..b85dcc473 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -688,16 +688,13 @@ async fn op_http_write_resource(
}
};
- let mut vec = vec![0u8; 64 * 1024];
- let vec_ptr = vec.as_mut_ptr();
+ let vec = vec![0u8; 64 * 1024]; // 64KB
let buf = ZeroCopyBuf::new_temp(vec);
- let nread = resource.clone().read(buf).await?;
+ let (nread, buf) = resource.clone().read_return(buf).await?;
if nread == 0 {
break;
}
- // SAFETY: ZeroCopyBuf keeps the Vec<u8> alive.
- let bytes =
- Bytes::from_static(unsafe { std::slice::from_raw_parts(vec_ptr, nread) });
+ let bytes = Bytes::from(buf.to_temp());
match body_tx.send_data(bytes).await {
Ok(_) => {}
Err(err) => {