Skip to content

m65common: non-blocking TCP reads on macOS (fixes tcp# hang) - #248

Open
silent-command wants to merge 1 commit into
MEGA65:developmentfrom
silent-command:macos-tcp-nonblocking-read
Open

silent-command wants to merge 1 commit into
MEGA65:developmentfrom
silent-command:macos-tcp-nonblocking-read

Conversation

@silent-command

Copy link
Copy Markdown

Problem

On macOS, m65.osx and mega65_ftp.osx hang right after connecting when the port is TCP (-l tcp#host:port), whatever the server. With Xemu, for example:

xmega65 -uartmon :4510 &
m65.osx -l tcp#127.0.0.1:4510 -S0    # prints the version banner, then never returns

Cause

do_serial_port_read() passes MSG_DONTWAIT to recv() on Linux but 0 on macOS (since 0b83e95, "get m65 working over tcp on linux"). Nothing else makes the socket non-blocking on macOS. Callers such as purge_input(), reached from rxbuff_detect() and monitor_sync() straight after the port is opened, read until nothing is left, so the first read with no data waiting blocks forever.

Fix

Use MSG_DONTWAIT on macOS too; macOS supports it. Linux behaviour is unchanged, and Windows has its own read path (FIONREAD first) and isn't touched.

Testing

On macOS (Apple silicon), built from this branch:

  • Xemu (xmega65 -headless -uartmon :4510): before, m65.osx -l tcp#127.0.0.1:4510 -S0 hung and was killed after 15 s; after, it returns the screen (READY.).
  • A real MEGA65 reached through a small TCP-to-serial bridge on a Raspberry Pi: -S0 screenshots work over tcp#, where the stock build hung the same way.

🤖 Generated with Claude Code

do_serial_port_read() passed MSG_DONTWAIT to recv() everywhere except
macOS, where the read blocked. Callers such as purge_input() read until
nothing is left, so over tcp# m65.osx and mega65_ftp.osx hang right
after connecting (m65.osx -l tcp#host:4510 -S0 stops after the Xemu
check), whatever the server. macOS supports MSG_DONTWAIT; use it on
both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant