|
|
@ -20,14 +20,18 @@ use super::database::Database;
|
|
|
|
use super::uri::Uri;
|
|
|
|
use super::uri::Uri;
|
|
|
|
use super::read_prefs::ReadPrefs;
|
|
|
|
use super::read_prefs::ReadPrefs;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: We're using a sort of poor man's Arc here
|
|
|
|
/// Client pool to a MongoDB cluster.
|
|
|
|
// with this root bool, there must be a better way.
|
|
|
|
///
|
|
|
|
|
|
|
|
/// This client pool cannot be cloned, but it can be shared between threads by using an `Arc`.
|
|
|
|
|
|
|
|
/// Use the pool to pop a client and do operations. The client will be automatically added
|
|
|
|
|
|
|
|
/// back to the pool when it goes out of scope.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// See: http://api.mongodb.org/c/current/mongoc_client_pool_t.html
|
|
|
|
pub struct ClientPool {
|
|
|
|
pub struct ClientPool {
|
|
|
|
root_instance: bool,
|
|
|
|
// Uri and SslOptions need to be present for the lifetime of this pool otherwise the C driver
|
|
|
|
// Uri and SslOptions need to be present for the
|
|
|
|
// loses access to resources it needs.
|
|
|
|
// lifetime of this pool.
|
|
|
|
|
|
|
|
uri: Uri,
|
|
|
|
uri: Uri,
|
|
|
|
ssl_options: Option<SslOptions>,
|
|
|
|
_ssl_options: Option<SslOptions>,
|
|
|
|
inner: *mut bindings::mongoc_client_pool_t
|
|
|
|
inner: *mut bindings::mongoc_client_pool_t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -55,9 +59,8 @@ impl ClientPool {
|
|
|
|
None => ()
|
|
|
|
None => ()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
ClientPool {
|
|
|
|
ClientPool {
|
|
|
|
root_instance: true,
|
|
|
|
|
|
|
|
uri: uri,
|
|
|
|
uri: uri,
|
|
|
|
ssl_options: ssl_options,
|
|
|
|
_ssl_options: ssl_options,
|
|
|
|
inner: pool
|
|
|
|
inner: pool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,6 +85,7 @@ impl ClientPool {
|
|
|
|
/// See: http://api.mongodb.org/c/current/mongoc_client_pool_push.html
|
|
|
|
/// See: http://api.mongodb.org/c/current/mongoc_client_pool_push.html
|
|
|
|
unsafe fn push(&self, mongo_client: *mut bindings::mongoc_client_t) {
|
|
|
|
unsafe fn push(&self, mongo_client: *mut bindings::mongoc_client_t) {
|
|
|
|
assert!(!self.inner.is_null());
|
|
|
|
assert!(!self.inner.is_null());
|
|
|
|
|
|
|
|
assert!(!mongo_client.is_null());
|
|
|
|
bindings::mongoc_client_pool_push(
|
|
|
|
bindings::mongoc_client_pool_push(
|
|
|
|
self.inner,
|
|
|
|
self.inner,
|
|
|
|
mongo_client
|
|
|
|
mongo_client
|
|
|
@ -98,27 +102,13 @@ impl fmt::Debug for ClientPool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Clone for ClientPool {
|
|
|
|
|
|
|
|
fn clone(&self) -> ClientPool {
|
|
|
|
|
|
|
|
assert!(!self.inner.is_null());
|
|
|
|
|
|
|
|
ClientPool {
|
|
|
|
|
|
|
|
root_instance: false,
|
|
|
|
|
|
|
|
uri: self.uri.clone(),
|
|
|
|
|
|
|
|
ssl_options: self.ssl_options.clone(),
|
|
|
|
|
|
|
|
inner: self.inner.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Drop for ClientPool {
|
|
|
|
impl Drop for ClientPool {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
if self.root_instance {
|
|
|
|
|
|
|
|
assert!(!self.inner.is_null());
|
|
|
|
assert!(!self.inner.is_null());
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
bindings::mongoc_client_pool_destroy(self.inner);
|
|
|
|
bindings::mongoc_client_pool_destroy(self.inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct SslOptions {
|
|
|
|
pub struct SslOptions {
|
|
|
|