Fix warnings.

v0.7.x
whitequark 2017-07-31 07:59:01 +00:00
parent 7825bc6070
commit 8724157b54
3 changed files with 17 additions and 18 deletions

View File

@ -93,7 +93,7 @@ fn main() {
if socket.can_send() {
debug!("tcp:6969 send greeting");
write!(socket, "hello\n");
write!(socket, "hello\n").unwrap();
debug!("tcp:6969 close");
socket.close();
}

View File

@ -186,8 +186,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
pub(crate) fn dispatch<F, R>(&mut self, _timestamp: u64, _limits: &DeviceLimits,
emit: &mut F) -> Result<R>
where F: FnMut(&IpRepr, &IpPayload) -> Result<R> {
fn prepare(version: IpVersion, protocol: IpProtocol,
buffer: &mut [u8]) -> Result<(IpRepr, RawRepr)> {
fn prepare(protocol: IpProtocol, buffer: &mut [u8]) -> Result<(IpRepr, RawRepr)> {
match IpVersion::of_packet(buffer.as_ref())? {
IpVersion::Ipv4 => {
let mut packet = Ipv4Packet::new_checked(buffer.as_mut())?;
@ -205,7 +204,7 @@ impl<'a, 'b> RawSocket<'a, 'b> {
}
let mut packet_buf = self.tx_buffer.dequeue()?;
match prepare(self.ip_version, self.ip_protocol, packet_buf.as_mut()) {
match prepare(self.ip_protocol, packet_buf.as_mut()) {
Ok((ip_repr, raw_repr)) => {
net_trace!("[{}]:{}:{}: sending {} octets",
self.debug_id, self.ip_version, self.ip_protocol,
@ -240,7 +239,7 @@ impl<'a> IpPayload for RawRepr<'a> {
#[cfg(test)]
mod test {
use wire::{IpAddress, Ipv4Address, IpRepr, Ipv4Repr};
use wire::{Ipv4Address, IpRepr, Ipv4Repr};
use super::*;
fn buffer(packets: usize) -> SocketBuffer<'static, 'static> {
@ -292,7 +291,7 @@ mod test {
let mut socket = socket(buffer(0), buffer(1));
assert!(socket.can_send());
assert_eq!(socket.dispatch(0, &limits, &mut |ip_repr, ip_payload| {
assert_eq!(socket.dispatch(0, &limits, &mut |_ip_repr, _ip_payload| {
unreachable!()
}), Err(Error::Exhausted) as Result<()>);
@ -333,7 +332,7 @@ mod test {
Ipv4Packet::new(&mut wrong_version).set_version(5);
assert_eq!(socket.send_slice(&wrong_version[..]), Ok(()));
assert_eq!(socket.dispatch(0, &limits, &mut |ip_repr, ip_payload| {
assert_eq!(socket.dispatch(0, &limits, &mut |_ip_repr, _ip_payload| {
unreachable!()
}), Err(Error::Rejected) as Result<()>);
@ -341,7 +340,7 @@ mod test {
Ipv4Packet::new(&mut wrong_protocol).set_protocol(IpProtocol::Tcp);
assert_eq!(socket.send_slice(&wrong_protocol[..]), Ok(()));
assert_eq!(socket.dispatch(0, &limits, &mut |ip_repr, ip_payload| {
assert_eq!(socket.dispatch(0, &limits, &mut |_ip_repr, _ip_payload| {
unreachable!()
}), Err(Error::Rejected) as Result<()>);
}

View File

@ -236,9 +236,7 @@ impl<'a> IpPayload for UdpRepr<'a> {
#[cfg(test)]
mod test {
use std::vec::Vec;
use wire::{IpAddress, Ipv4Address, IpRepr, Ipv4Repr, UdpRepr};
use socket::AsSocket;
use super::*;
fn buffer(packets: usize) -> SocketBuffer<'static, 'static> {
@ -294,7 +292,7 @@ mod test {
fn test_send_unaddressable() {
let mut socket = socket(buffer(0), buffer(1));
assert_eq!(socket.send_slice(b"abcdef", REMOTE_END), Err(Error::Unaddressable));
socket.bind(LOCAL_PORT);
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
assert_eq!(socket.send_slice(b"abcdef",
IpEndpoint { addr: IpAddress::Unspecified, ..REMOTE_END }),
Err(Error::Unaddressable));
@ -307,7 +305,8 @@ mod test {
#[test]
fn test_send_truncated() {
let mut socket = socket(buffer(0), buffer(1));
socket.bind(LOCAL_END);
assert_eq!(socket.bind(LOCAL_END), Ok(()));
assert_eq!(socket.send_slice(&[0; 32][..], REMOTE_END), Err(Error::Truncated));
}
@ -316,10 +315,10 @@ mod test {
let limits = DeviceLimits::default();
let mut socket = socket(buffer(0), buffer(1));
socket.bind(LOCAL_END);
assert_eq!(socket.bind(LOCAL_END), Ok(()));
assert!(socket.can_send());
assert_eq!(socket.dispatch(0, &limits, &mut |ip_repr, ip_payload| {
assert_eq!(socket.dispatch(0, &limits, &mut |_ip_repr, _ip_payload| {
unreachable!()
}), Err(Error::Exhausted) as Result<()>);
@ -367,13 +366,14 @@ mod test {
#[test]
fn test_recv_process() {
let mut socket = socket(buffer(1), buffer(0));
socket.bind(LOCAL_PORT);
assert!(!socket.can_recv());
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
let mut buffer = vec![0; REMOTE_UDP_REPR.buffer_len()];
REMOTE_UDP_REPR.emit(&mut UdpPacket::new(&mut buffer), &LOCAL_IP, &REMOTE_IP);
assert!(!socket.can_recv());
assert_eq!(socket.recv(), Err(Error::Exhausted));
assert_eq!(socket.process(0, &REMOTE_IP_REPR, &buffer),
Ok(()));
assert!(socket.can_recv());
@ -387,7 +387,7 @@ mod test {
#[test]
fn test_recv_truncated_slice() {
let mut socket = socket(buffer(1), buffer(0));
socket.bind(LOCAL_PORT);
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
let mut buffer = vec![0; REMOTE_UDP_REPR.buffer_len()];
REMOTE_UDP_REPR.emit(&mut UdpPacket::new(&mut buffer), &LOCAL_IP, &REMOTE_IP);
@ -401,7 +401,7 @@ mod test {
#[test]
fn test_recv_truncated_packet() {
let mut socket = socket(buffer(1), buffer(0));
socket.bind(LOCAL_PORT);
assert_eq!(socket.bind(LOCAL_PORT), Ok(()));
let udp_repr = UdpRepr { payload: &[0; 100][..], ..REMOTE_UDP_REPR };
let mut buffer = vec![0; udp_repr.buffer_len()];