diff options
| author | Gavin Andresen <[email protected]> | 2012-02-22 10:52:14 -0500 |
|---|---|---|
| committer | Gavin Andresen <[email protected]> | 2012-02-22 10:52:14 -0500 |
| commit | de737806b502dc86275d03f4aed7a83dcad67cce (patch) | |
| tree | 84327e3875f8fef7d6ae3716843e3f3fe5dd8e11 /src/net.cpp | |
| parent | Merge branch 'bugfix_bip14_ez' of https://github.com/luke-jr/bitcoin (diff) | |
| parent | Fix #626: RecvLine wrong error message (diff) | |
| download | discoin-de737806b502dc86275d03f4aed7a83dcad67cce.tar.xz discoin-de737806b502dc86275d03f4aed7a83dcad67cce.zip | |
Merge branch 'fix_626' of https://github.com/sipa/bitcoin
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp index fd488ce67..546bc6adc 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -83,6 +83,57 @@ void CNode::PushGetBlocks(CBlockIndex* pindexBegin, uint256 hashEnd) +bool RecvLine(SOCKET hSocket, string& strLine) +{ + strLine = ""; + loop + { + char c; + int nBytes = recv(hSocket, &c, 1, 0); + if (nBytes > 0) + { + if (c == '\n') + continue; + if (c == '\r') + return true; + strLine += c; + if (strLine.size() >= 9000) + return true; + } + else if (nBytes <= 0) + { + if (fShutdown) + return false; + if (nBytes < 0) + { + int nErr = WSAGetLastError(); + if (nErr == WSAEMSGSIZE) + continue; + if (nErr == WSAEWOULDBLOCK || nErr == WSAEINTR || nErr == WSAEINPROGRESS) + { + Sleep(10); + continue; + } + } + if (!strLine.empty()) + return true; + if (nBytes == 0) + { + // socket closed + printf("socket closed\n"); + return false; + } + else + { + // socket error + int nErr = WSAGetLastError(); + printf("recv failed: %d\n", nErr); + return false; + } + } + } +} + bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const char* pszKeyword, CNetAddr& ipRet) |