Repository navigation
m65common: non-blocking TCP reads on macOS (fixes tcp# hang) - #248
Open
silent-command wants to merge 1 commit into
Open
silent-command wants to merge 1 commit into
silent-command wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On macOS,
m65.osxandmega65_ftp.osxhang right after connecting when the port is TCP (-l tcp#host:port), whatever the server. With Xemu, for example:Cause
do_serial_port_read()passesMSG_DONTWAITtorecv()on Linux but0on macOS (since 0b83e95, "get m65 working over tcp on linux"). Nothing else makes the socket non-blocking on macOS. Callers such aspurge_input(), reached fromrxbuff_detect()andmonitor_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_DONTWAITon macOS too; macOS supports it. Linux behaviour is unchanged, and Windows has its own read path (FIONREADfirst) and isn't touched.Testing
On macOS (Apple silicon), built from this branch:
xmega65 -headless -uartmon :4510): before,m65.osx -l tcp#127.0.0.1:4510 -S0hung and was killed after 15 s; after, it returns the screen (READY.).-S0screenshots work overtcp#, where the stock build hung the same way.🤖 Generated with Claude Code