Attempt to fix data load conditions

This commit is contained in:
Ali
2020-05-20 00:10:48 +04:00
parent 5327342b92
commit 7e1bf68b71
2 changed files with 22 additions and 2 deletions

View File

@@ -104,7 +104,8 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa
var completedRequest = false
let disposable = data.start(next: { result in
let (data, isComplete) = result
if data.count == readCount || isComplete{
if data.count == readCount || isComplete {
precondition(data.count <= readCount)
fetchedData = data
completedRequest = true
semaphore.signal()
@@ -178,6 +179,7 @@ private func readPacketCallback(userData: UnsafeMutableRawPointer?, buffer: Unsa
}
}
if let fetchedData = fetchedData {
precondition(fetchedData.count <= readCount)
fetchedData.withUnsafeBytes { bytes -> Void in
precondition(bytes.baseAddress != nil)
memcpy(buffer, bytes.baseAddress, fetchedData.count)