From cdb4b4adda734c94bbef94b92a9479a733858c33 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 29 Aug 2010 23:55:35 +0000 Subject: - Improve background thread reconnect interaction with the interface; if the application is in a modal state, the background thread waits. This improves interface behaviour on multiple SSH disconnections after sleep/wake (finishing Issue #798) and also disconnections while the interface is modally locked (eg editing text/blobs). --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Frameworks/MCPKit') diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index b619db67..d7cd1fba 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -235,7 +235,9 @@ static BOOL sTruncateLongFieldInLogs = YES; } /** - * Ask the delegate for the connection lost decision, on the main thread. + * Ask the delegate for the connection lost decision. This can be called from + * any thread, and will call itself on the main thread if necessary, updating a global + * variable which is then returned on the child thread. */ - (MCPConnectionCheck)delegateDecisionForLostConnection { @@ -245,8 +247,9 @@ static BOOL sTruncateLongFieldInLogs = YES; lastDelegateDecisionForLostConnection = NSNotFound; - // If on the main thread, ask the delegate directly. Perform this in an NSLock to confirm thread safety, - // as this method may be called within itself. + // If on the main thread, ask the delegate directly. + // This is wrapped in a NSLock to ensure variables are completely committed for + // thread-safe access, even though the lock is constrained to this code block. if ([NSThread isMainThread]) { NSLock *delegateDecisionLock = [[NSLock alloc] init]; [delegateDecisionLock lock]; @@ -256,6 +259,10 @@ static BOOL sTruncateLongFieldInLogs = YES; // Otherwise call ourself on the main thread, waiting until the reply is received. } else { + + // First check whether the application is in a modal state; if so, wait + while ([NSApp modalWindow]) usleep(100000); + [self performSelectorOnMainThread:@selector(delegateDecisionForLostConnection) withObject:nil waitUntilDone:YES]; } -- cgit v1.2.3