Fix NWSocket deadlock and read/write

This commit is contained in:
世界
2026-02-04 22:26:28 +08:00
parent ef6d8d0fb8
commit 20e22b691a
3 changed files with 154 additions and 52 deletions
@@ -59,10 +59,13 @@
var message: Data
while true {
do {
message = try socket.read()
message = try await socket.read()
} catch {
throw NSError(domain: "ImportProfileViewModel", code: 0, userInfo: [NSLocalizedDescriptionKey: String(localized: "Read from connection: \(error.localizedDescription)")])
}
if message.isEmpty {
continue
}
var error: NSError?
switch Int64(message[0]) {
case LibboxMessageTypeError:
@@ -112,12 +115,15 @@
connection.stateUpdateHandler = nil
let request = LibboxProfileContentRequest()
request.profileID = profileID
do {
try socket.write(request.encode())
isImporting = true
} catch {
alert = AlertState(error: error)
reset()
isImporting = true
Task {
do {
try await socket.write(request.encode())
} catch {
isImporting = false
alert = AlertState(error: error)
reset()
}
}
}