Questions tagged [cfrunloop]

49 questions
15
votes
1 answer

CFRunLoopRun() vs [NSRunLoop run]

I have an NSRunLoop object, to which I attach timers and streams. It works great. Stopping it is another story alltogether. I run the loop using [runLoop run]. If I try to stop the loop using CRunLoopStop([[NSRunLoop currentRunLoop] getCFRunLoop]),…
Jörgen Sigvardsson
  • 4,839
  • 3
  • 28
  • 51
10
votes
2 answers

CFRunLoop in Swift Command Line Program

I am writing a command line application in Swift using a third-party framework that (if I understand the code correctly) relies on GCD callbacks to complete certain actions when a socket receives data. In order to better understand the framework, I…
Joseph
  • 466
  • 1
  • 6
  • 15
10
votes
2 answers

Stop an NSRunLoop

I have a connection in a thread, so I add it to the run loop to get all data: [[NSRunLoop currentRunLoop] run]; [connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; But I can't find any way to stop it -…
Makio
  • 465
  • 6
  • 15
9
votes
3 answers

Why call to CFRunLoopRunInMode() in Audio Queue Playback code?

I'm following the iOS "Audio Queue Programming Guide - Playing Audio". Near the end of the guide, there are calls to CFRunLoopRunInMode() in the step Start and Run an Audio Queue: do { // 5 …
Daniel S.
  • 6,458
  • 4
  • 35
  • 78
6
votes
2 answers

Is it safe to call CFRunLoopStop from another thread?

The Mac build of my (mainly POSIX) application spawns a child thread that calls CFRunLoopRun() to do an event loop (to get network configuration change events from MacOS). When it's time to pack things up and go away, the main thread calls…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
5
votes
1 answer

Using UnsafeMutablePointer and CFRunLoopObserverContext in swift 2

I have the following bit of code private func addRunLoopObserverForSaving() { var _self = self withUnsafeMutablePointer(&_self) { (pSelf) -> Void in var observerContext = CFRunLoopObserverContext( version: 0, …
Khanh Nguyen
  • 11,112
  • 10
  • 52
  • 65
4
votes
0 answers

Leak when calling CFNetworkExecuteProxyAutoConfigurationURL on Mac

I am using CFNetwork APIs to detect OS proxy settings. My setup is heavily based on this: https://github.com/adobe/chromium/blob/master/net/proxy/proxy_resolver_mac.cc which is pretty much the same as…
Maneugeant
  • 41
  • 3
3
votes
1 answer

Confusion about CFNetwork, CFReadStreamOpen, and CFRunLoopRun

That sinking feeling when you realize you have no idea what's going on... I've been using this code in my network code for almost two years without problems. if (!CFReadStreamOpen(myReadStream)) { CFStreamError myErr =…
alex_c
  • 2,058
  • 2
  • 26
  • 34
3
votes
1 answer

Create a CFRunLoopSourceRef using IOPSNotificationCreateRunLoopSource in Swift

I am trying to subscribe to changes in power state on macOS. I discovered there is a way using IOKit, though it is a bit convoluted. I need to import it using #import in an ObjC Bridging header. Then I get access to the…
Henrik
  • 3,908
  • 27
  • 48
3
votes
2 answers

Swift CFRunLoopTimerCreate - how to get "self" in timer callback

How do I get access to the class "self" instance to call class instance methods given the following code. If I try self.callSomeClassIntance(), as shown, I get a "A C function pointer cannot be formed fro a closure that captures context" error from…
MEB
  • 53
  • 6
3
votes
2 answers

NSTimer doesn't work without UIApplication?

I have a custom iPhone application which doesn't rely on UIKit in any way (it is not linked to UIKit). This means that I'm not using UIApplication and therefore not calling UIApplicationMain. The problem is that when I create a timer it never fires.…
Kristina
  • 15,859
  • 29
  • 111
  • 181
3
votes
2 answers

CFRunLoopWakeUp doesn't work?

I have a case where it seems that CFRunLoopWakeUp isn't working. Here's the setup: I have a "typical" while loop not on the main thread that waits for some work to complete: - (void)someFunc { self.runLoop = CFRunLoopGetCurrent(); …
kevlar
  • 1,110
  • 3
  • 17
  • 30
3
votes
1 answer

NSTimer v/s CFRunLoopTimer

My question is which one is better to use? As NSTimer in turn uses the CFRunLoopTimer object. What works better then other i got nothing about it on any site i googled for it but nothing, i got documents regarding both from Apple's documents but…
The iOSDev
  • 5,237
  • 7
  • 41
  • 78
3
votes
1 answer

NSRunLoop is consuming a lot of cpu and memory

I have a infinite loop that drives my worker thread. -(void) myThread { NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; while(![myThread isCancelled]) { [[NSRunLoop currentRunLoop] runUntilDate:[NSDate…
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
2
votes
0 answers

Issues creating multiple timers with CFRunLoopTimerCreate

I'm trying to create multiple periodic timers for my macOS launch daemon. I've written the following class to deal with the timer object: struct MyTimer { MyTimer() { } ~MyTimer() { stopTimer(); } bool setTimer(size_t nmsPeriod, //Period in…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
1
2 3 4