diff options
author | rowanbeentje <rowan@beent.je> | 2012-10-14 16:09:45 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-10-14 16:09:45 +0000 |
commit | dc45c654aab99cbccecda192396dc8baefd5690e (patch) | |
tree | a1b0a16eb468e191177c3617fc1f3c73c3e4750f /Source/SPConnectionController.m | |
parent | 7d14dae0476ee3e3ab7c2fac391c506ac320d5ea (diff) | |
download | sequelpro-dc45c654aab99cbccecda192396dc8baefd5690e.tar.gz sequelpro-dc45c654aab99cbccecda192396dc8baefd5690e.tar.bz2 sequelpro-dc45c654aab99cbccecda192396dc8baefd5690e.zip |
- In the SPMySQL.framework, separate framework-triggered connections and disconnections from external actions, and use that separation to perform safer disconnects
- When closing a database document, add a new notification, and use that to resolve retain cycles affecting connection processes
- Improve connection controller disconnection when the document is closed, fixing crashes, by building on those two features (addresses Issue #1396)
- Use some of the new functionality to improve SSH and MySQL connection cancellation, making both cancelable in the interface and making both respond much more quickly
Diffstat (limited to 'Source/SPConnectionController.m')
-rw-r--r-- | Source/SPConnectionController.m | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 409b89c0..23fe0911 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -93,6 +93,8 @@ static NSString *SPExportFavoritesFilename = @"SequelProFavorites.plist"; - (void)_startEditingConnection; +- (void)_documentWillClose:(NSNotification *)notification; + static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, void *key); #endif @@ -291,21 +293,41 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, } /** - * Cancels (or rather marks) the current connection is to be cancelled once established. - * - * Note, that once called this method does not mark the connection attempt to be immediately cancelled as - * there is no reliable way to actually cancel connection attempts via the MySQL client libs. Once the - * connection is established it will be immediately killed. + * Cancels the current connection - both SSH and MySQL. */ -- (IBAction)cancelMySQLConnection:(id)sender +- (IBAction)cancelConnection:(id)sender { #ifndef SP_REFACTOR [connectButton setEnabled:NO]; [progressIndicatorText setStringValue:NSLocalizedString(@"Cancelling...", @"cancelling task status message")]; [progressIndicatorText display]; - - mySQLConnectionCancelled = YES; + + if (mySQLConnection) { + [NSThread detachNewThreadSelector:@selector(disconnect) toTarget:mySQLConnection withObject:nil]; + } +#endif + + cancellingConnection = YES; + + // Cancel the MySQL connection - handing it off to a background thread - if one is present + if (mySQLConnection) { + [mySQLConnection setDelegate:nil]; + [NSThread detachNewThreadSelector:@selector(disconnect) toTarget:mySQLConnection withObject:nil]; + [mySQLConnection autorelease]; + mySQLConnection = nil; + } + + // Cancel the SSH tunnel if present + if (sshTunnel) { + [sshTunnel disconnect]; + [sshTunnel release]; + sshTunnel = nil; + } + +#ifndef SP_REFACTOR + // Restore the connection interface + [self _restoreConnectionInterface]; #endif } @@ -1558,9 +1580,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, // Re-enable favorites table view [favoritesOutlineView setEnabled:YES]; [(NSView *)favoritesOutlineView display]; - - mySQLConnectionCancelled = NO; - + // Revert the connect button back to its original selector [connectButton setAction:@selector(initiateConnection:)]; } @@ -1767,6 +1787,18 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, #pragma mark - +- (void)_documentWillClose:(NSNotification *)notification +{ + dbDocument = nil; + if (mySQLConnection) { + [mySQLConnection setDelegate:nil]; + [NSThread detachNewThreadSelector:@selector(disconnect) toTarget:mySQLConnection withObject:nil]; + [mySQLConnection autorelease]; + mySQLConnection = nil; + } + if (sshTunnel) [sshTunnel setConnectionStateChangeSelector:nil delegate:nil], [sshTunnel disconnect], [sshTunnel release]; +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -1809,12 +1841,6 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, for (id retainedObject in nibObjectsToRelease) [retainedObject release]; [nibObjectsToRelease release]; - - if (mySQLConnection) { - [mySQLConnection setDelegate:nil]; - [mySQLConnection release]; - } - if (sshTunnel) [sshTunnel setConnectionStateChangeSelector:nil delegate:nil], [sshTunnel disconnect], [sshTunnel release]; if (connectionKeychainID) [connectionKeychainID release]; if (connectionKeychainItemName) [connectionKeychainItemName release]; |