Loading...
Searching...
No Matches
pool.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/pool-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/pool.hpp> // IWYU pragma: export
#include <cstddef>
#include <functional>
#include <memory>
#include <utility>
#include <mongocxx/options/auto_encryption-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/string/view_or_value.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/database.hpp>
#include <mongocxx/options/pool.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class pool {
private:
v1::pool _pool;
public:
explicit MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE() pool(
v_noabi::uri const& mongodb_uri = {},
v_noabi::options::pool const& options = {});
~pool() = default;
pool(pool&&) = delete;
pool& operator=(pool&&) = delete;
pool(pool const&) = delete;
pool& operator=(pool const&) = delete;
class entry {
public:
v_noabi::client* operator->() const& noexcept {
return _client.get();
}
v_noabi::client* operator->() && = delete;
v_noabi::client& operator*() const& noexcept {
return *_client;
}
v_noabi::client& operator*() && = delete;
entry& operator=(std::nullptr_t) noexcept {
_client.reset();
return *this;
}
explicit operator bool() const noexcept {
return _client != nullptr;
}
// Allows the pool_entry["db_name"] syntax to be used to access a database within the
// entry's underlying client.
v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) const& {
return (*_client)[name];
}
v_noabi::database operator[](bsoncxx::v_noabi::string::view_or_value name) && = delete;
class internal;
private:
using ptr_type = std::unique_ptr<v_noabi::client, std::function<void MONGOCXX_ABI_CDECL(v_noabi::client*)>>;
ptr_type _client;
/* explicit(false) */ entry(ptr_type client) : _client{std::move(client)} {}
};
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(entry) acquire();
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::stdx::optional<entry>) try_acquire();
class internal;
};
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
auto_encryption-fwd.hpp
Declares mongocxx::v_noabi::options::auto_encryption.
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
bsoncxx::v_noabi::string::view_or_value
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
mongocxx::pool::pool
pool(v_noabi::uri const &mongodb_uri={}, v_noabi::options::pool const &options={})
Creates a pool associated with a connection string.
mongocxx::v1::pool
A thread-safe pool of client objects.
Definition pool.hpp:49
mongocxx::v_noabi::client
A client connection to a MongoDB server.
Definition client.hpp:77
mongocxx::v_noabi::database
A MongoDB database.
Definition database.hpp:63
mongocxx::v_noabi::options::pool
Used by mongocxx::v_noabi::pool.
Definition pool.hpp:36
mongocxx::v_noabi::pool::entry
An owning handle to a client obtained from a pool.
Definition pool.hpp:101
mongocxx::v_noabi::pool::entry::operator->
v_noabi::client * operator->() const &noexcept
Access a member of the client instance.
Definition pool.hpp:104
mongocxx::v_noabi::pool::entry::operator=
entry & operator=(std::nullptr_t) noexcept
Assign nullptr to this entry to release its client to the pool.
Definition pool.hpp:116
mongocxx::v_noabi::pool::entry::operator*
v_noabi::client & operator*() const &noexcept
Retrieve a reference to the client.
Definition pool.hpp:110
mongocxx::v_noabi::pool::~pool
~pool()=default
Destroys a pool.
mongocxx::v_noabi::pool::pool
pool(v_noabi::uri const &mongodb_uri={}, v_noabi::options::pool const &options={})
Creates a pool associated with a connection string.
mongocxx::v_noabi::pool::acquire
entry acquire()
Acquires a client from the pool. The calling thread will block until a connection is available.
mongocxx::v_noabi::uri
A MongoDB connection string URI.
Definition uri.hpp:55
MONGOCXX_ABI_CDECL
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
mongocxx::v_noabi::options
Declares entities representing options to use with various commands.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
view_or_value.hpp
Provides bsoncxx::v_noabi::string::view_or_value.
pool.hpp
Provides mongocxx::v1::pool.
optional.hpp
Provides std::optional-related polyfills for library API usage.
client.hpp
Provides mongocxx::v_noabi::client.
database.hpp
Provides mongocxx::v_noabi::database.
pool.hpp
Provides mongocxx::v_noabi::options::pool.
pool-fwd.hpp
Declares mongocxx::v_noabi::pool.
uri.hpp
Provides mongocxx::v_noabi::uri.