Tuukka Norri avatar Tuukka Norri committed 1edbe0f

Trying to sort out run loop -related issues by using a BaseTen-specific mode which is also made common

Comments (0)

Files changed (6)

Sources/BXConstants.h

 BX_EXPORT NSString* const kBXRelationshipsKey;
 BX_EXPORT NSString* const kBXPredicateKey;
 BX_EXPORT NSString* const kBXOwnerObjectVariableName;
+BX_EXPORT NSString* const kBXRunLoopCommonMode;
 
 BX_EXPORT NSString* const kBXErrorDomain;
 BX_EXPORT NSString* const kBXErrorMessageKey;

Sources/BXConstants.m

 
 NSString* const kBXErrorDomain = @"kBXErrorDomain";
 NSString* const kBXErrorMessageKey = @"kBXErrorMessageKey";
-NSString* const kBXObjectKey = @"kBXObjectKey";
+NSString* const kBXObjectKey = @"kBXObjectKey";
+
+NSString* const kBXRunLoopCommonMode = @"kBXRunLoopCommonMode";

Sources/PGTSConnection.h

 - (SSL *) SSLStruct;
 - (CFSocketRef) socket;
 - (BOOL) canSend;
+- (void) setCFRunLoop: (CFRunLoopRef) aRef;
 
 - (id <PGTSCertificateVerificationDelegate>) certificateVerificationDelegate;
 - (void) setCertificateVerificationDelegate: (id <PGTSCertificateVerificationDelegate>) anObject;

Sources/PGTSConnection.mm

 #import "BXLogger.h"
 #import "BXEnumerate.h"
 #import "BXArraySize.h"
+#import "BXConstants.h"
 
 #import "NSString+PGTSAdditions.h"
 
 	{
 		mQueue = [[NSMutableArray alloc] init];
 		mCertificateVerificationDelegate = [PGTSCertificateVerificationDelegate defaultCertificateVerificationDelegate];
+		[self setCFRunLoop: CFRunLoopGetCurrent ()];
 	}
 	return self;
 }
 
+- (void) setCFRunLoop: (CFRunLoopRef) aRef
+{
+	if (mRunLoop != aRef)
+	{
+		if (mRunLoop) CFRelease (mRunLoop);
+		if (aRef)
+		{
+			mRunLoop = aRef;
+			CFRetain (mRunLoop);
+			CFRunLoopAddCommonMode (mRunLoop, (CFStringRef) kBXRunLoopCommonMode);
+		}
+	}
+}
+
 - (void) freeCFTypes
 {
 	//Don't release the connection. Delegate will handle it.
 		BXAssertLog (mSocketSource, @"Expected socketSource to have been created.");
 		BXAssertLog (CFRunLoopSourceIsValid (mSocketSource), @"Expected socketSource to be valid.");
 		
-		CFRunLoopRef runloop = mRunLoop ?: CFRunLoopGetCurrent ();
-		CFStringRef mode = kCFRunLoopCommonModes;
 		CFSocketDisableCallBacks (mSocket, kCFSocketWriteCallBack);
 		CFSocketEnableCallBacks (mSocket, kCFSocketReadCallBack);
-		CFRunLoopAddSource (runloop, mSocketSource, mode);
+		CFRunLoopAddSource (mRunLoop, mSocketSource, (CFStringRef) kBXRunLoopCommonMode);
 		
-		[self beginTrackingNetworkStatusIn: runloop mode: mode];
+		[self beginTrackingNetworkStatusIn: mRunLoop mode: (CFStringRef) kBXRunLoopCommonMode];
 		
 		if (0 < [mQueue count])
 			[self sendNextQuery];

Sources/PGTSConnectionMonitor.m

 #import "PGTSProbes.h"
 #import "BXLogger.h"
 #import "BXArraySize.h"
+#import "BXConstants.h"
 #import <IOKit/pwr_mgt/IOPMLib.h>
 #import <IOKit/IOMessage.h>
 #import <AppKit/AppKit.h>
 		IONotificationPortRef ioNotificationPort = NULL;
 		mIOPowerSession = IORegisterForSystemPower (self, &ioNotificationPort, &WorkspaceWillSleep, &ioNotifier);
 		if (mIOPowerSession)
-			CFRunLoopAddSource (CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource (ioNotificationPort), kCFRunLoopCommonModes);
+		{
+			CFRunLoopRef rl = CFRunLoopGetCurrent ();
+			CFRunLoopAddCommonMode (rl, (CFStringRef) kBXRunLoopCommonMode);
+			CFRunLoopAddSource (rl, IONotificationPortGetRunLoopSource (ioNotificationPort), (CFStringRef) kBXRunLoopCommonMode);
+		}
 		else
+		{
 			BXLogError (@"Failed to register for system sleep.");
+		}
 	}
 	return self;
 }

