From: David VaĊĦek Date: Thu, 5 Mar 2020 13:57:27 +0000 (+0100) Subject: contrib/net: when sending data, reflect other transient errors as well X-Git-Tag: embedded_lmdb~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58045d51e5ea83defa2b058f4e35061d796402aa;p=thirdparty%2Fknot-dns.git contrib/net: when sending data, reflect other transient errors as well --- diff --git a/src/contrib/net.c b/src/contrib/net.c index 666a8c04ca..93963e0f29 100644 --- a/src/contrib/net.c +++ b/src/contrib/net.c @@ -321,13 +321,13 @@ static int poll_one(int fd, int events, int timeout_ms) */ static bool io_should_wait(int error) { - /* socket data not ready */ - if (error == EAGAIN || error == EWOULDBLOCK) { + if (error == EAGAIN || error == EWOULDBLOCK || /* Socket data not ready. */ + error == ENOMEM || error == ENOBUFS) { /* Insufficient resources. */ return true; } #ifndef __linux__ - /* FreeBSD: connection in progress */ + /* FreeBSD: connection in progress. */ if (error == ENOTCONN) { return true; } @@ -336,6 +336,20 @@ static bool io_should_wait(int error) return false; } +/*! + * \brief Check if we should wait again. + * + * \param error \a errno set by the failed wait operation. + */ +static bool wait_should_retry(int error) +{ + if (error == EINTR || /* System call interrupted. */ + error == EAGAIN || error == ENOMEM) { /* Insufficient resources. */ + return true; + } + return false; +} + /*! * \brief I/O operation callbacks. */ @@ -430,9 +444,9 @@ static ssize_t io_exec(const struct io *io, int fd, struct msghdr *msg, TIMEOUT_CTX_UPDATE /* Ready, retry process. */ break; - } else if (ret == -1 && errno == EINTR) { + } else if (ret == -1 && wait_should_retry(errno)) { TIMEOUT_CTX_UPDATE - /* Interrupted, continue waiting. */ + /* Interrupted or transient error, continue waiting. */ continue; } else if (ret == 0) { /* Timeouted, exit. */