mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Improve reliability on a slow system where there is no gdnc daemon (eg when
running regression tests for an uninstalled copy of gnustep). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39917 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
96909cf9cf
commit
98255fc40d
2 changed files with 36 additions and 5 deletions
|
@ -736,7 +736,7 @@ static NSDistributedNotificationCenter *netCenter = nil;
|
|||
}
|
||||
[NSTask launchedTaskWithLaunchPath: cmd arguments: args];
|
||||
|
||||
limit = [NSDate dateWithTimeIntervalSinceNow: 5.0];
|
||||
limit = [NSDate dateWithTimeIntervalSinceNow: 10.0];
|
||||
while (_remote == nil && [limit timeIntervalSinceNow] > 0)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
|
|
39
Tools/gdnc.m
39
Tools/gdnc.m
|
@ -37,6 +37,7 @@
|
|||
#import "Foundation/NSProcessInfo.h"
|
||||
#import "Foundation/NSRunLoop.h"
|
||||
#import "Foundation/NSTask.h"
|
||||
#import "Foundation/NSTimer.h"
|
||||
#import "Foundation/NSUserDefaults.h"
|
||||
|
||||
|
||||
|
@ -69,6 +70,8 @@ static BOOL debugging = NO;
|
|||
static BOOL is_daemon = NO; /* Currently running as daemon. */
|
||||
static BOOL auto_stop = NO; /* Should we shut down when unused? */
|
||||
|
||||
static NSTimer *timer = nil; /* When to shut down. */
|
||||
|
||||
#if defined(HAVE_SYSLOG) || defined(HAVE_SLOGF)
|
||||
# if defined(HAVE_SLOGF)
|
||||
# include <sys/slogcodes.h>
|
||||
|
@ -358,6 +361,20 @@ ihandler(int sig)
|
|||
|
||||
@implementation GDNCServer
|
||||
|
||||
- (void) autoStop: (NSTimer*)t
|
||||
{
|
||||
if (t == timer)
|
||||
{
|
||||
timer = nil;
|
||||
}
|
||||
if (auto_stop == YES && NSCountMapTable(connections) == 0)
|
||||
{
|
||||
/* There is nothing else using this process, stop.
|
||||
*/
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
@ -662,6 +679,11 @@ ihandler(int sig)
|
|||
table = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 0);
|
||||
NSMapInsert(connections, newConn, table);
|
||||
if (nil != timer)
|
||||
{
|
||||
[timer invalidate];
|
||||
timer = nil;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -697,10 +719,19 @@ ihandler(int sig)
|
|||
|
||||
if (auto_stop == YES && NSCountMapTable(connections) == 0)
|
||||
{
|
||||
/* If there is nothing else using this process, and this is not
|
||||
* a daemon, then we can quietly terminate.
|
||||
*/
|
||||
exit(EXIT_SUCCESS);
|
||||
/* There is nothing left using this notification center,
|
||||
* so schedule the auto_stop to occur in a short while
|
||||
* if nothing has connected to us.
|
||||
*/
|
||||
if (nil != timer)
|
||||
{
|
||||
[timer invalidate];
|
||||
}
|
||||
timer = [NSTimer scheduledTimerWithTimeInterval: 15.0
|
||||
target: self
|
||||
selector: @selector(autoStop:)
|
||||
userInfo: nil
|
||||
repeats: NO];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
|
|
Loading…
Reference in a new issue