-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: allow nullptr as slot value (#13883)
Commit Message: add support for null data to tls slot typed API, using optional references. To make these less cumbersome at call-sites, add a struct OptRef wrapper for absl::optional<std::reference_wrapper> that allows directly accessing via -> syntax if the caller can guarantee the optional reference is populated. Additional Description: Risk Level: low Testing: //test/... Docs Changes: n/a Release Notes: n/a Signed-off-by: Joshua Marantz <[email protected]>
- Loading branch information
Showing
23 changed files
with
229 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "absl/types/optional.h" | ||
|
||
namespace Envoy { | ||
|
||
// Helper class to make it easier to work with optional references, allowing: | ||
// foo(OptRef<T> t) { | ||
// if (t.has_value()) { | ||
// t->method(); | ||
// } | ||
// } | ||
// | ||
// Using absl::optional directly you must write optref.value().method() which is | ||
// a bit more awkward. | ||
template <class T> struct OptRef : public absl::optional<std::reference_wrapper<T>> { | ||
OptRef(T& t) : absl::optional<std::reference_wrapper<T>>(t) {} | ||
OptRef() = default; | ||
|
||
/** | ||
* Helper to call a method on T. The caller is responsible for ensuring | ||
* has_value() is true. | ||
*/ | ||
T* operator->() { | ||
T& ref = **this; | ||
return &ref; | ||
} | ||
|
||
/** | ||
* Helper to call a const method on T. The caller is responsible for ensuring | ||
* has_value() is true. | ||
*/ | ||
const T* operator->() const { | ||
const T& ref = **this; | ||
return &ref; | ||
} | ||
}; | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.