From bea7d6e019b037ca5ce624e43f75bef28ffa2aa8 Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Wed, 25 Oct 2017 10:05:36 -0700 Subject: [PATCH] Add BOOST_BEAST_NO_POSIX_FADVISE --- CHANGELOG.md | 6 ++++ include/boost/beast/core/impl/file_posix.ipp | 34 ++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 926488b3..a32194b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 127: + +* Add BOOST_BEAST_NO_POSIX_FADVISE + +-------------------------------------------------------------------------------- + Version 126: * Add CppCon2017 presentation link diff --git a/include/boost/beast/core/impl/file_posix.ipp b/include/boost/beast/core/impl/file_posix.ipp index 73a93c37..96ccdc3b 100644 --- a/include/boost/beast/core/impl/file_posix.ipp +++ b/include/boost/beast/core/impl/file_posix.ipp @@ -10,6 +10,20 @@ #ifndef BOOST_BEAST_CORE_IMPL_FILE_POSIX_IPP #define BOOST_BEAST_CORE_IMPL_FILE_POSIX_IPP +#if ! defined(BOOST_BEAST_NO_POSIX_FADVISE) +# if defined(__APPLE__) || (defined(ANDROID) && (__ANDROID_API__ < 21)) +# define BOOST_BEAST_NO_POSIX_FADVISE +# endif +#endif + +#if ! defined(BOOST_BEAST_USE_POSIX_FADVISE) +# if ! defined(BOOST_BEAST_NO_POSIX_FADVISE) +# define BOOST_BEAST_USE_POSIX_FADVISE 1 +# else +# define BOOST_BEAST_USE_POSIX_FADVISE 0 +# endif +#endif + #include #include #include @@ -117,7 +131,7 @@ open(char const* path, file_mode mode, error_code& ec) fd_ = -1; } int f = 0; -#ifndef __APPLE__ +#if BOOST_BEAST_USE_POSIX_FADVISE int advise = 0; #endif switch(mode) @@ -125,55 +139,55 @@ open(char const* path, file_mode mode, error_code& ec) default: case file_mode::read: f = O_RDONLY; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_RANDOM; #endif break; case file_mode::scan: f = O_RDONLY; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_SEQUENTIAL; #endif break; case file_mode::write: f = O_RDWR | O_CREAT | O_TRUNC; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_RANDOM; #endif break; case file_mode::write_new: f = O_RDWR | O_CREAT | O_EXCL; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_RANDOM; #endif break; case file_mode::write_existing: f = O_RDWR | O_EXCL; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_RANDOM; #endif break; case file_mode::append: f = O_RDWR | O_CREAT | O_TRUNC; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_SEQUENTIAL; #endif break; case file_mode::append_new: f = O_RDWR | O_CREAT | O_EXCL; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_SEQUENTIAL; #endif break; case file_mode::append_existing: f = O_RDWR | O_EXCL; - #ifndef __APPLE__ + #if BOOST_BEAST_USE_POSIX_FADVISE advise = POSIX_FADV_SEQUENTIAL; #endif break; @@ -190,7 +204,7 @@ open(char const* path, file_mode mode, error_code& ec) return; } } -#ifndef __APPLE__ +#if BOOST_BEAST_USE_POSIX_FADVISE if(::posix_fadvise(fd_, 0, 0, advise)) { auto const ev = errno;