Skip to content

Commit ae0de61

Browse files
author
Ryan Dingman
committed
Return to configuring the minimum and maximum buffer size through StreamOptions
1 parent 4bac06a commit ae0de61

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

Sources/Subprocess/Platforms/Subprocess+Darwin.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public struct PlatformOptions: Sendable {
5858
/// i.e. Detach from the terminal.
5959
public var createSession: Bool = false
6060

61-
private(set) var preferredStreamBufferSizeRange: (any RangeExpression & Sendable)? = nil
61+
public var streamOptions: StreamOptions = .init()
6262

6363
/// An ordered list of steps in order to tear down the child
6464
/// process in case the parent task is cancelled before
@@ -85,16 +85,18 @@ public struct PlatformOptions: Sendable {
8585
) throws -> Void
8686
)? = nil
8787

88-
public init() {
89-
self.preferredStreamBufferSizeRange = nil
90-
}
88+
public init() {}
89+
}
9190

92-
public init<R>(preferredStreamBufferSizeRange: R?) where R: RangeExpression & Sendable, R.Bound == Int {
93-
self.preferredStreamBufferSizeRange = preferredStreamBufferSizeRange
94-
}
91+
extension PlatformOptions {
92+
public struct StreamOptions: Sendable {
93+
let minimumBufferSize: Int?
94+
let maximumBufferSize: Int?
9595

96-
mutating func setPreferredStreamBufferSizeRange<R>(_ range: R?) where R: RangeExpression & Sendable, R.Bound == Int {
97-
self.preferredStreamBufferSizeRange = range
96+
public init(minimumBufferSize: Int? = nil, maximumBufferSize: Int? = nil) {
97+
self.minimumBufferSize = minimumBufferSize
98+
self.maximumBufferSize = maximumBufferSize
99+
}
98100
}
99101
}
100102

Sources/Subprocess/Platforms/Subprocess+Linux.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public struct PlatformOptions: Sendable {
177177
// i.e. Detach from the terminal.
178178
public var createSession: Bool = false
179179

180-
private(set) var preferredStreamBufferSizeRange: (any RangeExpression & Sendable)? = nil
180+
public var streamOptions: StreamOptions = .init()
181181

182182
/// An ordered list of steps in order to tear down the child
183183
/// process in case the parent task is cancelled before
@@ -197,16 +197,18 @@ public struct PlatformOptions: Sendable {
197197
/// call any necessary process setup functions.
198198
public var preSpawnProcessConfigurator: (@convention(c) @Sendable () -> Void)? = nil
199199

200-
public init() {
201-
self.preferredStreamBufferSizeRange = nil
202-
}
200+
public init() {}
201+
}
203202

204-
public init<R>(preferredStreamBufferSizeRange: R?) where R: RangeExpression & Sendable, R.Bound == Int {
205-
self.preferredStreamBufferSizeRange = preferredStreamBufferSizeRange
206-
}
203+
extension PlatformOptions {
204+
public struct StreamOptions: Sendable {
205+
public let minimumBufferSize: Int?
206+
public let maximumBufferSize: Int?
207207

208-
mutating func setPreferredStreamBufferSizeRange<R>(_ range: R?) where R: RangeExpression & Sendable, R.Bound == Int {
209-
self.preferredStreamBufferSizeRange = range
208+
public init(minimumBufferSize: Int? = nil, maximumBufferSize: Int? = nil) {
209+
self.minimumBufferSize = minimumBufferSize
210+
self.maximumBufferSize = maximumBufferSize
211+
}
210212
}
211213
}
212214

Sources/Subprocess/Platforms/Subprocess+Unix.swift

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,12 @@ extension CreatedPipe {
439439
}
440440
)
441441

442-
if let preferredStreamBufferSizeRange = options.preferredStreamBufferSizeRange {
443-
if let range = preferredStreamBufferSizeRange as? Range<Int> {
444-
dispatchIO.setLimit(lowWater: range.lowerBound)
445-
dispatchIO.setLimit(highWater: range.upperBound)
446-
} else if let range = preferredStreamBufferSizeRange as? ClosedRange<Int> {
447-
dispatchIO.setLimit(lowWater: range.lowerBound)
448-
dispatchIO.setLimit(highWater: range.upperBound)
449-
} else if let range = preferredStreamBufferSizeRange as? PartialRangeFrom<Int> {
450-
dispatchIO.setLimit(lowWater: range.lowerBound)
451-
} else if let range = preferredStreamBufferSizeRange as? PartialRangeUpTo<Int> {
452-
dispatchIO.setLimit(highWater: range.upperBound - 1)
453-
} else if let range = preferredStreamBufferSizeRange as? PartialRangeThrough<Int> {
454-
dispatchIO.setLimit(highWater: range.upperBound)
455-
} else {
456-
fatalError("Unsupported preferredStreamBufferSizeRange: \(preferredStreamBufferSizeRange)")
457-
}
442+
if let minimumBufferSize = options.streamOptions.minimumBufferSize {
443+
dispatchIO.setLimit(lowWater: minimumBufferSize)
444+
}
445+
446+
if let maximumBufferSize = options.streamOptions.maximumBufferSize {
447+
dispatchIO.setLimit(lowWater: maximumBufferSize)
458448
}
459449

460450
readEnd = .init(

Tests/SubprocessTests/SubprocessTests+Unix.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ extension SubprocessUnixTests {
676676
"""
677677

678678
var platformOptions = PlatformOptions()
679-
platformOptions.setPreferredStreamBufferSizeRange(0...)
679+
platformOptions.streamOptions = .init(minimumBufferSize: 0)
680680

681681
let start = ContinuousClock().now
682682

0 commit comments

Comments
 (0)