MongoDB::PooledConnection: Prevent unwanted release by disabling copy semantics. Enabled move semantics for C++11.

This commit is contained in:
Matej Kenda
2016-02-03 21:23:18 +01:00
parent e395f416fb
commit 0ba1e62811

View File

@@ -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;
};