broker
broker copied to clipboard
Re-visit API for Creating Endpoints
Currently, users create an endpoint directly by calling its constructor. However, creating an endpoint can fail for several reasons. The same is true for configuration.
In https://github.com/zeek/broker/pull/81#issuecomment-575914374, we've discussed this straw-man proposal to improve error signaling to the user by going through factory functions:
int main(int argc, char** argv) {
if (auto ep = endpoint::make(argc, argv); // passing (argc, argv) is optional
not ep) {
// oops, configuration error
auto& err = ep.error();
// ...
} else {
// ok, endpoint up and running
}
}
// With explicitly using a configuration.
int main(int argc, char** argv) {
configuration conf;
// ... tweak default settings ...
if (auto err = conf.init(argc, argv)) {
// deal with error explicitly, this step is optional and otherwise performed by endoint::run
}
if (auto ep = endpoint::make(std::move(conf);
not ep) {
// ...
} else {
// ...
}
}