33
33
namespace mongocxx {
34
34
MONGOCXX_INLINE_NAMESPACE_BEGIN
35
35
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
+
36
48
void pool::_release (client* client) {
37
49
libmongoc::client_pool_push (_impl->client_pool_t , client->_get_impl ().client_t );
38
50
// prevent client destructor from destroying the underlying mongoc_client_t
@@ -43,7 +55,7 @@ void pool::_release(client* client) {
43
55
pool::~pool () = default ;
44
56
45
57
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 ))} {
47
59
#if defined(MONGOCXX_ENABLE_SSL) && defined(MONGOC_ENABLE_SSL)
48
60
if (options.client_opts ().tls_opts ()) {
49
61
if (!uri.tls ())
@@ -132,17 +144,5 @@ stdx::optional<pool::entry> pool::try_acquire() {
132
144
entry::unique_client (new client (cli), [this ](client* client) { _release (client); }));
133
145
}
134
146
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
-
147
147
MONGOCXX_INLINE_NAMESPACE_END
148
148
} // namespace mongocxx
0 commit comments