| 103 | |
| 104 | |
| 105 | bool RecvLine(SOCKET hSocket, string& strLine) { |
| 106 | strLine = ""; |
| 107 | while (true) { |
| 108 | char c; |
| 109 | int32_t nBytes = recv(hSocket, &c, 1, 0); |
| 110 | if (nBytes > 0) { |
| 111 | if (c == '\n') |
| 112 | continue; |
| 113 | if (c == '\r') |
| 114 | return true; |
| 115 | strLine += c; |
| 116 | if (strLine.size() >= 9000) |
| 117 | return true; |
| 118 | } else if (nBytes <= 0) { |
| 119 | boost::this_thread::interruption_point(); |
| 120 | if (nBytes < 0) { |
| 121 | int32_t nErr = WSAGetLastError(); |
| 122 | if (nErr == WSAEMSGSIZE) |
| 123 | continue; |
| 124 | if (nErr == WSAEWOULDBLOCK || nErr == WSAEINTR || nErr == WSAEINPROGRESS) { |
| 125 | MilliSleep(10); |
| 126 | continue; |
| 127 | } |
| 128 | } |
| 129 | if (!strLine.empty()) |
| 130 | return true; |
| 131 | if (nBytes == 0) { |
| 132 | // socket closed |
| 133 | LogPrint(BCLog::NET, "socket closed\n"); |
| 134 | return false; |
| 135 | } else { |
| 136 | // socket error |
| 137 | int32_t nErr = WSAGetLastError(); |
| 138 | LogPrint(BCLog::NET, "recv failed: %s\n", NetworkErrorString(nErr)); |
| 139 | return false; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // used when scores of local addresses may have changed |
| 146 | // pushes better local address to peers |
nothing calls this directly
no test coverage detected