diff --git a/mio/configure b/mio/configure index 4317df1..2aa954b 100755 --- a/mio/configure +++ b/mio/configure @@ -17828,7 +17828,7 @@ _ACEOF fi done -for ac_func in lstat fchmod fsync ftruncate +for ac_func in lstat fchmod fsync ftruncate posix_fadvise do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/mio/configure.ac b/mio/configure.ac index 596cb2d..3781d03 100644 --- a/mio/configure.ac +++ b/mio/configure.ac @@ -152,7 +152,7 @@ AC_CHECK_FUNCS([mbsnrtowcs mbsrtowcs wcsnrtombs wcsrtombs]) AC_CHECK_FUNCS([wctype iswctype wctrans towctrans]) AC_CHECK_FUNCS([isblank iswblank]) AC_CHECK_FUNCS([lseek64 stat64 fstat64 lstat64 ftruncate64 readdir64 dirfd]) -AC_CHECK_FUNCS([lstat fchmod fsync ftruncate]) +AC_CHECK_FUNCS([lstat fchmod fsync ftruncate posix_fadvise]) AC_CHECK_FUNCS([timegm timelocal localtime_r gettimeofday settimeofday clock_gettime clock_settime]) AC_CHECK_FUNCS([utime utimes futimes lutimes futimens]) AC_CHECK_FUNCS([sysconf prctl fdopendir setrlimit getrlimit getpgid getpgrp]) diff --git a/mio/lib/Makefile.in b/mio/lib/Makefile.in index 6c384b5..57a6a49 100644 --- a/mio/lib/Makefile.in +++ b/mio/lib/Makefile.in @@ -408,7 +408,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/mio/lib/http-fil.c b/mio/lib/http-fil.c index 476d27c..dc869ef 100644 --- a/mio/lib/http-fil.c +++ b/mio/lib/http-fil.c @@ -610,6 +610,7 @@ static int open_peer (file_state_t* file_state, const mio_bch_t* actual_file) file_state_send_final_status_to_client (file_state, ERRNO_TO_STATUS_CODE(errno), 1); return -1; } + return 0; case MIO_HTTP_PUT: @@ -643,6 +644,14 @@ static int open_peer (file_state_t* file_state, const mio_bch_t* actual_file) return -1; } +static MIO_INLINE void fadvise_on_peer (file_state_t* file_state) +{ +#if defined(HAVE_POSIX_FADVISE) + if (file_state->req_method == MIO_HTTP_GET) + posix_fadvise (file_state->peer, file_state->start_offset, file_state->end_offset - file_state->start_offset + 1, POSIX_FADV_SEQUENTIAL); +#endif +} + int mio_svc_htts_dofile (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t* req, const mio_bch_t* docroot, const mio_bch_t* file) { mio_t* mio = htts->mio; @@ -682,6 +691,8 @@ int mio_svc_htts_dofile (mio_svc_htts_t* htts, mio_dev_sck_t* csck, mio_htre_t* if (open_peer(file_state, actual_file) <= -1 || process_range_header(file_state, req) <= -1) goto oops; + fadvise_on_peer (file_state); + #if !defined(FILE_ALLOW_UNLIMITED_REQ_CONTENT_LENGTH) if (file_state->req_content_length_unlimited) { diff --git a/mio/lib/mio-cfg.h.in b/mio/lib/mio-cfg.h.in index 43d214b..7d2f770 100644 --- a/mio/lib/mio-cfg.h.in +++ b/mio/lib/mio-cfg.h.in @@ -376,6 +376,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_OPENSSL_SSL_H +/* Define to 1 if you have the `posix_fadvise' function. */ +#undef HAVE_POSIX_FADVISE + /* Define to 1 if you have the `posix_spawn' function. */ #undef HAVE_POSIX_SPAWN