Using read_unaligned
instead of memcpy
.
This commit is contained in:
parent
8783b06bd2
commit
8784ffbb4e
1 changed files with 6 additions and 8 deletions
|
@ -4,7 +4,7 @@ use crate::marker::PhantomData;
|
|||
use crate::mem::{size_of, zeroed};
|
||||
use crate::os::unix::io::RawFd;
|
||||
use crate::path::Path;
|
||||
use crate::ptr::null_mut;
|
||||
use crate::ptr::{null_mut, read_unaligned};
|
||||
use crate::slice::from_raw_parts;
|
||||
use crate::sys::unix::ext::net::addr::{sockaddr_un, SocketAddr};
|
||||
use crate::sys::unix::net::Socket;
|
||||
|
@ -131,18 +131,16 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> {
|
|||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<T> {
|
||||
unsafe {
|
||||
let mut unit = zeroed();
|
||||
if size_of::<T>() <= self.data.len() {
|
||||
let unit_ptr: *mut T = &mut unit;
|
||||
libc::memcpy(unit_ptr.cast(), self.data.as_ptr().cast(), size_of::<T>());
|
||||
unsafe {
|
||||
let unit = read_unaligned(self.data.as_ptr().cast());
|
||||
self.data = &self.data[size_of::<T>()..];
|
||||
Some(unit)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[unstable(feature = "unix_socket_ancillary_data", issue = "none")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue