Skip to content

Commit e3f514d

Browse files
authored
Merge pull request #884 from nethraravindran/nsurlsession-branch
2 parents f750832 + 7702c00 commit e3f514d

File tree

5 files changed

+10
-33
lines changed

5 files changed

+10
-33
lines changed

Foundation/NSURLSession/EasyHandle.swift

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,8 @@ extension _EasyHandle {
167167
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPROTOCOLS, protocols).asError()
168168
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionREDIR_PROTOCOLS, protocols).asError()
169169
//TODO: Added in libcurl 7.45.0
170-
// "https".withCString {
171-
// try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionDEFAULT_PROTOCOL, UnsafeMutablePointer($0)).asError()
172-
//}
170+
//TODO: Set default protocol for schemeless URLs
171+
//CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
173172
}
174173

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

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

201-
/// set numerical stream weight
197+
///TODO: Set numerical stream weight when CURLOPT_PIPEWAIT is enabled
202198
/// - Parameter weight: values are clamped to lie between 0 and 1
203199
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_STREAM_WEIGHT.html
204200
/// - SeeAlso: http://httpwg.org/specs/rfc7540.html#StreamPriority
205-
//func set(streamWeight weight: Float) {
206-
// // Scale and clamp such that the range 0->1 ends up 1->256
207-
// let w = 1 + max(0, min(255, Int(round(weight * 255))))
208-
// try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPIPEWAIT, w).asError()
209-
//}
201+
210202
/// Enable automatic decompression of HTTP downloads
211203
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html
212204
/// - SeeAlso: https://curl.haxx.se/libcurl/c/CURLOPT_HTTP_CONTENT_DECODING.html
205+
213206
func set(automaticBodyDecompression flag: Bool) {
214207
if flag {
215208
"".withCString {

Foundation/NSURLSession/HTTPBodySource.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ internal func copyDispatchData<T>(_ data: DispatchData, infoBuffer buffer: Unsaf
3737

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

Foundation/NSURLSession/MultiHandle.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ extension URLSession {
3636
internal final class _MultiHandle {
3737
let rawHandle = CFURLSessionMultiHandleInit()
3838
let queue: DispatchQueue
39-
//let queue = DispatchQueue(label: "MultiHandle.isolation", attributes: .serial)
4039
let group = DispatchGroup()
4140
fileprivate var easyHandles: [_EasyHandle] = []
4241
fileprivate var timeoutSource: _TimeoutSource? = nil
4342

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

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

317314
rawSource.scheduleRepeating(deadline: start, interval: .milliseconds(Int(delay)), leeway: (milliseconds == 1) ? .microseconds(Int(1)) : .milliseconds(Int(1)))

Foundation/NSURLSession/NSURLSession.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ import Dispatch
174174

175175
fileprivate var sessionCounter = Int32(0)
176176
fileprivate func nextSessionIdentifier() -> Int32 {
177-
//TODO: find an alternative for this on Linux
178-
//return OSAtomicIncrement32Barrier(&sessionCounter)
177+
//TODO: find an alternative for OSAtomicIncrement32Barrier() on Linux
179178
sessionCounter += 1
180179
return sessionCounter
181180
}

Foundation/NSURLSession/NSURLSessionTask.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ open class URLSessionTask : NSObject, NSCopying {
116116
self.easyHandle = _EasyHandle(delegate: self)
117117
}
118118
deinit {
119-
//TODO: Can we ensure this somewhere else? This might run on the wrong
120-
// thread / queue.
121-
//if internalState.isEasyHandleAddedToMultiHandle {
122-
// session.removeHandle(easyHandle)
123-
//}
119+
//TODO: Do we remove the EasyHandle from the session here? This might run on the wrong thread / queue.
124120
}
125121

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

563-
//Options unavailable on Ubuntu 14.04 (libcurl 7.36)
564-
//TODO: Introduce something like an #if
565-
//easyHandle.set(waitForPipeliningAndMultiplexing: true)
566-
//easyHandle.set(streamWeight: priority)
559+
//TODO: The CURLOPT_PIPEDWAIT option is unavailable on Ubuntu 14.04 (libcurl 7.36)
560+
//TODO: Introduce something like an #if, if we want to set them here
567561

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

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

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

0 commit comments

Comments
 (0)