Codechange: encapsulate network error handling

This commit is contained in:
rubidium42
2021-04-30 15:38:22 +02:00
committed by rubidium42
parent 0eb17a70af
commit 22720332eb
10 changed files with 183 additions and 83 deletions

View File

@@ -225,10 +225,10 @@ int NetworkHTTPSocketHandler::Receive()
for (;;) {
ssize_t res = recv(this->sock, (char *)this->recv_buffer + this->recv_pos, lengthof(this->recv_buffer) - this->recv_pos, 0);
if (res == -1) {
int err = NetworkGetLastError();
if (err != EWOULDBLOCK) {
/* Something went wrong... (ECONNRESET is connection reset by peer) */
if (err != ECONNRESET) DEBUG(net, 0, "recv failed with error %s", NetworkGetErrorString(err));
NetworkError err = NetworkError::GetLast();
if (!err.WouldBlock()) {
/* Something went wrong... */
if (!err.IsConnectionReset()) DEBUG(net, 0, "recv failed with error %s", err.AsString());
return -1;
}
/* Connection would block, so stop for now */