From: Lennart Poettering Date: Wed, 10 Apr 2019 17:40:40 +0000 (+0200) Subject: errno-util: add new ERRNO_IS_ACCEPT_AGAIN() test X-Git-Tag: v242~5^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fb0302ddbc47f61349286abfe7fbaa12c7069e25;p=thirdparty%2Fsystemd.git errno-util: add new ERRNO_IS_ACCEPT_AGAIN() test 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. --- diff --git a/src/basic/errno-util.h b/src/basic/errno-util.h index ebb204128ed..d7a5ea771f4 100644 --- a/src/basic/errno-util.h +++ b/src/basic/errno-util.h @@ -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),