mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2024-10-07 08:32:16 +08:00
Add SIGTERM support to -runWithOptions:error:
This commit is contained in:
parent
3b75f9dd20
commit
420ed719e8
@ -351,9 +351,9 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
|||||||
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;
|
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the server synchronously using -startWithOptions: until a SIGINT signal
|
* Runs the server synchronously using -startWithOptions: until a SIGTERM or
|
||||||
* is received i.e. Ctrl-C. This method is intended to be used by command line
|
* SIGINT signal is received i.e. Ctrl-C in Terminal. This method is intended to
|
||||||
* tools.
|
* be used by command line tools.
|
||||||
*
|
*
|
||||||
* Returns NO if the server failed to start and sets "error" argument if not NULL.
|
* Returns NO if the server failed to start and sets "error" argument if not NULL.
|
||||||
*
|
*
|
||||||
|
@ -668,8 +668,9 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
DCHECK([NSThread isMainThread]);
|
DCHECK([NSThread isMainThread]);
|
||||||
BOOL success = NO;
|
BOOL success = NO;
|
||||||
_run = YES;
|
_run = YES;
|
||||||
void (*handler)(int) = signal(SIGINT, _SignalHandler);
|
void (*termHandler)(int) = signal(SIGTERM, _SignalHandler);
|
||||||
if (handler != SIG_ERR) {
|
void (*intHandler)(int) = signal(SIGINT, _SignalHandler);
|
||||||
|
if ((termHandler != SIG_ERR) && (intHandler != SIG_ERR)) {
|
||||||
if ([self startWithOptions:options error:error]) {
|
if ([self startWithOptions:options error:error]) {
|
||||||
while (_run) {
|
while (_run) {
|
||||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, true);
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0, true);
|
||||||
@ -677,7 +678,8 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
|||||||
[self stop];
|
[self stop];
|
||||||
success = YES;
|
success = YES;
|
||||||
}
|
}
|
||||||
signal(SIGINT, handler);
|
signal(SIGINT, intHandler);
|
||||||
|
signal(SIGTERM, termHandler);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user