2020-08-07 20:27:53 -07:00
|
|
|
#![doc(html_root_url = "https://docs.rs/tokio-util/0.4.0")]
|
2019-12-21 00:54:43 +03:00
|
|
|
#![allow(clippy::needless_doctest_main)]
|
2019-10-22 10:13:49 -07:00
|
|
|
#![warn(
|
|
|
|
|
missing_debug_implementations,
|
|
|
|
|
missing_docs,
|
|
|
|
|
rust_2018_idioms,
|
|
|
|
|
unreachable_pub
|
|
|
|
|
)]
|
2020-09-13 15:50:40 +02:00
|
|
|
#![cfg_attr(docsrs, deny(broken_intra_doc_links))]
|
2019-10-22 10:13:49 -07:00
|
|
|
#![doc(test(
|
|
|
|
|
no_crate_inject,
|
|
|
|
|
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
|
|
|
|
|
))]
|
2019-11-22 15:55:10 -08:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
2019-10-22 10:13:49 -07:00
|
|
|
|
|
|
|
|
//! Utilities for working with Tokio.
|
2020-03-04 17:27:18 -05:00
|
|
|
//!
|
|
|
|
|
//! This crate is not versioned in lockstep with the core
|
|
|
|
|
//! [`tokio`] crate. However, `tokio-util` _will_ respect Rust's
|
|
|
|
|
//! semantic versioning policy, especially with regard to breaking changes.
|
|
|
|
|
//!
|
|
|
|
|
//! [`tokio`]: https://docs.rs/tokio
|
2019-10-22 10:13:49 -07:00
|
|
|
|
2019-11-22 15:55:10 -08:00
|
|
|
#[macro_use]
|
|
|
|
|
mod cfg;
|
|
|
|
|
|
2020-08-23 08:45:52 -07:00
|
|
|
mod loom;
|
|
|
|
|
|
2019-11-22 15:55:10 -08:00
|
|
|
cfg_codec! {
|
|
|
|
|
pub mod codec;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 13:02:15 -07:00
|
|
|
/*
|
|
|
|
|
Disabled due to removal of poll_ functions on UdpSocket.
|
|
|
|
|
|
|
|
|
|
See https://github.com/tokio-rs/tokio/issues/2830
|
2019-11-22 15:55:10 -08:00
|
|
|
cfg_udp! {
|
|
|
|
|
pub mod udp;
|
|
|
|
|
}
|
2020-09-23 13:02:15 -07:00
|
|
|
*/
|
2020-01-29 11:14:24 -08:00
|
|
|
|
|
|
|
|
cfg_compat! {
|
|
|
|
|
pub mod compat;
|
|
|
|
|
}
|
2020-08-23 08:45:52 -07:00
|
|
|
|
2020-09-08 09:12:32 +02:00
|
|
|
cfg_io! {
|
|
|
|
|
pub mod io;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:44:54 -04:00
|
|
|
cfg_rt_core! {
|
|
|
|
|
pub mod context;
|
|
|
|
|
}
|
2020-08-27 17:33:43 +02:00
|
|
|
|
2020-08-23 08:45:52 -07:00
|
|
|
pub mod sync;
|
2020-09-08 10:14:08 +03:00
|
|
|
|
|
|
|
|
pub mod either;
|
2020-09-24 17:26:03 -07:00
|
|
|
|
2020-10-05 14:25:04 -07:00
|
|
|
#[cfg(feature = "time")]
|
|
|
|
|
pub mod time;
|
|
|
|
|
|
2020-09-24 17:26:03 -07:00
|
|
|
#[cfg(any(feature = "io", feature = "codec"))]
|
|
|
|
|
mod util {
|
|
|
|
|
use tokio::io::{AsyncRead, ReadBuf};
|
|
|
|
|
|
|
|
|
|
use bytes::BufMut;
|
|
|
|
|
use futures_core::ready;
|
|
|
|
|
use std::io;
|
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
use std::task::{Context, Poll};
|
|
|
|
|
|
|
|
|
|
pub(crate) fn poll_read_buf<T: AsyncRead>(
|
|
|
|
|
cx: &mut Context<'_>,
|
|
|
|
|
io: Pin<&mut T>,
|
|
|
|
|
buf: &mut impl BufMut,
|
|
|
|
|
) -> Poll<io::Result<usize>> {
|
|
|
|
|
if !buf.has_remaining_mut() {
|
|
|
|
|
return Poll::Ready(Ok(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let orig = buf.bytes_mut().as_ptr() as *const u8;
|
|
|
|
|
let mut b = ReadBuf::uninit(buf.bytes_mut());
|
|
|
|
|
|
|
|
|
|
ready!(io.poll_read(cx, &mut b))?;
|
|
|
|
|
let n = b.filled().len();
|
|
|
|
|
|
|
|
|
|
// Safety: we can assume `n` bytes were read, since they are in`filled`.
|
|
|
|
|
assert_eq!(orig, b.filled().as_ptr());
|
|
|
|
|
unsafe {
|
|
|
|
|
buf.advance_mut(n);
|
|
|
|
|
}
|
|
|
|
|
Poll::Ready(Ok(n))
|
|
|
|
|
}
|
|
|
|
|
}
|