int CTcpServer::DoSendSafe(TSocketObj* pSocketObj) { if(pSocketObj->sndCount == 0 && !pSocketObj->IsSmooth()) { CCriSecLock locallock(pSocketObj->csSend); if(pSocketObj->sndCount == 0) pSocketObj->smooth = TRUE; } if(!pSocketObj->IsCanSend()) return NO_ERROR; int result = NO_ERROR; if(pSocketObj->IsPending() && pSocketObj->IsSmooth()) { CCriSecLock locallock(pSocketObj->csSend); if(pSocketObj->IsPending() && pSocketObj->IsSmooth()) { pSocketObj->smooth = FALSE; result = SendItem(pSocketObj); if(result == NO_ERROR) pSocketObj->smooth = TRUE; } } if(!IOCP_SUCCESS(result)) CheckError(pSocketObj, SO_SEND, result); return result; }
int CTcpServer::DoSendPack(TSocketObj* pSocketObj) { if(!pSocketObj->IsCanSend()) return NO_ERROR; int result = NO_ERROR; if(pSocketObj->IsPending() && pSocketObj->TurnOffSmooth()) { { CCriSecLock locallock(pSocketObj->csSend); if(pSocketObj->IsPending()) result = SendItem(pSocketObj); pSocketObj->TurnOnSmooth(); } if(result == WSA_IO_PENDING && pSocketObj->IsSmooth()) ::PostIocpSend(m_hCompletePort, pSocketObj->connID); } if(!IOCP_SUCCESS(result)) CheckError(pSocketObj, SO_SEND, result); return result; }
int CTcpServer::SendItem(TSocketObj* pSocketObj) { int result = NO_ERROR; while(pSocketObj->sndBuff.Size() > 0) { TBufferObj* pBufferObj = pSocketObj->sndBuff.PopFront(); int iBufferSize = pBufferObj->buff.len; ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwSocketBufferSize); pSocketObj->pending -= iBufferSize; ::InterlockedExchangeAdd(&pSocketObj->sndCount, iBufferSize); result = ::PostSendNotCheck(pSocketObj, pBufferObj); LONG sndCounter = pBufferObj->ReleaseSendCounter(); if(sndCounter == 0 || !IOCP_SUCCESS(result)) AddFreeBufferObj(pBufferObj); if(result != NO_ERROR) break; } return result; }
int CTcpAgent::DoSendPack(TSocketObj* pSocketObj) { int result = NO_ERROR; if(TSocketObj::IsPending(pSocketObj)) { CCriSecLock locallock(pSocketObj->crisec); if(TSocketObj::IsValid(pSocketObj)) result = SendItem(pSocketObj); } if(!IOCP_SUCCESS(result)) CheckError(pSocketObj->connID, SO_SEND, result); return result; }
int CUdpServer::DoSendPack(TUdpSocketObj* pSocketObj) { int result = NO_ERROR; if(TUdpSocketObj::IsPending(pSocketObj)) { CCriSecLock locallock(pSocketObj->crisec); if(TUdpSocketObj::IsValid(pSocketObj)) result = SendItem(pSocketObj); } if(!IOCP_SUCCESS(result)) VERIFY(!HasStarted()); return result; }
int CTcpAgent::DoSendSafe(TSocketObj* pSocketObj) { int result = NO_ERROR; if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) { CCriSecLock locallock(pSocketObj->crisec); if(TSocketObj::IsPending(pSocketObj) && TSocketObj::IsSmooth(pSocketObj)) { pSocketObj->smooth = FALSE; result = SendItem(pSocketObj); if(result == NO_ERROR) pSocketObj->smooth = TRUE; } } if(!IOCP_SUCCESS(result)) CheckError(pSocketObj->connID, SO_SEND, result); return result; }
int CUdpServer::DoSendSafe(TUdpSocketObj* pSocketObj) { int result = NO_ERROR; if(TUdpSocketObj::IsPending(pSocketObj) && TUdpSocketObj::IsSmooth(pSocketObj)) { CCriSecLock locallock(pSocketObj->crisec); if(TUdpSocketObj::IsPending(pSocketObj) && TUdpSocketObj::IsSmooth(pSocketObj)) { pSocketObj->smooth = FALSE; result = SendItem(pSocketObj); if(result == NO_ERROR) pSocketObj->smooth = TRUE; } } if(!IOCP_SUCCESS(result)) VERIFY(!HasStarted()); return result; }