Skip to content

FoundationNetworking: make CFURLSessionInterface `@_implementationO… #2891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/FoundationNetworking/URLSession/BodySource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Foundation
#endif

@_implementationOnly import CoreFoundation
import CFURLSessionInterface
@_implementationOnly import CFURLSessionInterface
import Dispatch


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation
#endif

@_implementationOnly import CoreFoundation
import CFURLSessionInterface
@_implementationOnly import CFURLSessionInterface
import Dispatch

internal class _HTTPURLProtocol: _NativeProtocol {
Expand Down
54 changes: 28 additions & 26 deletions Sources/FoundationNetworking/URLSession/libcurl/EasyHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Foundation
#endif

@_implementationOnly import CoreFoundation
import CFURLSessionInterface
@_implementationOnly import CFURLSessionInterface
import Dispatch


Expand Down Expand Up @@ -76,9 +76,12 @@ internal final class _EasyHandle {
}
}

extension _EasyHandle: Equatable {}
internal func ==(lhs: _EasyHandle, rhs: _EasyHandle) -> Bool {
return lhs.rawHandle == rhs.rawHandle
internal func ==(lhs: _EasyHandle, rhs: _EasyHandle) -> Bool {
return lhs.rawHandle == rhs.rawHandle
}

internal func ~=(lhs: _EasyHandle, rhs: _EasyHandle) -> Bool {
return lhs == rhs
}

extension _EasyHandle {
Expand Down Expand Up @@ -392,23 +395,24 @@ internal extension _EasyHandle {
}


extension CFURLSessionInfo : Equatable {
public static func ==(lhs: CFURLSessionInfo, rhs: CFURLSessionInfo) -> Bool {
return lhs.value == rhs.value
}
internal func ==(lhs: CFURLSessionInfo, rhs: CFURLSessionInfo) -> Bool {
return lhs.value == rhs.value
}
internal func ~=(lhs: CFURLSessionInfo, rhs: CFURLSessionInfo) -> Bool {
return lhs == rhs
}

extension CFURLSessionInfo {
public var debugHeader: String {
internal var debugHeader: String {
switch self {
case CFURLSessionInfoTEXT: return " "
case CFURLSessionInfoHEADER_OUT: return "=> Send header ";
case CFURLSessionInfoDATA_OUT: return "=> Send data ";
case CFURLSessionInfoSSL_DATA_OUT: return "=> Send SSL data ";
case CFURLSessionInfoHEADER_IN: return "<= Recv header ";
case CFURLSessionInfoDATA_IN: return "<= Recv data ";
case CFURLSessionInfoSSL_DATA_IN: return "<= Recv SSL data ";
default: return " "
case CFURLSessionInfoHEADER_OUT: return "=> Send header "
case CFURLSessionInfoDATA_OUT: return "=> Send data "
case CFURLSessionInfoSSL_DATA_OUT: return "=> Send SSL data "
case CFURLSessionInfoHEADER_IN: return "<= Recv header "
case CFURLSessionInfoDATA_IN: return "<= Recv data "
case CFURLSessionInfoSSL_DATA_IN: return "<= Recv SSL data "
default: return " "
}
}
}
Expand Down Expand Up @@ -671,18 +675,16 @@ extension _EasyHandle._CurlStringList {
}
}

extension CFURLSessionEasyCode : Equatable {
public static func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
return lhs.value == rhs.value
}
internal func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
return lhs.value == rhs.value
}
extension CFURLSessionEasyCode : Error {
public var _domain: String { return "libcurl.Easy" }
public var _code: Int { return Int(self.value) }
internal func ~=(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
return lhs == rhs
}
internal extension CFURLSessionEasyCode {
func asError() throws {

extension CFURLSessionEasyCode {
internal func asError() throws {
if self == CFURLSessionEasyCodeOK { return }
throw self
throw NSError(domain: "libcurl.Easy", code: Int(self.value))
}
}
44 changes: 28 additions & 16 deletions Sources/FoundationNetworking/URLSession/libcurl/MultiHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Foundation
#endif

@_implementationOnly import CoreFoundation
import CFURLSessionInterface
@_implementationOnly import CFURLSessionInterface
import Dispatch


Expand Down Expand Up @@ -150,6 +150,17 @@ fileprivate extension URLSession._MultiHandle {
}
}

extension Collection where Element == _EasyHandle {
internal func firstIndex(of element: Element) -> Index? {
var i = self.startIndex
while i != self.endIndex {
if self[i] == element { return i }
self.formIndex(after: &i)
}
return nil
}
}

internal extension URLSession._MultiHandle {
/// Add an easy handle -- start its transfer.
func add(_ handle: _EasyHandle) {
Expand Down Expand Up @@ -277,6 +288,13 @@ fileprivate extension _EasyHandle {
}
}

internal func ==(lhs: CFURLSessionPoll, rhs: CFURLSessionPoll) -> Bool {
return lhs.value == rhs.value
}
internal func ~=(lhs: CFURLSessionPoll, rhs: CFURLSessionPoll) -> Bool {
return lhs == rhs
}

fileprivate extension URLSession._MultiHandle._SocketRegisterAction {
init(rawValue: CFURLSessionPoll) {
switch rawValue {
Expand All @@ -295,11 +313,7 @@ fileprivate extension URLSession._MultiHandle._SocketRegisterAction {
}
}
}
extension CFURLSessionPoll : Equatable {
public static func ==(lhs: CFURLSessionPoll, rhs: CFURLSessionPoll) -> Bool {
return lhs.value == rhs.value
}
}

fileprivate extension URLSession._MultiHandle._SocketRegisterAction {
/// Should a libdispatch source be registered for **read** readiness?
var needsReadSource: Bool {
Expand Down Expand Up @@ -470,18 +484,16 @@ extension _SocketSources {
}


extension CFURLSessionMultiCode : Equatable {
public static func ==(lhs: CFURLSessionMultiCode, rhs: CFURLSessionMultiCode) -> Bool {
return lhs.value == rhs.value
}
internal func ==(lhs: CFURLSessionMultiCode, rhs: CFURLSessionMultiCode) -> Bool {
return lhs.value == rhs.value
}
extension CFURLSessionMultiCode : Error {
public var _domain: String { return "libcurl.Multi" }
public var _code: Int { return Int(self.value) }
internal func ~=(lhs: CFURLSessionMultiCode, rhs: CFURLSessionMultiCode) -> Bool {
return lhs == rhs
}
internal extension CFURLSessionMultiCode {
func asError() throws {

extension CFURLSessionMultiCode {
internal func asError() throws {
if self == CFURLSessionMultiCodeOK { return }
throw self
throw NSError(domain: "libcurl.multi", code: Int(self.value))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@_implementationOnly import CoreFoundation
import CFURLSessionInterface
@_implementationOnly import CFURLSessionInterface

//TODO: Move things in this file?

Expand Down