diff options
Diffstat (limited to 'Frameworks/PostgresKit/Source')
-rw-r--r-- | Frameworks/PostgresKit/Source/PGPostgresConnection.m | 102 | ||||
-rw-r--r-- | Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m | 46 |
2 files changed, 72 insertions, 76 deletions
diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnection.m b/Frameworks/PostgresKit/Source/PGPostgresConnection.m index 600be9a0..5e1ac2bf 100644 --- a/Frameworks/PostgresKit/Source/PGPostgresConnection.m +++ b/Frameworks/PostgresKit/Source/PGPostgresConnection.m @@ -297,64 +297,62 @@ static void _PGPostgresConnectionNoticeProcessor(void *arg, const char *message) */ - (void)_pollConnection:(NSNumber *)isReset { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - BOOL reset = isReset && [isReset boolValue]; - - int 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 = reset ? PQresetPoll(_connection) : PQconnectPoll(_connection); - - if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) { - if (poll(fdinfo, 1, -1) < 0) break; - } - } - while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED); - - if (status == PGRES_POLLING_OK && [self isConnected]) { - - // Increase error verbosity - PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE); - - // Set notice processor - PQsetNoticeProcessor(_connection, _PGPostgresConnectionNoticeProcessor, self); - - // Register or clear type extensions - NSInteger success = reset ? PQclearTypes(_connection) : PQinitTypes(_connection); - - if (!success) { - NSLog(@"PostgresKit: Error: Failed to initialise or clear type extensions. Connection might return unexpected results!"); + @autoreleasepool { + BOOL reset = isReset && [isReset boolValue]; + + int sock = PQsocket(_connection); + + if (sock == -1) { + [pool release]; + return; } - - [self _loadDatabaseParameters]; - - if (reset) { - if (_delegate && [_delegate respondsToSelector:@selector(connectionReset:)]) { - [_delegate performSelectorOnMainThread:@selector(connectionReset:) withObject:self waitUntilDone:NO]; + + struct pollfd fdinfo[1]; + + fdinfo[0].fd = sock; + fdinfo[0].events = POLLIN|POLLOUT; + + PostgresPollingStatusType status; + + do + { + status = reset ? PQresetPoll(_connection) : PQconnectPoll(_connection); + + if (status == PGRES_POLLING_READING || status == PGRES_POLLING_WRITING) { + if (poll(fdinfo, 1, -1) < 0) break; } } - else { - if (_delegate && [_delegate respondsToSelector:@selector(connectionEstablished:)]) { - [_delegate performSelectorOnMainThread:@selector(connectionEstablished:) withObject:self waitUntilDone:NO]; + while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED); + + if (status == PGRES_POLLING_OK && [self isConnected]) { + + // Increase error verbosity + PQsetErrorVerbosity(_connection, PQERRORS_VERBOSE); + + // Set notice processor + PQsetNoticeProcessor(_connection, _PGPostgresConnectionNoticeProcessor, self); + + // Register or clear type extensions + NSInteger success = reset ? PQclearTypes(_connection) : PQinitTypes(_connection); + + if (!success) { + NSLog(@"PostgresKit: Error: Failed to initialise or clear type extensions. Connection might return unexpected results!"); + } + + [self _loadDatabaseParameters]; + + if (reset) { + if (_delegate && [_delegate respondsToSelector:@selector(connectionReset:)]) { + [_delegate performSelectorOnMainThread:@selector(connectionReset:) withObject:self waitUntilDone:NO]; + } + } + else { + if (_delegate && [_delegate respondsToSelector:@selector(connectionEstablished:)]) { + [_delegate performSelectorOnMainThread:@selector(connectionEstablished:) withObject:self waitUntilDone:NO]; + } } } } - - [pool release]; } /** diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m index e179f110..dc233664 100644 --- a/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m +++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionParameters.m @@ -138,32 +138,30 @@ */ - (void)_loadParameters:(id)object { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - pthread_mutex_lock(&_readLock); - - NSArray *parameters = (NSArray *)object; - - if (!_parameters) { - _parameters = [[NSMutableDictionary alloc] initWithCapacity:[parameters count]]; - } - - for (NSString *parameter in parameters) - { - const char *value = PQparameterStatus([_connection postgresConnection], [parameter UTF8String]); - - if (!value) continue; - - NSString *stringValue = [NSString stringWithUTF8String:value]; + @autoreleasepool { + pthread_mutex_lock(&_readLock); - id paramObject = [self _isBooleanParameterValue:stringValue] ? (id)[NSNumber numberWithBool:[self _booleanForParameterValue:stringValue]] : stringValue; - - [_parameters setObject:paramObject forKey:parameter]; + NSArray *parameters = (NSArray *)object; + + if (!_parameters) { + _parameters = [[NSMutableDictionary alloc] initWithCapacity:[parameters count]]; + } + + for (NSString *parameter in parameters) + { + const char *value = PQparameterStatus([_connection postgresConnection], [parameter UTF8String]); + + if (!value) continue; + + NSString *stringValue = [NSString stringWithUTF8String:value]; + + id paramObject = [self _isBooleanParameterValue:stringValue] ? (id)[NSNumber numberWithBool:[self _booleanForParameterValue:stringValue]] : stringValue; + + [_parameters setObject:paramObject forKey:parameter]; + } + + pthread_mutex_unlock(&_readLock); } - - pthread_mutex_unlock(&_readLock); - - [pool release]; } /** |