Author: mlytwyn
Date: Mon Oct 3 14:40:06 2016
New Revision: 40115
URL: http://svn.gna.org/viewcvs/gnustep?rev=40115&view=rev
Log:
Merge Tools/gdnc.m with base trunk 40072
Modified:
libs/base/branches/gnustep_testplant_branch/Tools/gdnc.m
Modified: libs/base/branches/gnustep_testplant_branch/Tools/gdnc.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Tools/gdnc.m?rev=40115&r1=40114&r2=40115&view=diff
==============================================================================
--- libs/base/branches/gnustep_testplant_branch/Tools/gdnc.m (original)
+++ libs/base/branches/gnustep_testplant_branch/Tools/gdnc.m Mon Oct 3
14:40:06 2016
@@ -37,6 +37,7 @@
#import "Foundation/NSProcessInfo.h"
#import "Foundation/NSRunLoop.h"
#import "Foundation/NSTask.h"
+#import "Foundation/NSTimer.h"
#import "Foundation/NSUserDefaults.h"
@@ -68,6 +69,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)
@@ -358,6 +361,20 @@
@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 @@
table = NSCreateMapTable(NSObjectMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
NSMapInsert(connections, newConn, table);
+ if (nil != timer)
+ {
+ [timer invalidate];
+ timer = nil;
+ }
return YES;
}
@@ -697,11 +719,20 @@
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.
+ /* 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.
*/
- exit(EXIT_SUCCESS);
- }
+ if (nil != timer)
+ {
+ [timer invalidate];
+ }
+ timer = [NSTimer scheduledTimerWithTimeInterval: 15.0
+ target: self
+ selector: @selector(autoStop:)
+ userInfo: nil
+ repeats: NO];
+ }
}
return nil;
}
@@ -1170,9 +1201,7 @@
RELEASE(pool);
{
-#if GS_WITH_GC == 0
CREATE_AUTORELEASE_POOL(pool);
-#endif
NSUserDefaults *defs;
int sym;
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs