mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-11 02:51:11 +00:00
Disconnect only after sending last frame
This commit is contained in:
1 parent
a1b4a075a6
commit
c10facbedd
1 file changed
+19
-8
@@ -263,7 +263,10 @@ class NearbyConnection {
|
||||
UInt8(truncatingIfNeeded: length),
|
||||
])
|
||||
lengthPrefixedData.append(frame)
|
||||
connection.send(content: lengthPrefixedData, completion: .contentProcessed { _ in
|
||||
connection.send(content: lengthPrefixedData, completion: .contentProcessed { error in
|
||||
if let error = error {
|
||||
log("[NearbyConnection \(self.id)] Error while sending frame: \(error)")
|
||||
}
|
||||
if let completion = completion {
|
||||
completion()
|
||||
}
|
||||
@@ -556,15 +559,23 @@ class NearbyConnection {
|
||||
offlineFrame.version = .v1
|
||||
offlineFrame.v1.type = .disconnection
|
||||
offlineFrame.v1.disconnection = Location_Nearby_Connections_DisconnectionFrame()
|
||||
|
||||
if encryptionDone {
|
||||
try encryptAndSendOfflineFrame(offlineFrame)
|
||||
} else {
|
||||
try sendFrameAsync(offlineFrame.serializedData())
|
||||
|
||||
if connectionClosed {
|
||||
disconnect()
|
||||
return
|
||||
}
|
||||
|
||||
let finishDisconnect: () -> Void = {
|
||||
log("[NearbyConnection \(self.id)] Sent disconnection frame during sendDisconnectionAndDisconnect")
|
||||
self.disconnect()
|
||||
}
|
||||
|
||||
log("[NearbyConnection \(self.id)] Sent disconnection frame during sendDisconnectionAndDisconnect")
|
||||
disconnect()
|
||||
if encryptionDone {
|
||||
try encryptAndSendOfflineFrame(offlineFrame, completion: finishDisconnect)
|
||||
} else {
|
||||
let data = try offlineFrame.serializedData()
|
||||
sendFrameAsync(data, completion: finishDisconnect)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user