diff options
author | ng0 <ng0@n0.is> | 2019-07-18 16:18:30 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-07-18 16:18:30 +0000 |
commit | 843b844d64578aa20749658c656d93ea2e17710c (patch) | |
tree | 0ffc21e3a3966a687a0c79f9795f9e3d62a09162 | |
parent | 2a08acaa218a1e887f60af3019db33f9ec68cbe2 (diff) | |
download | libmicrohttpd-843b844d64578aa20749658c656d93ea2e17710c.tar.gz libmicrohttpd-843b844d64578aa20749658c656d93ea2e17710c.zip |
mhd_send.c: Use daemon from connection struct.
-rw-r--r-- | src/microhttpd/mhd_send.c | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index c6218870..d32533a8 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -90,13 +90,13 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
90 | const MHD_SCKT_OPT_BOOL_ on_val = 1; | 90 | const MHD_SCKT_OPT_BOOL_ on_val = 1; |
91 | const int err = MHD_socket_get_error_ (); | 91 | const int err = MHD_socket_get_error_ (); |
92 | 92 | ||
93 | // error handling from send_param_adapter() | 93 | /* error handling from send_param_adapter() */ |
94 | if ((MHD_INVALID_SOCKET == s) || (MHD_CONNECTION_CLOSED == connection->state)) | 94 | if ((MHD_INVALID_SOCKET == s) || (MHD_CONNECTION_CLOSED == connection->state)) |
95 | { | 95 | { |
96 | return MHD_ERR_NOTCONN_; | 96 | return MHD_ERR_NOTCONN_; |
97 | } | 97 | } |
98 | 98 | ||
99 | // from send_param_adapter() | 99 | /* from send_param_adapter() */ |
100 | if (buffer_size > MHD_SCKT_SEND_MAX_SIZE_) | 100 | if (buffer_size > MHD_SCKT_SEND_MAX_SIZE_) |
101 | buffer_size = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */ | 101 | buffer_size = MHD_SCKT_SEND_MAX_SIZE_; /* return value limit */ |
102 | 102 | ||
@@ -142,17 +142,18 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
142 | { | 142 | { |
143 | if (have_cork && ! want_cork) | 143 | if (have_cork && ! want_cork) |
144 | { | 144 | { |
145 | setsockopt (connection->socket_fd, | 145 | if (0 == setsockopt (connection->socket_fd, |
146 | IPPROTO_TCP, | 146 | IPPROTO_TCP, |
147 | TCP_CORK, | 147 | TCP_CORK, |
148 | (const void *) &on_val, | 148 | (const void *) &on_val, |
149 | sizeof (on_val)) || | 149 | sizeof (on_val))) |
150 | (setsockopt (connection->socket_fd, | 150 | else if (0 == setsockopt (connection->socket_fd, |
151 | IPPROTO_TCP, | 151 | IPPROTO_TCP, |
152 | TCP_NODELAY, | 152 | TCP_NODELAY, |
153 | (const void *) &on_val, | 153 | (const void *) &on_val, |
154 | sizeof (on_val)) && | 154 | sizeof (on_val))) { |
155 | (connection->sk_tcp_nodelay = true)); | 155 | connection->sk_tcp_nodelay = true; |
156 | } | ||
156 | //setsockopt (cork-on); // or nodelay on // + update connection->sk_tcp_nodelay_on | 157 | //setsockopt (cork-on); // or nodelay on // + update connection->sk_tcp_nodelay_on |
157 | // When we have CORK, we can have NODELAY on the same system, | 158 | // When we have CORK, we can have NODELAY on the same system, |
158 | // at least since Linux 2.2 and both can be combined since | 159 | // at least since Linux 2.2 and both can be combined since |
@@ -215,12 +216,11 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
215 | */ | 216 | */ |
216 | 217 | ||
217 | /* for TLS*/ | 218 | /* for TLS*/ |
218 | /* | 219 | |
219 | if (0 != (daemon->options & MHD_USE_TLS)) | 220 | if (0 != (connection->daemon->options & MHD_USE_TLS)) |
220 | TLS; | 221 | /* old TLS code here */; |
221 | else | 222 | else |
222 | no-TLS; | 223 | no-TLS; |
223 | */ | ||
224 | 224 | ||
225 | // shouldn't we return 0 or -1? Why re-use the _ERR_ functions? | 225 | // shouldn't we return 0 or -1? Why re-use the _ERR_ functions? |
226 | // error handling from send_param_adapter(): | 226 | // error handling from send_param_adapter(): |
@@ -256,17 +256,18 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
256 | if (! have_cork && want_cork && ! have_more) | 256 | if (! have_cork && want_cork && ! have_more) |
257 | { | 257 | { |
258 | //setsockopt (cork-off); // or nodelay off // + update connection->sk_tcp_nodelay_on | 258 | //setsockopt (cork-off); // or nodelay off // + update connection->sk_tcp_nodelay_on |
259 | setsockopt (connection->socket_fd, | 259 | if (0 == setsockopt (connection->socket_fd, |
260 | IPPROTO_TCP, | 260 | IPPROTO_TCP, |
261 | TCP_CORK, | 261 | TCP_CORK, |
262 | (const void *) &off_val, | 262 | (const void *) &off_val, |
263 | sizeof (off_val)) || | 263 | sizeof (off_val))) |
264 | (setsockopt (connection->socket_fd, | 264 | else if (0 == setsockopt (connection->socket_fd, |
265 | IPPROTO_TCP, | 265 | IPPROTO_TCP, |
266 | TCP_NODELAY, | 266 | TCP_NODELAY, |
267 | (const void *) &off_val, | 267 | (const void *) &off_val, |
268 | sizeof (off_val)) && | 268 | sizeof (off_val))) { |
269 | (connection->sk_tcp_nodelay_on = false)); | 269 | connection->sk_tcp_nodelay_on = false; |
270 | } | ||
270 | } | 271 | } |
271 | } | 272 | } |
272 | #elif TCP_NOPUSH | 273 | #elif TCP_NOPUSH |
@@ -283,12 +284,13 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
283 | if (have_cork && ! want_cork) | 284 | if (have_cork && ! want_cork) |
284 | { | 285 | { |
285 | // setsockopt (nodelay - on); | 286 | // setsockopt (nodelay - on); |
286 | setsockopt (connection->socket_fd, | 287 | if (0 == setsockopt (connection->socket_fd, |
287 | IPPROTO_TCP, | 288 | IPPROTO_TCP, |
288 | TCP_NODELAY, | 289 | TCP_NODELAY, |
289 | (const void *) &on_val, | 290 | (const void *) &on_val, |
290 | sizeof (on_val)) && | 291 | sizeof (on_val))) { |
291 | (connection->sk_tcp_nodelay_on = true); | 292 | connection->sk_tcp_nodelay_on = true; |
293 | } | ||
292 | } | 294 | } |
293 | // ... | 295 | // ... |
294 | } | 296 | } |
@@ -337,12 +339,13 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
337 | if (! have_cork && want_cork) | 339 | if (! have_cork && want_cork) |
338 | { | 340 | { |
339 | // setsockopt (nodelay-off); | 341 | // setsockopt (nodelay-off); |
340 | setsockopt (connection->socket_fd, | 342 | if (0 == setsockopt (connection->socket_fd, |
341 | IPPROTO_TCP, | 343 | IPPROTO_TCP, |
342 | TCP_NODELAY, | 344 | TCP_NODELAY, |
343 | (const void *) &off_val, | 345 | (const void *) &off_val, |
344 | sizeof (off_val)) && | 346 | sizeof (off_val))) { |
345 | (connection->sk_tcp_nodelay = false); | 347 | connection->sk_tcp_nodelay = false; |
348 | } | ||
346 | } | 349 | } |
347 | // ... | 350 | // ... |
348 | } | 351 | } |