Repository navigation
Initialize Winsock before the host transports open a socket - #213
Merged
Merged
Conversation
This was referenced Oct 27, 2026
chrisuthe
marked this pull request as ready for review
October 27, 2026 04:27
This was referenced Oct 27, 2026
kahrendt
added a commit
that referenced
this pull request
Nov 4, 2026
Depends on #213 (Winsock init): this branch is stacked on it, and `basic_client` cannot dial or listen on Windows without it. Review only the top commit; the base switches to `main` once #213 merges. ## Summary - **PortAudio on Windows.** Windows has no pkg-config or system PortAudio, so `examples/basic_client/CMakeLists.txt` fetches PortAudio v19.7.0 on `WIN32` and builds it as a static library. POSIX keeps the pkg-config lookup. - **`getopt()` for Windows.** `examples/common/win_getopt.h` is a minimal stand-in for the missing one. It covers grouped flags, `-x val` / `-xval`, and stops at the first non-option or `--`. Errors return `?` without a message, since the example prints its usage on that. - **The pairing-window gesture.** Console keys `p` / `c` stand in for `SIGUSR1` / `SIGUSR2`. A single `#ifdef _WIN32` block defines the key poll (a no-op on POSIX) and the hint strings, so the usage text and the pairing-window prompt name the right gesture on each platform. - **Persistence.** The provider writes through `_open` / `_write` / `_commit` and replaces the file with `std::filesystem::rename()`, because `std::rename()` won't replace an existing file on Windows. It falls back to `%USERPROFILE%` when `HOME` is unset. Each `write_file()` variant has its own doc comment. - **README.** `examples/basic_client/README.md` gets a Windows section covering the build, no mDNS (so dial with `-u`), the `p`/`c` keys, and the persistence file's permissions. - **The default build.** `tui_client` includes POSIX `<getopt.h>`, so the top-level `CMakeLists.txt` skips it on `WIN32` with a status message, the way `source_client` already skips itself without PortAudio. A standalone Windows build with the examples on (the default) now succeeds. - **CRT warnings.** `basic_client` defines `_CRT_SECURE_NO_WARNINGS` on `WIN32`, since the persistence provider's `getenv()` and `_open()` otherwise draw deprecation warnings pointing at `_dupenv_s` / `_sopen_s`. ## Notes - The persistence file can't be created 0600 on Windows. It inherits its directory's ACL, which under `%USERPROFILE%` grants only the user, SYSTEM and Administrators. - `tui_client`, `source_client` and the tests remain POSIX-only. The top-level README's "macOS/Linux" wording is left alone, since #210 deferred the library's Windows support scope. - Split out of #211. ## Testing - Windows 11, clang-cl 22.1.3 (Visual Studio 2026, Ninja, Release), from #211: `sendspin` and `basic_client` built with no warnings from the library's own sources. `basic_client.exe -p 8929 -u ws://<music-assistant>:8927/sendspin` completed the Noise handshake, was admitted (unpaired) and listened locally. Pairing and playback were not exercised. - Windows 11, clang-cl (Visual Studio 2026, Ninja), on this branch: a clean configure and build with the default `BUILD_EXAMPLES` succeeds, skipping `tui_client` and `source_client`, with no warnings from the repo's own sources. `basic_client.exe -h` names the `p`/`c` keys, an unknown option prints the usage, and `basic_client.exe -p 8931` starts and listens on 8931. - The trimmed `win_getopt.h` was checked on Linux against `basic_client`'s optstring: grouped flags, `-pVAL`, `-p VAL`, `--`, a lone `-`, an unknown option, a missing argument and `-:`. - Linux, GCC 16: host build including the examples is clean, and `sendspin_tests` passes 705/705. The sanitizer runs are this PR's CI. --------- Co-authored-by: Kevin Ahrendt <[email protected]>
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.
On Windows every socket call fails until
WSAStartup()runs, and IXWebSocket leaves that to the application throughix::initNetSystem(). The client could neither dial a server ("Either the application has not called WSAStartup") nor listen.Summary
SendspinWsServer::start()andSendspinClientConnection::start()callix::initNetSystem()once, through a function-local static, before their first socket. It is never undone; Windows releases it at process exit.start()returns a bool, so it logs and returns false. The client'sstart()has no failure return, so it logs and lets the attempt go ahead; its first socket call then fails and IXWebSocket reports it as the connection'sError, which already reports the close.Notes
initNetSystem()returns true without doing anything there).Testing
basic_clientdials Music Assistant with-uand listens on its own port; before this change both failed with the WSAStartup error.sendspin_testsall pass. The ASan/UBSan and TSan runs are this PR's CI (no sanitizer runtime on the local machine).