mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
fix timeouts, peek
- timeouts were being overwritten before they were read - peek now behaves according to what the test bench expects
This commit is contained in:
parent
32e78039b7
commit
495ca1e2b7
1 changed files with 44 additions and 11 deletions
|
|
@ -153,6 +153,7 @@ pub(crate) fn std_tcp_rx(
|
||||||
iface: &mut Interface::<NetPhy>,
|
iface: &mut Interface::<NetPhy>,
|
||||||
tcp_rx_waiting: &mut Vec<Option<WaitingSocket>>,
|
tcp_rx_waiting: &mut Vec<Option<WaitingSocket>>,
|
||||||
our_sockets: &Vec<Option<SocketHandle>>,
|
our_sockets: &Vec<Option<SocketHandle>>,
|
||||||
|
nonblocking: bool,
|
||||||
) {
|
) {
|
||||||
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
||||||
let body = match msg.body.memory_message_mut() {
|
let body = match msg.body.memory_message_mut() {
|
||||||
|
|
@ -162,6 +163,9 @@ pub(crate) fn std_tcp_rx(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let expiry = body
|
||||||
|
.offset
|
||||||
|
.map(|x| unsafe { NonZeroU64::new_unchecked(x.get() as u64 + timer.elapsed_ms()) });
|
||||||
|
|
||||||
// Offset is used as a flag to indicate an error. `None` means an error occured. `Some` means no error.
|
// Offset is used as a flag to indicate an error. `None` means an error occured. `Some` means no error.
|
||||||
body.offset = None;
|
body.offset = None;
|
||||||
|
|
@ -177,7 +181,12 @@ pub(crate) fn std_tcp_rx(
|
||||||
let socket = iface.get_socket::<TcpSocket>(*handle);
|
let socket = iface.get_socket::<TcpSocket>(*handle);
|
||||||
if socket.can_recv() {
|
if socket.can_recv() {
|
||||||
log::debug!("receiving data right away");
|
log::debug!("receiving data right away");
|
||||||
match socket.recv_slice(body.buf.as_slice_mut()) {
|
let buflen = if let Some(valid) = body.valid {
|
||||||
|
valid.get()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
match socket.recv_slice(&mut body.buf.as_slice_mut()[..buflen]) {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
// it's actually valid to receive 0 bytes, but the encoding of this field doesn't allow it.
|
// it's actually valid to receive 0 bytes, but the encoding of this field doesn't allow it.
|
||||||
// so, `None` is abused to represent the value of "0" bytes, which is what is naturally returned
|
// so, `None` is abused to represent the value of "0" bytes, which is what is naturally returned
|
||||||
|
|
@ -193,14 +202,18 @@ pub(crate) fn std_tcp_rx(
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if nonblocking {
|
||||||
|
respond_with_error(msg, NetError::WouldBlock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log::debug!("socket was not able to receive, adding it to list of waiting messages");
|
log::debug!("socket was not able to receive, adding it to list of waiting messages");
|
||||||
|
|
||||||
// Add the message to the TcpRxWaiting list, which will prevent it from getting
|
// Add the message to the TcpRxWaiting list, which will prevent it from getting
|
||||||
// responded to right away.
|
// responded to right away.
|
||||||
let expiry = body
|
if expiry.is_some() {
|
||||||
.offset
|
log::debug!("read with timeout set: {:?}", expiry);
|
||||||
.map(|x| unsafe { NonZeroU64::new_unchecked(x.get() as u64 + timer.elapsed_ms()) });
|
}
|
||||||
insert_or_append(
|
insert_or_append(
|
||||||
tcp_rx_waiting,
|
tcp_rx_waiting,
|
||||||
WaitingSocket {
|
WaitingSocket {
|
||||||
|
|
@ -213,8 +226,11 @@ pub(crate) fn std_tcp_rx(
|
||||||
|
|
||||||
pub(crate) fn std_tcp_peek(
|
pub(crate) fn std_tcp_peek(
|
||||||
mut msg: xous::MessageEnvelope,
|
mut msg: xous::MessageEnvelope,
|
||||||
|
timer: &Ticktimer,
|
||||||
iface: &mut Interface::<NetPhy>,
|
iface: &mut Interface::<NetPhy>,
|
||||||
our_sockets: &Vec<Option<SocketHandle>>,
|
our_sockets: &Vec<Option<SocketHandle>>,
|
||||||
|
tcp_peek_waiting: &mut Vec<Option<WaitingSocket>>,
|
||||||
|
nonblocking: bool,
|
||||||
) {
|
) {
|
||||||
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
let connection_handle_index = (msg.body.id() >> 16) & 0xffff;
|
||||||
let body = match msg.body.memory_message_mut() {
|
let body = match msg.body.memory_message_mut() {
|
||||||
|
|
@ -224,6 +240,9 @@ pub(crate) fn std_tcp_peek(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let expiry = body
|
||||||
|
.offset
|
||||||
|
.map(|x| unsafe { NonZeroU64::new_unchecked(x.get() as u64 + timer.elapsed_ms()) });
|
||||||
|
|
||||||
// Offset is used to indicate an error. None=>Error, Some=>no error
|
// Offset is used to indicate an error. None=>Error, Some=>no error
|
||||||
body.offset = None;
|
body.offset = None;
|
||||||
|
|
@ -238,8 +257,13 @@ pub(crate) fn std_tcp_peek(
|
||||||
|
|
||||||
let socket = iface.get_socket::<TcpSocket>(*handle);
|
let socket = iface.get_socket::<TcpSocket>(*handle);
|
||||||
if socket.can_recv() {
|
if socket.can_recv() {
|
||||||
log::trace!("receiving data right away");
|
log::debug!("peeking data right away");
|
||||||
match socket.peek_slice(body.buf.as_slice_mut()) {
|
let buflen = if let Some(valid) = body.valid {
|
||||||
|
valid.get()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
match socket.peek_slice(&mut body.buf.as_slice_mut()[..buflen]) {
|
||||||
Ok(bytes) => {
|
Ok(bytes) => {
|
||||||
// it's actually valid to receive 0 bytes, but the encoding of this field doesn't allow it.
|
// it's actually valid to receive 0 bytes, but the encoding of this field doesn't allow it.
|
||||||
// so, `None` is abused to represent the value of "0" bytes, which is what is naturally returned
|
// so, `None` is abused to represent the value of "0" bytes, which is what is naturally returned
|
||||||
|
|
@ -254,11 +278,20 @@ pub(crate) fn std_tcp_peek(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No data available, so indicate `None`
|
if nonblocking {
|
||||||
body.valid = None;
|
respond_with_error(msg, NetError::WouldBlock);
|
||||||
// Also indicate no error
|
} else {
|
||||||
body.offset = xous::MemoryAddress::new(1);
|
// Add the message to the TcpRxWaiting list, which will prevent it from getting
|
||||||
body.buf.as_slice_mut::<u32>()[0] = 0;
|
// responded to right away.
|
||||||
|
insert_or_append(
|
||||||
|
tcp_peek_waiting,
|
||||||
|
WaitingSocket {
|
||||||
|
env: msg,
|
||||||
|
handle: *handle,
|
||||||
|
expiry,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue