From 0ce8ebbefde39a95dafa3d496ed45f64a46a929b Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 9 Feb 2019 11:32:33 -0800 Subject: [PATCH] Fix posix_file::close handling of EINTR: fix #1445 These changes optimize for Linux at the possible expense of non-conforming platforms like HP-UX. --- CHANGELOG.md | 6 ++++ include/boost/beast/core/impl/file_posix.hpp | 29 ++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff5a34c1..03e9184b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 213: + +* Fix posix_file::close handling of EINTR + +-------------------------------------------------------------------------------- + Version 212: * dynamic_buffer_ref tests and tidy diff --git a/include/boost/beast/core/impl/file_posix.hpp b/include/boost/beast/core/impl/file_posix.hpp index 9ac97b52..5113fbab 100644 --- a/include/boost/beast/core/impl/file_posix.hpp +++ b/include/boost/beast/core/impl/file_posix.hpp @@ -40,19 +40,30 @@ int file_posix:: native_close(native_handle_type& fd) { +/* https://github.com/boostorg/beast/issues/1445 + + This function is tuned for Linux / Mac OS: + + * only calls close() once + * returns the error directly to the caller + * does not loop on EINTR + + If this is incorrect for the platform, then the + caller will need to implement their own type + meeting the File requirements and use the correct + behavior. + + See: + http://man7.org/linux/man-pages/man2/close.2.html +*/ + int ev = 0; if(fd != -1) { - for(;;) - { - if(::close(fd) == 0) - break; - int const ev = errno; - if(errno != EINTR) - return ev; - } + if(::close(fd) != 0) + ev = errno; fd = -1; } - return 0; + return ev; } file_posix::