Repository navigation
Fix Windows peer clock consensus and Central coexistence (#212) - #214
Merged
Merged
Conversation
Peer clock consensus never ran on Windows: the peer config reader was a stub, so an NSP never borrowed a HUB's offset and NSP/HUB1-3 never voted. Replace it with cbshm::NativeConfigReader, a cross-platform read-only mapping of a peer's NATIVE config segment that shares the owner-liveness check with ShmemSession and rejects segments from another config layout. Consensus now also drops a peer's mapping once its owner exits, so a restarted peer is picked up again. Central CLIENT attach hardcoded 7.8's instrument slots (NSP = 3), which overran Central 7.7's three slots and rejected every Gemini NSP (#210). The slot table now follows the running Central's version, taken from CentralDlg.cpp at each release tag: 7.5 NSP=0/HUB1=1; 7.6-7.7 HUB1=0, HUB2=1, NSP=2; 7.8 HUB1-3=0-2, NSP=3. Under 7.7 a HUB3 session used to attach to slot 2 and silently serve the NSP's config. When Central is running and has a slot for the device, a failed attach is now an error instead of falling through to STANDALONE, which would compete with Central for the device. On Windows the device and probe sockets use SO_EXCLUSIVEADDRUSE instead of SO_REUSEADDR, so Central can no longer bind a port an active STANDALONE session owns. The device bind error now reports the Winsock error and the address actually bound. The send thread's idle poll was a QPC busy-wait, keeping a core fully busy for the life of every STANDALONE session on Windows. It now blocks on a high-resolution waitable timer: ~101% -> ~1% of a core with simple_device. Fixes #212 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 6, 2026
Talk to the device directly by default, alongside Central; deprecate Central-compat mode (#213)
#215
Merged
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.
Fixes #212. Addresses the CereLink side of #210.
Changes
Peer clock consensus on Windows. The peer config reader was a stub on Windows, so an NSP never borrowed a HUB's clock offset and the NSP/HUB median vote never happened. It's replaced by
cbshm::NativeConfigReader(cbshm/native_peer.h):isProcessAlive()withShmemSession::isOwnerAlive();Central instrument slots are per version. CereLink hardcoded 7.8's slots (NSP = 3). That overran Central 7.7's three slots, so every Gemini NSP attach on 7.7 was rejected. The table now comes from
CentralDlg.cppat each release tag:A legacy NSP is slot 0 on every version.
No STANDALONE fall-through while Central owns the device. If
Central.exeis running and has a slot for the device, a failed CENTRAL attach (or an undetectable Central version) is now an error. Devices that this Central never connects to (NPLAY, or HUB3 before 7.8) still take the NATIVE path.Exclusive device/probe ports on Windows.
SO_EXCLUSIVEADDRUSEreplacesSO_REUSEADDRon Windows; POSIX is unchanged. The device bind error now reports the Winsock error and the address actually bound.Send-thread idle poll no longer spins. The QPC busy-wait kept one core fully busy for the life of every STANDALONE session on Windows. It now blocks on a high-resolution waitable timer, falling back to
Sleep(1).Docs describing the old fixed slot mapping are updated.
Bench results (Windows 10, Gemini NSP + HUB1 + HUB2), master vs this branch
Run twice: with Central 7.7.0 and its firmware, then again with Central 7.8.0 and the 7.8 firmware.
simple_device NPLAYCPUFailed to bind probe socket (winsock err 10013)(#210)With only the NSP open, its own clock estimate on the 7.8 firmware was up to ~190 ms off. That's the NSP's coarse probe-reply timestamps. Consensus corrects it only when hub sessions are also running.
Central exiting when CereLink owns the device
This is expected: a STANDALONE session owns the device, so Central can't take it. Central doesn't handle the bind failure gracefully: it crashes (0xc0000005) on both 7.7 and 7.8. In the
GEMSTART == 2block, a failedOpen()NULLsm_icInstrument[idx]without marking the slotNSP_NOIPADDR. That's Central's behaviour and not something CereLink needs to work around. The alternative, deliberately coexisting with Central, is explored in #213.How the #210 asymmetry happened
DeviceSession::create()binds0.0.0.0(it resolves the client address but binds the caller's empty one), while the protocol probe binds the resolved192.168.137.199. Central binds that same specific address withoutSO_REUSEADDR. The probe'sSO_REUSEADDRrebind is refused with 10013, but Windows lets the wildcard device socket coexist. This PR leaves the0.0.0.0bind alone, because changing it affects Linux broadcast reception and NPLAY loopback. Details in #213.Tests
NativeConfigReaderTest.*andProcessLiveness.*drive the real reader against a real STANDALONE segment. The old multidevice test replicated the voting logic, so it passed on Windows despite the stub.CentralInstrumentIndex.*checks the per-version table, and that every slot fits that version'sgetMaxProcs()(the check that failed in Using Cerelink together with Central on the same Windows computer does not always work #210).DeviceSessionTest.Windows_*tests. WithSO_REUSEADDRrestored,Windows_PortIsExclusiveWhileSessionIsActivefails because a plain bind of the same port succeeds, which is the Using Cerelink together with Central on the same Windows computer does not always work #210 situation.Not yet run: Linux/macOS builds (CI, plus a Mac test before merge).
🤖 Generated with Claude Code