Add BOOST_BEAST_NO_POSIX_FADVISE

This commit is contained in:
Berkus Decker
2017-10-25 10:05:36 -07:00
committed by Vinnie Falco
parent 1e9fcbad61
commit bea7d6e019
2 changed files with 30 additions and 10 deletions

View File

@ -1,3 +1,9 @@
Version 127:
* Add BOOST_BEAST_NO_POSIX_FADVISE
--------------------------------------------------------------------------------
Version 126: Version 126:
* Add CppCon2017 presentation link * Add CppCon2017 presentation link

View File

@ -10,6 +10,20 @@
#ifndef BOOST_BEAST_CORE_IMPL_FILE_POSIX_IPP #ifndef BOOST_BEAST_CORE_IMPL_FILE_POSIX_IPP
#define 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 <limits> #include <limits>
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
@ -117,7 +131,7 @@ open(char const* path, file_mode mode, error_code& ec)
fd_ = -1; fd_ = -1;
} }
int f = 0; int f = 0;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
int advise = 0; int advise = 0;
#endif #endif
switch(mode) switch(mode)
@ -125,55 +139,55 @@ open(char const* path, file_mode mode, error_code& ec)
default: default:
case file_mode::read: case file_mode::read:
f = O_RDONLY; f = O_RDONLY;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_RANDOM; advise = POSIX_FADV_RANDOM;
#endif #endif
break; break;
case file_mode::scan: case file_mode::scan:
f = O_RDONLY; f = O_RDONLY;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_SEQUENTIAL; advise = POSIX_FADV_SEQUENTIAL;
#endif #endif
break; break;
case file_mode::write: case file_mode::write:
f = O_RDWR | O_CREAT | O_TRUNC; f = O_RDWR | O_CREAT | O_TRUNC;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_RANDOM; advise = POSIX_FADV_RANDOM;
#endif #endif
break; break;
case file_mode::write_new: case file_mode::write_new:
f = O_RDWR | O_CREAT | O_EXCL; f = O_RDWR | O_CREAT | O_EXCL;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_RANDOM; advise = POSIX_FADV_RANDOM;
#endif #endif
break; break;
case file_mode::write_existing: case file_mode::write_existing:
f = O_RDWR | O_EXCL; f = O_RDWR | O_EXCL;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_RANDOM; advise = POSIX_FADV_RANDOM;
#endif #endif
break; break;
case file_mode::append: case file_mode::append:
f = O_RDWR | O_CREAT | O_TRUNC; f = O_RDWR | O_CREAT | O_TRUNC;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_SEQUENTIAL; advise = POSIX_FADV_SEQUENTIAL;
#endif #endif
break; break;
case file_mode::append_new: case file_mode::append_new:
f = O_RDWR | O_CREAT | O_EXCL; f = O_RDWR | O_CREAT | O_EXCL;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_SEQUENTIAL; advise = POSIX_FADV_SEQUENTIAL;
#endif #endif
break; break;
case file_mode::append_existing: case file_mode::append_existing:
f = O_RDWR | O_EXCL; f = O_RDWR | O_EXCL;
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
advise = POSIX_FADV_SEQUENTIAL; advise = POSIX_FADV_SEQUENTIAL;
#endif #endif
break; break;
@ -190,7 +204,7 @@ open(char const* path, file_mode mode, error_code& ec)
return; return;
} }
} }
#ifndef __APPLE__ #if BOOST_BEAST_USE_POSIX_FADVISE
if(::posix_fadvise(fd_, 0, 0, advise)) if(::posix_fadvise(fd_, 0, 0, advise))
{ {
auto const ev = errno; auto const ev = errno;