-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Signals | ||
|
||
Seastar provides an interface to handle signals natively and safely as asynchronous tasks. | ||
|
||
It provides a dedicated header called [seastar/core/signal.hh](../include/seastar/core/signal.hh). | ||
|
||
## Usage | ||
|
||
You should call `seastar::handle_signal` procedure in order to register the provided signal handler for the specified signal based on the configuration params. | ||
|
||
The procedure must be called inside the `app.run()` lambda, otherwise it's UB. | ||
|
||
### Examples | ||
|
||
```C++ | ||
#include <seastar/core/app-template.hh> | ||
#include <seastar/core/signal.hh> | ||
|
||
int main(int argc, char** argv) { | ||
seastar::app_template app; | ||
return app.run(argc, argv, [] { | ||
seastar::handle_signal(SIGINT, [&] { | ||
std::cout << "caught sigint\n"; | ||
}, true); | ||
}); | ||
} | ||
``` | ||
- [tests/unit/signal_test.cc](../tests/unit/signal_test.cc) | ||
- [apps/lib/stop_signal.hh](../apps/lib/stop_signal.hh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is open source software, licensed to you under the terms | ||
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. You may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
/// \file | ||
|
||
// Seastar interface for POSIX signals. | ||
#include <seastar/util/modules.hh> | ||
#include <seastar/util/noncopyable_function.hh> | ||
|
||
namespace seastar { | ||
|
||
SEASTAR_MODULE_EXPORT_BEGIN | ||
|
||
/// \brief Sets a signal handler for the specified signal. | ||
/// | ||
/// \param signo Signal number. | ||
/// \param handler Function to handle the signal. | ||
/// \param once Should the handler be invoked only once. | ||
void handle_signal(int signo, noncopyable_function<void ()>&& handler, bool once = false); | ||
|
||
SEASTAR_MODULE_EXPORT_END | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is open source software, licensed to you under the terms | ||
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. You may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifdef SEASTAR_MODULE | ||
module; | ||
#endif | ||
|
||
#include <stdexcept> | ||
|
||
#ifdef SEASTAR_MODULE | ||
module seastar; | ||
#else | ||
#include <seastar/core/signal.hh> | ||
#include <seastar/core/reactor.hh> | ||
#endif | ||
|
||
namespace seastar { | ||
|
||
void handle_signal(int signo, noncopyable_function<void ()>&& handler, bool once) { | ||
auto& r = engine(); | ||
if (once) { | ||
r._signals.handle_signal_once(signo, std::move(handler)); | ||
} else { | ||
r._signals.handle_signal(signo, std::move(handler)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters