aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-07-25 19:06:13 +0000
committerng0 <ng0@n0.is>2019-07-25 19:06:13 +0000
commitb76dadc0fda1ea9565211093db8a9021a41361e8 (patch)
tree71c887813efb9ffb692820ac9011102c7070378a
parentd5c3f00f9f96cbf9ed227b1f8c870d5232bb9039 (diff)
downloadlibmicrohttpd-b76dadc0fda1ea9565211093db8a9021a41361e8.tar.gz
libmicrohttpd-b76dadc0fda1ea9565211093db8a9021a41361e8.zip
remove dead code, comment new code.
-rw-r--r--src/microhttpd/mhd_send.c207
-rw-r--r--src/microhttpd/mhd_send.h22
2 files changed, 17 insertions, 212 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index ee627e10..513b7dfb 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -24,8 +24,6 @@
24 * @author ng0 <ng0@n0.is> 24 * @author ng0 <ng0@n0.is>
25 */ 25 */
26 26
27/* TODO: sendfile() wrapper, in connection.c */
28
29/* Worth considering for future improvements and additions: 27/* Worth considering for future improvements and additions:
30 * NetBSD has no sendfile or sendfile64. The way to work 28 * NetBSD has no sendfile or sendfile64. The way to work
31 * with this seems to be to mmap the file and write(2) as 29 * with this seems to be to mmap the file and write(2) as
@@ -38,7 +36,13 @@
38 36
39#include "mhd_send.h" 37#include "mhd_send.h"
40 38
41int 39/**
40 * Handle setsockopt calls.
41 *
42 * @param connection the MHD_Connection structure
43 * @param want_cork cork state, boolean
44 */
45static void
42post_cork_setsockopt (struct MHD_Connection *connection, 46post_cork_setsockopt (struct MHD_Connection *connection,
43 bool want_cork) 47 bool want_cork)
44{ 48{
@@ -50,7 +54,7 @@ post_cork_setsockopt (struct MHD_Connection *connection,
50 if (connection->sk_cork_on == want_cork) 54 if (connection->sk_cork_on == want_cork)
51 { 55 {
52 /* nothing to do, success! */ 56 /* nothing to do, success! */
53 return 0; 57 return;
54 } 58 }
55 ret = -1; 59 ret = -1;
56#if TCP_CORK 60#if TCP_CORK
@@ -76,20 +80,25 @@ post_cork_setsockopt (struct MHD_Connection *connection,
76 return ret; 80 return ret;
77} 81}
78 82
79int 83/**
84 * Handle setsockopt calls.
85 *
86 * @param connection the MHD_Connection structure
87 * @param want_cork cork state, boolean
88 */
89static void
80pre_cork_setsockopt (struct MHD_Connection *connection, 90pre_cork_setsockopt (struct MHD_Connection *connection,
81 bool want_cork) 91 bool want_cork)
82{ 92{
83 int ret; 93 int ret;
84 // const MHD_SCKT_OPT_BOOL_ state_val = val ? 1 : 0;
85 const MHD_SCKT_OPT_BOOL_ off_val = 0; 94 const MHD_SCKT_OPT_BOOL_ off_val = 0;
86 const MHD_SCKT_OPT_BOOL_ on_val = 1; 95 const MHD_SCKT_OPT_BOOL_ on_val = 1;
87 96
88 // if sk_tcp_nodelay_on is already what we pass in, return. 97 /* if sk_tcp_nodelay_on is already what we pass in, return. */
89 if (connection->sk_cork_on == want_cork) 98 if (connection->sk_cork_on == want_cork)
90 { 99 {
91 /* nothing to do, success! */ 100 /* nothing to do, success! */
92 return 0; 101 return;
93 } 102 }
94 103
95 ret = -1; 104 ret = -1;
@@ -122,188 +131,6 @@ pre_cork_setsockopt (struct MHD_Connection *connection,
122} 131}
123 132
124/** 133/**
125 * Set TCP_NODELAY flag on socket and save the
126 * #sk_tcp_nodelay_on state.
127 *
128 * @param connection the MHD_Connection structure
129 * @param value the state to set, boolean
130 */
131void
132MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection,
133 bool value)
134{
135#if TCP_NODELAY
136 const MHD_SCKT_OPT_BOOL_ state_val = value ? 1 : 0;
137
138 if (0 == setsockopt (connection->socket_fd,
139 IPPROTO_TCP,
140 TCP_NODELAY,
141 (const void *) &state_val,
142 sizeof (state_val)))
143 {
144 connection->sk_tcp_nodelay_on = value;
145 }
146#endif
147}
148
149/*
150void
151MHD_setsockopt_pre_ (struct MHD_Connection *connection,
152 bool value)
153{
154 bool using_tls = false;
155#ifdef HTTPS_SUPPORT
156 using_tls = (0 != (connection->daemon->options & MHD_USE_TLS));
157#endif
158 const MHD_SCKT_OPT_BOOL_ state_val = value ? 1 : 0;
159 const MHD_SCKT_OPT_BOOL_ off_val = 0;
160 const MHD_SCKT_OPT_BOOL_ on_val = 1;
161
162 if (connection->sk_tcp_nodelay_on == value)
163 {
164 return
165 }
166 if (0 == setsockopt (connection->socket_fd,
167 IPPROTO_TCP,
168#if TCP_CORK && (! using_tls)
169 TCP_CORK,
170 (const void *) &off_val,
171 sizeof (off_val)))
172 {
173 connection->sk_tcp_nodelay_on = on_val;
174 }
175#elif TCP_NODELAY
176 TCP_NODELAY,
177 (const void *) &off_val,
178 sizeof (off_val)))
179#endif
180#if TCP_NOPUSH
181#endif
182 (const void *) &state_val,
183 sizeof (state_val)))
184}
185*/
186/*
187void
188MHD_setsockopt_post_ (struct MHD_Connection *connection,
189 bool value)
190{
191 if (connection->sk_tcp_nodelay_on == value)
192 {
193 return
194 }
195 if (0 == setsockopt (connection->socket_fd,
196 IPPROTO_TCP,
197#if TCP_NODELAY
198 TCP_NODELAY,
199#endif
200#if TCP_NOPUSH
201 TCP_NOPUSH,
202#endif
203#if TCP_CORK
204 TCP_CORK,
205#endif
206
207
208 (const void *) &state_val,
209 sizeof (state_val)))
210 {
211 // When TRUE above, this is usually FALSE, but
212 // not always. We can't use the negation of
213 // value for that reason.
214 connection->sk_tcp_nodelay_on = state_store;
215 }
216}
217*/
218void
219MHD_setsockopt_ (struct MHD_Connection *connection,
220 int optname,
221 bool value,
222 bool state_store)
223{
224 const MHD_SCKT_OPT_BOOL_ state_val = value ? 1 : 0;
225
226 if (0 == setsockopt (connection->socket_fd,
227 IPPROTO_TCP,
228 optname,
229 (const void *) &state_val,
230 sizeof (state_val)))
231 {
232 connection->sk_tcp_nodelay_on = state_store;
233 }
234}
235
236/**
237 * Set TCP_NOCORK or TCP_NODELAY flag on socket and save the
238 * #sk_tcp_nodelay_on state.
239 *
240 * @param connection the MHD_Connection structure
241 * @param cork_value the state to set, boolean
242 * @param cork_state the boolean value passed to #sk_tcp_nodelay_on
243 * @param nodelay_value the state to set, boolean
244 * @param nodelay_state the boolean value passed to #sk_tcp_nodelay_on
245 */
246void
247MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection,
248 bool cork_value,
249 bool cork_state,
250 bool nodelay_value,
251 bool nodelay_state)
252{
253#if TCP_CORK && TCP_NODELAY
254 const MHD_SCKT_OPT_BOOL_ cork_state_val = cork_value ? 1 : 0;
255 const MHD_SCKT_OPT_BOOL_ nodelay_state_val = nodelay_value ? 1 : 0;
256
257 if (0 == setsockopt (connection->socket_fd,
258 IPPROTO_TCP,
259 TCP_CORK,
260 (const void *) &cork_state_val,
261 sizeof (cork_state_val)))
262 {
263 connection->sk_tcp_nodelay_on = cork_state;
264 }
265 else if (0 == setsockopt (connection->socket_fd,
266 IPPROTO_TCP,
267 TCP_NODELAY,
268 (const void *) &nodelay_state_val,
269 sizeof (nodelay_state_val)))
270 {
271 connection->sk_tcp_nodelay_on = nodelay_state;
272 }
273#endif
274}
275
276/**
277 * Set TCP_NOPUSH flag on socket and save the
278 * #sk_tcp_nodelay_on state.
279 *
280 * @param connection the #MHD_Connection structure
281 * @param value the state to set, boolean
282 * @param state_store the boolean value passed to #sk_tcp_nodelay_on
283 */
284void
285MHD_send_socket_state_nopush_ (struct MHD_Connection *connection,
286 bool value,
287 bool state_store)
288{
289#if TCP_NOPUSH
290 const MHD_SCKT_OPT_BOOL_ state_val = value ? 1 : 0;
291
292 if (0 == setsockopt (connection->socket_fd,
293 IPPROTO_TCP,
294 TCP_NOPUSH,
295 (const void *) &state_val,
296 sizeof (state_val)))
297 {
298 /* When TRUE above, this is usually FALSE, but
299 * not always. We can't use the negation of
300 * value for that reason. */
301 connection->sk_tcp_nodelay_on = state_store;
302 }
303#endif
304}
305
306/**
307 * Send buffer on connection, and remember the current state of 134 * Send buffer on connection, and remember the current state of
308 * the socket options; only call setsockopt when absolutely 135 * the socket options; only call setsockopt when absolutely
309 * necessary. 136 * necessary.
diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h
index e94ed509..5f0f8155 100644
--- a/src/microhttpd/mhd_send.h
+++ b/src/microhttpd/mhd_send.h
@@ -92,28 +92,6 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
92ssize_t 92ssize_t
93MHD_sendfile_on_connection_ (struct MHD_Connection *connection); 93MHD_sendfile_on_connection_ (struct MHD_Connection *connection);
94 94
95void
96MHD_setsockopt_ (struct MHD_Connection *connection,
97 int optname,
98 bool value,
99 bool state_store);
100
101void
102MHD_send_socket_state_nopush_ (struct MHD_Connection *connection,
103 bool value,
104 bool state_store);
105
106void
107MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection,
108 bool value);
109
110void
111MHD_send_socket_state_cork_nodelay_ (struct MHD_Connection *connection,
112 bool cork_value,
113 bool cork_state,
114 bool nodelay_value,
115 bool nodelay_state);
116
117#if defined(_MHD_HAVE_SENDFILE) 95#if defined(_MHD_HAVE_SENDFILE)
118ssize_t 96ssize_t
119sendfile_adapter (struct MHD_Connection *connection); 97sendfile_adapter (struct MHD_Connection *connection);