mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-27 15:48:54 +00:00
ios: reconnect servers when network changes
iOS does not report the sockets of the previous network as broken, so after switching between Wi-Fi and mobile the agent keeps using dead sessions - setting network info does not drop them. Recovery only happened when the OS finally failed the socket, via TCP keep-alive or the SMP ping monitor, taking from ~90 seconds to tens of minutes. Reconnect the servers on every network change after the first one, when the network is online. Changes that keep the same network type, e.g. switching between Wi-Fi networks, are not detected, as network info only has the network type.
This commit is contained in:
@@ -35,8 +35,12 @@ class NetworkObserver {
|
||||
online: path.status == .satisfied
|
||||
)
|
||||
if (prevInfo != info) {
|
||||
// iOS does not report the sockets of the previous network as broken, so the servers have to
|
||||
// be reconnected. There is nothing to reconnect before the first network info is set.
|
||||
let shouldReconnect = prevInfo != nil && info.online
|
||||
prevInfo = info
|
||||
setNetworkInfo(info)
|
||||
if shouldReconnect { reconnectServers() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,4 +74,15 @@ class NetworkObserver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func reconnectServers() {
|
||||
Task {
|
||||
if !hasChatCtrl() { return }
|
||||
do {
|
||||
try await reconnectAllServers()
|
||||
} catch let err {
|
||||
logger.error("reconnectAllServers error: \(responseError(err))")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user