mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-25 07:46:02 +00:00
Try to fix issue if connection state update handler called early -> aborts connection
This commit is contained in:
1 parent
46997ab9fc
commit
c68ca3376b
1 file changed
+25
-8
@@ -57,8 +57,32 @@ class NearbyConnection {
|
|||||||
self.connectionReady()
|
self.connectionReady()
|
||||||
self.receiveFrameAsync()
|
self.receiveFrameAsync()
|
||||||
} else if case let .failed(err) = state {
|
} else if case let .failed(err) = state {
|
||||||
|
|
||||||
|
// If connection reset by peer, it could still be a valid file transfer that has not been processed yet. => Wait
|
||||||
|
if err == .posix(.ECONNRESET) {
|
||||||
|
NearbyConnection.dispatchQueue.asyncAfter(deadline: .now() + 0.5) {
|
||||||
|
|
||||||
|
// If already closed, ignore the error, as file transfer has been processed
|
||||||
|
if !self.connectionClosed {
|
||||||
|
recordErrorAndDisconnect(err: err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
recordErrorAndDisconnect(err: err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log("Connection already closed, ignoring state update: \(state)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// connection.start(queue: .global(qos: .utility))
|
||||||
|
connection.start(queue: NearbyConnection.dispatchQueue)
|
||||||
|
|
||||||
|
func recordErrorAndDisconnect(err: NWError) {
|
||||||
self.lastError = err
|
self.lastError = err
|
||||||
log("Error opening socket: \(err)")
|
log("Connection Error: \(err)")
|
||||||
|
|
||||||
if err == .posix(.ENOTCONN) {
|
if err == .posix(.ENOTCONN) {
|
||||||
ConnectionFailureTracker.shared.recordFailure {
|
ConnectionFailureTracker.shared.recordFailure {
|
||||||
@@ -69,13 +93,6 @@ class NearbyConnection {
|
|||||||
self.handleConnectionClosure()
|
self.handleConnectionClosure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
log("Connection already closed, ignoring state update: \(state)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// connection.start(queue: .global(qos: .utility))
|
|
||||||
connection.start(queue: NearbyConnection.dispatchQueue)
|
|
||||||
}
|
|
||||||
|
|
||||||
func connectionReady() {}
|
func connectionReady() {}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user