Skip to content

Commit 4ec7394

Browse files
tunnellnia-e
andcommitted
std/sys/net/xous: read NetError code from byte 4 in recv/accept paths
`respond_with_error` in xous-core's `services/net/src/std_glue.rs` writes the `NetError` code at byte 4 of the 8-byte response buffer. The send path in `tcpstream.rs::write` correctly reads `send_request.raw[4]`. The recv-side decoders, however, read `result[1]` / `raw[1]`, which under the historical `[1, 1, 1, 1, code, 0, 0, 0]` layout is always `1` — so `ErrorKind::TimedOut` and `ErrorKind::WouldBlock` were unreachable from the recv side. Three files affected, identical pattern: - `tcpstream.rs::read_or_peek` (recv decode) - `udp.rs` (UDP recv decode) - `tcplistener.rs` (accept decode) Each `result[1]` / `raw[1]` becomes `result[4]` / `raw[4]`, matching the send path. Behavior is unchanged for any kernel that respects the existing 8-byte error layout. A complementary kernel-side change in betrusted-io/xous-core (betrusted-io/xous-core#877) mirrors the code at byte 1 too, so existing toolchain versions also see the right value immediately. The two changes are non- conflicting. Co-authored-by: Nia <nia-e@haecceity.cc>
1 parent 99eed20 commit 4ec7394

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

library/std/src/sys/net/connection/xous/tcplistener.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,13 @@ impl TcpListener {
129129
0,
130130
) {
131131
if receive_request.raw[0] != 0 {
132-
// error case
133-
if receive_request.raw[1] == NetError::TimedOut as u8 {
132+
// Error case — code lives at byte 4 (where the send path
133+
// also reads it). Byte 1 is part of the marker header.
134+
if receive_request.raw[4] == NetError::TimedOut as u8 {
134135
return Err(io::const_error!(io::ErrorKind::TimedOut, "accept timed out"));
135-
} else if receive_request.raw[1] == NetError::WouldBlock as u8 {
136+
} else if receive_request.raw[4] == NetError::WouldBlock as u8 {
136137
return Err(io::const_error!(io::ErrorKind::WouldBlock, "accept would block"));
137-
} else if receive_request.raw[1] == NetError::LibraryError as u8 {
138+
} else if receive_request.raw[4] == NetError::LibraryError as u8 {
138139
return Err(io::const_error!(io::ErrorKind::Other, "library error"));
139140
} else {
140141
return Err(io::const_error!(io::ErrorKind::Other, "library error"));

library/std/src/sys/net/connection/xous/tcpstream.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,14 @@ impl TcpStream {
213213
} else {
214214
let result = receive_request.raw;
215215
if result[0] != 0 {
216-
if result[1] == 8 {
216+
// The error code lives at byte 4 of the kernel's response buffer
217+
// (matches the byte the send path reads in `write` below). Byte 1
218+
// is part of the marker header, not the code.
219+
if result[4] == 8 {
217220
// timed out
218221
return Err(io::const_error!(io::ErrorKind::TimedOut, "timeout"));
219222
}
220-
if result[1] == 9 {
223+
if result[4] == 9 {
221224
// would block
222225
return Err(io::const_error!(io::ErrorKind::WouldBlock, "would block"));
223226
}

library/std/src/sys/net/connection/xous/udp.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ impl UdpSocket {
145145
0,
146146
) {
147147
if receive_request.raw[0] != 0 {
148-
// error case
149-
if receive_request.raw[1] == NetError::TimedOut as u8 {
148+
// Error case — code lives at byte 4 (where `send_message`
149+
// also reads it). Byte 1 is part of the marker header.
150+
if receive_request.raw[4] == NetError::TimedOut as u8 {
150151
return Err(io::const_error!(io::ErrorKind::TimedOut, "recv timed out"));
151-
} else if receive_request.raw[1] == NetError::WouldBlock as u8 {
152+
} else if receive_request.raw[4] == NetError::WouldBlock as u8 {
152153
return Err(io::const_error!(io::ErrorKind::WouldBlock, "recv would block"));
153-
} else if receive_request.raw[1] == NetError::LibraryError as u8 {
154+
} else if receive_request.raw[4] == NetError::LibraryError as u8 {
154155
return Err(io::const_error!(io::ErrorKind::Other, "library error"));
155156
} else {
156157
return Err(io::const_error!(io::ErrorKind::Other, "library error"));

0 commit comments

Comments
 (0)