MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
pool.hpp
1// Copyright 2015 MongoDB Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <functional>
18#include <memory>
19
20#include <bsoncxx/stdx/optional.hpp>
21#include <mongocxx/options/ssl.hpp>
22#include <mongocxx/stdx.hpp>
23#include <mongocxx/uri.hpp>
24
25#include <mongocxx/config/prelude.hpp>
26
27namespace mongocxx {
28MONGOCXX_INLINE_NAMESPACE_BEGIN
29
30class client;
31
49class MONGOCXX_API pool {
50 public:
62 pool(const uri& mongodb_uri = mongocxx::uri(),
63 stdx::optional<options::ssl> ssl_options = stdx::nullopt);
64
69
76 using entry = std::unique_ptr<client, std::function<void MONGOCXX_CALL(client*)>>;
77
83
88 stdx::optional<entry> try_acquire();
89
90 private:
91 MONGOCXX_PRIVATE void _release(client* client);
92
93 class MONGOCXX_PRIVATE impl;
94 const std::unique_ptr<impl> _impl;
95};
96
97MONGOCXX_INLINE_NAMESPACE_END
98} // namespace mongocxx
99
100#include <mongocxx/config/postlude.hpp>
Class representing a client connection to MongoDB.
Definition client.hpp:49
A pool of client objects associated with a MongoDB deployment.
Definition pool.hpp:49
pool(const uri &mongodb_uri=mongocxx::uri(), stdx::optional< options::ssl > ssl_options=stdx::nullopt)
Creates a pool associated with a connection string.
~pool()
Destroys a pool.
std::unique_ptr< client, std::function< void(client *)> > entry
An entry is a handle on a client object acquired via the pool.
Definition pool.hpp:76
entry acquire()
Acquires a client from the pool.
stdx::optional< entry > try_acquire()
Acquires a client from the pool.
Class representing a MongoDB connection string URI.
Definition uri.hpp:40