in wangle/example/ssl/Client.cpp [123:175]
int main(int argc, char** argv) {
folly::Init init(&argc, &argv);
folly::ssl::init();
// an in memory ssl session cache used for caching sessions
std::shared_ptr<SSLSessionPersistentCache> cache;
if (!FLAGS_cache_file.empty()) {
cache = std::make_shared<SSLSessionPersistentCache>(
FLAGS_cache_file,
wangle::PersistentCacheConfig::Builder()
.setCapacity(100)
.setSyncInterval(std::chrono::seconds(60))
.build());
}
EchoClientBootstrap client;
client.group(std::make_shared<IOThreadPoolExecutor>(1));
client.pipelineFactory(std::make_shared<EchoPipelineFactory>());
if (FLAGS_ssl) {
auto ctx = createSSLContext();
// attach the context to the cache
if (cache) {
wangle::SSLSessionCallbacks::attachCallbacksToContext(
ctx.get(), cache.get());
}
client.sslContext(ctx);
}
SocketAddress addr(FLAGS_ip.c_str(), FLAGS_port);
VLOG(0) << "Connecting";
auto pipeline = client.connect(addr).get();
VLOG(0) << "Connected";
try {
while (true) {
std::string line;
std::getline(std::cin, line);
if (line == "") {
VLOG(0) << "End";
break;
}
VLOG(0) << "Sending " << line;
pipeline->write(line + "\r\n").get();
if (line == "bye") {
pipeline->close();
break;
}
}
} catch (const std::exception& e) {
std::cout << exceptionStr(e) << std::endl;
}
return 0;
}