I am using a UDP CFSocket to receive and process large amounts of data.
Processing of the data is fairly simple before it is dispalyed. Creating the display happens on a background thread, and I use GCD.
My problem is that I drop UDP data and I do not think that I should be doing this already. I am getting new data packets in every 100 ms, but they are large, so the overall throughput is around 140 Mbps.
My socket is added to the main run loop with:
// Add to run loop:
let rls = CFSocketCreateRunLoopSource(nil, cfSock, 0)
if (rls == nil) {
error("Could not get run loop source.")
return
}
CFRunLoopAddSource(CFRunLoopGetMain(), rls, CFRunLoopMode.defaultMode);
This means my callback, passed when creating the socket is called on the main thread.
I would like to add the socket to a run loop in a dedicated processing thread but got stuck trying to do so. I am use to the CGD async calls. I've tried the following, but it does not work:
DispatchQueue.global(qos: .userInitiated).async {
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, CFRunLoopMode.defaultMode);
}
How do I move to a dedicated processing run loop, and can I expect it to make a difference? My hope is for data processing to always succeed, and drop the data when displaying, not processing it.