小さなtcpチャットサーバーで書いていますが、「エレガントに」解決する方法がわからない問題がいくつか発生しています。
以下は私のメインループのコードです:それは次のとおりです: 
1。新しいtcp接続が確立されると、フラグが立てられた基本イベントでベクターを開始します。
2.この接続を取得し、それをベクトルにプッシュバックします。次に、ソケットを使用してCSingleConnectionオブジェクトを作成し、ソケットをそのオブジェクトに渡します。
  2.1。接続がデータを受信したときにフラグが立てられるCSingleConnectionからイベントを取得します... 
3。データを受信したとき。待機がいっぱいになり、配列内のハンドルの数が返されます...他のすべてのベクトルを使用すると、現在送信しているベクトルを判別できるようです...  
しかし、誰もが理解できるように、この方法論は本当に不十分です...接続ソケットを取得したり、単一の接続を作成したりするなど、これらすべてをより適切に行う方法がわかりません:/ ...
提案、改善などはありますか?...
void CServer::MainLoop()
{
    DWORD dwResult = 0;
    bool bMainLoop = true;
    std::vector<std::string> vecData;
    std::vector<HANDLE> vecEvents;              //Contains the handles to wait on
    std::vector<SOCKET> vecSocks;               //contains the sockets
    enum
    {
        ACCEPTOR = 0,           //First element: sequence is mandatory
        EVENTSIZE                   //Keep as the last element!
    };
    //initiate the vector with the basic handles
    vecEvents.clear();
    GetBasicEvents(vecEvents);
    while(bMainLoop)
    {
        //wait for event handle(s)
        dwResult = WaitForMultipleObjects(vecEvents.size(), &vecEvents[0], true, INFINITE);
        //New connection(s) made
        if(dwResult == (int)ACCEPTOR)
        {
            //Get the sockets for the new connections
            m_pAcceptor->GetOutData(vecSocks);
            //Create new connections
            for(unsigned int i = 0; i < vecSocks.size(); i++)
            {
                //Add a new connection
                CClientConnection Conn(vecSocks[i]);
                m_vecConnections.push_back(Conn);
                //Add event
                vecEvents.push_back(Conn.GetOutEvent());
            }
        }
        //Data from one of the connections
        if(dwResult >= (int)EVENTSIZE)
        {
            Inc::MSG Msg;
            //get received string data
            m_vecConnections[dwResult].GetOutData(vecData);
            //handle the data
            for(unsigned int i = 0; i < vecData.size(); i++)
            {
                //convert data into message
                if(Inc::StringToMessage(vecData[i], Msg) != Inc::SOK)
                    continue;
                //Add the socket to the sender information
                Msg.Sender.sock = vecSocks[dwResult];
                //Evaluate and delegate data and task
                EvaluateMessage(Msg);
            }
        }
    }
}