15CFRunLoop
Unix networking uses file descriptors for reading and writing. Using file descriptors in server programs is pretty easy with the select() and kevent() functions. Using sockets in end-user GUI apps presents a problem, though. You cannot call select() on the main thread to wait for network activity. This will cause the UI to hang until there is something to be done on the network. Blocking the UI thread would cause your program to become unresponsive, and your process would be killed on iOS devices.
There are some options available to you. You can put your blocking function into a new thread. That thread can then block to its heart’s content until there is activity on the network, and then it can inform the UI thread that there is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access