mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
dhcp fix
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15275 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b718bd40ad
commit
610a34df85
3 changed files with 54 additions and 36 deletions
|
@ -5,6 +5,8 @@
|
|||
* Source/NSConnection.m: Experimental code to keep local objects
|
||||
retained long enough to deal with most cases where the remote
|
||||
process may want them again.
|
||||
* Source/NSHost.m: Don't cache local host name ... it may change
|
||||
due to use of DHCP etc.
|
||||
|
||||
2002-12-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
|
|
|
@ -3125,27 +3125,29 @@ static void callEncoder (DOContext *ctxt)
|
|||
counter->ref--;
|
||||
if ((val = counter->ref) == 0)
|
||||
{
|
||||
id item;
|
||||
/*
|
||||
* If this proxy has been vended onwards by another process, we
|
||||
* need to keep a reference to the local object around for a
|
||||
* while in case that other process needs it.
|
||||
*/
|
||||
if (timer == nil)
|
||||
if (1)
|
||||
{
|
||||
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
|
||||
target: connectionClass
|
||||
selector: @selector(_timeout:)
|
||||
userInfo: nil
|
||||
repeats: YES];
|
||||
id item;
|
||||
/*
|
||||
* If this proxy has been vended onwards by another process, we
|
||||
* need to keep a reference to the local object around for a
|
||||
* while in case that other process needs it.
|
||||
*/
|
||||
if (timer == nil)
|
||||
{
|
||||
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
|
||||
target: connectionClass
|
||||
selector: @selector(_timeout:)
|
||||
userInfo: nil
|
||||
repeats: YES];
|
||||
}
|
||||
item = [CachedLocalObject newWithObject: counter time: 30];
|
||||
NSMapInsert(targetToCached, (void*)target, item);
|
||||
RELEASE(item);
|
||||
if (debug_connection > 3)
|
||||
NSLog(@"placed local object (0x%x) target (0x%x) in cache",
|
||||
(gsaddr)anObj, target);
|
||||
}
|
||||
item = [CachedLocalObject newWithObject: counter time: 30];
|
||||
NSMapInsert(targetToCached, (void*)target, item);
|
||||
RELEASE(item);
|
||||
if (debug_connection > 3)
|
||||
NSLog(@"placed local object (0x%x) target (0x%x) in cache",
|
||||
(gsaddr)anObj, target);
|
||||
|
||||
NSMapRemove(objectToCounter, (void*)anObj);
|
||||
NSMapRemove(targetToCounter, (void*)target);
|
||||
}
|
||||
|
@ -3247,7 +3249,6 @@ static void callEncoder (DOContext *ctxt)
|
|||
}
|
||||
}
|
||||
RETAIN(counter);
|
||||
M_UNLOCK(global_proxies_gate);
|
||||
if (counter == nil)
|
||||
{
|
||||
if(debug_connection > 3)
|
||||
|
@ -3263,6 +3264,7 @@ static void callEncoder (DOContext *ctxt)
|
|||
RELEASE(counter);
|
||||
}
|
||||
}
|
||||
M_UNLOCK(global_proxies_gate);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,6 @@ static Class hostClass;
|
|||
static NSLock *_hostCacheLock = nil;
|
||||
static BOOL _hostCacheEnabled = YES;
|
||||
static NSMutableDictionary *_hostCache = nil;
|
||||
static NSString *myHostName = nil;
|
||||
|
||||
|
||||
@interface NSHost (Private)
|
||||
|
@ -260,24 +259,39 @@ static NSString *myHostName = nil;
|
|||
*/
|
||||
#define GSMAXHOSTNAMELEN 255
|
||||
|
||||
/**
|
||||
* Return the current host name ... may change if we are using dhcp etc
|
||||
*/
|
||||
static NSString*
|
||||
myHostName()
|
||||
{
|
||||
static NSString *name = nil;
|
||||
static char old[GSMAXHOSTNAMELEN+1];
|
||||
char buf[GSMAXHOSTNAMELEN+1];
|
||||
int res;
|
||||
|
||||
[_hostCacheLock lock];
|
||||
res = gethostname(buf, GSMAXHOSTNAMELEN);
|
||||
if (res < 0 || *buf == '\0')
|
||||
{
|
||||
NSLog(@"Unable to get name of current host - using 'localhost'");
|
||||
ASSIGN(name, @"localhost");
|
||||
}
|
||||
else if (name == nil || strcmp(old, buf) != 0)
|
||||
{
|
||||
strcpy(old, buf);
|
||||
RELEASE(name);
|
||||
name = [[NSString alloc] initWithCString: buf];
|
||||
}
|
||||
[_hostCacheLock unlock];
|
||||
return name;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSHost class])
|
||||
{
|
||||
char buf[GSMAXHOSTNAMELEN+1];
|
||||
int res;
|
||||
|
||||
hostClass = self;
|
||||
res = gethostname(buf, GSMAXHOSTNAMELEN);
|
||||
if (res < 0 || *buf == '\0')
|
||||
{
|
||||
NSLog(@"Unable to get name of current host - using 'localhost'");
|
||||
myHostName = @"localhost";
|
||||
}
|
||||
else
|
||||
{
|
||||
myHostName = [[NSString alloc] initWithCString: buf];
|
||||
}
|
||||
_hostCacheLock = [[NSRecursiveLock alloc] init];
|
||||
_hostCache = [NSMutableDictionary new];
|
||||
}
|
||||
|
@ -285,7 +299,7 @@ static NSString *myHostName = nil;
|
|||
|
||||
+ (NSHost*) currentHost
|
||||
{
|
||||
return [self hostWithName: myHostName];
|
||||
return [self hostWithName: myHostName()];
|
||||
}
|
||||
|
||||
+ (NSHost*) hostWithName: (NSString*)name
|
||||
|
@ -326,7 +340,7 @@ static NSString *myHostName = nil;
|
|||
h = gethostbyname((char*)[name cString]);
|
||||
if (h == 0)
|
||||
{
|
||||
if ([name isEqualToString: myHostName] == YES)
|
||||
if ([name isEqualToString: myHostName()] == YES)
|
||||
{
|
||||
NSLog(@"No network address appears to be available "
|
||||
@"for this machine (%@) - using loopback address "
|
||||
|
|
Loading…
Reference in a new issue