Skip to content

Commit 1561b2c

Browse files
fjtrujyclaude
andcommitted
fix: [udptty] return size from udp_send for pre-link-up writes
lwIP 2.2.1 correctly fails lwip_sendto() with EHOSTUNREACH if it is called before the SMAP driver reports NETIF_FLAG_LINK_UP (~3 s into boot), because ip4_route() needs link state to pick a netif. udptty's udp_send() ignored the lwip_sendto() return and unconditionally returned 0 — so when the IOP stdio layer interpreted that as "0 bytes written" it retried the write forever, hanging the loader. Report `size` instead so the caller treats the data as consumed (silently dropped on the wire when there's no route yet, written normally once link comes up). Independent of any 2.2.1-specific behaviour: 0 was always the wrong return value for a successful no-op. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 586784c commit 1561b2c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

iop/network/udptty/src/udptty.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int _start(int argc, char *argv[])
205205

206206
close(0);
207207
open(DEVNAME "00:", 0x1000 | O_RDWR);
208-
208+
209209
close(1);
210210
open(DEVNAME "00:", O_WRONLY);
211211

@@ -230,7 +230,9 @@ int _shutdown()
230230
}
231231

232232
/* Copy the data into place, calculate the various checksums, and send the
233-
final packet. */
233+
final packet. Always reports `size` bytes consumed, even when the UDP
234+
send fails (e.g. before SMAP has reported link-up): otherwise the IOP's
235+
stdio layer retries on a short write and ends up in an infinite loop. */
234236
static int udp_send(void *buf, size_t size)
235237
{
236238
struct sockaddr_in peer;
@@ -241,7 +243,7 @@ static int udp_send(void *buf, size_t size)
241243

242244
lwip_sendto(udp_socket, buf, size, 0, (struct sockaddr *)&peer, sizeof(peer));
243245

244-
return 0;
246+
return (int)size;
245247
}
246248

247249
/* TTY driver. */

0 commit comments

Comments
 (0)