Skip to content

Commit

Permalink
Change optional fields to use std::optional from folly::Optional
Browse files Browse the repository at this point in the history
Summary:
Most optional members nowadays are using folly::Optional now, generally we should prefer the standard library version since now std::optional and folly::Optional are the same in most cases.

Also we should return members as const optional& which saves a copy.

Reviewed By: praihan

Differential Revision: D26900622

fbshipit-source-id: 08788e801f449c7cae674d8a669cddd71ce36310
  • Loading branch information
zhxchen17 authored and facebook-github-bot committed Mar 9, 2021
1 parent 78f7bd9 commit 1fefc21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions thrift/lib/cpp2/server/ThriftServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ class ThriftServer : public apache::thrift::BaseThriftServer,
public wangle::ServerBootstrap<Pipeline> {
private:
//! SSL context
folly::Optional<folly::observer::Observer<wangle::SSLContextConfig>>
std::optional<folly::observer::Observer<wangle::SSLContextConfig>>
sslContextObserver_;
folly::Optional<wangle::TLSTicketKeySeeds> ticketSeeds_;
std::optional<wangle::TLSTicketKeySeeds> ticketSeeds_;
folly::observer::CallbackHandle getSSLCallbackHandle();

folly::Optional<bool> reusePort_;
folly::Optional<bool> enableTFO_;
std::optional<bool> reusePort_;
std::optional<bool> enableTFO_;
uint32_t fastOpenQueueSize_{10000};

folly::Optional<wangle::SSLCacheOptions> sslCacheOptions_;
std::optional<wangle::SSLCacheOptions> sslCacheOptions_;
wangle::FizzConfig fizzConfig_;
ThriftTlsConfig thriftConfig_;

Expand Down Expand Up @@ -129,9 +129,9 @@ class ThriftServer : public apache::thrift::BaseThriftServer,

//! The folly::EventBase currently driving serve(). NULL when not serving.
std::atomic<folly::EventBase*> serveEventBase_{nullptr};
folly::Optional<IdleServerAction> idleServer_;
std::optional<IdleServerAction> idleServer_;
std::chrono::milliseconds idleServerTimeout_ = std::chrono::milliseconds(0);
folly::Optional<std::chrono::milliseconds> sslHandshakeTimeout_;
std::optional<std::chrono::milliseconds> sslHandshakeTimeout_;
std::atomic<std::chrono::steady_clock::duration::rep> lastRequestTime_;

std::chrono::steady_clock::time_point lastRequestTime() const noexcept;
Expand Down Expand Up @@ -408,11 +408,12 @@ class ThriftServer : public apache::thrift::BaseThriftServer,
* Set the ssl handshake timeout.
*/
void setSSLHandshakeTimeout(
folly::Optional<std::chrono::milliseconds> timeout) {
std::optional<std::chrono::milliseconds> timeout) {
sslHandshakeTimeout_ = timeout;
}

folly::Optional<std::chrono::milliseconds> getSSLHandshakeTimeout() const {
const std::optional<std::chrono::milliseconds>& getSSLHandshakeTimeout()
const {
return sslHandshakeTimeout_;
}

Expand Down Expand Up @@ -450,28 +451,28 @@ class ThriftServer : public apache::thrift::BaseThriftServer,
fastOpenQueueSize_ = fastOpenQueueSize;
}

folly::Optional<bool> getTFOEnabled() {
std::optional<bool> getTFOEnabled() {
return enableTFO_;
}

void setReusePort(bool reusePort) {
reusePort_ = reusePort;
}

folly::Optional<bool> getReusePort() {
std::optional<bool> getReusePort() {
return reusePort_;
}

folly::Optional<folly::observer::Observer<wangle::SSLContextConfig>>
const std::optional<folly::observer::Observer<wangle::SSLContextConfig>>&
getSSLConfig() const {
return sslContextObserver_;
}

folly::Optional<wangle::TLSTicketKeySeeds> getTicketSeeds() const {
const std::optional<wangle::TLSTicketKeySeeds>& getTicketSeeds() const {
return ticketSeeds_;
}

folly::Optional<wangle::SSLCacheOptions> getSSLCacheOptions() const {
const std::optional<wangle::SSLCacheOptions>& getSSLCacheOptions() const {
return sslCacheOptions_;
}

Expand Down
2 changes: 1 addition & 1 deletion thrift/lib/cpp2/test/server/ThriftServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ TEST(ThriftServer, ServerConfigTest) {
EXPECT_EQ(serverConfig.sslHandshakeTimeout, std::chrono::milliseconds(100));

// Clear it and expect it to be zero again (due to idle timeout = 0)
server.setSSLHandshakeTimeout(folly::none);
server.setSSLHandshakeTimeout(std::nullopt);
serverConfig = server.getServerSocketConfig();
EXPECT_EQ(
serverConfig.sslHandshakeTimeout, std::chrono::milliseconds::zero());
Expand Down

0 comments on commit 1fefc21

Please sign in to comment.