Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/multicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn main() {
}

let socket = sockets.get_mut::<udp::Socket>(udp_handle);
if !socket.is_open() {
if !socket.is_bound() {
socket.bind(MDNS_PORT).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn main() {

// udp:6969: respond "hello"
let socket = sockets.get_mut::<udp::Socket>(udp_handle);
if !socket.is_open() {
if !socket.is_bound() {
socket.bind(6969).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/sixlowpan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn main() {

// udp:6969: respond "hello"
let socket = sockets.get_mut::<udp::Socket>(udp_handle);
if !socket.is_open() {
if !socket.is_bound() {
socket.bind(6969).unwrap()
}

Expand Down
19 changes: 10 additions & 9 deletions src/socket/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,16 +745,12 @@ impl<'a> Socket<'a> {
/// Start listening on the given endpoint.
///
/// This function returns `Err(Error::Illegal)` if the socket was already open
/// (see [is_open](#method.is_open)), and `Err(Error::Unaddressable)`
/// if the port in the given endpoint is zero.
/// (see [is_open](#method.is_open)).
pub fn listen<T>(&mut self, local_endpoint: T) -> Result<(), ListenError>
where
T: Into<IpListenEndpoint>,
{
let local_endpoint = local_endpoint.into();
if local_endpoint.port == 0 {
return Err(ListenError::Unaddressable);
}

if self.is_open() {
return Err(ListenError::InvalidState);
Expand Down Expand Up @@ -1349,7 +1345,9 @@ impl<'a> Socket<'a> {
Some(addr) => ip_repr.dst_addr() == addr,
None => true,
};
addr_ok && repr.dst_port != 0 && repr.dst_port == self.listen_endpoint.port
addr_ok
&& repr.dst_port != 0
&& (self.listen_endpoint.port == 0 || repr.dst_port == self.listen_endpoint.port)
}
}

Expand Down Expand Up @@ -1868,7 +1866,10 @@ impl<'a> Socket<'a> {
let assembler_was_empty = self.assembler.is_empty();

// Try adding payload octets to the assembler.
let Ok(contig_len) = self.assembler.add_then_remove_front(payload_offset, payload_len) else {
let Ok(contig_len) = self
.assembler
.add_then_remove_front(payload_offset, payload_len)
else {
net_debug!(
"assembler: too many holes to add {} octets at offset {}",
payload_len,
Expand Down Expand Up @@ -2895,9 +2896,9 @@ mod test {
}

#[test]
fn test_listen_validation() {
fn test_listen_any_port() {
let mut s = socket();
assert_eq!(s.listen(0), Err(ListenError::Unaddressable));
assert_eq!(s.listen(0), Ok(()));
}

#[test]
Expand Down
Loading