diff options
author | Kyle Suarez <kyle.suarez@mongodb.com> | 2016-08-08 13:58:16 -0400 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2016-08-08 13:58:16 -0400 |
commit | 9a1688ba6c07117405c46cc6fb1275cb1fcbb4cf (patch) | |
tree | 5f1cfcc03d547925207c8f9be2115e590e0a723f /src/mongo/db/client.h | |
parent | e4fcbcf49f07f6b6958cfbd6fc947f57000f626a (diff) | |
download | mongo-9a1688ba6c07117405c46cc6fb1275cb1fcbb4cf.tar.gz |
SERVER-25488 merge ClientBasic and Client
Diffstat (limited to 'src/mongo/db/client.h')
-rw-r--r-- | src/mongo/db/client.h | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index ca9a159d579..8e313379b9c 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -36,14 +36,19 @@ #pragma once -#include "mongo/db/client_basic.h" +#include "mongo/base/disallow_copying.h" +#include "mongo/db/client.h" #include "mongo/db/namespace_string.h" #include "mongo/db/service_context.h" #include "mongo/platform/random.h" #include "mongo/platform/unordered_set.h" #include "mongo/stdx/thread.h" +#include "mongo/transport/session.h" #include "mongo/util/concurrency/spin_lock.h" #include "mongo/util/concurrency/threadlocal.h" +#include "mongo/util/decorable.h" +#include "mongo/util/net/abstract_message_port.h" +#include "mongo/util/net/hostandport.h" namespace mongo { @@ -57,8 +62,10 @@ class Session; typedef long long ConnectionId; -/** the database's concept of an outside "client" */ -class Client : public ClientBasic { +/** + * The database's concept of an outside "client". + * */ +class Client final : public Decorable<Client> { public: /** * Creates a Client object and stores it in TLS for the current thread. @@ -74,6 +81,38 @@ public: ServiceContext* serviceContext, transport::Session* session); + static Client* getCurrent(); + + bool getIsLocalHostConnection() { + if (!hasRemote()) { + return false; + } + return getRemote().isLocalHost(); + } + + bool hasRemote() const { + return _session; + } + + HostAndPort getRemote() const { + verify(_session); + return _session->remote(); + } + + /** + * Returns the ServiceContext that owns this client session context. + */ + ServiceContext* getServiceContext() const { + return _serviceContext; + } + + /** + * Returns the Session to which this client is bound, if any. + */ + transport::Session* session() const { + return _session; + } + /** * Inits a thread if that thread has not already been init'd, setting the thread name to * "desc". @@ -165,6 +204,8 @@ private: friend class ServiceContext; Client(std::string desc, ServiceContext* serviceContext, transport::Session* session = nullptr); + ServiceContext* const _serviceContext; + transport::Session* const _session; // Description for the client (e.g. conn8) const std::string _desc; |