mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-19 12:56:06 +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),
|
UInt8(truncatingIfNeeded: length),
|
||||||
])
|
])
|
||||||
lengthPrefixedData.append(frame)
|
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 {
|
if let completion = completion {
|
||||||
completion()
|
completion()
|
||||||
}
|
}
|
||||||
@@ -556,15 +559,23 @@ class NearbyConnection {
|
|||||||
offlineFrame.version = .v1
|
offlineFrame.version = .v1
|
||||||
offlineFrame.v1.type = .disconnection
|
offlineFrame.v1.type = .disconnection
|
||||||
offlineFrame.v1.disconnection = Location_Nearby_Connections_DisconnectionFrame()
|
offlineFrame.v1.disconnection = Location_Nearby_Connections_DisconnectionFrame()
|
||||||
|
|
||||||
if encryptionDone {
|
if connectionClosed {
|
||||||
try encryptAndSendOfflineFrame(offlineFrame)
|
disconnect()
|
||||||
} else {
|
return
|
||||||
try sendFrameAsync(offlineFrame.serializedData())
|
}
|
||||||
|
|
||||||
|
let finishDisconnect: () -> Void = {
|
||||||
|
log("[NearbyConnection \(self.id)] Sent disconnection frame during sendDisconnectionAndDisconnect")
|
||||||
|
self.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
log("[NearbyConnection \(self.id)] Sent disconnection frame during sendDisconnectionAndDisconnect")
|
if encryptionDone {
|
||||||
disconnect()
|
try encryptAndSendOfflineFrame(offlineFrame, completion: finishDisconnect)
|
||||||
|
} else {
|
||||||
|
let data = try offlineFrame.serializedData()
|
||||||
|
sendFrameAsync(data, completion: finishDisconnect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user