Skip to content

Commit 89384b6

Browse files
committed
move construct_client_pool into .cpp for accurate return type
1 parent 1ddf9c5 commit 89384b6

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/mongocxx/pool.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
namespace mongocxx {
3434
MONGOCXX_INLINE_NAMESPACE_BEGIN
3535

36+
// Attempts to create a new client pool using the uri. Throws an exception upon error.
37+
static mongoc_client_pool_t* construct_client_pool(mongoc_uri_t* uri) {
38+
bson_error_t error;
39+
auto pool = libmongoc::client_pool_new_with_error(uri, &error);
40+
if (error.code) {
41+
// If constructing a client pool failed, throw an exception from the bson_error_t.
42+
throw_exception<operation_exception>(error);
43+
}
44+
45+
return pool;
46+
}
47+
3648
void pool::_release(client* client) {
3749
libmongoc::client_pool_push(_impl->client_pool_t, client->_get_impl().client_t);
3850
// prevent client destructor from destroying the underlying mongoc_client_t
@@ -43,7 +55,7 @@ void pool::_release(client* client) {
4355
pool::~pool() = default;
4456

4557
pool::pool(const uri& uri, const options::pool& options)
46-
: _impl{stdx::make_unique<impl>((mongoc_client_pool_t*)construct_client_pool(uri))} {
58+
: _impl{stdx::make_unique<impl>(construct_client_pool(uri._impl->uri_t))} {
4759
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
4860
if (options.client_opts().tls_opts()) {
4961
if (!uri.tls())
@@ -132,17 +144,5 @@ stdx::optional<pool::entry> pool::try_acquire() {
132144
entry::unique_client(new client(cli), [this](client* client) { _release(client); }));
133145
}
134146

135-
void* pool::construct_client_pool(const uri& uri) {
136-
bson_error_t error = {};
137-
mongoc_client_pool_t* temp_impl =
138-
libmongoc::client_pool_new_with_error(uri._impl->uri_t, &error);
139-
if (error.code) {
140-
// If constructing a client pool failed, throw an exception from the bson_error_t.
141-
throw_exception<operation_exception>(error);
142-
}
143-
144-
return temp_impl;
145-
}
146-
147147
MONGOCXX_INLINE_NAMESPACE_END
148148
} // namespace mongocxx

src/mongocxx/pool.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ class MONGOCXX_API pool {
109109
///
110110
stdx::optional<entry> try_acquire();
111111

112-
// Attempts to create a new client pool using the uri. Throws an exception upon error.
113-
void* construct_client_pool(const uri& uri);
114-
115112
private:
116113
friend class options::auto_encryption;
117114

0 commit comments

Comments
 (0)