aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMMCPConnection.h
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-02-18 21:47:29 +0000
committerrowanbeentje <rowan@beent.je>2009-02-18 21:47:29 +0000
commit3ca168863ddbdc3ac3bba0cfd9a64ce262cbfea8 (patch)
tree19639d2095efd7c3d48ac2dedf893653f8a60c2e /Source/CMMCPConnection.h
parent2525366dbfed3aef78beaed89630ea543389cec1 (diff)
downloadsequelpro-3ca168863ddbdc3ac3bba0cfd9a64ce262cbfea8.tar.gz
sequelpro-3ca168863ddbdc3ac3bba0cfd9a64ce262cbfea8.tar.bz2
sequelpro-3ca168863ddbdc3ac3bba0cfd9a64ce262cbfea8.zip
Sets and enforces a connection timeout, and handles connection timeouts appropriately - offering to retry, reconnect, or disconnect. This fixes Issue #93, Issue #69, and Issue #77.
The gory details: Previously, MCPKit was correctly running mysql_ping to ensure a connection still existed before running a query, and aborted the query if the connection was no longer active.However the code very rarely checked the response of this, so if a query failed subsequent queries would continue to be run and the program would end up checking non-existent results, throwing Cocoa exceptions and generally breaking. However, mysql_ping would also use the default timeout (30 seconds) for each check - when running the (previous to r333) 14 queries to switch tables, this resulted in a long hang before the program even broke. To exacerbate the issue, certain situations triggered a bug present in mysql_ping in the old client binaries we're using (http://bugs.mysql.com/bug.php?id=9678), causing mysql_ping to never return despite the presence of a timeout, and so causing an indefinite hang. This issue has been fixed by: - Setting a new 10 second connection timeout for both new connections (Issue #69) and for mysql_pings. Once preferences have been redesigned we'll probably make this value editable. - Enforce the 10 second timeout even if mysql_ping hangs by using interrupts. - Wrap mysql_ping in a new method to do the above and also catch re-established connections without reporting false failures. - When a connection has failed, prompt the user to Retry, Reconnect, or Disconnect. Reconnect uses the original details for the old connection to establish a new connection, also attempting to preserve the current encoding. - Do not return control to the main loop until a connection has been reestablished (or disconnected) - this ensures the program is never in a broken state without having to rewrite all query usage. Much of the above patches the MCPKit connection methods as necessary.
Diffstat (limited to 'Source/CMMCPConnection.h')
-rw-r--r--Source/CMMCPConnection.h31
1 files changed, 28 insertions, 3 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h
index 7b379d01..3a6b4016 100644
--- a/Source/CMMCPConnection.h
+++ b/Source/CMMCPConnection.h
@@ -26,6 +26,11 @@
#import <MCPKit_bundled/MCPKit_bundled.h>
#import "CMMCPResult.h"
+// Set the connection timeout to enforce for all connections - used for the initial connection
+// timeout and ping timeouts, but not for long queries/reads/writes.
+// Probably worth moving this to a preference at some point.
+#define SP_CONNECTION_TIMEOUT 10
+
@interface NSObject (CMMCPConnectionDelegate)
- (void)willQueryString:(NSString *)query;
@@ -34,11 +39,31 @@
@end
@interface CMMCPConnection : MCPConnection {
+ IBOutlet NSWindow *connectionErrorDialog;
+ NSWindow *parentWindow;
id delegate;
+
+ BOOL nibLoaded;
+ NSString *connectionLogin;
+ NSString *connectionPassword;
+ NSString *connectionHost;
+ int connectionPort;
+ NSString *connectionSocket;
}
-- (CMMCPResult *)queryString:(NSString *) query;
-- (void)setDelegate:(id)object;
-- (NSTimeZone *)timeZone;
+- (id) init;
+- (id) initToHost:(NSString *) host withLogin:(NSString *) login password:(NSString *) pass usingPort:(int) port;
+- (id) initToSocket:(NSString *) socket withLogin:(NSString *) login password:(NSString *) pass;
+- (void) initSPExtensions;
+- (BOOL) connectWithLogin:(NSString *) login password:(NSString *) pass host:(NSString *) host port:(int) port socket:(NSString *) socket;
+- (void) disconnect;
+- (BOOL) reconnect;
+- (IBAction) closeSheet:(id)sender;
+- (void) setParentWindow:(NSWindow *)theWindow;
+- (CMMCPResult *) queryString:(NSString *) query;
+- (BOOL) checkConnection;
+- (void) setDelegate:(id)object;
+- (NSTimeZone *) timeZone;
+- (BOOL) pingConnection;
@end