diff options
author | ng0 <ng0@n0.is> | 2019-06-25 18:33:48 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-06-25 18:33:48 +0000 |
commit | 09ef9de1ca62bb47fe7cb320fc595275911f6a14 (patch) | |
tree | e9aad38ea17373c56958c32f7089557b146a4752 | |
parent | ee0942b2e0ea1683d9329f45cc81b193908672ec (diff) | |
download | libmicrohttpd-09ef9de1ca62bb47fe7cb320fc595275911f6a14.tar.gz libmicrohttpd-09ef9de1ca62bb47fe7cb320fc595275911f6a14.zip |
mhd_send: Use MHD_SCKT_OPT_BOOL_ for setsockopt optval.
-rw-r--r-- | src/microhttpd/mhd_send.c | 48 | ||||
-rw-r--r-- | src/microhttpd/mhd_send.h | 3 |
2 files changed, 23 insertions, 28 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index 50013c13..85616e52 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -82,6 +82,8 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
82 | /* The socket. */ | 82 | /* The socket. */ |
83 | MHD_socket s = connection->socket_fd; | 83 | MHD_socket s = connection->socket_fd; |
84 | int eno, ret, optval; | 84 | int eno, ret, optval; |
85 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | ||
86 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | ||
85 | 87 | ||
86 | // new code... | 88 | // new code... |
87 | /* Get socket options, change/set options if necessary. */ | 89 | /* Get socket options, change/set options if necessary. */ |
@@ -125,17 +127,16 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
125 | { | 127 | { |
126 | if (have_cork && ! want_cork) | 128 | if (have_cork && ! want_cork) |
127 | { | 129 | { |
128 | optval = 1; | ||
129 | setsockopt (connection->socket_fd, | 130 | setsockopt (connection->socket_fd, |
130 | IPPROTO_TCP, | 131 | IPPROTO_TCP, |
131 | TCP_CORK, | 132 | TCP_CORK, |
132 | &optval, | 133 | (const void *) &on_val, |
133 | sizeof (&optval)) || | 134 | sizeof (on_val)) || |
134 | (setsockopt (connection->socket_fd, | 135 | (setsockopt (connection->socket_fd, |
135 | IPPROTO_TCP, | 136 | IPPROTO_TCP, |
136 | TCP_NODELAY, | 137 | TCP_NODELAY, |
137 | &optval, | 138 | (const void *) &on_val, |
138 | sizeof (&optval)) && | 139 | sizeof (on_val)) && |
139 | (connection->sk_tcp_nodelay = true)); | 140 | (connection->sk_tcp_nodelay = true)); |
140 | //setsockopt (cork-on); // or nodelay on // + update connection->sk_tcp_nodelay_on | 141 | //setsockopt (cork-on); // or nodelay on // + update connection->sk_tcp_nodelay_on |
141 | // When we have CORK, we can have NODELAY on the same system, | 142 | // When we have CORK, we can have NODELAY on the same system, |
@@ -153,12 +154,11 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
153 | { | 154 | { |
154 | if (have_cork && ! want_cork) | 155 | if (have_cork && ! want_cork) |
155 | { | 156 | { |
156 | optval = 1; | ||
157 | setsockopt (connection->socket_fd, | 157 | setsockopt (connection->socket_fd, |
158 | IPPROTO_TCP, | 158 | IPPROTO_TCP, |
159 | TCP_NOPUSH, | 159 | TCP_NOPUSH, |
160 | &optval, | 160 | (const void *) &on_val, |
161 | sizeof (&optval)); | 161 | sizeof (on_val)); |
162 | // TODO: set corknopush to true here? | 162 | // TODO: set corknopush to true here? |
163 | // connection->sk_tcp_cork_nopush_on = true; | 163 | // connection->sk_tcp_cork_nopush_on = true; |
164 | } | 164 | } |
@@ -169,13 +169,12 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
169 | { | 169 | { |
170 | if (! have_cork && want_cork) | 170 | if (! have_cork && want_cork) |
171 | { | 171 | { |
172 | optval = 0; | ||
173 | // setsockopt (nodelay-off); | 172 | // setsockopt (nodelay-off); |
174 | setsockopt (connection->socket_fd, | 173 | setsockopt (connection->socket_fd, |
175 | IPPROTO_TCP, | 174 | IPPROTO_TCP, |
176 | TCP_NODELAY, | 175 | TCP_NODELAY, |
177 | &optval, | 176 | (const void *) &off_val, |
178 | sizeof (&optval)); | 177 | sizeof (off_val)); |
179 | connection->sk_tcp_nodelay_on = false; | 178 | connection->sk_tcp_nodelay_on = false; |
180 | } | 179 | } |
181 | // ... | 180 | // ... |
@@ -197,18 +196,17 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
197 | { | 196 | { |
198 | if (! have_cork && want_cork && ! have_more) | 197 | if (! have_cork && want_cork && ! have_more) |
199 | { | 198 | { |
200 | optval = 0; | ||
201 | //setsockopt (cork-off); // or nodelay off // + update connection->sk_tcp_nodelay_on | 199 | //setsockopt (cork-off); // or nodelay off // + update connection->sk_tcp_nodelay_on |
202 | setsockopt (connection->socket_fd, | 200 | setsockopt (connection->socket_fd, |
203 | IPPROTO_TCP, | 201 | IPPROTO_TCP, |
204 | TCP_CORK, | 202 | TCP_CORK, |
205 | &optval, | 203 | (const void *) &off_val, |
206 | sizeof (&optval)) || | 204 | sizeof (off_val)) || |
207 | (setsockopt (connection->socket_fd, | 205 | (setsockopt (connection->socket_fd, |
208 | IPPROTO_TCP, | 206 | IPPROTO_TCP, |
209 | TCP_NODELAY, | 207 | TCP_NODELAY, |
210 | &optval, | 208 | (const void *) &off_val, |
211 | sizeof (&optval)) && | 209 | sizeof (off_val)) && |
212 | (connection->sk_tcp_nodelay_on = false)); | 210 | (connection->sk_tcp_nodelay_on = false)); |
213 | } | 211 | } |
214 | } | 212 | } |
@@ -225,13 +223,12 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
225 | { | 223 | { |
226 | if (have_cork && ! want_cork) | 224 | if (have_cork && ! want_cork) |
227 | { | 225 | { |
228 | optval = 1; | ||
229 | // setsockopt (nodelay - on); | 226 | // setsockopt (nodelay - on); |
230 | setsockopt (connection->socket_fd, | 227 | setsockopt (connection->socket_fd, |
231 | IPPROTO_TCP, | 228 | IPPROTO_TCP, |
232 | TCP_NODELAY, | 229 | TCP_NODELAY, |
233 | &optval, | 230 | (const void *) &on_val, |
234 | sizeof (&optval)) && | 231 | sizeof (on_val)) && |
235 | (connection->sk_tcp_nodelay_on = true); | 232 | (connection->sk_tcp_nodelay_on = true); |
236 | } | 233 | } |
237 | // ... | 234 | // ... |
@@ -260,7 +257,8 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
260 | #if HAVE_WRITEV | 257 | #if HAVE_WRITEV |
261 | MHD_socket s = connection->socket_fd; | 258 | MHD_socket s = connection->socket_fd; |
262 | bool have_cork, have_more; | 259 | bool have_cork, have_more; |
263 | int iovcnt, optval, eno; | 260 | int iovcnt, eno; |
261 | const MHD_SCKT_OPT_BOOL_ off_val = 0; | ||
264 | struct iovec vector[2]; | 262 | struct iovec vector[2]; |
265 | 263 | ||
266 | have_cork = ! connection->sk_tcp_nodelay_on; | 264 | have_cork = ! connection->sk_tcp_nodelay_on; |
@@ -277,13 +275,12 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
277 | { | 275 | { |
278 | if (! have_cork && want_cork) | 276 | if (! have_cork && want_cork) |
279 | { | 277 | { |
280 | optval = 0; | ||
281 | // setsockopt (nodelay-off); | 278 | // setsockopt (nodelay-off); |
282 | setsockopt (connection->socket_fd, | 279 | setsockopt (connection->socket_fd, |
283 | IPPROTO_TCP, | 280 | IPPROTO_TCP, |
284 | TCP_NODELAY, | 281 | TCP_NODELAY, |
285 | &optval, | 282 | (const void *) &off_val, |
286 | sizeof (&optval)) && | 283 | sizeof (off_val)) && |
287 | (connection->sk_tcp_nodelay = false); | 284 | (connection->sk_tcp_nodelay = false); |
288 | } | 285 | } |
289 | // ... | 286 | // ... |
@@ -304,12 +301,11 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
304 | if ((ret == header_len + buffer_len) && have_cork) | 301 | if ((ret == header_len + buffer_len) && have_cork) |
305 | { | 302 | { |
306 | // response complete, definitely uncork! | 303 | // response complete, definitely uncork! |
307 | optval = 0; | ||
308 | setsockopt (connection->socket_fd, | 304 | setsockopt (connection->socket_fd, |
309 | IPPROTO_TCP, | 305 | IPPROTO_TCP, |
310 | TCP_CORK, | 306 | TCP_CORK, |
311 | &optval, | 307 | (const void *) &off_val, |
312 | sizeof (&optval)); | 308 | sizeof (off_val)); |
313 | } | 309 | } |
314 | errno = eno; | 310 | errno = eno; |
315 | } | 311 | } |
diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h index 2ff39a05..11b9bce6 100644 --- a/src/microhttpd/mhd_send.h +++ b/src/microhttpd/mhd_send.h | |||
@@ -29,12 +29,11 @@ | |||
29 | 29 | ||
30 | #include "platform.h" | 30 | #include "platform.h" |
31 | #include "internal.h" | 31 | #include "internal.h" |
32 | |||
33 | #if defined(HAVE_STDBOOL_H) | 32 | #if defined(HAVE_STDBOOL_H) |
34 | #include <stdbool.h> | 33 | #include <stdbool.h> |
35 | #endif /* HAVE_STDBOOL_H */ | 34 | #endif /* HAVE_STDBOOL_H */ |
36 | |||
37 | #include <errno.h> | 35 | #include <errno.h> |
36 | #include "mhd_sockets.h" | ||
38 | 37 | ||
39 | enum MHD_SendSocketOptions | 38 | enum MHD_SendSocketOptions |
40 | { | 39 | { |