Skip to content

Commit c332bb7

Browse files
committed
FoundationNetworking: make CFURLSessionInterface @_implementationOnly
Remove the public exposure to `CFURLSessionInterface` which was never meant to be public. This requires removal of some of the `Equatable` conformances as scoped conformances are not yet a part of the language. This does the minimal change for to get `FoundationNetworking` to build.
1 parent 7e9c243 commit c332bb7

File tree

5 files changed

+59
-45
lines changed

5 files changed

+59
-45
lines changed

Sources/FoundationNetworking/URLSession/BodySource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Foundation
2323
#endif
2424

2525
@_implementationOnly import CoreFoundation
26-
import CFURLSessionInterface
26+
@_implementationOnly import CFURLSessionInterface
2727
import Dispatch
2828

2929

Sources/FoundationNetworking/URLSession/HTTP/HTTPURLProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
#endif
1515

1616
@_implementationOnly import CoreFoundation
17-
import CFURLSessionInterface
17+
@_implementationOnly import CFURLSessionInterface
1818
import Dispatch
1919

2020
internal class _HTTPURLProtocol: _NativeProtocol {

Sources/FoundationNetworking/URLSession/libcurl/EasyHandle.swift

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Foundation
2424
#endif
2525

2626
@_implementationOnly import CoreFoundation
27-
import CFURLSessionInterface
27+
@_implementationOnly import CFURLSessionInterface
2828
import Dispatch
2929

3030

@@ -76,9 +76,12 @@ internal final class _EasyHandle {
7676
}
7777
}
7878

