Skip to content

[gardening]Remove commented code from URLSession #884

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 2 commits into from
Feb 23, 2017
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
19 changes: 6 additions & 13 deletions Foundation/NSURLSession/EasyHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ extension _EasyHandle {
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPROTOCOLS, protocols).asError()
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionREDIR_PROTOCOLS, protocols).asError()
//TODO: Added in libcurl 7.45.0
// "https".withCString {
// try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionDEFAULT_PROTOCOL, UnsafeMutablePointer($0)).asError()
//}
//TODO: Set default protocol for schemeless URLs
//CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
}

//TODO: Proxy setting, namely CFURLSessionOptionPROXY, CFURLSessionOptionPROXYPORT,
Expand All @@ -189,27 +188,21 @@ extension _EasyHandle {
// We need to retain the list for as long as the rawHandle is in use.
headerList = list
}
/// Wait for pipelining/multiplexing
///TODO: Wait for pipelining/multiplexing. Unavailable on Ubuntu 14.0
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_PIPEWAIT.html
//func set(waitForPipeliningAndMultiplexing flag: Bool) {
// try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPIPEWAIT, flag ? 1 : 0).asError()
//}

//TODO: The public API does not allow us to use CFURLSessionOptionSTREAM_DEPENDS / CFURLSessionOptionSTREAM_DEPENDS_E
// Might be good to add support for it, though.

/// set numerical stream weight
///TODO: Set numerical stream weight when CURLOPT_PIPEWAIT is enabled
/// - Parameter weight: values are clamped to lie between 0 and 1
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_STREAM_WEIGHT.html
/// - SeeAlso: http://httpwg.org/specs/rfc7540.html#StreamPriority
//func set(streamWeight weight: Float) {
// // Scale and clamp such that the range 0->1 ends up 1->256
// let w = 1 + max(0, min(255, Int(round(weight * 255))))
// try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPIPEWAIT, w).asError()
//}

/// Enable automatic decompression of HTTP downloads
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_HTTP_CONTENT_DECODING.html

func set(automaticBodyDecompression flag: Bool) {
if flag {
"".withCString {
Expand Down
4 changes: 0 additions & 4 deletions Foundation/NSURLSession/HTTPBodySource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ internal func copyDispatchData<T>(_ data: DispatchData, infoBuffer buffer: Unsaf

/// Split `dispatch_data_t` into `(head, tail)` pair.
internal func splitData(dispatchData data: DispatchData, atPosition position: Int) -> (DispatchData,DispatchData) {
/*let length = dispatch_data_get_size(data)
let head = dispatch_data_create_subrange(data, 0, position)
let tail = dispatch_data_create_subrange(data, position, length - position)
return (head, tail)*/
return (data.subdata(in: 0..<position), data.subdata(in: position..<data.count))
}

Expand Down
3 changes: 0 additions & 3 deletions Foundation/NSURLSession/MultiHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ extension URLSession {
internal final class _MultiHandle {
let rawHandle = CFURLSessionMultiHandleInit()
let queue: DispatchQueue
//let queue = DispatchQueue(label: "MultiHandle.isolation", attributes: .serial)
let group = DispatchGroup()
fileprivate var easyHandles: [_EasyHandle] = []
fileprivate var timeoutSource: _TimeoutSource? = nil

init(configuration: URLSession._Configuration, workQueue: DispatchQueue) {
//queue.setTarget(queue: workQueue)
queue = DispatchQueue(label: "MultiHandle.isolation", target: workQueue)
setupCallbacks()
configure(with: configuration)
Expand Down Expand Up @@ -311,7 +309,6 @@ fileprivate class _TimeoutSource {
self.rawSource = DispatchSource.makeTimerSource(queue: queue) as! DispatchSource

let delay = UInt64(max(1, milliseconds - 1))
//let leeway: UInt64 = (milliseconds == 1) ? NSEC_PER_USEC : NSEC_PER_MSEC
let start = DispatchTime.now() + DispatchTimeInterval.milliseconds(Int(delay))

rawSource.scheduleRepeating(deadline: start, interval: .milliseconds(Int(delay)), leeway: (milliseconds == 1) ? .microseconds(Int(1)) : .milliseconds(Int(1)))
Expand Down
3 changes: 1 addition & 2 deletions Foundation/NSURLSession/NSURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ import Dispatch

fileprivate var sessionCounter = Int32(0)
fileprivate func nextSessionIdentifier() -> Int32 {
//TODO: find an alternative for this on Linux
//return OSAtomicIncrement32Barrier(&sessionCounter)
//TODO: find an alternative for OSAtomicIncrement32Barrier() on Linux
sessionCounter += 1
return sessionCounter
}
Expand Down
14 changes: 3 additions & 11 deletions Foundation/NSURLSession/NSURLSessionTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ open class URLSessionTask : NSObject, NSCopying {
self.easyHandle = _EasyHandle(delegate: self)
}
deinit {
//TODO: Can we ensure this somewhere else? This might run on the wrong
// thread / queue.
//if internalState.isEasyHandleAddedToMultiHandle {
// session.removeHandle(easyHandle)
//}
//TODO: Do we remove the EasyHandle from the session here? This might run on the wrong thread / queue.
}

open override func copy() -> Any {
Expand Down Expand Up @@ -560,10 +556,8 @@ fileprivate extension URLSessionTask {
easyHandle.set(followLocation: false)
easyHandle.set(customHeaders: curlHeaders(for: request))

//Options unavailable on Ubuntu 14.04 (libcurl 7.36)
//TODO: Introduce something like an #if
//easyHandle.set(waitForPipeliningAndMultiplexing: true)
//easyHandle.set(streamWeight: priority)
//TODO: The CURLOPT_PIPEDWAIT option is unavailable on Ubuntu 14.04 (libcurl 7.36)
//TODO: Introduce something like an #if, if we want to set them here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May make sense to document what the CURLOPT_PIPEWAIT option helps achieve here ..


//set the request timeout
//TODO: the timeout value needs to be reset on every data transfer
Expand Down Expand Up @@ -933,8 +927,6 @@ extension URLSessionTask {

//TODO: Should the `public response: URLResponse` property be updated
// before we call delegate API
// `func urlSession(session: session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: NSHTTPURLResponse, newRequest request: NSURLRequest, completionHandler: (NSURLRequest?) -> Void)`
// ?

internalState = .waitingForRedirectCompletionHandler(response: response, bodyDataDrain: bodyDataDrain)
// We need this ugly cast in order to be able to support `URLSessionTask.init()`
Expand Down