I can't add CFSocket to Run Loop that is running within System Extension

As title, I try to call CFSocketCreateRunLoopSource() function to add my CFSocket to the Run Loop. It added successfully in App Extension. But, In System extensions it did not.

Code Block
CFSocketCreateRunLoopSource(_,_,_)
It does not return any results. There is no way to check that it get called successfully or not. So, I use
Code Block
CFRunLoopRunInMode(_,_,_)
to check that if a source added successfully the status of Run Loop' status is must not Finish. But it aways return Finish.

What's happening? I can't find any documentation about that Run Loop in System Extension.

Can anybody help me. Tell me what's happening?
Thank You.


System extensions do not run a run loop by default. If you’re using a run-loop based API, you’ll need to start a thread that’s dedicated to running the run loop and then schedule your run loop sources on that thread.

Having said that, what are you doing with CFSocket? It’s hard to think of any case where CFSocket is the right API to use these days. If you explain what you’re trying to do, I should be able to point you in the direction of a more moderne API, one that doesn’t depend on the run loop.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I was trying to connect a socket(CFSocket) to other socket(A plain socket) that is for that connect to the server directly to receive data. Because there is core module written in C that used in many cross platform. In initial design time, I have no idea to connect them.

But as you pointed out, it is not necessary. a kind of misuse.

Can you tell me that another technique that doesn't depend on Run Loop?

I always love to learn new techniques.

Thank You.
Accepted Answer

Can you tell me that another technique that doesn't depend on Run Loop?

I generally recommend that you use Network framework for network connections. It has a whole bunch of benefits over BSD Sockets. Watch WWDC 2018 Session 715 Introducing Network.framework: A modern alternative to Sockets for an introduction.

If you must stick with BSD Sockets then the easiest way to get async integration is via a Dispatch source.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
I can't add CFSocket to Run Loop that is running within System Extension
 
 
Q