Add check if connection already closed

This commit is contained in:
Leon Böttger committed 2025-05-30 20:55:33 +02:00
1 parent e5ae0c250e
commit 46997ab9fc
1 file changed
+17 -12
+17 -12
View File
@@ -52,20 +52,25 @@ class NearbyConnection {
func start() {
connection.stateUpdateHandler = { state in
if case .ready = state {
self.connectionReady()
self.receiveFrameAsync()
} else if case let .failed(err) = state {
self.lastError = err
log("Error opening socket: \(err)")
if err == .posix(.ENOTCONN) {
ConnectionFailureTracker.shared.recordFailure {
NearbyConnectionManager.shared.mainAppDelegate?.showFirewallAlert()
if !self.connectionClosed {
if case .ready = state {
self.connectionReady()
self.receiveFrameAsync()
} else if case let .failed(err) = state {
self.lastError = err
log("Error opening socket: \(err)")
if err == .posix(.ENOTCONN) {
ConnectionFailureTracker.shared.recordFailure {
NearbyConnectionManager.shared.mainAppDelegate?.showFirewallAlert()
}
}
self.handleConnectionClosure()
}
self.handleConnectionClosure()
}
else {
log("Connection already closed, ignoring state update: \(state)")
}
}
// connection.start(queue: .global(qos: .utility))