]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
errno-util: add new ERRNO_IS_ACCEPT_AGAIN() test
authorLennart Poettering <lennart@poettering.net>
Wed, 10 Apr 2019 17:40:40 +0000 (19:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 10 Apr 2019 18:03:38 +0000 (20:03 +0200)
This is modelled after the existing ERRNO_IS_RESOURCES() and in
particular ERRNO_IS_DISCONNECT(). It returns true for all transient
network errors that should be handled like EAGAIN whenever we call
accept() or accept4(). This is per documentation in the accept(2) man
page that explicitly says to do so in the its "RETURN VALUE" section.

The error list we cover is a bit more comprehensive, and based on
existing code of ours. For example EINTR is included too (since we need
that to cover cases where we call accept()/accept4() on a blocking
socket), and of course ERRNO_IS_DISCONNECT() is a bit more comprehensive
than the list in the man page too.

src/basic/errno-util.h

index ebb204128ed54bc286190f4460bb3051cfef92c6..d7a5ea771f4ffaea05efdf19094797d6fb3f1ede 100644 (file)
@@ -50,6 +50,16 @@ static inline bool ERRNO_IS_DISCONNECT(int r) {
                       ESHUTDOWN);
 }
 
+/* Transient errors we might get on accept() that we should ignore. As per error handling comment in
+ * the accept(2) man page. */
+static inline bool ERRNO_IS_ACCEPT_AGAIN(int r) {
+        return ERRNO_IS_DISCONNECT(r) ||
+                IN_SET(abs(r),
+                       EAGAIN,
+                       EINTR,
+                       EOPNOTSUPP);
+}
+
 /* Resource exhaustion, could be our fault or general system trouble */
 static inline bool ERRNO_IS_RESOURCE(int r) {
         return IN_SET(abs(r),