Add a new Socket Stream Protocol#47
Conversation
d87eac9 to
1d6247e
Compare
1d6247e to
27f4de0
Compare
agnosticdev
left a comment
There was a problem hiding this comment.
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)) } |
There was a problem hiding this comment.
Can we us NetworkError instead or NSError?
| @@ -14,14 +14,18 @@ | |||
|
|
|||
| import XCTest | |||
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
This lets us use Kernel TCP socket streams for when userspace TCP isn't available.