Shut down server when all connections are dead

This commit is contained in:
Gregory John Casamento 2020-02-08 06:08:27 -05:00
parent eda8259f53
commit 07bf3d32e4
3 changed files with 42 additions and 27 deletions

View file

@ -36,30 +36,11 @@
id _speechRecognitionServer = nil;
BOOL _serverLaunchTested = NO;
static int clients;
#define SPEECH_RECOGNITION_SERVER @"GSSpeechRecognitionServer"
@implementation NSSpeechRecognizer
/**
* If the remote end exits before freeing the GSSpeechRecognizer then we need
* to send it a -release message to make sure it dies.
*/
+ (void)connectionDied: (NSNotification*)aNotification
{
NSEnumerator *e = [[[aNotification object] localObjects] objectEnumerator];
NSObject *o = nil;
for (o = [e nextObject] ; nil != o ; o = [e nextObject])
{
if ([o isKindOfClass: self])
{
[o release];
}
}
}
+ (void) initialize
{
if (self == [NSSpeechRecognizer class])
@ -71,12 +52,6 @@ static int clients;
showIcon: NO
autolaunch: NO];
}
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(connectionDied:)
name: NSConnectionDidDieNotification
object: nil];
}
}
@ -123,7 +98,6 @@ static int clients;
if (nil != _speechRecognitionServer)
{
NSLog(@"Server found!!!");
clients++;
break;
}
[NSThread sleepForTimeInterval: 0.1];