Skip to content

Modernize sockets to Network.framework#50

Draft
ccahoon wants to merge 8 commits into
mainfrom
nw-modernization
Draft

Modernize sockets to Network.framework#50
ccahoon wants to merge 8 commits into
mainfrom
nw-modernization

Conversation

@ccahoon
Copy link
Copy Markdown
Contributor

@ccahoon ccahoon commented May 28, 2026

DO NOT MERGE. proof it's possible and for reference.

i did not watch every line get written on this, but guided many choices and drove test implementation and parity audits with the new swift implementation

The commit message has a lot of details

Replaces the vendored CocoaAsyncSocket stack with nw_* primitives across
F53OSCSocket, F53OSCBrowser, and F53OSCServer. F53OSCClient is unchanged
on the public surface.

Cribbed from F53OSC-Swift:
- Vectorized SLIP encoder and decoder. ~6x encode, ~2.3x decode on typical
  OSC payloads, validated by a paired legacy/vectorized A/B benchmark in
  F53OSC_CodecBenchmark. 1.1x near-parity on adversarial high-density-
  specials input, confirming no regression on worst-case payloads.
- SLIP 16 MB frame-size guard with reset-on-overflow.
- nw_browser-based service discovery, replacing the deprecated
  NSNetServiceBrowser path.
- F53OSCStats lock-free atomic counters (no more @synchronized).
- Tests adapted from the Swift suite. Each header carries an attribution
  comment naming the source file and pinned revision.
    F53OSC_ThroughputTests       <- OSCThroughputTests.swift
    F53OSC_StatsTests            <- OSCStatsTests.swift
    F53OSC_SLIPRoundtripTests    <- SLIPFramingTests.swift
    F53OSC_UDPFlowTests          <- OSCServerUDPFlowTests.swift

Behavior parity additions:
- connectTimeout property on F53OSCClient and F53OSCSocket (default 30s).
- tcpIdleTimeout property on F53OSCServer, sharing the UDP-flow sweep
  timer for unified idle-connection cleanup.
- Interface binding by name via nw_path_monitor lookup.
- Port-0 bind-back. startListening writes the actual OS-assigned port
  to the .port property, so callers can request 0 and read it back.

New tests written for this branch (no Swift analog):
- F53OSC_UDPClientHostChangeTest. Verifies the client correctly retargets
  the underlying nw_connection when client.port or client.host changes.
- F53OSC_PerformanceTests. Characterization suite covering one-way
  latency (TCP and UDP, p50/p99 over 100 samples at low rate), payload
  throughput (24 B / 256 B / 4 KB across TCP and UDP), 16-producer
  multi-sender contention (both a kernel-ceiling burst variant and a
  controlled-burst variant that asserts near-100% delivery), routable-
  host variant exercising the kernel routing layer, and a 60-second
  sustained test gated on F53OSC_RUN_SUSTAINED.

Documentation:
- docs/MODERNIZATION.md: API additions, removed APIs, contract changes
  from the legacy GCDAsync behavior, the measured kernel UDP receive
  ceiling on macOS, and known follow-up items.
- docs/PARITY_BENCH_PLAN.md and docs/VCR_RECORDER_PLAN.md: scaffolds
  for the cross-implementation parity bench and the test-utility
  traffic recorder. Both describe work not yet started.
@ccahoon ccahoon force-pushed the nw-modernization branch 2 times, most recently from bed4c6b to b6c8cd1 Compare May 29, 2026 16:24
@ccahoon ccahoon changed the title Modernize sockets to Network.framework; retire CocoaAsyncSocket Modernize sockets to Network.framework May 29, 2026
balord added 7 commits May 29, 2026 15:08
- Measures throughput (UDP/TCP), concurrency (10 TCP clients), and payload encode/decode performance.
…ng from sender side

- removes `testMultiSender_UDP_16Producers_ControlledBurst` since existing `testMultiSender_UDP_16Producers` now can assert full delivery.
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.

2 participants