aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-09-09 11:35:32 +0000
committerstuconnolly <stuart02@gmail.com>2012-09-09 11:35:32 +0000
commitcb6a338da45d92e697335a6d066cdc9be6d4474b (patch)
tree9ab05733540387ab492d2d2cd7fc0da299dcaf4b /Frameworks
parentd45b89f6a308e9ef1aa3ef239c492b9c8513f156 (diff)
downloadsequelpro-cb6a338da45d92e697335a6d066cdc9be6d4474b.tar.gz
sequelpro-cb6a338da45d92e697335a6d066cdc9be6d4474b.tar.bz2
sequelpro-cb6a338da45d92e697335a6d066cdc9be6d4474b.zip
Fix connection polling.
Diffstat (limited to 'Frameworks')
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresConnection.m47
1 files changed, 27 insertions, 20 deletions
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m
index cba07dae..df00dc8e 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresConnection.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresConnection.m
@@ -31,7 +31,8 @@
#import "FLXPostgresStatement.h"
#import "FLXPostgresResult.h"
-#import "pthread.h"
+#import <pthread.h>
+#import <poll.h>
// Connection default constants
static NSUInteger FLXPostgresConnectionDefaultTimeout = 30;
@@ -307,28 +308,34 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message
- (void)_pollConnection
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSInteger sock = PQsocket(_connection);
+
+ if (sock == -1) {
+ [pool release];
+ return;
+ }
+
+ struct pollfd fdinfo[1];
+
+ fdinfo[0].fd = sock;
+ fdinfo[0].events = POLLIN|POLLOUT;
+
+ PostgresPollingStatusType status;
+
+ do
+ {
+ status = PQconnectPoll(_connection);
- BOOL failed = NO;
- BOOL connected = NO;
-
- while (!connected && !failed)
- {
- switch (PQconnectPoll(_connection))
- {
- case PGRES_POLLING_READING:
- case PGRES_POLLING_WRITING:
- case PGRES_POLLING_ACTIVE:
- break;
- case PGRES_POLLING_OK:
- connected = YES;
- break;
- case PGRES_POLLING_FAILED:
- failed = YES;
- break;
+ if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) {
+ NSInteger result = poll(fdinfo, 1, -1);
+
+ if (result < 0) break;
}
}
+ while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
- if (connected) {
+ if (status == PGRES_POLLING_OK && [self isConnected]) {
// Increase error verbosity
PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE);
@@ -416,7 +423,7 @@ static void _FLXPostgresConnectionNoticeProcessor(void *arg, const char *message
_connectionParamValues[2] = [_encoding UTF8String];
_connectionParamNames[3] = FLXPostgresKeepAliveParam;
- _connectionParamValues[4] = _useKeepAlive ? "1" : "0";
+ _connectionParamValues[3] = _useKeepAlive ? "1" : "0";
_connectionParamNames[4] = FLXPostgresKeepAliveIntervalParam;
_connectionParamValues[4] = [[[NSNumber numberWithUnsignedInteger:_keepAliveInterval] stringValue] UTF8String];