Conceptually I run following Swift pseudo code to regulate UDP sent data bitrate
let sendQueue = DispatchQueue(label: "_send_queue", qos: .userInitiated)
sendQueue.async {
for data in datas {
socket.send(data)
if let timespec = getTimeToSleep() {
var ts = timespec
nanosleep(&ts, nil)
}
}
}
In my case time talculated to sleep is usually about 0.001s. In general the real spent in nanosleep()
is a couple of percent higher. So far so good - but after some time nanosleep()
return after MUCH longer time - easily it's seconds or even a minute. I'm pretty sure I do not request such a long interval. I tried following with no result
- build the app with
release
config - ran the app outside debugger
What is strange that if this happens while ran from debugger - when I pause and resume the app it runs fine again for a while.
Any clues?