Try to manage count of connected clients better

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38608 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-06-10 08:05:59 +00:00
parent 85d8389ba0
commit 11bf21a930

View file

@ -926,27 +926,27 @@ static int poolConnections = 0;
e = NSEnumerateHashTable(clientsHash); e = NSEnumerateHashTable(clientsHash);
while (nil != (o = (SQLClient*)NSNextHashEnumeratorItem(&e))) while (nil != (o = (SQLClient*)NSNextHashEnumeratorItem(&e)))
{ {
if (since != nil) if (YES == o->connected)
{ {
NSTimeInterval when = o->_lastOperation; connectionCount++;
if (since != nil)
if (when < o->_lastStart)
{ {
when = o->_lastStart; NSTimeInterval when = o->_lastOperation;
}
if (when < t && YES == o->connected) if (when < o->_lastStart)
{
if (nil == a)
{ {
a = [NSMutableArray array]; when = o->_lastStart;
} }
[a addObject: o]; if (when < t)
} {
} if (nil == a)
else if ([o connected] == YES) {
{ a = [NSMutableArray array];
connectionCount++; }
} [a addObject: o];
}
}
}
} }
NSEndHashTableEnumeration(&e); NSEndHashTableEnumeration(&e);
[clientsLock unlock]; [clientsLock unlock];
@ -958,27 +958,30 @@ static int poolConnections = 0;
o = [a lastObject]; o = [a lastObject];
if ([o->lock tryLock]) if ([o->lock tryLock])
{ {
NSTimeInterval when = o->_lastOperation; if (YES == o->connected)
{
NSTimeInterval when = o->_lastOperation;
if (when < o->_lastStart) if (when < o->_lastStart)
{
when = o->_lastStart;
}
if (when < t && YES == o->connected)
{
NS_DURING
{ {
[o disconnect]; when = o->_lastStart;
if ([o connected] == YES) }
if (when < t)
{
NS_DURING
{ {
connectionCount++; [o disconnect];
} }
NS_HANDLER
{
NSLog(@"Problem disconnecting: %@", localException);
}
NS_ENDHANDLER
} }
NS_HANDLER }
{ if (NO == o->connected)
NSLog(@"Problem disconnecting: %@", localException); {
} connectionCount--;
NS_ENDHANDLER
} }
[o->lock unlock]; [o->lock unlock];
} }