Store plain DeviceT instead of Managed<_> in EthernetInterface

This commit is contained in:
Philipp Oppermann 2017-11-08 10:20:50 +01:00 committed by whitequark
parent d9fa7f6bc6
commit c3e07dad9a
5 changed files with 16 additions and 18 deletions

View File

@ -42,7 +42,7 @@ fn main() {
let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 2), 24)];
let default_v4_gw = Ipv4Address::new(192, 168, 69, 100);
let mut iface = EthernetInterface::new(
Box::new(device), Box::new(arp_cache) as Box<ArpCache>,
device, Box::new(arp_cache) as Box<ArpCache>,
ethernet_addr, ip_addrs, Some(default_v4_gw));
let mut sockets = SocketSet::new(vec![]);

View File

@ -69,10 +69,10 @@ mod mock {
fn main() {
let clock = mock::Clock::new();
let mut device = Loopback::new();
let device = Loopback::new();
#[cfg(feature = "std")]
let mut device = {
let device = {
let clock = clock.clone();
utils::setup_logging_with_clock("", move || clock.elapsed());
@ -90,7 +90,7 @@ fn main() {
let mut ip_addrs = [IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8)];
let mut iface = EthernetInterface::new(
&mut device, &mut arp_cache as &mut ArpCache,
device, &mut arp_cache as &mut ArpCache,
EthernetAddress::default(), &mut ip_addrs[..], None);
let server_socket = {

View File

@ -60,7 +60,7 @@ fn main() {
let ip_addr = IpCidr::new(IpAddress::from(local_addr), 24);
let default_v4_gw = Ipv4Address::new(192, 168, 69, 100);
let mut iface = EthernetInterface::new(
Box::new(device), Box::new(arp_cache) as Box<ArpCache>,
device, Box::new(arp_cache) as Box<ArpCache>,
ethernet_addr, [ip_addr], Some(default_v4_gw));
let mut sockets = SocketSet::new(vec![]);

View File

@ -56,7 +56,7 @@ fn main() {
let ethernet_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
let ip_addrs = [IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24)];
let mut iface = EthernetInterface::new(
Box::new(device), Box::new(arp_cache) as Box<ArpCache>,
device, Box::new(arp_cache) as Box<ArpCache>,
ethernet_addr, ip_addrs, None);
let mut sockets = SocketSet::new(vec![]);

View File

@ -31,8 +31,8 @@ use super::ArpCache;
/// The network interface logically owns a number of other data structures; to avoid
/// a dependency on heap allocation, it instead owns a `BorrowMut<[T]>`, which can be
/// a `&mut [T]`, or `Vec<T>` if a heap is available.
pub struct Interface<'a, 'b, 'c, DeviceT: for<'d> Device<'d> + 'a> {
device: Managed<'a, DeviceT>,
pub struct Interface<'b, 'c, DeviceT: for<'d> Device<'d>> {
device: DeviceT,
inner: InterfaceInner<'b, 'c>,
}
@ -64,24 +64,22 @@ enum Packet<'a> {
Tcp((IpRepr, TcpRepr<'a>))
}
impl<'a, 'b, 'c, DeviceT> Interface<'a, 'b, 'c, DeviceT>
where DeviceT: for<'d> Device<'d> + 'a {
impl<'b, 'c, DeviceT> Interface<'b, 'c, DeviceT>
where DeviceT: for<'d> Device<'d> {
/// Create a network interface using the provided network device.
///
/// # Panics
/// See the restrictions on [set_hardware_addr](#method.set_hardware_addr)
/// and [set_protocol_addrs](#method.set_protocol_addrs) functions.
pub fn new<DeviceMT, ArpCacheMT, ProtocolAddrsMT, Ipv4GatewayAddrT>
(device: DeviceMT, arp_cache: ArpCacheMT,
pub fn new<ArpCacheMT, ProtocolAddrsMT, Ipv4GatewayAddrT>
(device: DeviceT, arp_cache: ArpCacheMT,
ethernet_addr: EthernetAddress,
ip_addrs: ProtocolAddrsMT,
ipv4_gateway: Ipv4GatewayAddrT) ->
Interface<'a, 'b, 'c, DeviceT>
where DeviceMT: Into<Managed<'a, DeviceT>>,
ArpCacheMT: Into<Managed<'b, ArpCache>>,
Interface<'b, 'c, DeviceT>
where ArpCacheMT: Into<Managed<'b, ArpCache>>,
ProtocolAddrsMT: Into<ManagedSlice<'c, IpCidr>>,
Ipv4GatewayAddrT: Into<Option<Ipv4Address>>, {
let device = device.into();
let ip_addrs = ip_addrs.into();
InterfaceInner::check_ethernet_addr(&ethernet_addr);
InterfaceInner::check_ip_addrs(&ip_addrs);
@ -717,7 +715,7 @@ mod test {
use {Result, Error};
fn create_loopback<'a, 'b>() ->
(EthernetInterface<'a, 'static, 'b, Loopback>, SocketSet<'static, 'a, 'b>) {
(EthernetInterface<'static, 'b, Loopback>, SocketSet<'static, 'a, 'b>) {
// Create a basic device
let device = Loopback::new();
@ -725,7 +723,7 @@ mod test {
let ip_addr = IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8);
(EthernetInterface::new(
Box::new(device), Box::new(arp_cache) as Box<ArpCache>,
device, Box::new(arp_cache) as Box<ArpCache>,
EthernetAddress::default(), [ip_addr], None), SocketSet::new(vec![]))
}