int main(int argc, char** argv) { std::cout << "Ships: Start server" << std::endl; if (!Database.Open(MySQLConnectionInfo("localhost", "3036", "ships", "root", "root"))) return 0; // Start the Boost based thread pool int numThreads = THREAD_POOL; std::vector<std::thread> threadPool; if (numThreads < 1) numThreads = 1; sSocketMgr.StartNetwork(_ioService, "0.0.0.0", PORT, 1); for (int i = 0; i < numThreads; ++i) threadPool.push_back(std::thread(boost::bind(&boost::asio::io_service::run, &_ioService))); ServerUpdateLoop(); ShutdownThreadPool(threadPool); sSocketMgr.StopNetwork(); Database.Close(); return 0; }
/*! This function creates a new MySQL connection for every MapUpdate thread and every unbundled task. */ void DatabaseWorkerPool::Init_MySQL_Connection() { MySQLConnection* conn = new MySQLConnection(); conn->Open(m_infoString); { ACE_Guard<ACE_Thread_Mutex> guard(m_connectionMap_mtx); m_sync_connections[ACE_Based::Thread::current()] = conn; } sLog.outDebug("Core thread with ID ["UI64FMTD"] initializing MySQL connection.", (uint64)ACE_Based::Thread::currentId()); ++m_connections; }
int DatabaseWorker::svc() { MySQLConnection thrConn; if (!thrConn.Open(m_connectionInfo, m_initHookFnPtr)) return 0; while (1) { SQLOperation *request; if (m_queue.dequeue(request) == -1) break; request->execute(&thrConn); delete request; } MySQLHelper::stopThread(); return 0; }