[6.0] aafb13257 Make VTCP_Check() accept EAGAIN/EWOULDBLOCK as acceptable errno

Reza Naghibi reza at naghibi.com
Thu Apr 22 15:55:06 UTC 2021


commit aafb132571ddb1047b6a59202a26702a8d66f5ff
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Oct 7 14:56:38 2020 +0200

    Make VTCP_Check() accept EAGAIN/EWOULDBLOCK as acceptable errno
    
    When a socket timeout is set on a socket and the timeout expires, read()
    and write() calls on that socket will return (-1) with errno set to
    EAGAIN/EWOULDBLOCK.
    
     Conflicts:
            lib/libvarnish/vtcp.c

diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index eaf075c9a..9f253dd56 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -562,6 +562,14 @@ VTCP_Check(int a)
 		return (1);
 	if (errno == ECONNRESET || errno == ENOTCONN || errno == EPIPE)
 		return (1);
+	/* Accept EAGAIN (and EWOULDBLOCK in case they are not the same)
+	 * as errno values. Even though our sockets are all non-blocking,
+	 * when a SO_{SND|RCV}TIMEO expires, read() or write() on the
+	 * socket will return (-1) and errno set to EAGAIN. (This is not
+	 * documented in the read(2) and write(2) manpages, but is
+	 * described in the socket(7) manpage.) */
+	if (errno == EAGAIN || errno == EWOULDBLOCK)
+		return (1);
 #if (defined (__SVR4) && defined (__sun)) || defined (__NetBSD__)
 	/*
 	 * Solaris returns EINVAL if the other end unexpectedly reset the


More information about the varnish-commit mailing list