diff options
Diffstat (limited to 'src/microhttpd/mhd_send.c')
-rw-r--r-- | src/microhttpd/mhd_send.c | 91 |
1 files changed, 66 insertions, 25 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index 335aa13a..987a694b 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -36,8 +36,74 @@ | |||
36 | * and every place where sendfile(), sendfile64(), setsockopt() | 36 | * and every place where sendfile(), sendfile64(), setsockopt() |
37 | * are used. */ | 37 | * are used. */ |
38 | 38 | ||
39 | #ifdef MHD_LINUX_SOLARIS_SENDFILE | ||
40 | #include <sys/sendfile.h> | ||
41 | #endif /* MHD_LINUX_SOLARIS_SENDFILE */ | ||
42 | #if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE) | ||
43 | #include <sys/types.h> | ||
44 | #include <sys/socket.h> | ||
45 | #include <sys/uio.h> | ||
46 | #endif /* HAVE_FREEBSD_SENDFILE || HAVE_DARWIN_SENDFILE */ | ||
47 | #ifdef HAVE_SYS_PARAM_H | ||
48 | /* For FreeBSD version identification */ | ||
49 | #include <sys/param.h> | ||
50 | #endif /* HAVE_SYS_PARAM_H */ | ||
39 | #include "mhd_send.h" | 51 | #include "mhd_send.h" |
40 | 52 | ||
53 | |||
54 | /** | ||
55 | * sendfile() chuck size | ||
56 | */ | ||
57 | #define MHD_SENFILE_CHUNK_ (0x20000) | ||
58 | |||
59 | /** | ||
60 | * sendfile() chuck size for thread-per-connection | ||
61 | */ | ||
62 | #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) | ||
63 | |||
64 | #ifdef HAVE_FREEBSD_SENDFILE | ||
65 | #ifdef SF_FLAGS | ||
66 | /** | ||
67 | * FreeBSD sendfile() flags | ||
68 | */ | ||
69 | static int freebsd_sendfile_flags_; | ||
70 | |||
71 | /** | ||
72 | * FreeBSD sendfile() flags for thread-per-connection | ||
73 | */ | ||
74 | static int freebsd_sendfile_flags_thd_p_c_; | ||
75 | #endif /* SF_FLAGS */ | ||
76 | /** | ||
77 | * Initialises static variables | ||
78 | */ | ||
79 | void | ||
80 | MHD_send_init_static_vars_ (void) | ||
81 | { | ||
82 | /* FreeBSD 11 and later allow to specify read-ahead size | ||
83 | * and handles SF_NODISKIO differently. | ||
84 | * SF_FLAGS defined only on FreeBSD 11 and later. */ | ||
85 | #ifdef SF_FLAGS | ||
86 | long sys_page_size = sysconf (_SC_PAGESIZE); | ||
87 | if (0 > sys_page_size) | ||
88 | { /* Failed to get page size. */ | ||
89 | freebsd_sendfile_flags_ = SF_NODISKIO; | ||
90 | freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | freebsd_sendfile_flags_ = | ||
95 | SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_ / sys_page_size), SF_NODISKIO); | ||
96 | freebsd_sendfile_flags_thd_p_c_ = | ||
97 | SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_THR_P_C_ / sys_page_size), | ||
98 | SF_NODISKIO); | ||
99 | } | ||
100 | #endif /* SF_FLAGS */ | ||
101 | } | ||
102 | |||
103 | |||
104 | #endif /* HAVE_FREEBSD_SENDFILE */ | ||
105 | |||
106 | |||
41 | /** | 107 | /** |
42 | * Handle setsockopt calls. | 108 | * Handle setsockopt calls. |
43 | * | 109 | * |
@@ -471,31 +537,6 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
471 | } | 537 | } |
472 | 538 | ||
473 | 539 | ||
474 | /** | ||
475 | * sendfile() chuck size | ||
476 | */ | ||
477 | #define MHD_SENFILE_CHUNK_ (0x20000) | ||
478 | |||
479 | /** | ||
480 | * sendfile() chuck size for thread-per-connection | ||
481 | */ | ||
482 | #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) | ||
483 | |||
484 | #ifdef HAVE_FREEBSD_SENDFILE | ||
485 | #ifdef SF_FLAGS | ||
486 | /** | ||
487 | * FreeBSD sendfile() flags | ||
488 | */ | ||
489 | static int freebsd_sendfile_flags_; | ||
490 | |||
491 | /** | ||
492 | * FreeBSD sendfile() flags for thread-per-connection | ||
493 | */ | ||
494 | static int freebsd_sendfile_flags_thd_p_c_; | ||
495 | #endif /* SF_FLAGS */ | ||
496 | |||
497 | #endif /* HAVE_FREEBSD_SENDFILE */ | ||
498 | |||
499 | #if defined(_MHD_HAVE_SENDFILE) | 540 | #if defined(_MHD_HAVE_SENDFILE) |
500 | /** | 541 | /** |
501 | * Function for sending responses backed by file FD. | 542 | * Function for sending responses backed by file FD. |