Преглед на файлове

Get rid of unused arguments in Socket::{process,dispatch}.

I've left those "for consistency" but it just implies data
dependencies where there are none, and bloats signatures.
whitequark преди 7 години
родител
ревизия
3974dc780f
променени са 5 файла, в които са добавени 30 реда и са изтрити 45 реда
  1. 6 7
      src/iface/ethernet.rs
  2. 0 2
      src/socket/mod.rs
  3. 11 18
      src/socket/raw.rs
  4. 4 4
      src/socket/tcp.rs
  5. 9 14
      src/socket/udp.rs

+ 6 - 7
src/iface/ethernet.rs

@@ -203,8 +203,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
         let mut handled_by_raw_socket = false;
         for raw_socket in sockets.iter_mut().filter_map(
                 <Socket as AsSocket<RawSocket>>::try_as_socket) {
-            match raw_socket.process(timestamp, &IpRepr::Ipv4(ipv4_repr),
-                                     ipv4_packet.payload()) {
+            match raw_socket.process(&ipv4_repr.into(), ipv4_packet.payload()) {
                 // The packet is valid and handled by socket.
                 Ok(()) => handled_by_raw_socket = true,
                 // The packet isn't addressed to the socket, or cannot be accepted by it.
@@ -223,7 +222,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
             IpProtocol::Icmp =>
                 Self::process_icmpv4(ipv4_repr, ipv4_packet.payload()),
             IpProtocol::Udp =>
-                Self::process_udpv4(sockets, timestamp, ipv4_repr, ipv4_packet.payload()),
+                Self::process_udpv4(sockets, ipv4_repr, ipv4_packet.payload()),
             IpProtocol::Tcp =>
                 Self::process_tcp(sockets, timestamp, ipv4_repr.into(), ipv4_packet.payload()),
             _ if handled_by_raw_socket =>
@@ -277,14 +276,14 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
         }
     }
 
-    fn process_udpv4<'frame>(sockets: &mut SocketSet, timestamp: u64,
+    fn process_udpv4<'frame>(sockets: &mut SocketSet,
                              ipv4_repr: Ipv4Repr, ip_payload: &'frame [u8]) ->
                             Result<Response<'frame>> {
         let ip_repr = IpRepr::Ipv4(ipv4_repr);
 
         for udp_socket in sockets.iter_mut().filter_map(
                 <Socket as AsSocket<UdpSocket>>::try_as_socket) {
-            match udp_socket.process(timestamp, &ip_repr, ip_payload) {
+            match udp_socket.process(&ip_repr, ip_payload) {
                 // The packet is valid and handled by socket.
                 Ok(()) => return Ok(Response::Nop),
                 // The packet isn't addressed to the socket.
@@ -344,10 +343,10 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
         for socket in sockets.iter_mut() {
             let result = match socket {
                 &mut Socket::Raw(ref mut socket) =>
-                    socket.dispatch(timestamp, &limits, |response|
+                    socket.dispatch(|response|
                         self.dispatch_response(timestamp, Response::Raw(response))),
                 &mut Socket::Udp(ref mut socket) =>
-                    socket.dispatch(timestamp, &limits, |response|
+                    socket.dispatch(|response|
                         self.dispatch_response(timestamp, Response::Udp(response))),
                 &mut Socket::Tcp(ref mut socket) =>
                     socket.dispatch(timestamp, &limits, |response|

+ 0 - 2
src/socket/mod.rs

@@ -10,8 +10,6 @@
 //! The interface implemented by this module uses explicit buffering: you decide on the good
 //! size for a buffer, allocate it, and let the networking stack use it.
 
-use Result;
-use phy::DeviceLimits;
 use wire::IpRepr;
 
 mod raw;

+ 11 - 18
src/socket/raw.rs

@@ -2,7 +2,6 @@ use core::cmp::min;
 use managed::Managed;
 
 use {Error, Result};
-use phy::DeviceLimits;
 use wire::{IpVersion, IpProtocol, Ipv4Repr, Ipv4Packet};
 use socket::{IpRepr, Socket};
 use storage::{Resettable, RingBuffer};
@@ -167,8 +166,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
         Ok(length)
     }
 
-    pub(crate) fn process(&mut self, _timestamp: u64, ip_repr: &IpRepr,
-                          payload: &[u8]) -> Result<()> {
+    pub(crate) fn process(&mut self, ip_repr: &IpRepr, payload: &[u8]) -> Result<()> {
         if ip_repr.version() != self.ip_version { return Err(Error::Rejected) }
         if ip_repr.protocol() != self.ip_protocol { return Err(Error::Rejected) }
 
@@ -183,8 +181,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
         Ok(())
     }
 
-    pub(crate) fn dispatch<F>(&mut self, _timestamp: u64, _limits: &DeviceLimits,
-                              emit: F) -> Result<()>
+    pub(crate) fn dispatch<F>(&mut self, emit: F) -> Result<()>
             where F: FnOnce((IpRepr, &[u8])) -> Result<()> {
         fn prepare(protocol: IpProtocol, buffer: &mut [u8]) -> Result<(IpRepr, &[u8])> {
             match IpVersion::of_packet(buffer.as_ref())? {
@@ -273,26 +270,24 @@ mod test {
 
     #[test]
     fn test_send_dispatch() {
-        let limits = DeviceLimits::default();
-
         let mut socket = socket(buffer(0), buffer(1));
 
         assert!(socket.can_send());
-        assert_eq!(socket.dispatch(0, &limits, |_| unreachable!()),
+        assert_eq!(socket.dispatch(|_| unreachable!()),
                    Err(Error::Exhausted));
 
         assert_eq!(socket.send_slice(&PACKET_BYTES[..]), Ok(()));
         assert_eq!(socket.send_slice(b""), Err(Error::Exhausted));
         assert!(!socket.can_send());
 
-        assert_eq!(socket.dispatch(0, &limits, |(ip_repr, ip_payload)| {
+        assert_eq!(socket.dispatch(|(ip_repr, ip_payload)| {
             assert_eq!(ip_repr, HEADER_REPR);
             assert_eq!(ip_payload, &PACKET_PAYLOAD);
             Err(Error::Unaddressable)
         }), Err(Error::Unaddressable));
         /*assert!(!socket.can_send());*/
 
-        assert_eq!(socket.dispatch(0, &limits, |(ip_repr, ip_payload)| {
+        assert_eq!(socket.dispatch(|(ip_repr, ip_payload)| {
             assert_eq!(ip_repr, HEADER_REPR);
             assert_eq!(ip_payload, &PACKET_PAYLOAD);
             Ok(())
@@ -302,22 +297,20 @@ mod test {
 
     #[test]
     fn test_send_illegal() {
-        let limits = DeviceLimits::default();
-
         let mut socket = socket(buffer(0), buffer(1));
 
         let mut wrong_version = PACKET_BYTES.clone();
         Ipv4Packet::new(&mut wrong_version).set_version(5);
 
         assert_eq!(socket.send_slice(&wrong_version[..]), Ok(()));
-        assert_eq!(socket.dispatch(0, &limits, |_| unreachable!()),
+        assert_eq!(socket.dispatch(|_| unreachable!()),
                    Err(Error::Rejected));
 
         let mut wrong_protocol = PACKET_BYTES.clone();
         Ipv4Packet::new(&mut wrong_protocol).set_protocol(IpProtocol::Tcp);
 
         assert_eq!(socket.send_slice(&wrong_protocol[..]), Ok(()));
-        assert_eq!(socket.dispatch(0, &limits, |_| unreachable!()),
+        assert_eq!(socket.dispatch(|_| unreachable!()),
                    Err(Error::Rejected));
     }
 
@@ -330,11 +323,11 @@ mod test {
         Ipv4Packet::new(&mut cksumd_packet).fill_checksum();
 
         assert_eq!(socket.recv(), Err(Error::Exhausted));
-        assert_eq!(socket.process(0, &HEADER_REPR, &PACKET_PAYLOAD),
+        assert_eq!(socket.process(&HEADER_REPR, &PACKET_PAYLOAD),
                    Ok(()));
         assert!(socket.can_recv());
 
-        assert_eq!(socket.process(0, &HEADER_REPR, &PACKET_PAYLOAD),
+        assert_eq!(socket.process(&HEADER_REPR, &PACKET_PAYLOAD),
                    Err(Error::Exhausted));
         assert_eq!(socket.recv(), Ok(&cksumd_packet[..]));
         assert!(!socket.can_recv());
@@ -344,7 +337,7 @@ mod test {
     fn test_recv_truncated_slice() {
         let mut socket = socket(buffer(1), buffer(0));
 
-        assert_eq!(socket.process(0, &HEADER_REPR, &PACKET_PAYLOAD),
+        assert_eq!(socket.process(&HEADER_REPR, &PACKET_PAYLOAD),
                    Ok(()));
 
         let mut slice = [0; 4];
@@ -359,7 +352,7 @@ mod test {
         let mut buffer = vec![0; 128];
         buffer[..PACKET_BYTES.len()].copy_from_slice(&PACKET_BYTES[..]);
 
-        assert_eq!(socket.process(0, &HEADER_REPR, &buffer),
+        assert_eq!(socket.process(&HEADER_REPR, &buffer),
                    Err(Error::Truncated));
     }
 }

+ 4 - 4
src/socket/tcp.rs

@@ -729,7 +729,7 @@ impl<'a> TcpSocket<'a> {
     }
 
     pub(crate) fn ack_reply(&self, ip_repr: &IpRepr, repr: &TcpRepr) ->
-            (IpRepr, TcpRepr<'static>) {
+                           (IpRepr, TcpRepr<'static>) {
         let (ip_reply_repr, mut reply_repr) = Self::reply(ip_repr, repr);
 
         // From RFC793:
@@ -743,8 +743,8 @@ impl<'a> TcpSocket<'a> {
         (ip_reply_repr, reply_repr)
     }
 
-    pub(crate) fn process(&mut self, timestamp: u64, ip_repr: &IpRepr,
-                          payload: &[u8]) -> Result<Option<(IpRepr, TcpRepr<'static>)>> {
+    pub(crate) fn process(&mut self, timestamp: u64, ip_repr: &IpRepr, payload: &[u8]) ->
+                         Result<Option<(IpRepr, TcpRepr<'static>)>> {
         debug_assert!(ip_repr.protocol() == IpProtocol::Tcp);
 
         if self.state == State::Closed { return Err(Error::Rejected) }
@@ -1355,7 +1355,7 @@ mod test {
     };
 
     fn send(socket: &mut TcpSocket, timestamp: u64, repr: &TcpRepr) ->
-            Result<Option<TcpRepr<'static>>> {
+           Result<Option<TcpRepr<'static>>> {
         trace!("send: {}", repr);
         let mut buffer = vec![0; repr.buffer_len()];
         let mut packet = TcpPacket::new(&mut buffer);

+ 9 - 14
src/socket/udp.rs

@@ -2,7 +2,6 @@ use core::cmp::min;
 use managed::Managed;
 
 use {Error, Result};
-use phy::DeviceLimits;
 use wire::{IpProtocol, IpEndpoint};
 use wire::{UdpPacket, UdpRepr};
 use socket::{Socket, IpRepr};
@@ -181,8 +180,7 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
         Ok((length, endpoint))
     }
 
-    pub(crate) fn process(&mut self, _timestamp: u64, ip_repr: &IpRepr,
-                          payload: &[u8]) -> Result<()> {
+    pub(crate) fn process(&mut self, ip_repr: &IpRepr, payload: &[u8]) -> Result<()> {
         debug_assert!(ip_repr.protocol() == IpProtocol::Udp);
 
         let packet = UdpPacket::new_checked(&payload[..ip_repr.payload_len()])?;
@@ -202,8 +200,7 @@ impl<'a, 'b> UdpSocket<'a, 'b> {
         Ok(())
     }
 
-    pub(crate) fn dispatch<F>(&mut self, _timestamp: u64, _limits: &DeviceLimits,
-                              emit: F) -> Result<()>
+    pub(crate) fn dispatch<F>(&mut self, emit: F) -> Result<()>
             where F: FnOnce((IpRepr, UdpRepr)) -> Result<()> {
         let packet_buf = self.tx_buffer.dequeue()?;
         net_trace!("[{}]{}:{}: sending {} octets",
@@ -303,27 +300,25 @@ mod test {
 
     #[test]
     fn test_send_dispatch() {
-        let limits = DeviceLimits::default();
-
         let mut socket = socket(buffer(0), buffer(1));
         assert_eq!(socket.bind(LOCAL_END), Ok(()));
 
         assert!(socket.can_send());
-        assert_eq!(socket.dispatch(0, &limits, |_| unreachable!()),
+        assert_eq!(socket.dispatch(|_| unreachable!()),
                    Err(Error::Exhausted));
 
         assert_eq!(socket.send_slice(b"abcdef", REMOTE_END), Ok(()));
         assert_eq!(socket.send_slice(b"123456", REMOTE_END), Err(Error::Exhausted));
         assert!(!socket.can_send());
 
-        assert_eq!(socket.dispatch(0, &limits, |(ip_repr, udp_repr)| {
+        assert_eq!(socket.dispatch(|(ip_repr, udp_repr)| {
             assert_eq!(ip_repr, LOCAL_IP_REPR);
             assert_eq!(udp_repr, LOCAL_UDP_REPR);
             Err(Error::Unaddressable)
         }), Err(Error::Unaddressable));
         /*assert!(!socket.can_send());*/
 
-        assert_eq!(socket.dispatch(0, &limits, |(ip_repr, udp_repr)| {
+        assert_eq!(socket.dispatch(|(ip_repr, udp_repr)| {
             assert_eq!(ip_repr, LOCAL_IP_REPR);
             assert_eq!(udp_repr, LOCAL_UDP_REPR);
             Ok(())
@@ -354,11 +349,11 @@ mod test {
         assert!(!socket.can_recv());
         assert_eq!(socket.recv(), Err(Error::Exhausted));
 
-        assert_eq!(socket.process(0, &REMOTE_IP_REPR, &buffer),
+        assert_eq!(socket.process(&REMOTE_IP_REPR, &buffer),
                    Ok(()));
         assert!(socket.can_recv());
 
-        assert_eq!(socket.process(0, &REMOTE_IP_REPR, &buffer),
+        assert_eq!(socket.process(&REMOTE_IP_REPR, &buffer),
                    Err(Error::Exhausted));
         assert_eq!(socket.recv(), Ok((&b"abcdef"[..], REMOTE_END)));
         assert!(!socket.can_recv());
@@ -371,7 +366,7 @@ mod test {
 
         let mut buffer = vec![0; REMOTE_UDP_REPR.buffer_len()];
         REMOTE_UDP_REPR.emit(&mut UdpPacket::new(&mut buffer), &LOCAL_IP, &REMOTE_IP);
-        assert_eq!(socket.process(0, &REMOTE_IP_REPR, &buffer), Ok(()));
+        assert_eq!(socket.process(&REMOTE_IP_REPR, &buffer), Ok(()));
 
         let mut slice = [0; 4];
         assert_eq!(socket.recv_slice(&mut slice[..]), Ok((4, REMOTE_END)));
@@ -386,7 +381,7 @@ mod test {
         let udp_repr = UdpRepr { payload: &[0; 100][..], ..REMOTE_UDP_REPR };
         let mut buffer = vec![0; udp_repr.buffer_len()];
         udp_repr.emit(&mut UdpPacket::new(&mut buffer), &LOCAL_IP, &REMOTE_IP);
-        assert_eq!(socket.process(0, &REMOTE_IP_REPR, &buffer),
+        assert_eq!(socket.process(&REMOTE_IP_REPR, &buffer),
                    Err(Error::Truncated));
     }
 }