Skip to content

Commit

Permalink
Don't raise SIGPIPE on connected TCP clients
Browse files Browse the repository at this point in the history
  • Loading branch information
tagavari committed Jul 20, 2022
1 parent 7890d9b commit eb22fc8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions AirMessage/Connection/Direct/DataProxyTCP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class DataProxyTCP: DataProxy {
}

//Configure the socket
var opt: Int32 = -1
let setOptResult = setsockopt(socketHandle.fileDescriptor, SOL_SOCKET, SO_REUSEADDR, &opt, socklen_t(MemoryLayout<Int32>.size))
var opt: Int32 = 1
let setOptResult = setsockopt(socketHandle.fileDescriptor, SOL_SOCKET, SO_REUSEADDR, &opt, socklen_t(MemoryLayout.size(ofValue: opt)))
guard setOptResult == 0 else {
LogManager.log("Failed to set socket opt: \(errno)", level: .error)

Expand Down Expand Up @@ -102,6 +102,18 @@ class DataProxyTCP: DataProxy {
return
}

//Configure the socket to not raise SIGPIPE
var opt: Int32 = 1
let setOptResult = setsockopt(clientFD, SOL_SOCKET, SO_NOSIGPIPE, &opt, socklen_t(MemoryLayout.size(ofValue: opt)))
guard setOptResult == 0 else {
LogManager.log("Failed to set client socket opt: \(errno)", level: .error)

if let self = self, self.serverRunning {
self.delegate?.dataProxy(self, didStopWithState: .errorTCPInternal, isRecoverable: false)
}
return
}

//Get the client address
let clientAddress: String
switch Int32(addr.sa_family) {
Expand Down

0 comments on commit eb22fc8

Please sign in to comment.