How to register a socket event in macOS and iOS?

Hi,

I have a C++ application connected to a specific socket. The problem is that when the application is not in use, macOS idle wakeups become very low.

I am quite new in Apple development but as I understand applications get low priority when the idle wakeups are low. Therefore, application only wakes up when the set period of time (say a few seconds) is reached and it does not respond to requests immediately. To improve performance, I am trying to implement an event listening mechanism in the application that would be triggered by socket activity.

In the documentation, there is some information on network events (see Table 7.1): https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/Timers.html

I guess every messaging app is implementing a similar mechanism i.e. rather than waiting for the idle wakeup period to wake the application, an event is triggered when user data arrives at the socket application is connected to.

My questions are

  • Is my understanding of idle wakeups mechanism correct?
  • What options are available to solve this problem and improve app performance i.e. response time?
  • Are there any sample code snippets showing how to register that kind of a network event listener?

Many thanks

Is my understanding of idle wakeups mechanism correct?

No. Nothing I’ve read above gels with my understanding of how the system works.

The problem is that when the application is not in use

What do you mean by this? Is the app in the foreground but just not being actively used by the user? Or is the app in the background?

Note that screen locking the device moves the app to the background.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks eskimo. If my understanding is not correct then can you please elaborate on how the idle wakeups work in macOS and iOS?

What I mean by "..when the application is not in use" is that when the application is not being actively used.

How to register a socket event in macOS and iOS?
 
 
Q