79-
extension _EasyHandle: Equatable {}
80-
internal func ==(lhs: _EasyHandle, rhs: _EasyHandle) -> Bool {
81-
return lhs.rawHandle == rhs.rawHandle
79+
internal func ==(lhs: _EasyHandle, rhs: _EasyHandle) -> Bool {
80+
return lhs.rawHandle == rhs.rawHandle
81+
}
82+
83+
internal func ~=(lhs: _EasyHandle, rhs: _EasyHandle) -> Bool {
84+
return lhs == rhs
8285
}
8386

8487
extension _EasyHandle {
@@ -392,23 +395,24 @@ internal extension _EasyHandle {
392395
}
393396

394397

395-
extension CFURLSessionInfo : Equatable {
396-
public static func ==(lhs: CFURLSessionInfo, rhs: CFURLSessionInfo) -> Bool {
397-
return lhs.value == rhs.value
398-
}
398+
internal func ==(lhs: CFURLSessionInfo, rhs: CFURLSessionInfo) -> Bool {
399+
return lhs.value == rhs.value
400+
}
401+
internal func ~=(lhs: CFURLSessionInfo, rhs: CFURLSessionInfo) -> Bool {
402+
return lhs == rhs
399403
}
400404

401405
extension CFURLSessionInfo {
402-
public var debugHeader: String {
406+
internal var debugHeader: String {
403407
switch self {
404408
case CFURLSessionInfoTEXT: return " "
405-
case CFURLSessionInfoHEADER_OUT: return "=> Send header ";
406-
case CFURLSessionInfoDATA_OUT: return "=> Send data ";
407-
case CFURLSessionInfoSSL_DATA_OUT: return "=> Send SSL data ";
408-
case CFURLSessionInfoHEADER_IN: return "<= Recv header ";
409-
case CFURLSessionInfoDATA_IN: return "<= Recv data ";
410-
case CFURLSessionInfoSSL_DATA_IN: return "<= Recv SSL data ";
411-
default: return " "
409+
case CFURLSessionInfoHEADER_OUT: return "=> Send header "
410+
case CFURLSessionInfoDATA_OUT: return "=> Send data "
411+
case CFURLSessionInfoSSL_DATA_OUT: return "=> Send SSL data "
412+
case CFURLSessionInfoHEADER_IN: return "<= Recv header "
413+
case CFURLSessionInfoDATA_IN: return "<= Recv data "
414+
case CFURLSessionInfoSSL_DATA_IN: return "<= Recv SSL data "
415+
default: return " "
412416
}
413417
}
414418
}
@@ -671,18 +675,16 @@ extension _EasyHandle._CurlStringList {
671675
}
672676
}
673677

674-
extension CFURLSessionEasyCode : Equatable {
675-
public static func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
676-
return lhs.value == rhs.value
677-
}
678+
internal func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
679+
return lhs.value == rhs.value
678680
}
679-
extension CFURLSessionEasyCode : Error {
680-
public var _domain: String { return "libcurl.Easy" }
681-
public var _code: Int { return Int(self.value) }
681+
internal func ~=(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
682+
return lhs == rhs
682683
}
683-
internal extension CFURLSessionEasyCode {
684-
func asError() throws {
684+
685+
extension CFURLSessionEasyCode {
686+
internal func asError() throws {
685687
if self == CFURLSessionEasyCodeOK { return }
686-
throw self
688+
throw NSError(domain: "libcurl.Easy", code: Int(self.value))
687689
}
688690
}

Sources/FoundationNetworking/URLSession/libcurl/MultiHandle.swift

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Foundation
2323
#endif
2424

2525
@_implementationOnly import CoreFoundation
26-
import CFURLSessionInterface
26+
@_implementationOnly import CFURLSessionInterface
2727
import Dispatch
2828

2929

@@ -150,6 +150,17 @@ fileprivate extension URLSession._MultiHandle {
150150
}
151151
}
152152

153+
extension Collection where Element == _EasyHandle {
154+
internal func firstIndex(of element: Element) -> Index? {
155+
var i = self.startIndex
156+
while i != self.endIndex {
157+
if self[i] == element { return i }
158+
self.formIndex(after: &i)
159+
}
160+
return nil
161+
}
162+
}
163+
153164
internal extension URLSession._MultiHandle {
154165
/// Add an easy handle -- start its transfer.
155166
func add(_ handle: _EasyHandle) {
@@ -277,6 +288,13 @@ fileprivate extension _EasyHandle {
277288
}
278289
}
279290

291+
internal func ==(lhs: CFURLSessionPoll, rhs: CFURLSessionPoll) -> Bool {
292+
return lhs.value == rhs.value
293+
}
294+
internal func ~=(lhs: CFURLSessionPoll, rhs: CFURLSessionPoll) -> Bool {
295+
return lhs == rhs
296+
}
297+
280298
fileprivate extension URLSession._MultiHandle._SocketRegisterAction {
281299
init(rawValue: CFURLSessionPoll) {
282300
switch rawValue {
@@ -295,11 +313,7 @@ fileprivate extension URLSession._MultiHandle._SocketRegisterAction {
295313
}
296314
}
297315
}
298-
extension CFURLSessionPoll : Equatable {
299-
public static func ==(lhs: CFURLSessionPoll, rhs: CFURLSessionPoll) -> Bool {
300-
return lhs.value == rhs.value
301-
}
302-
}
316+
303317
fileprivate extension URLSession._MultiHandle._SocketRegisterAction {
304318
/// Should a libdispatch source be registered for **read** readiness?
305319
var needsReadSource: Bool {
@@ -470,18 +484,16 @@ extension _SocketSources {
470484
}
471485

472486

473-
extension CFURLSessionMultiCode : Equatable {
474-
public static func ==(lhs: CFURLSessionMultiCode, rhs: CFURLSessionMultiCode) -> Bool {
475-
return lhs.value == rhs.value
476-
}
487+
internal func ==(lhs: CFURLSessionMultiCode, rhs: CFURLSessionMultiCode) -> Bool {
488+
return lhs.value == rhs.value
477489
}
478-
extension CFURLSessionMultiCode : Error {
479-
public var _domain: String { return "libcurl.Multi" }
480-
public var _code: Int { return Int(self.value) }
490+
internal func ~=(lhs: CFURLSessionMultiCode, rhs: CFURLSessionMultiCode) -> Bool {
491+
return lhs == rhs
481492
}
482-
internal extension CFURLSessionMultiCode {
483-
func asError() throws {
493+
494+
extension CFURLSessionMultiCode {
495+
internal func asError() throws {
484496
if self == CFURLSessionMultiCodeOK { return }
485-
throw self
497+
throw NSError(domain: "libcurl.multi", code: Int(self.value))
486498
}
487499
}

Sources/FoundationNetworking/URLSession/libcurl/libcurlHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
@_implementationOnly import CoreFoundation
21-
import CFURLSessionInterface
21+
@_implementationOnly import CFURLSessionInterface
2222

2323
//TODO: Move things in this file?
2424

0 commit comments

Comments
 (0)