diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-02-19 19:05:41 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-02-19 19:06:42 +0100 |
commit | a3342d096f3456e5e8d087bb3c8eea8b25eb6b57 (patch) | |
tree | 593c21e6c05cd92079831784f436bdf4ca653e70 /src/net.cpp | |
parent | e0b8d459b189ee2b7e95a47b217e4b02bfb523b3 (diff) |
Fix #626: RecvLine wrong error message
Also moved RecvLine to net.cpp.
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 fd488ce671..546bc6adc8 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) |