Skip to content

Add a new Socket Stream Protocol - #47

Merged
PayasR merged 4 commits into
mainfrom
payasr/SocketProtocol
Aug 11, 2026
Merged

Add a new Socket Stream Protocol#47
PayasR merged 4 commits into
mainfrom
payasr/SocketProtocol

Conversation

@PayasR

@PayasR PayasR commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This lets us use Kernel TCP socket streams for when userspace TCP isn't available.

@PayasR
PayasR requested a review from holleman July 13, 2026 17:44
@PayasR PayasR changed the title Adds a new Socket Stream Protocol Add a new Socket Stream Protocol Jul 13, 2026
@PayasR
PayasR force-pushed the payasr/SocketProtocol branch 2 times, most recently from 1d6247e to 27f4de0 Compare July 13, 2026 18:53

@agnosticdev agnosticdev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things, mainly on creating test harness code.

Comment thread Tests/SwiftNetworkTests/SwiftNetworkSocketTests.swift Outdated
Comment thread Tests/SwiftNetworkTests/SwiftNetworkSocketTests.swift
Comment thread Sources/Tools/SocketTransfer/main.swift Outdated
Comment thread Sources/SwiftNetwork/System/SystemSocket.swift Outdated

@agnosticdev agnosticdev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, it just looks like there are some linux test failures outstanding.

let harness = UDPLoopbackHarness(basePort: 10840)
harness.start()
harness.expectDeliver([0xFF])
harness.teardown()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is exactly what we want, thanks!

@PayasR
PayasR force-pushed the payasr/SocketProtocol branch from f9d3b02 to 471a92d Compare August 7, 2026 17:02
@PayasR
PayasR force-pushed the payasr/SocketProtocol branch 12 times, most recently from 8245a76 to adf0813 Compare August 10, 2026 18:42
@PayasR
PayasR force-pushed the payasr/SocketProtocol branch from adf0813 to f7e3928 Compare August 10, 2026 19:40
@PayasR
PayasR requested a review from agnosticdev August 10, 2026 20:10
The read DispatchSource was armed in setup(), before connect completed. On
Linux a spurious readable edge at connect-completion left it permanently
silent, stalling all receives. Resume the read source only after connect
completes.

Also consolidate the read and write sources onto one shared dup'd fd (closed
via a refcount once both cancel) to avoid epoll fd-aliasing and the EPOLLFREE
abort that fires when a still-registered socket fd is closed. Applied to both
SocketStreamProtocol and SocketDatagramProtocol.
@PayasR
PayasR force-pushed the payasr/SocketProtocol branch from 6b8ec6c to 66157a7 Compare August 10, 2026 20:18

@agnosticdev agnosticdev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you very much @PayasR !

guard let reference = TCPProtocol().newProtocolInstance(context: context) else {
throw NetworkError.posix(EINVAL)
if case .custom(let linkOptions) = stack.link,
linkOptions.identifier == BridgeDatagramProtocol.identifier

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little unusual to be using the BridgeDatagramProtocol for TCP

} else {
let socketReference = SocketStreamProtocol.instance(context: context)
options.setProtocolInstance(socketReference)
let linkage = OutboundStreamLinkage(reference: socketReference)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lot of this is repeated - it's really about setting the instance and getting the linkage and the rest is the same.


@_spi(ProtocolProvider)
@available(Network 0.1.0, *)
public func parseIPv4(_ string: String) -> IPv4Address? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PayasR
PayasR merged commit cdb7499 into main Aug 11, 2026
23 checks passed
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.

4 participants