就像标题所说的那样,在与 I/O 完成端口关联的套接字上成功 WSASend
调用是否有可能因为线程结束以外的任何原因不发布完成?
我有一个奇怪的情况,看起来没有为 a 发布完成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.
}