diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-10-15 12:55:24 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-10-15 16:27:45 +0300 |
commit | 16d9f9e426a8ea1f5c05a21554824b7981c0df3b (patch) | |
tree | 06e377c9a9b33600dc5f6ef68e61c4d09a29d2e5 | |
parent | a123fcc9ee0bf7a3d02f1230395b92b55bc56202 (diff) | |
download | libmicrohttpd-16d9f9e426a8ea1f5c05a21554824b7981c0df3b.tar.gz libmicrohttpd-16d9f9e426a8ea1f5c05a21554824b7981c0df3b.zip |
mhd_send: fixed broken sendfile() on FreeBSD, v0.9.67 regression
-rw-r--r-- | src/microhttpd/connection.c | 41 | ||||
-rw-r--r-- | src/microhttpd/connection.h | 10 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 3 | ||||
-rw-r--r-- | src/microhttpd/mhd_send.c | 91 | ||||
-rw-r--r-- | src/microhttpd/mhd_send.h | 21 |
5 files changed, 76 insertions, 90 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 5d7f52fb..98e58123 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -125,47 +125,6 @@ | |||
125 | */ | 125 | */ |
126 | #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) | 126 | #define MHD_SENFILE_CHUNK_THR_P_C_ (0x200000) |
127 | 127 | ||
128 | #ifdef HAVE_FREEBSD_SENDFILE | ||
129 | #ifdef SF_FLAGS | ||
130 | /** | ||
131 | * FreeBSD sendfile() flags | ||
132 | */ | ||
133 | static int freebsd_sendfile_flags_; | ||
134 | |||
135 | /** | ||
136 | * FreeBSD sendfile() flags for thread-per-connection | ||
137 | */ | ||
138 | static int freebsd_sendfile_flags_thd_p_c_; | ||
139 | #endif /* SF_FLAGS */ | ||
140 | /** | ||
141 | * Initialises static variables | ||
142 | */ | ||
143 | void | ||
144 | MHD_conn_init_static_ (void) | ||
145 | { | ||
146 | /* FreeBSD 11 and later allow to specify read-ahead size | ||
147 | * and handles SF_NODISKIO differently. | ||
148 | * SF_FLAGS defined only on FreeBSD 11 and later. */ | ||
149 | #ifdef SF_FLAGS | ||
150 | long sys_page_size = sysconf (_SC_PAGESIZE); | ||
151 | if (0 > sys_page_size) | ||
152 | { /* Failed to get page size. */ | ||
153 | freebsd_sendfile_flags_ = SF_NODISKIO; | ||
154 | freebsd_sendfile_flags_thd_p_c_ = SF_NODISKIO; | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | freebsd_sendfile_flags_ = | ||
159 | SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_ / sys_page_size), SF_NODISKIO); | ||
160 | freebsd_sendfile_flags_thd_p_c_ = | ||
161 | SF_FLAGS ((uint16_t) (MHD_SENFILE_CHUNK_THR_P_C_ / sys_page_size), | ||
162 | SF_NODISKIO); | ||
163 | } | ||
164 | #endif /* SF_FLAGS */ | ||
165 | } | ||
166 | |||
167 | |||
168 | #endif /* HAVE_FREEBSD_SENDFILE */ | ||
169 | /** | 128 | /** |
170 | * Callback for receiving data from the socket. | 129 | * Callback for receiving data from the socket. |
171 | * | 130 | * |
diff --git a/src/microhttpd/connection.h b/src/microhttpd/connection.h index 29724a24..8b1a0946 100644 --- a/src/microhttpd/connection.h +++ b/src/microhttpd/connection.h | |||
@@ -62,16 +62,6 @@ | |||
62 | #define MHD_ERR_INVAL_ (-3078) | 62 | #define MHD_ERR_INVAL_ (-3078) |
63 | 63 | ||
64 | 64 | ||
65 | #ifdef HAVE_FREEBSD_SENDFILE | ||
66 | /** | ||
67 | * Initialises static variables | ||
68 | */ | ||
69 | void | ||
70 | MHD_conn_init_static_ (void); | ||
71 | |||
72 | #endif /* HAVE_FREEBSD_SENDFILE */ | ||
73 | |||
74 | |||
75 | /** | 65 | /** |
76 | * Set callbacks for this connection to those for HTTP. | 66 | * Set callbacks for this connection to those for HTTP. |
77 | * | 67 | * |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 6888db28..2eefdef5 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include "mhd_sockets.h" | 42 | #include "mhd_sockets.h" |
43 | #include "mhd_itc.h" | 43 | #include "mhd_itc.h" |
44 | #include "mhd_compat.h" | 44 | #include "mhd_compat.h" |
45 | #include "mhd_send.h" | ||
45 | 46 | ||
46 | #if HAVE_SEARCH_H | 47 | #if HAVE_SEARCH_H |
47 | #include <search.h> | 48 | #include <search.h> |
@@ -7496,7 +7497,7 @@ MHD_init (void) | |||
7496 | #endif /* HTTPS_SUPPORT */ | 7497 | #endif /* HTTPS_SUPPORT */ |
7497 | MHD_monotonic_sec_counter_init (); | 7498 | MHD_monotonic_sec_counter_init (); |
7498 | #ifdef HAVE_FREEBSD_SENDFILE | 7499 | #ifdef HAVE_FREEBSD_SENDFILE |
7499 | MHD_conn_init_static_ (); | 7500 | MHD_send_init_static_vars_ (); |
7500 | #endif /* HAVE_FREEBSD_SENDFILE */ | 7501 | #endif /* HAVE_FREEBSD_SENDFILE */ |
7501 | MHD_init_mem_pools_ (); | 7502 | MHD_init_mem_pools_ (); |
7502 | } | 7503 | } |
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. |
diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h index 22d934b3..12ac1ac6 100644 --- a/src/microhttpd/mhd_send.h +++ b/src/microhttpd/mhd_send.h | |||
@@ -39,19 +39,14 @@ | |||
39 | #include "connection_https.h" | 39 | #include "connection_https.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #ifdef MHD_LINUX_SOLARIS_SENDFILE | 42 | #ifdef HAVE_FREEBSD_SENDFILE |
43 | #include <sys/sendfile.h> | 43 | /** |
44 | #endif /* MHD_LINUX_SOLARIS_SENDFILE */ | 44 | * Initialises static variables |
45 | #if defined(HAVE_FREEBSD_SENDFILE) || defined(HAVE_DARWIN_SENDFILE) | 45 | */ |
46 | #include <sys/types.h> | 46 | void |
47 | #include <sys/socket.h> | 47 | MHD_send_init_static_vars_ (void); |
48 | #include <sys/uio.h> | 48 | |
49 | #endif /* HAVE_FREEBSD_SENDFILE || HAVE_DARWIN_SENDFILE */ | 49 | #endif /* HAVE_FREEBSD_SENDFILE */ |
50 | |||
51 | #ifdef HAVE_SYS_PARAM_H | ||
52 | /* For FreeBSD version identification */ | ||
53 | #include <sys/param.h> | ||
54 | #endif /* HAVE_SYS_PARAM_H */ | ||
55 | 50 | ||
56 | /** | 51 | /** |
57 | * The enumeration of send socket options. | 52 | * The enumeration of send socket options. |