Skip to content

Commit

Permalink
Merge pull request #14 from lyft/global-sigpipe
Browse files Browse the repository at this point in the history
Globally disable SIGPIPE
  • Loading branch information
Reflejo committed Jan 20, 2017
2 parents 3d357f1 + 6b10ff6 commit 4afd00d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Kronos.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Kronos'
s.version = '0.2.2'
s.version = '0.2.3'
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
5 changes: 2 additions & 3 deletions Sources/NTPClient.swift
Expand Up @@ -145,6 +145,8 @@ final class NTPClient {
private func sendAsyncUDPQuery(to ip: InternetAddress, port: Int, timeout: TimeInterval,
completion: UnsafeMutableRawPointer) -> (CFRunLoopSource, CFSocket)?
{
signal(SIGPIPE, SIG_IGN)

let callback: CFSocketCallBack = { socket, callbackType, address, data, info in
if callbackType == .writeCallBack {
var packet = NTPPacket()
Expand Down Expand Up @@ -179,9 +181,6 @@ final class NTPClient {

let runLoopSource = CFSocketCreateRunLoopSource(kCFAllocatorDefault, socket, 0)
CFRunLoopAddSource(CFRunLoopGetMain(), runLoopSource, CFRunLoopMode.commonModes)

var noSIGPIPE: UInt32 = 1
setsockopt(CFSocketGetNative(socket), SOL_SOCKET, SO_NOSIGPIPE, &noSIGPIPE, 4)
CFSocketConnectToAddress(socket, ip.addressData(withPort: port), timeout)
return (runLoopSource!, socket)
}
Expand Down

0 comments on commit 4afd00d

Please sign in to comment.