Fixed bug in musik::core::Crypt, forgot to seed boost::random.

Fixed problem with musikServer when joining Connection threads.
This commit is contained in:
Daniel Önnerby 2008-09-12 22:01:13 +00:00
parent 49c0d5d271
commit 21e97a719b
4 changed files with 22 additions and 10 deletions

View File

@ -51,7 +51,8 @@ std::string Crypt::GenerateSalt(){
typedef boost::mt19937 RandomGenerator;
RandomGenerator randomGenerator;
randomGenerator.seed(static_cast<unsigned int>(std::time(0)));
boost::uniform_int<> randDistribution(0,(int)characters.size()-1);
boost::variate_generator<RandomGenerator&, boost::uniform_int<> > rand(randomGenerator, randDistribution);

View File

@ -56,11 +56,16 @@ Server::Server(unsigned int port,unsigned int httpPort)
}
Server::~Server(void){
this->connections.clear();
this->nextConnection.reset();
this->Exit();
{
boost::mutex::scoped_lock lock(this->serverMutex);
this->connectedUsers.clear();
this->connections.clear();
}
this->nextConnection.reset();
this->threads.join_all();
}
@ -136,17 +141,22 @@ void Server::SetNextConnection(){
void Server::AcceptConnection(const boost::system::error_code& error){
if(!error){
this->CleanupConnections();
// Start the connection
this->nextConnection->Startup();
this->connections.push_back(this->nextConnection);
this->SetNextConnection();
{
boost::mutex::scoped_lock lock(this->serverMutex);
this->connections.push_back(this->nextConnection);
this->SetNextConnection();
}
this->CleanupConnections();
}
}
void Server::CleanupConnections(){
boost::mutex::scoped_lock lock(this->serverMutex);
for(server::ConnectionVector::iterator connection=this->connections.begin();connection!=this->connections.end();){
if( (*connection)->Exited() ){
connection = this->connections.erase(connection);

View File

@ -268,7 +268,7 @@ void Connection::WriteThread(){
// Wait for outgoingQueries
{
boost::mutex::scoped_lock lock(this->libraryMutex);
if(this->outgoingQueries.empty()){
if(this->outgoingQueries.empty() && !this->exit){
this->waitCondition.wait(lock);
}
@ -337,4 +337,5 @@ void Connection::Exit(){
this->exit = true;
}
this->waitCondition.notify_all();
this->authCondition.notify_all();
}

View File

@ -76,7 +76,7 @@ void SyncPathModel::UpdateSyncPaths(){
}
this->SetRowCount(0);
this->SetRowCount(this->paths.size());
this->SetRowCount((int)this->paths.size());
}