|
|
@ -708,6 +708,30 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// requires LOCK(cs_vSend)
|
|
|
|
|
|
|
|
void SocketSendData(CNode *pnode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CDataStream& vSend = pnode->vSend;
|
|
|
|
|
|
|
|
if (vSend.empty())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int nBytes = send(pnode->hSocket, &vSend[0], vSend.size(), MSG_NOSIGNAL | MSG_DONTWAIT);
|
|
|
|
|
|
|
|
if (nBytes > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
vSend.erase(vSend.begin(), vSend.begin() + nBytes);
|
|
|
|
|
|
|
|
pnode->nLastSend = GetTime();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nBytes < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// error
|
|
|
|
|
|
|
|
int nErr = WSAGetLastError();
|
|
|
|
|
|
|
|
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("socket send error %d\n", nErr);
|
|
|
|
|
|
|
|
pnode->CloseSocketDisconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ThreadSocketHandler(void* parg)
|
|
|
|
void ThreadSocketHandler(void* parg)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -994,28 +1018,7 @@ void ThreadSocketHandler2(void* parg)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TRY_LOCK(pnode->cs_vSend, lockSend);
|
|
|
|
TRY_LOCK(pnode->cs_vSend, lockSend);
|
|
|
|
if (lockSend)
|
|
|
|
if (lockSend)
|
|
|
|
{
|
|
|
|
SocketSendData(pnode);
|
|
|
|
CDataStream& vSend = pnode->vSend;
|
|
|
|
|
|
|
|
if (!vSend.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int nBytes = send(pnode->hSocket, &vSend[0], vSend.size(), MSG_NOSIGNAL | MSG_DONTWAIT);
|
|
|
|
|
|
|
|
if (nBytes > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
vSend.erase(vSend.begin(), vSend.begin() + nBytes);
|
|
|
|
|
|
|
|
pnode->nLastSend = GetTime();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (nBytes < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// error
|
|
|
|
|
|
|
|
int nErr = WSAGetLastError();
|
|
|
|
|
|
|
|
if (nErr != WSAEWOULDBLOCK && nErr != WSAEMSGSIZE && nErr != WSAEINTR && nErr != WSAEINPROGRESS)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("socket send error %d\n", nErr);
|
|
|
|
|
|
|
|
pnode->CloseSocketDisconnect();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|