mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Simplify
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27203 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ca1b828428
commit
b27a7e351c
2 changed files with 26 additions and 47 deletions
|
@ -79,15 +79,17 @@ zfree(void *opaque, void *mem)
|
||||||
|
|
||||||
@implementation GSSocketStreamPair
|
@implementation GSSocketStreamPair
|
||||||
|
|
||||||
static NSMutableDictionary *pairByHost = nil;
|
static NSMutableArray *pairCache = nil;
|
||||||
static NSLock *pairLock = nil;
|
static NSLock *pairLock = nil;
|
||||||
static unsigned pairsCached = 0;
|
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (pairByHost == nil)
|
if (pairCache == nil)
|
||||||
{
|
{
|
||||||
pairByHost = [NSMutableDictionary new];
|
/* No use trying to use a dictionary ... NSHost objects all hash
|
||||||
|
* to the same value.
|
||||||
|
*/
|
||||||
|
pairCache = [NSMutableArray new];
|
||||||
pairLock = [NSLock new];
|
pairLock = [NSLock new];
|
||||||
/* Purge expired pairs at intervals.
|
/* Purge expired pairs at intervals.
|
||||||
*/
|
*/
|
||||||
|
@ -100,29 +102,17 @@ static unsigned pairsCached = 0;
|
||||||
+ (void) purge: (NSNotification*)n
|
+ (void) purge: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSDate *now = [NSDate date];
|
NSDate *now = [NSDate date];
|
||||||
NSEnumerator *enumerator;
|
unsigned count;
|
||||||
NSHost *key;
|
|
||||||
|
|
||||||
[pairLock lock];
|
[pairLock lock];
|
||||||
enumerator = [[pairByHost allKeys] objectEnumerator];
|
count = [pairCache count];
|
||||||
while ((key = [enumerator nextObject]) != nil)
|
while (count-- > 0)
|
||||||
{
|
{
|
||||||
NSMutableArray *items = [pairByHost objectForKey: key];
|
GSSocketStreamPair *p = [pairCache objectAtIndex: count];
|
||||||
unsigned count = [items count];
|
|
||||||
|
|
||||||
while (count-- > 0)
|
if ([[p expires] timeIntervalSinceDate: now] <= 0.0)
|
||||||
{
|
{
|
||||||
GSSocketStreamPair *p = [items objectAtIndex: count];
|
[pairCache removeObjectAtIndex: count];
|
||||||
|
|
||||||
if ([[p expires] timeIntervalSinceDate: now] <= 0.0)
|
|
||||||
{
|
|
||||||
[items removeObjectAtIndex: count];
|
|
||||||
pairsCached--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ([items count] == 0)
|
|
||||||
{
|
|
||||||
[pairByHost removeObjectForKey: key];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[pairLock unlock];
|
[pairLock unlock];
|
||||||
|
@ -130,19 +120,9 @@ static unsigned pairsCached = 0;
|
||||||
|
|
||||||
- (void) cache: (NSDate*)when
|
- (void) cache: (NSDate*)when
|
||||||
{
|
{
|
||||||
NSMutableArray *items;
|
|
||||||
|
|
||||||
ASSIGN(expires, when);
|
ASSIGN(expires, when);
|
||||||
[pairLock lock];
|
[pairLock lock];
|
||||||
items = [pairByHost objectForKey: host];
|
[pairCache addObject: self];
|
||||||
if (items == nil)
|
|
||||||
{
|
|
||||||
items = [NSMutableArray new];
|
|
||||||
[pairByHost setObject: items forKey: host];
|
|
||||||
[items release];
|
|
||||||
}
|
|
||||||
[items addObject: self];
|
|
||||||
pairsCached++;
|
|
||||||
[pairLock unlock];
|
[pairLock unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,34 +148,27 @@ static unsigned pairsCached = 0;
|
||||||
|
|
||||||
- (id) initWithHost: (NSHost*)h port: (uint16_t)p forSSL: (BOOL)s;
|
- (id) initWithHost: (NSHost*)h port: (uint16_t)p forSSL: (BOOL)s;
|
||||||
{
|
{
|
||||||
NSMutableArray *items;
|
|
||||||
unsigned count;
|
unsigned count;
|
||||||
unsigned index;
|
|
||||||
NSDate *now;
|
NSDate *now;
|
||||||
|
|
||||||
now = [NSDate date];
|
now = [NSDate date];
|
||||||
[pairLock lock];
|
[pairLock lock];
|
||||||
items = [pairByHost objectForKey: h];
|
count = [pairCache count];
|
||||||
count = [items count];
|
while (count-- > 0)
|
||||||
for (index = 0; index < count; index++)
|
|
||||||
{
|
{
|
||||||
GSSocketStreamPair *pair = [items objectAtIndex: count];
|
GSSocketStreamPair *pair = [pairCache objectAtIndex: count];
|
||||||
|
|
||||||
if ([pair->expires timeIntervalSinceDate: now] <= 0.0)
|
if ([pair->expires timeIntervalSinceDate: now] <= 0.0)
|
||||||
{
|
{
|
||||||
[items removeObjectAtIndex: index];
|
[pairCache removeObjectAtIndex: count];
|
||||||
pairsCached--;
|
|
||||||
index--;
|
|
||||||
count--;
|
|
||||||
}
|
}
|
||||||
else if (pair->port == p && pair->ssl == s)
|
else if (pair->port == p && pair->ssl == s && [pair->host isEqual: h])
|
||||||
{
|
{
|
||||||
/* Found a match ... remove from cache and return as self.
|
/* Found a match ... remove from cache and return as self.
|
||||||
*/
|
*/
|
||||||
[self release];
|
[self release];
|
||||||
self = [pair retain];
|
self = [pair retain];
|
||||||
[items removeObjectAtIndex: index];
|
[pairCache removeObjectAtIndex: count];
|
||||||
pairsCached--;
|
|
||||||
[pairLock unlock];
|
[pairLock unlock];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1305,11 +1305,17 @@ static retval_t apply_block(void* data)
|
||||||
return __builtin_apply((apply_t)return_block, args, sizeof(void*));
|
return __builtin_apply((apply_t)return_block, args, sizeof(void*));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
static retval_t apply_char(char data)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
static retval_t apply_char(char data)
|
static retval_t apply_char(char data)
|
||||||
{
|
{
|
||||||
void* args = __builtin_apply_args();
|
void* args = __builtin_apply_args();
|
||||||
return __builtin_apply((apply_t)return_char, args, sizeof(void*));
|
return __builtin_apply((apply_t)return_char, args, sizeof(void*));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
static retval_t apply_float(float data)
|
static retval_t apply_float(float data)
|
||||||
{
|
{
|
||||||
void* args = __builtin_apply_args();
|
void* args = __builtin_apply_args();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue