私は IOCP サーバー (オーバーラップ I/O、4 つのスレッド、、、など) で作業してCreateIoCompletionPort
いGetQueuedCompletionStatus
ますWSASend
。また、自動リセット イベントを作成し、非同期 I/O 操作ごとにハンドルを OVERLAPPED 構造体に配置しました。
問題は、接続されているすべてのソケットにバッファを適切に送信する方法です。各ソケットは、コンテキスト情報構造のリンクされたリストに格納されます。
以下のアプローチが大丈夫かどうかわかりませんか?
...
DWORD WINAPI WorkerThread() { // 1 of 4 workthread
...
GetQueuedCompletionStatus(...);
...
PPER_SOCKET_CONTEXT pTmp1, pTmp2;
pTmp1 = g_pCtxtList; // start of linked list with sockets
EnterCriticalSection(&g_CriticalSection);
while( pTmp1 )
{
pTmp2 = pTmp1->pCtxtBack;
WaitForSingleObject(pTmp1->pIOContext->Overlapped.hEvent,infinite);
// if there is any pending wsasend on this socket,wait to completed, so
// we can post another wsasend using the same overlapped structure
// and buffer
WSASend(pTmp1->Socket,...,&(pTmp1->pIOContext->Overlapped), NULL);
pTmp1 = pTmp2;
}
LeaveCriticalSection(&g_CriticalSection);
...
}
また、別のスレッドも同時に同じ作業を行おうとするとどうなりますか?
すべてのスレッドで GQCS と待機機能を使用することは良い考えですか? マルチスレッド iocp サーバーのすべてのクライアント
に関する手がかりをいただければ幸いです。
どうもwsasends