예제 #1
0
        public bool InitPool(string host, int nThreadNum)
        {
            m_dbForSync = new MysqlOps();
            if (!m_dbForSync.Connect(host))
            {
                FFLog.Error(string.Format("DbMgr::connectDB failed<{0}>", m_dbForSync.ErrorMsg()));
                m_dbForSync = null;
                return(false);
            }
            m_dbPool = new DBConnectionInfo[nThreadNum];
            for (int i = 0; i < nThreadNum; ++i)
            {
                MysqlOps db = new MysqlOps();
                if (!db.Connect(host))
                {
                    FFLog.Error(string.Format("DbMgr::connectDB failed<{0}>", db.ErrorMsg()));
                    return(false);
                }

                m_dbPool[i] = new DBConnectionInfo()
                {
                    tq = new TaskQueue(),
                    db = db
                };
                m_dbPool[i].tq.Run();
            }
            FFLog.Info(string.Format("DbMgr::connectDB host<{0}>,num<{1}>", host, nThreadNum));
            return(true);
        }
예제 #2
0
        public bool AsyncQuery(Int64 modid, string sql, QueryCallback cb = null)
        {
            if (m_dbPool.Length == 0)
            {
                return(false);
            }
            DBConnectionInfo dbinfo = m_dbPool[modid % m_dbPool.Length];

            dbinfo.tq.Post(() => {
                dbinfo.db.ExeSql(sql, cb);
            });
            return(true);
        }