Remove braces that were previously needed to workaround SocketRef borrow issues.
parent
f8cc1eacbe
commit
8c43fdd443
|
@ -119,7 +119,6 @@ fn main() {
|
|||
}
|
||||
|
||||
// tcp:1234: emit data
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp1_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(1234).unwrap();
|
||||
|
@ -136,10 +135,8 @@ fn main() {
|
|||
processed += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tcp:1235: sink data
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp2_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(1235).unwrap();
|
||||
|
@ -156,7 +153,6 @@ fn main() {
|
|||
processed += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match iface.poll_at(timestamp) {
|
||||
Some(poll_at) if timestamp < poll_at => {
|
||||
|
|
|
@ -54,10 +54,8 @@ fn main() {
|
|||
|
||||
let tcp_handle = iface.add_socket(tcp_socket);
|
||||
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp_handle);
|
||||
socket.connect((address, port), 49500).unwrap();
|
||||
}
|
||||
|
||||
let mut tcp_active = false;
|
||||
loop {
|
||||
|
@ -69,7 +67,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp_handle);
|
||||
if socket.is_active() && !tcp_active {
|
||||
debug!("connected");
|
||||
|
@ -106,7 +103,6 @@ fn main() {
|
|||
debug!("close");
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
|
||||
}
|
||||
|
|
|
@ -76,7 +76,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp_handle);
|
||||
|
||||
state = match state {
|
||||
|
@ -114,8 +113,7 @@ fn main() {
|
|||
break;
|
||||
}
|
||||
_ => state,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
|
||||
}
|
||||
|
|
|
@ -135,7 +135,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
let mut socket = iface.get_socket::<TcpSocket>(server_handle);
|
||||
if !socket.is_active() && !socket.is_listening() {
|
||||
if !did_listen {
|
||||
|
@ -153,9 +152,7 @@ fn main() {
|
|||
socket.close();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let mut socket = iface.get_socket::<TcpSocket>(client_handle);
|
||||
if !socket.is_open() {
|
||||
if !did_connect {
|
||||
|
@ -175,7 +172,6 @@ fn main() {
|
|||
socket.send_slice(b"0123456789abcdef").unwrap();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
match iface.poll_delay(clock.elapsed()) {
|
||||
Some(Duration::ZERO) => debug!("resuming"),
|
||||
|
|
|
@ -77,7 +77,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
let socket = iface.get_socket::<RawSocket>(raw_handle);
|
||||
|
||||
if socket.can_recv() {
|
||||
|
@ -91,8 +90,7 @@ fn main() {
|
|||
.map(|igmp_repr| println!("IGMP packet: {:?}", igmp_repr))
|
||||
.unwrap_or_else(|e| println!("Recv IGMP error: {:?}", e));
|
||||
}
|
||||
}
|
||||
{
|
||||
|
||||
let socket = iface.get_socket::<UdpSocket>(udp_handle);
|
||||
if !socket.is_open() {
|
||||
socket.bind(MDNS_PORT).unwrap()
|
||||
|
@ -106,7 +104,6 @@ fn main() {
|
|||
})
|
||||
.unwrap_or_else(|e| println!("Recv UDP error: {:?}", e));
|
||||
}
|
||||
}
|
||||
|
||||
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
|
||||
}
|
||||
|
|
|
@ -155,7 +155,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
let timestamp = Instant::now();
|
||||
let socket = iface.get_socket::<IcmpSocket>(icmp_handle);
|
||||
if !socket.is_open() {
|
||||
|
@ -210,8 +209,7 @@ fn main() {
|
|||
match remote_addr {
|
||||
IpAddress::Ipv4(_) => {
|
||||
let icmp_packet = Icmpv4Packet::new_checked(&payload).unwrap();
|
||||
let icmp_repr =
|
||||
Icmpv4Repr::parse(&icmp_packet, &device_caps.checksum).unwrap();
|
||||
let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &device_caps.checksum).unwrap();
|
||||
get_icmp_pong!(
|
||||
Icmpv4Repr,
|
||||
icmp_repr,
|
||||
|
@ -257,7 +255,6 @@ fn main() {
|
|||
if seq_no == count as u16 && waiting_queue.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let timestamp = Instant::now();
|
||||
match iface.poll_at(timestamp) {
|
||||
|
|
|
@ -80,7 +80,6 @@ fn main() {
|
|||
}
|
||||
|
||||
// udp:6969: respond "hello"
|
||||
{
|
||||
let socket = iface.get_socket::<UdpSocket>(udp_handle);
|
||||
if !socket.is_open() {
|
||||
socket.bind(6969).unwrap()
|
||||
|
@ -105,10 +104,8 @@ fn main() {
|
|||
);
|
||||
socket.send_slice(data, endpoint).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// tcp:6969: respond "hello"
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp1_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(6969).unwrap();
|
||||
|
@ -120,10 +117,8 @@ fn main() {
|
|||
debug!("tcp:6969 close");
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
// tcp:6970: echo with reverse
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp2_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(6970).unwrap()
|
||||
|
@ -164,10 +159,8 @@ fn main() {
|
|||
debug!("tcp:6970 close");
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
// tcp:6971: sinkhole
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp3_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(6971).unwrap();
|
||||
|
@ -187,10 +180,8 @@ fn main() {
|
|||
} else if socket.may_send() {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
// tcp:6972: fountain
|
||||
{
|
||||
let socket = iface.get_socket::<TcpSocket>(tcp4_handle);
|
||||
if !socket.is_open() {
|
||||
socket.listen(6972).unwrap()
|
||||
|
@ -209,7 +200,6 @@ fn main() {
|
|||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
|
||||
}
|
||||
|
|
|
@ -100,7 +100,6 @@ fn main() {
|
|||
}
|
||||
|
||||
// udp:6969: respond "hello"
|
||||
{
|
||||
let socket = iface.get_socket::<UdpSocket>(udp_handle);
|
||||
if !socket.is_open() {
|
||||
socket.bind(6969).unwrap()
|
||||
|
@ -125,7 +124,6 @@ fn main() {
|
|||
);
|
||||
socket.send_slice(data, endpoint).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
phy_wait(fd, iface.poll_delay(timestamp)).expect("wait error");
|
||||
}
|
||||
|
|
|
@ -2942,13 +2942,11 @@ mod test {
|
|||
hop_limit: 0x40,
|
||||
});
|
||||
|
||||
{
|
||||
// Bind the socket to port 68
|
||||
let socket = iface.get_socket::<UdpSocket>(socket_handle);
|
||||
assert_eq!(socket.bind(68), Ok(()));
|
||||
assert!(!socket.can_recv());
|
||||
assert!(socket.can_send());
|
||||
}
|
||||
|
||||
udp_repr.emit(
|
||||
&mut packet,
|
||||
|
@ -2968,7 +2966,6 @@ mod test {
|
|||
Ok(None)
|
||||
);
|
||||
|
||||
{
|
||||
// Make sure the payload to the UDP packet processed by process_udp is
|
||||
// appended to the bound sockets rx_buffer
|
||||
let socket = iface.get_socket::<UdpSocket>(socket_handle);
|
||||
|
@ -2978,7 +2975,6 @@ mod test {
|
|||
Ok((&UDP_PAYLOAD[..], IpEndpoint::new(src_ip.into(), 67)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "proto-ipv4")]
|
||||
|
@ -3194,10 +3190,8 @@ mod test {
|
|||
frame.set_dst_addr(EthernetAddress::BROADCAST);
|
||||
frame.set_src_addr(remote_hw_addr);
|
||||
frame.set_ethertype(EthernetProtocol::Arp);
|
||||
{
|
||||
let mut packet = ArpPacket::new_unchecked(frame.payload_mut());
|
||||
repr.emit(&mut packet);
|
||||
}
|
||||
|
||||
let cx = iface.context(Instant::from_secs(0));
|
||||
|
||||
|
@ -3255,7 +3249,6 @@ mod test {
|
|||
frame.set_dst_addr(EthernetAddress([0x33, 0x33, 0x00, 0x00, 0x00, 0x00]));
|
||||
frame.set_src_addr(remote_hw_addr);
|
||||
frame.set_ethertype(EthernetProtocol::Ipv6);
|
||||
{
|
||||
ip_repr.emit(frame.payload_mut(), &ChecksumCapabilities::default());
|
||||
solicit.emit(
|
||||
&remote_ip_addr.into(),
|
||||
|
@ -3263,7 +3256,6 @@ mod test {
|
|||
&mut Icmpv6Packet::new_unchecked(&mut frame.payload_mut()[ip_repr.buffer_len()..]),
|
||||
&ChecksumCapabilities::default(),
|
||||
);
|
||||
}
|
||||
|
||||
let icmpv6_expected = Icmpv6Repr::Ndisc(NdiscRepr::NeighborAdvert {
|
||||
flags: NdiscNeighborFlags::SOLICITED,
|
||||
|
@ -3326,10 +3318,8 @@ mod test {
|
|||
frame.set_dst_addr(EthernetAddress::BROADCAST);
|
||||
frame.set_src_addr(remote_hw_addr);
|
||||
frame.set_ethertype(EthernetProtocol::Arp);
|
||||
{
|
||||
let mut packet = ArpPacket::new_unchecked(frame.payload_mut());
|
||||
repr.emit(&mut packet);
|
||||
}
|
||||
|
||||
let cx = iface.context(Instant::from_secs(0));
|
||||
|
||||
|
@ -3442,11 +3432,9 @@ mod test {
|
|||
let seq_no = 0x5432;
|
||||
let echo_data = &[0xff; 16];
|
||||
|
||||
{
|
||||
let socket = iface.get_socket::<IcmpSocket>(socket_handle);
|
||||
// Bind to the ID 0x1234
|
||||
assert_eq!(socket.bind(IcmpEndpoint::Ident(ident)), Ok(()));
|
||||
}
|
||||
|
||||
// Ensure the ident we bound to and the ident of the packet are the same.
|
||||
let mut bytes = [0xff; 24];
|
||||
|
@ -3470,9 +3458,7 @@ mod test {
|
|||
|
||||
// Open a socket and ensure the packet is handled due to the listening
|
||||
// socket.
|
||||
{
|
||||
assert!(!iface.get_socket::<IcmpSocket>(socket_handle).can_recv());
|
||||
}
|
||||
|
||||
// Confirm we still get EchoReply from `smoltcp` even with the ICMP socket listening
|
||||
let echo_reply = Icmpv4Repr::EchoReply {
|
||||
|
@ -3493,7 +3479,6 @@ mod test {
|
|||
Ok(Some(IpPacket::Icmpv4((ipv4_reply, echo_reply))))
|
||||
);
|
||||
|
||||
{
|
||||
let socket = iface.get_socket::<IcmpSocket>(socket_handle);
|
||||
assert!(socket.can_recv());
|
||||
assert_eq!(
|
||||
|
@ -3504,7 +3489,6 @@ mod test {
|
|||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "proto-ipv6")]
|
||||
|
@ -3854,13 +3838,12 @@ mod test {
|
|||
let udp_tx_buffer = UdpSocketBuffer::new(vec![UdpPacketMetadata::EMPTY], vec![0; 15]);
|
||||
let udp_socket = UdpSocket::new(udp_rx_buffer, udp_tx_buffer);
|
||||
let udp_socket_handle = iface.add_socket(udp_socket);
|
||||
{
|
||||
|
||||
// Bind the socket to port 68
|
||||
let socket = iface.get_socket::<UdpSocket>(udp_socket_handle);
|
||||
assert_eq!(socket.bind(68), Ok(()));
|
||||
assert!(!socket.can_recv());
|
||||
assert!(socket.can_send());
|
||||
}
|
||||
|
||||
let packets = 1;
|
||||
let raw_rx_buffer =
|
||||
|
@ -3927,7 +3910,6 @@ mod test {
|
|||
Ok(None)
|
||||
);
|
||||
|
||||
{
|
||||
// Make sure the UDP socket can still receive in presence of a Raw socket that handles UDP
|
||||
let socket = iface.get_socket::<UdpSocket>(udp_socket_handle);
|
||||
assert!(socket.can_recv());
|
||||
|
@ -3936,5 +3918,4 @@ mod test {
|
|||
Ok((&UDP_PAYLOAD[..], IpEndpoint::new(src_addr.into(), 67)))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue