Skip to content

Commit

Permalink
util: change udp feat to net
Browse files Browse the repository at this point in the history
  • Loading branch information
leshow committed Oct 27, 2020
1 parent a42ea5d commit 96a4c74
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tokio-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ categories = ["asynchronous"]
default = []

# Shorthand for enabling everything
full = ["codec", "compat", "io", "time", "udp"]
full = ["codec", "compat", "io", "time", "net"]

udp = ["tokio/net"]
net = ["tokio/net"]
compat = ["futures-io",]
codec = ["tokio/io-util", "tokio/stream"]
time = ["tokio/time","slab"]
Expand Down
6 changes: 3 additions & 3 deletions tokio-util/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ macro_rules! cfg_compat {
}
}

macro_rules! cfg_udp {
macro_rules! cfg_net {
($($item:item)*) => {
$(
#[cfg(all(feature = "udp", feature = "codec"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "udp", feature = "codec"))))]
#[cfg(all(feature = "net", feature = "codec"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "net", feature = "codec"))))]
$item
)*
}
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cfg_codec! {
pub mod codec;
}

cfg_udp! {
cfg_net! {
pub mod udp;
}

Expand Down
4 changes: 1 addition & 3 deletions tokio-util/src/udp/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use bytes::{BufMut, BytesMut};
use futures_core::ready;
use futures_sink::Sink;
use std::io;
use std::mem::MaybeUninit;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use std::pin::Pin;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -72,8 +71,7 @@ impl<C: Decoder + Unpin> Stream for UdpFramed<C> {
let addr = unsafe {
// Convert `&mut [MaybeUnit<u8>]` to `&mut [u8]` because we will be
// writing to it via `poll_recv_from` and therefore initializing the memory.
let buf: &mut [u8] =
&mut *(pin.rd.bytes_mut() as *mut [MaybeUninit<u8>] as *mut [u8]);
let buf: &mut [u8] = &mut *(pin.rd.bytes_mut() as *mut _ as *mut [u8]);
let mut read = ReadBuf::new(buf);
let res = ready!(Pin::new(&mut pin.socket).poll_recv_from(cx, &mut read));

Expand Down

0 comments on commit 96a4c74

Please sign in to comment.