Skip to content

Add a new Socket Stream Protocol#47

Open
PayasR wants to merge 1 commit into
mainfrom
payasr/SocketProtocol
Open

Add a new Socket Stream Protocol#47
PayasR wants to merge 1 commit into
mainfrom
payasr/SocketProtocol

Conversation

@PayasR

@PayasR PayasR commented Jul 13, 2026

Copy link
Copy Markdown

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 from d87eac9 to 1d6247e Compare July 13, 2026 18:04
@PayasR PayasR force-pushed the payasr/SocketProtocol branch 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.

let type = SOCK_STREAM
#endif
let fd = socket(family, type, 0)
guard fd >= 0 else { throw NSError(domain: "TCPEchoServer", code: Int(errno)) }

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.

Can we us NetworkError instead or NSError?

@@ -14,14 +14,18 @@

import XCTest

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.

There is a lot of repetitive code throughout this suite, let's consolidate it into a test harness as much as possible. Take a look at QUICTestHarness as an example. We could use the test harness to setup the server, and the connection and then pass in the variables you need to run the test. Not 100% of the tests here will be able to fold into a pattern like this but a good chunk should be able too.

func makeParams(localEndpoint: Endpoint) -> ParametersBuilder<UDP> {
// MARK: - UDP helpers

private func makeUDPParams(localEndpoint: Endpoint) -> ParametersBuilder<UDP> {

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.

On Darwin we'll want to add @available(Network 0.1.0, *) to these global functions or even better yet add them to SwiftNetworkBenchmarks and import SwiftNetworkBenchmarks here to expose these utility functions.


/// Read pending socket error via SO_ERROR (and clear it). Returns 0 if no error.
public func getSocketError() -> CInt {
(try? getSocketOption(level: SOL_SOCKET, name: SO_ERROR, defaultValue: CInt(0))) ?? 0

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.

For this statement and others like it let's turn them into guard's for readability:

guard let error = try? getSocketOption(level: SOL_SOCKET, name: SO_ERROR, defaultValue: CInt(0)) else {
    return 0
}
return error

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