Skip to content

PR 426 - Fixing a test and removing debug prints #590

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
Aug 24, 2016
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
16 changes: 0 additions & 16 deletions Foundation/NSURLSession/EasyHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ extension _EasyHandle {
///
/// - SeeAlso: https://curl.haxx.se/libcurl/c/curl_easy_pause.html
func pauseReceive() {
URLSession.printDebug("[EasyHandle] pause receive (\(pauseState))")
guard !pauseState.contains(.receivePaused) else { return }
pauseState.insert(.receivePaused)
pauseState.setState(on: self)
Expand All @@ -322,7 +321,6 @@ extension _EasyHandle {
/// will be called before this method returns.
/// - SeeAlso: https://curl.haxx.se/libcurl/c/curl_easy_pause.html
func unpauseReceive() {
URLSession.printDebug("[EasyHandle] unpause receive (\(pauseState))")
guard pauseState.contains(.receivePaused) else { return }
pauseState.remove(.receivePaused)
pauseState.setState(on: self)
Expand All @@ -331,7 +329,6 @@ extension _EasyHandle {
///
/// - SeeAlso: https://curl.haxx.se/libcurl/c/curl_easy_pause.html
func pauseSend() {
URLSession.printDebug("[EasyHandle] pause send (\(pauseState))")
guard !pauseState.contains(.sendPaused) else { return }
pauseState.insert(.sendPaused)
pauseState.setState(on: self)
Expand All @@ -342,7 +339,6 @@ extension _EasyHandle {
/// will be called before this method returns.
/// - SeeAlso: https://curl.haxx.se/libcurl/c/curl_easy_pause.html
func unpauseSend() {
URLSession.printDebug("[EasyHandle] unpause send (\(pauseState))")
guard pauseState.contains(.sendPaused) else { return }
pauseState.remove(.sendPaused)
pauseState.setState(on: self)
Expand Down Expand Up @@ -461,53 +457,45 @@ fileprivate extension _EasyHandle {
///
/// - SeeAlso: <https://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html>
func didReceive(data: UnsafeMutablePointer<Int8>, size: Int, nmemb: Int) -> Int {
URLSession.printDebug("[EasyHandle] -> write callback \(size * nmemb)")
let d: Int = {
let buffer = Data(bytes: data, count: size*nmemb)
switch delegate.didReceive(data: buffer) {
case .proceed: return size * nmemb
case .abort: return 0
case .pause:
URLSession.printDebug("[EasyHandle] pausing receive from callback (\(pauseState))")
pauseState.insert(.receivePaused)
return Int(CFURLSessionWriteFuncPause)
}
}()
URLSession.printDebug("[EasyHandle] <- write callback \(d)")
return d
}
/// This callback function gets called by libcurl when it receives header
/// data.
///
/// - SeeAlso: <https://curl.haxx.se/libcurl/c/CURLOPT_HEADERFUNCTION.html>
func didReceive(headerData data: UnsafeMutablePointer<Int8>, size: Int, nmemb: Int, fileLength: Double) -> Int {
URLSession.printDebug("[EasyHandle] -> header callback \(size * nmemb)")
self.fileLength = Int64(fileLength)
let d: Int = {
let buffer = Data(bytes: data, count: size*nmemb)
switch delegate.didReceive(headerData: buffer) {
case .proceed: return size * nmemb
case .abort: return 0
case .pause:
URLSession.printDebug("[EasyHandle] pausing receive from callback (\(pauseState))")
pauseState.insert(.receivePaused)
return Int(CFURLSessionWriteFuncPause)
}
}()
URLSession.printDebug("[EasyHandle] <- header callback \(d)")
return d
}
/// This callback function gets called by libcurl when it wants to send data
/// it to the network.
///
/// - SeeAlso: <https://curl.haxx.se/libcurl/c/CURLOPT_READFUNCTION.html>
func fill(writeBuffer data: UnsafeMutablePointer<Int8>, size: Int, nmemb: Int) -> Int {
URLSession.printDebug("[EasyHandle] -> read callback \(size * nmemb)")
let d: Int = {
let buffer = UnsafeMutableBufferPointer(start: data, count: size * nmemb)
switch delegate.fill(writeBuffer: buffer) {
case .pause:
URLSession.printDebug("[EasyHandle] pausing send from callback (\(pauseState))")
pauseState.insert(.sendPaused)
return Int(CFURLSessionReadFuncPause)
case .abort:
Expand All @@ -516,12 +504,10 @@ fileprivate extension _EasyHandle {
return length
}
}()
URLSession.printDebug("[EasyHandle] <- read callback \(d)")
return d
}

func setSocketOptions(for fd: CInt) throws {
URLSession.printDebug("[EasyHandle] -- socket options callback \(fd)")
//TODO: At this point we should call setsockopt(2) to set the QoS on
// the socket based on the QoS of the request.
//
Expand All @@ -539,7 +525,6 @@ fileprivate extension _EasyHandle {
}

func seekInputStream(offset: Int64, origin: CInt) -> CInt {
URLSession.printDebug("[EasyHandle] -> seek callback \(offset) \(origin)")
let d: Int32 = {
/// libcurl should only use SEEK_SET
guard origin == SEEK_SET else { fatalError("Unexpected 'origin' in seek.") }
Expand All @@ -550,7 +535,6 @@ fileprivate extension _EasyHandle {
return CFURLSessionSeekCantSeek
}
}()
URLSession.printDebug("[EasyHandle] <- seek callback \(d)")
return d
}
}
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSURLSession/MultiHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fileprivate extension _EasyHandle {
return NSURLErrorTimedOut
default:
//TODO: Need to map to one of the NSURLError... constants
NSUnimplemented()
return NSURLErrorUnknown
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestURLSession : XCTestCase {
let result = first as? [String : Any]
expectedResult = result!["capital"] as! String
} catch { }
XCTAssertEqual("Washington D.C.", expectedResult, "Did not receive expected value")
XCTAssertEqual("Washington, D.C.", expectedResult, "Did not receive expected value")
expect.fulfill()
}
task.resume()
Expand Down