mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 13:47:10 +01:00
MongoDB::PooledConnection: Prevent unwanted release by disabling copy semantics. Enabled move semantics for C++11.
This commit is contained in:
@@ -86,7 +86,10 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
_pool.returnObject(_connection);
|
||||
if (_connection)
|
||||
{
|
||||
_pool.returnObject(_connection);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -99,7 +102,24 @@ public:
|
||||
return _connection;
|
||||
}
|
||||
|
||||
#if defined(POCO_ENABLE_CPP11)
|
||||
// Disable copy to prevent unwanted release of resources: C++11 way
|
||||
PooledConnection(const PooledConnection&) = delete;
|
||||
PooledConnection& operator=(const PooledConnection&) = delete;
|
||||
|
||||
// Enable move semantics
|
||||
PooledConnection(PooledConnection&& other) = default;
|
||||
PooledConnection& operator=(PooledConnection&&) = default;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
#if ! defined(POCO_ENABLE_CPP11)
|
||||
// Disable copy to prevent unwanted release of resources: pre C++11 way
|
||||
PooledConnection(const PooledConnection&);
|
||||
PooledConnection& operator=(const PooledConnection&);
|
||||
#endif
|
||||
|
||||
Poco::ObjectPool<Connection, Connection::Ptr>& _pool;
|
||||
Connection::Ptr _connection;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user