mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
util: update to bytes 0.6 (#3071)
Copies the implementation of poll_read_buf() from tokio::io::util::read_buf.
This commit is contained in:
parent
a3ef4e4cf5
commit
3965d91a5e
@ -11,7 +11,7 @@ tokio = { version = "0.3.0", path = "../tokio", features = ["full", "tracing"] }
|
|||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.2.7", default-features = false, features = ["fmt", "ansi", "env-filter", "chrono", "tracing-log"] }
|
tracing-subscriber = { version = "0.2.7", default-features = false, features = ["fmt", "ansi", "env-filter", "chrono", "tracing-log"] }
|
||||||
tokio-util = { version = "0.4.0", path = "../tokio-util", features = ["full"] }
|
tokio-util = { version = "0.4.0", path = "../tokio-util", features = ["full"] }
|
||||||
bytes = "0.5"
|
bytes = "0.6"
|
||||||
futures = "0.3.0"
|
futures = "0.3.0"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
@ -35,7 +35,7 @@ rt = ["tokio/rt"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "0.3.0", path = "../tokio" }
|
tokio = { version = "0.3.0", path = "../tokio" }
|
||||||
|
|
||||||
bytes = "0.5.0"
|
bytes = "0.6.0"
|
||||||
futures-core = "0.3.0"
|
futures-core = "0.3.0"
|
||||||
futures-sink = "0.3.0"
|
futures-sink = "0.3.0"
|
||||||
futures-io = { version = "0.3.0", optional = true }
|
futures-io = { version = "0.3.0", optional = true }
|
||||||
|
@ -65,6 +65,7 @@ mod util {
|
|||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
@ -77,17 +78,24 @@ mod util {
|
|||||||
return Poll::Ready(Ok(0));
|
return Poll::Ready(Ok(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
let orig = buf.bytes_mut().as_ptr() as *const u8;
|
let n = {
|
||||||
let mut b = ReadBuf::uninit(buf.bytes_mut());
|
let dst = buf.bytes_mut();
|
||||||
|
let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit<u8>]) };
|
||||||
|
let mut buf = ReadBuf::uninit(dst);
|
||||||
|
let ptr = buf.filled().as_ptr();
|
||||||
|
ready!(io.poll_read(cx, &mut buf)?);
|
||||||
|
|
||||||
ready!(io.poll_read(cx, &mut b))?;
|
// Ensure the pointer does not change from under us
|
||||||
let n = b.filled().len();
|
assert_eq!(ptr, buf.filled().as_ptr());
|
||||||
|
buf.filled().len()
|
||||||
|
};
|
||||||
|
|
||||||
// Safety: we can assume `n` bytes were read, since they are in`filled`.
|
// Safety: This is guaranteed to be the number of initialized (and read)
|
||||||
assert_eq!(orig, b.filled().as_ptr());
|
// bytes due to the invariants provided by `ReadBuf::filled`.
|
||||||
unsafe {
|
unsafe {
|
||||||
buf.advance_mut(n);
|
buf.advance_mut(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Ready(Ok(n))
|
Poll::Ready(Ok(n))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user