Permalink
Browse files

P2P: improve RX/TX flow control

  • Loading branch information...
Tranz5 committed Jul 22, 2014
1 parent 69948a6 commit d548cba9a559f9ccb31579846f53a8d2cc848bcf
Showing with 14 additions and 6 deletions.
  1. +9 −6 src/net.cpp
  2. +5 −0 src/net.h
@@ -863,14 +863,17 @@ void ThreadSocketHandler2(void* parg)
{
if (pnode->hSocket == INVALID_SOCKET)
continue;
FD_SET(pnode->hSocket, &fdsetRecv);
FD_SET(pnode->hSocket, &fdsetError);
hSocketMax = max(hSocketMax, pnode->hSocket);
have_fds = true;
{
TRY_LOCK(pnode->cs_vSend, lockSend);
if (lockSend && !pnode->vSend.empty())
FD_SET(pnode->hSocket, &fdsetSend);
if (lockSend) {
// do not read, if draining write queue
if (!pnode->vSend.empty())
FD_SET(pnode->hSocket, &fdsetSend);
else
FD_SET(pnode->hSocket, &fdsetRecv);
FD_SET(pnode->hSocket, &fdsetError);
hSocketMax = max(hSocketMax, pnode->hSocket);
have_fds = true;
}
}
}
@@ -41,6 +41,7 @@ unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError=REF(std::string()));
void StartNode(void* parg);
bool StopNode();
void SocketSendData(CNode *pnode);
void ThreadStakeMinter(void* parg);
enum
@@ -457,6 +458,10 @@ class CNode
printf("(%d bytes)\n", nSize);
}
// If write queue empty, attempt "optimistic write"
if (nHeaderStart == 0)
SocketSendData(this);
nHeaderStart = -1;
nMessageStart = -1;
LEAVE_CRITICAL_SECTION(cs_vSend);

0 comments on commit d548cba

Please sign in to comment.