本文整理汇总了C++中Try::out方法的典型用法代码示例。如果您正苦于以下问题:C++ Try::out方法的具体用法?C++ Try::out怎么用?C++ Try::out使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Try
的用法示例。
在下文中一共展示了Try::out方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Failure
Future<Nothing> NetworkCniIsolatorProcess::detach(
const ContainerID& containerId,
const std::string& networkName)
{
CHECK(infos.contains(containerId));
CHECK(infos[containerId]->containerNetworks.contains(networkName));
const ContainerNetwork& containerNetwork =
infos[containerId]->containerNetworks[networkName];
// Prepare environment variables for CNI plugin.
map<string, string> environment;
environment["CNI_COMMAND"] = "DEL";
environment["CNI_CONTAINERID"] = containerId.value();
environment["CNI_PATH"] = pluginDir.get();
environment["CNI_IFNAME"] = containerNetwork.ifName;
environment["CNI_NETNS"] =
paths::getNamespacePath(rootDir.get(), containerId.value());
// Some CNI plugins need to run "iptables" to set up IP Masquerade, so we
// need to set the "PATH" environment variable so that the plugin can locate
// the "iptables" executable file.
Option<string> value = os::getenv("PATH");
if (value.isSome()) {
environment["PATH"] = value.get();
} else {
environment["PATH"] =
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
}
const NetworkConfigInfo& networkConfig = networkConfigs[networkName];
// Invoke the CNI plugin.
const string& plugin = networkConfig.config.type();
Try<Subprocess> s = subprocess(
path::join(pluginDir.get(), plugin),
{plugin},
Subprocess::PATH(networkConfig.path),
Subprocess::PIPE(),
Subprocess::PATH("/dev/null"),
NO_SETSID,
None(),
environment);
if (s.isError()) {
return Failure(
"Failed to execute the CNI plugin '" + plugin + "': " + s.error());
}
return await(s->status(), io::read(s->out().get()))
.then(defer(
PID<NetworkCniIsolatorProcess>(this),
&NetworkCniIsolatorProcess::_detach,
containerId,
networkName,
plugin,
lambda::_1));
}
示例2: Failure
Future<Nothing> HealthCheckerProcess::_tcpHealthCheck()
{
CHECK_EQ(HealthCheck::TCP, check.type());
CHECK(check.has_tcp());
// TCP_CHECK_COMMAND should be reachable.
CHECK(os::exists(launcherDir));
const HealthCheck::TCPCheckInfo& tcp = check.tcp();
VLOG(1) << "Launching TCP health check at port '" << tcp.port() << "'";
const string tcpConnectPath = path::join(launcherDir, TCP_CHECK_COMMAND);
const vector<string> tcpConnectArguments = {
tcpConnectPath,
"--ip=" + DEFAULT_DOMAIN,
"--port=" + stringify(tcp.port())
};
Try<Subprocess> s = subprocess(
tcpConnectPath,
tcpConnectArguments,
Subprocess::PATH("/dev/null"),
Subprocess::PIPE(),
Subprocess::PIPE(),
nullptr,
None(),
clone);
if (s.isError()) {
return Failure(
"Failed to create the " + string(TCP_CHECK_COMMAND) +
" subprocess: " + s.error());
}
pid_t tcpConnectPid = s->pid();
Duration timeout = Seconds(static_cast<int64_t>(check.timeout_seconds()));
return await(
s->status(),
process::io::read(s->out().get()),
process::io::read(s->err().get()))
.after(timeout,
[timeout, tcpConnectPid](Future<tuple<Future<Option<int>>,
Future<string>,
Future<string>>> future) {
future.discard();
if (tcpConnectPid != -1) {
// Cleanup the TCP_CHECK_COMMAND process.
VLOG(1) << "Killing the TCP health check process " << tcpConnectPid;
os::killtree(tcpConnectPid, SIGKILL);
}
return Failure(
string(TCP_CHECK_COMMAND) + " has not returned after " +
stringify(timeout) + "; aborting");
})
.then(defer(self(), &Self::__tcpHealthCheck, lambda::_1));
}