]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
contrib/net: when sending data, reflect other transient errors as well
authorDavid Vašek <david.vasek@nic.cz>
Thu, 5 Mar 2020 13:57:27 +0000 (14:57 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 29 Apr 2020 14:55:25 +0000 (16:55 +0200)
src/contrib/net.c

index 666a8c04cac1453b1b58fb0fda35184dc9264d88..93963e0f2984b34e1f01574ccfa87b416125366f 100644 (file)
@@ -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. */