タイトルにあるように、I / O完了ポートに関連付けられたソケットで正常 WSASend
に呼び出された場合、スレッドの終了以外の理由で完了を通知しない可能性はありますか?
完了が投稿されていないように見える奇妙な状況がありWSASend
、その結果、ソケットリークが発生します。アプリケーションは、送信がまだソケットに対して保留中であると見なし、それを解放することを拒否します。
送信コードは次のとおりです。
void CSocketServer::Write(
Socket *pSocket,
CIOBuffer *pBuffer) const
{
pSocket->AddRef();
pBuffer->SetOperation(IO_Write_Completed);
pBuffer->SetupWrite();
pBuffer->AddRef();
DWORD dwFlags = 0;
DWORD dwSendNumBytes = 0;
if (SOCKET_ERROR == ::WSASend(
pSocket->m_socket,
pBuffer->GetWSABUF(),
1,
&dwSendNumBytes,
dwFlags,
pBuffer,
NULL))
{
DWORD lastError = ::WSAGetLastError();
if (ERROR_IO_PENDING != lastError)
{
pSocket->OnConnectionError(WriteError, pBuffer, lastError);
pSocket->WriteCompleted(); // this pending write will never complete...
pSocket->Release();
pBuffer->Release();
}
}
// Note: even if WSASend returns SUCCESS an IO Completion Packet is
// queued to the IOCP the same as if ERROR_IO_PENDING was returned.
// Thus we need no special handling for the non error return case.
// See http://support.microsoft.com/default.aspx?scid=kb;en-us;Q192800
// for details.
}