Skip to content

Commit

Permalink
Resovle comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed Oct 22, 2021
1 parent ac02f33 commit e172d0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/lib/core/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

namespace chip {

/// An empty class type used to indicate optional type with uninitialized state.
struct NullOptionalType
{
explicit NullOptionalType() = default;
};
constexpr NullOptionalType NullOptional{};

/**
* Pairs an object with a boolean value to determine if the object value
* is actually valid or not.
Expand All @@ -38,6 +45,8 @@ class Optional
{
public:
constexpr Optional() : mHasValue(false) {}
constexpr Optional(NullOptionalType) : mHasValue(false){};

~Optional()
{
if (mHasValue)
Expand Down
3 changes: 1 addition & 2 deletions src/transport/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
Optional<SessionHandle> CreateUnauthenticatedSession(const Transport::PeerAddress & peerAddress)
{
Optional<Transport::UnauthenticatedSessionHandle> session = mUnauthenticatedSessions.FindOrAllocateEntry(peerAddress);
return session.HasValue() ? Optional<SessionHandle>::Value(SessionHandle(session.Value()))
: Optional<SessionHandle>::Missing();
return session.HasValue() ? MakeOptional<SessionHandle>(session.Value()) : NullOptional;
}

private:
Expand Down
4 changes: 2 additions & 2 deletions src/transport/UnauthenticatedSessionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class UnauthenticatedSessionTable
{
public:
/**
* Get a peer given the peer id. If the peer doesn't exist in the cache, allocate a new entry for it.
* Get a session given the peer address. If the session doesn't exist in the cache, allocate a new entry for it.
*
* @return the peer found or allocated, nullptr if not found and allocate failed.
* @return the session found or allocated, nullptr if not found and allocation failed.
*/
CHECK_RETURN_VALUE
Optional<UnauthenticatedSessionHandle> FindOrAllocateEntry(const PeerAddress & address)
Expand Down

0 comments on commit e172d0d

Please sign in to comment.