本文整理汇总了C++中folly::StringPiece::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::toString方法的具体用法?C++ StringPiece::toString怎么用?C++ StringPiece::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::StringPiece
的用法示例。
在下文中一共展示了StringPiece::toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSSLContext
std::shared_ptr<SSLContext> getSSLContext(folly::StringPiece pemCertPath,
folly::StringPiece pemKeyPath,
folly::StringPiece pemCaPath) {
static constexpr std::chrono::minutes kSslReloadInterval{5};
thread_local std::unordered_map<CertPaths, ContextInfo, CertPathsHasher>
localContexts;
CertPaths paths;
paths.pemCertPath = pemCertPath;
paths.pemKeyPath = pemKeyPath;
paths.pemCaPath = pemCaPath;
auto iter = localContexts.find(paths);
if (localContexts.find(paths) == localContexts.end()) {
// Copy strings.
ContextInfo info;
info.pemCertPath = pemCertPath.toString();
info.pemKeyPath = pemKeyPath.toString();
info.pemCaPath = pemCaPath.toString();
// Point all StringPiece's to our own strings.
paths.pemCertPath = info.pemCertPath;
paths.pemKeyPath = info.pemKeyPath;
paths.pemCaPath = info.pemCaPath;
iter = localContexts.insert(std::make_pair(paths, std::move(info))).first;
}
auto& contextInfo = iter->second;
auto now = std::chrono::steady_clock::now();
if (contextInfo.context == nullptr ||
now - contextInfo.lastLoadTime > kSslReloadInterval) {
try {
auto sslContext = std::make_shared<SSLContext>();
sslContext->loadCertificate(pemCertPath.begin());
sslContext->loadPrivateKey(pemKeyPath.begin());
sslContext->loadTrustedCertificates(pemCaPath.begin());
sslContext->loadClientCAList(pemCaPath.begin());
// Disable compression if possible to reduce CPU and memory usage.
#ifdef SSL_OP_NO_COMPRESSION
sslContext->setOptions(SSL_OP_NO_COMPRESSION);
#endif
contextInfo.lastLoadTime = now;
contextInfo.context = std::move(sslContext);
} catch (const apache::thrift::transport::TTransportException& ex) {
LOG(ERROR) << "Failed to load certificate, ex: " << ex.what();
}
}
return contextInfo.context;
}
示例2: getSSLContext
std::shared_ptr<SSLContext> getSSLContext(folly::StringPiece pemCertPath,
folly::StringPiece pemKeyPath,
folly::StringPiece pemCaPath) {
static constexpr std::chrono::minutes kSslReloadInterval{5};
thread_local std::unordered_map<CertPaths, ContextInfo, CertPathsHasher>
localContexts;
CertPaths paths;
paths.pemCertPath = pemCertPath;
paths.pemKeyPath = pemKeyPath;
paths.pemCaPath = pemCaPath;
auto iter = localContexts.find(paths);
if (localContexts.find(paths) == localContexts.end()) {
// Copy strings.
ContextInfo info;
info.pemCertPath = pemCertPath.toString();
info.pemKeyPath = pemKeyPath.toString();
info.pemCaPath = pemCaPath.toString();
// Point all StringPiece's to our own strings.
paths.pemCertPath = info.pemCertPath;
paths.pemKeyPath = info.pemKeyPath;
paths.pemCaPath = info.pemCaPath;
iter = localContexts.insert(std::make_pair(paths, std::move(info))).first;
}
auto& contextInfo = iter->second;
auto now = std::chrono::steady_clock::now();
if (contextInfo.context == nullptr ||
now - contextInfo.lastLoadTime > kSslReloadInterval) {
if (auto updated =
handleSSLCertsUpdate(pemCertPath, pemKeyPath, pemCaPath)) {
contextInfo.lastLoadTime = now;
contextInfo.context = std::move(updated);
}
}
return contextInfo.context;
}