Skip to content

Commit

Permalink
Merge pull request #11 from lyft/fix-any-crash
Browse files Browse the repository at this point in the history
Fix crash after Swift 3 migration (Any size)
  • Loading branch information
Reflejo authored Oct 15, 2016
2 parents 684eb9d + cb81768 commit d12f364
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.
`Kronos` adheres to [Semantic Versioning](http://semver.org/).

## [0.2.1](https://github.com/lyft/Kronos/releases/tag/0.2.1)
- Fix crash on DNS timeout after Swift 3 integration

## [0.2.0](https://github.com/lyft/Kronos/releases/tag/0.2.0)
- Added Swift 3 support

Expand Down
2 changes: 1 addition & 1 deletion Kronos.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Kronos'
s.version = '0.2.0'
s.version = '0.2.1'
s.license = { :type => 'Apache License, Version 2.0', :file => 'LICENSE' }
s.summary = 'Elegant NTP client in Swift'
s.homepage = 'https://github.com/lyft/Kronos'
Expand Down
6 changes: 3 additions & 3 deletions Kronos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,20 @@
C2C037011C2B1A14003FB853 /* Tests */ = {
isa = PBXGroup;
children = (
C2E17C5F1C7944E400C90E46 /* Kronos */,
C2E17C5F1C7944E400C90E46 /* KronosTests */,
);
path = Tests;
sourceTree = "<group>";
};
C2E17C5F1C7944E400C90E46 /* Kronos */ = {
C2E17C5F1C7944E400C90E46 /* KronosTests */ = {
isa = PBXGroup;
children = (
26447D851D6E54FF00159BEE /* ClockTests.swift */,
26447D861D6E54FF00159BEE /* DNSResolverTests.swift */,
26447D871D6E54FF00159BEE /* NTPClientTests.swift */,
26447D881D6E54FF00159BEE /* NTPPacketTests.swift */,
);
path = Kronos;
path = KronosTests;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down
10 changes: 5 additions & 5 deletions Sources/DNSResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ final class DNSResolver {
retain: nil, release: nil, copyDescription: kCopyNoOperation)

let hostReference = CFHostCreateWithName(kCFAllocatorDefault, host as CFString).takeUnretainedValue()
CFHostSetClient(hostReference, callback, &clientContext)
CFHostScheduleWithRunLoop(hostReference, CFRunLoopGetCurrent(), CFRunLoopMode.commonModes.rawValue)
CFHostStartInfoResolution(hostReference, .addresses, nil)

resolver.timer = Timer.scheduledTimer(timeInterval: timeout, target: resolver,
selector: #selector(DNSResolver.onTimeout),
userInfo: hostReference, repeats: false)

CFHostSetClient(hostReference, callback, &clientContext)
CFHostScheduleWithRunLoop(hostReference, CFRunLoopGetCurrent(), CFRunLoopMode.commonModes.rawValue)
CFHostStartInfoResolution(hostReference, .addresses, nil)
}

@objc
Expand All @@ -77,7 +77,7 @@ final class DNSResolver {
return
}

let hostReference = unsafeBitCast(userInfo, to: CFHost.self)
let hostReference = unsafeBitCast(userInfo as AnyObject, to: CFHost.self)
CFHostCancelInfoResolution(hostReference, .addresses)
CFHostUnscheduleFromRunLoop(hostReference, CFRunLoopGetCurrent(), CFRunLoopMode.commonModes.rawValue)
CFHostSetClient(hostReference, nil, nil)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ final class DNSResolverTests: XCTestCase {

self.waitForExpectations(timeout: 5) { _ in }
}

func testTimeout() {
let expectation = self.expectation(description: "DNS times out")
DNSResolver.resolve(host: "ip6.nl", timeout: 0) { addresses in
XCTAssertEqual(addresses.count, 0)
expectation.fulfill()
}

self.waitForExpectations(timeout: 1.0) { _ in }
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit d12f364

Please sign in to comment.