List:MySQL++« Previous MessageNext Message »
From:Bernd Prager Date:August 3 2012 6:58pm
Subject:connection list problems
View as plain text  
Hi,

I defined my own little simple connection pool, since I store there 
(compile time dependent) either PostgreSQL or MySQL connections.

std::list<boost::any> connectionPool;

void Dal::putConnection(boost::any connection) {
     if((int)connectionPool.size() == connectionPoolMax) {
         // pool is full
         boost::lock_guard<boost::mutex> lock(mutex);
         destroyConnection(connection);
     }
     connectionPool.push_back(connection);
}

boost::any Dal::getConnection(){
     boost::any conn;
     boost::lock_guard<boost::mutex> lock(mutex);

     if ( connectionPool.size() > 0 ) {
         conn = connectionPool.front();
         connectionPool.pop_front();
     } else
         return createConnection();

     return conn;
}

The MySQL specific code then looks like:

boost::any con = getConnection();
mysqlpp::Query query = boost::any_cast<mysqlpp::Connection>(con).query();

The code worked quite fine for a while.
But now with recent library updates to  mysql-5.5.25a and mysql++-3.1 I 
start getting invalid MySQL connections back from the pool.
(PostgreSQL connections keep working fine.)

Does anybody else experiences something similar or has any idea what 
could be going wrong?

Thank you for any suggestions.
Regards,
-- Bernd
Thread
connection list problemsBernd Prager3 Aug
  • Re: connection list problemsWarren Young3 Aug
    • Re: connection list problemsBernd Prager3 Aug