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.
[I] used Wireshark to effectively probe point "E". I can see that my data is received.
OK. There’s two possibilities here:
There’s something wrong with the code that’s actually receiving the data (X).
The kernel is dropping the data because the receive buffer is full (Y).
I’d investigate both of these in turn. With regards X, for testing purposes I’d write a small tool that receives data synchronously using BSD Sockets and then records what got received. If that sees the data and your real app doesn’t, you can look at why.
If your test project also drops data, you can test for Y but tweaking the socket’s receive buffer size (using
SO_RCVBUF).
ps Is your receiving code running on the Mac? Or iOS?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"