mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
More host updates.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@5525 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3cbac61b46
commit
2f7945b57f
3 changed files with 67 additions and 59 deletions
|
@ -1,3 +1,12 @@
|
|||
Wed Dec 15 18:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSHost.m: Update again - record current host name for duration
|
||||
of process and cache hosts keyed on the name under which they were
|
||||
created. This can result in multiple cache entries for the same host,
|
||||
but this seems to be necessary as DNS name <--> address mappings can
|
||||
be asymmetric.
|
||||
Thanks to dan@services.iiruc.ro for pointing this out.
|
||||
|
||||
Wed Dec 15 17:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/Foundation/NSObject.h: dealloc notification stuff for Helge
|
||||
|
|
|
@ -69,6 +69,11 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
{
|
||||
return nil;
|
||||
}
|
||||
if (name == nil)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
if (entry == (struct hostent*)NULL)
|
||||
{
|
||||
RELEASE(self);
|
||||
|
@ -98,28 +103,9 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
}
|
||||
|
||||
if (_hostCacheEnabled == YES)
|
||||
{
|
||||
NSEnumerator *enumerator;
|
||||
NSString *key;
|
||||
|
||||
enumerator = [_names objectEnumerator];
|
||||
while ((key = [enumerator nextObject]) != nil)
|
||||
{
|
||||
[_hostCache setObject: self forKey: key];
|
||||
}
|
||||
enumerator = [_addresses objectEnumerator];
|
||||
while ((key = [enumerator nextObject]) != nil)
|
||||
{
|
||||
[_hostCache setObject: self forKey: key];
|
||||
}
|
||||
/*
|
||||
* In addition to official names, use the name we were called with.
|
||||
*/
|
||||
if (name != nil)
|
||||
{
|
||||
[_hostCache setObject: self forKey: name];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -128,38 +114,38 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
|
||||
@implementation NSHost
|
||||
|
||||
- (id) init
|
||||
{
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSHost class])
|
||||
{
|
||||
_hostCacheLock = [[NSLock alloc] init];
|
||||
_hostCache = [NSMutableDictionary new];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Max hostname length in line with RFC 1123
|
||||
*/
|
||||
#define GSMAXHOSTNAMELEN 255
|
||||
|
||||
+ (NSHost*) currentHost
|
||||
static NSString *myHost = nil;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
char name[GSMAXHOSTNAMELEN+1];
|
||||
if (self == [NSHost class])
|
||||
{
|
||||
char buf[GSMAXHOSTNAMELEN+1];
|
||||
int res;
|
||||
|
||||
res = gethostname(name, GSMAXHOSTNAMELEN);
|
||||
res = gethostname(buf, GSMAXHOSTNAMELEN);
|
||||
if (res < 0)
|
||||
{
|
||||
return nil;
|
||||
NSLog(@"Unable to get name of current host - using 'localhost'");
|
||||
myHost = @"localhost";
|
||||
}
|
||||
name[GSMAXHOSTNAMELEN] = '\0';
|
||||
return [self hostWithName: [NSString stringWithCString: name]];
|
||||
else
|
||||
{
|
||||
myHost = [[NSString alloc] initWithCString: buf];
|
||||
}
|
||||
_hostCacheLock = [[NSLock alloc] init];
|
||||
_hostCache = [NSMutableDictionary new];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSHost*) currentHost
|
||||
{
|
||||
return [self hostWithName: myHost];
|
||||
}
|
||||
|
||||
+ (NSHost*) hostWithName: (NSString*)name
|
||||
|
@ -168,7 +154,7 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
|
||||
if (name == nil)
|
||||
{
|
||||
NSLog(@"Nil host name sent to +[NSHost hostWithName]");
|
||||
NSLog(@"Nil host name sent to [NSHost +hostWithName:]");
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -196,7 +182,7 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
|
||||
if (address == nil)
|
||||
{
|
||||
NSLog(@"Nil host address sent to +[NSHost hostWithName]");
|
||||
NSLog(@"Nil host address sent to [NSHost +hostWithName:]");
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -289,6 +275,19 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
return host;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_names);
|
||||
RELEASE(_addresses);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
* The OpenStep spec says that [-hash] must be the same for any two
|
||||
* objects that [-isEqual: ] returns YES for. We have a problem in
|
||||
|
@ -326,11 +325,6 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
if ([_addresses containsObject: [a objectAtIndex: i]])
|
||||
return YES;
|
||||
|
||||
a = [aHost names];
|
||||
for (i = 0; i < [a count]; i++)
|
||||
if ([_addresses containsObject: [a objectAtIndex: i]])
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -360,11 +354,4 @@ static NSMutableDictionary *_hostCache = nil;
|
|||
[self name], [self names], [self addresses]];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_names);
|
||||
RELEASE(_addresses);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -37,12 +37,24 @@ main ()
|
|||
displayHost(a);
|
||||
|
||||
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
||||
printf("c isEqual: n ... %d\n", [c isEqual: n]);
|
||||
printf("n isEqual: c ... %d\n", [n isEqual: c]);
|
||||
printf("c isEqual: a ... %d\n", [c isEqual: a]);
|
||||
printf("a isEqual: c ... %d\n", [a isEqual: c]);
|
||||
printf("n isEqual: a ... %d\n", [n isEqual: a]);
|
||||
printf("a isEqual: n ... %d\n", [a isEqual: n]);
|
||||
|
||||
[NSHost setHostCacheEnabled:NO];
|
||||
|
||||
n = [NSHost hostWithName:[c name]];
|
||||
displayHost(n);
|
||||
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
||||
printf("c isEqual: n ... %d\n", [c isEqual: n]);
|
||||
printf("n isEqual: c ... %d\n", [n isEqual: c]);
|
||||
printf("c isEqual: a ... %d\n", [c isEqual: a]);
|
||||
printf("a isEqual: c ... %d\n", [a isEqual: c]);
|
||||
printf("n isEqual: a ... %d\n", [n isEqual: a]);
|
||||
printf("a isEqual: n ... %d\n", [a isEqual: n]);
|
||||
|
||||
[arp release];
|
||||
exit (0);
|
||||
|
|
Loading…
Reference in a new issue