日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)C#.NET → Socket Server連接客服端的簡(jiǎn)單實(shí)現(xiàn)

      Socket Server連接客服端的簡(jiǎn)單實(shí)現(xiàn)

      相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:本站整理時(shí)間:2010/9/12 21:54:41字體大。A-A+

      作者:佚名點(diǎn)擊:922次評(píng)論:0次標(biāo)簽: Socket 客服端

      • 類型:服務(wù)器區(qū)大小:21KB語言:中文 評(píng)分:6.6
      • 標(biāo)簽:
      立即下載
      4 頁 連接池的實(shí)現(xiàn)
      四、連接池的實(shí)現(xiàn)
      每個(gè)連接池保存一個(gè)鏈表保存已經(jīng)建立的連接:list<MyConnection *> * m_connections

      當(dāng)然這個(gè)鏈表也需要鎖來進(jìn)行多線程保護(hù):pthread_mutex_t m_connectionMutex;

      此處一個(gè)MyConnection也是一個(gè)MyTask,由一個(gè)線程來負(fù)責(zé)。

      線程池也作為連接池的成員變量:MyThreadPool * m_threadPool

      連接池由類MyConnectionPool負(fù)責(zé),其主要函數(shù)如下:

      void MyConnectionPool::addConnection(MyConnection * pConn)
      {

      pthread_mutex_lock(&m_connectionMutex);

      m_connections->push_back(pConn);

      pthread_mutex_unlock(&m_connectionMutex);

      m_threadPool->addTask(pConn);
      }
       

      MyConnectionPool也要啟動(dòng)一個(gè)背后的線程,來管理這些連接,移除結(jié)束的連接和錯(cuò)誤的連接。

      void MyConnectionPool::managePool()
      {

      pthread_mutex_lock(&m_connectionMutex);

      for (list<MyConnection *>::iterator itr = m_connections->begin(); itr!=m_connections->end(); )
      {
      MyConnection *conn = *itr;
      if (conn->isFinish())
      {
      delete conn;
      conn = NULL;
      list<MyConnection *>::iterator pos = itr++;
      m_connections->erase(pos);
      }
      else if (conn->isError())
      {

      //處理錯(cuò)誤的連接
      ++itr;
      }
      else
      {
      ++itr;
      }
      }

      pthread_mutex_unlock(&m_connectionMutex);

      }
       

        相關(guān)評(píng)論

        閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評(píng)論

        最新評(píng)論

        發(fā)表評(píng)論 查看所有評(píng)論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)