Sources/PGTSConnector.m

 #import "PGTSConnector.h"
 #import "PGTSConnection.h"
 #import "PGTSConstants.h"
+#import "BXConstants.h"
 #import "PGTSCertificateVerificationDelegateProtocol.h"
 #import "BXLogger.h"
 #import "BXError.h"
 ScheduleHost (CFHostRef theHost, CFRunLoopRef theRunLoop)
 {
 	if (theHost && theRunLoop)
-		CFHostUnscheduleFromRunLoop (theHost, theRunLoop, kCFRunLoopCommonModes);
+		CFHostUnscheduleFromRunLoop (theHost, theRunLoop, (CFStringRef) kBXRunLoopCommonMode);
 }
 
 
 UnscheduleHost (CFHostRef theHost, CFRunLoopRef theRunLoop)
 {
 	if (theHost && theRunLoop)
-		CFHostScheduleWithRunLoop (theHost, theRunLoop, kCFRunLoopCommonModes);
+		CFHostScheduleWithRunLoop (theHost, theRunLoop, (CFStringRef) kBXRunLoopCommonMode);
 }
 
 
 	if ((self = [super init]))
 	{
 		mExpectedCallBack = 0;
+		[self setCFRunLoop: CFRunLoopGetCurrent ()];
 	}
 	return self;
 }
 		{
 			mRunLoop = aRef;
 			CFRetain (mRunLoop);
+			CFRunLoopAddCommonMode (mRunLoop, (CFStringRef) kBXRunLoopCommonMode);
 		}
 	}
 }
 	if (0 < [name length] && '/' != [name characterAtIndex: 0])
 	{
 		Boolean status = FALSE;
-		CFRunLoopRef runloop = mRunLoop ?: CFRunLoopGetCurrent ();
 		CFHostClientContext ctx = {
 			0,
 			self,
 		mHost = CFHostCreateWithName (NULL, (CFStringRef) name);
 		status = CFHostSetClient (mHost, &HostReady, &ctx);
 		BXLogDebug (@"Set host client: %d.", status);
-		ScheduleHost (mHost, runloop);
+		ScheduleHost (mHost, mRunLoop);
 		
 		status = CFHostStartInfoResolution (mHost, kCFHostAddresses, &mHostError);
 		BXLogDebug (@"Started host info resolution: %d.", status);
 		if (! status)
 		{
-			UnscheduleHost (mHost, runloop);
+			UnscheduleHost (mHost, mRunLoop);
 			[self continueFromNameResolution: &mHostError];
 		}
 	}
 	BXAssertLog (mSocketSource, @"Expected socketSource to have been created.");
 	BXAssertLog (CFRunLoopSourceIsValid (mSocketSource), @"Expected socketSource to be valid.");
 	
-	CFRunLoopRef runloop = mRunLoop ?: CFRunLoopGetCurrent ();
 	CFSocketDisableCallBacks (mSocket, kCFSocketReadCallBack);
 	CFSocketEnableCallBacks (mSocket, kCFSocketWriteCallBack);
 	mExpectedCallBack = kCFSocketWriteCallBack;
-	CFRunLoopAddSource (runloop, mSocketSource, kCFRunLoopCommonModes);
+	CFRunLoopAddSource (mRunLoop, mSocketSource, (CFStringRef) kBXRunLoopCommonMode);
 }
 @end
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.