aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-07-24 15:49:59 +0000
committerng0 <ng0@n0.is>2019-07-24 15:49:59 +0000
commite072dbba655ff8ee52ecd00631b4732334320c93 (patch)
tree16d9db7faa3ef28ae3e57b546e0b6af8844248cf
parent51cfb23f17b55708fb569b46df90914e70b5a077 (diff)
downloadlibmicrohttpd-e072dbba655ff8ee52ecd00631b4732334320c93.tar.gz
libmicrohttpd-e072dbba655ff8ee52ecd00631b4732334320c93.zip
Start reworking into generic setsockopt wrapper.
-rw-r--r--src/microhttpd/mhd_send.c35
-rw-r--r--src/microhttpd/mhd_send.h6
2 files changed, 29 insertions, 12 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index b235c6ff..47ff09cc 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -63,8 +63,26 @@ MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection,
63#endif 63#endif
64} 64}
65 65
66void
67MHD_setsockopt_ (struct MHD_Connection *connection,
68 int optname,
69 bool value,
70 bool state_store)
71{
72 const MHD_SCKT_OPT_BOOL_ state_val = value ? 1 : 0;
73
74 if (0 == setsockopt (connection->socket_fd,
75 IPPROTO_TCP,
76 optname,
77 (const void *) &state_val,
78 sizeof (state_val)))
79 {
80 connection->sk_tcp_nodelay_on = state_store;
81 }
82}
83
66/** 84/**
67 * Set TCP_NODELAY flag on socket and save the 85 * Set TCP_NOCORK or TCP_NODELAY flag on socket and save the
68 * #sk_tcp_nodelay_on state. 86 * #sk_tcp_nodelay_on state.
69 * 87 *
70 * @param connection the MHD_Connection structure 88 * @param connection the MHD_Connection structure
@@ -241,7 +259,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
241#if TCP_NODELAY 259#if TCP_NODELAY
242 if ((! using_tls) && (! use_corknopush) && (! have_cork && want_cork)) 260 if ((! using_tls) && (! use_corknopush) && (! have_cork && want_cork))
243 { 261 {
244 MHD_send_socket_state_nodelay_ (connection, false); 262 MHD_setsockopt_ (connection, TCP_NODELAY, false, false);
245 } 263 }
246#endif 264#endif
247 265
@@ -348,7 +366,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
348#if TCP_NODELAY 366#if TCP_NODELAY
349 if ((! using_tls) && (! use_corknopush) && (have_cork && ! want_cork)) 367 if ((! using_tls) && (! use_corknopush) && (have_cork && ! want_cork))
350 { 368 {
351 MHD_send_socket_state_nodelay_ (connection, true); 369 MHD_setsockopt_ (connection, TCP_NODELAY, true, true);
352 } 370 }
353#endif 371#endif
354 372
@@ -401,7 +419,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
401#if TCP_NODELAY 419#if TCP_NODELAY
402 if ((! use_corknopush) && (! have_cork && want_cork)) 420 if ((! use_corknopush) && (! have_cork && want_cork))
403 { 421 {
404 MHD_send_socket_state_nodelay_ (connection, false); 422 MHD_setsockopt_(connection, TCP_NODELAY, false, false);
405 } 423 }
406#endif 424#endif
407 425
@@ -429,14 +447,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
429 if ((ret == header_len + buffer_len) && have_cork) 447 if ((ret == header_len + buffer_len) && have_cork)
430 { 448 {
431 // Response complete, definitely uncork! 449 // Response complete, definitely uncork!
432 if (0 == setsockopt (s, 450 MHD_setsockopt_(connection, TCP_CORK, false, true);
433 IPPROTO_TCP,
434 TCP_CORK,
435 (const void *) &off_val,
436 sizeof (off_val)))
437 {
438 connection->sk_tcp_nodelay_on = true;
439 }
440 } 451 }
441 errno = eno; 452 errno = eno;
442 } 453 }
diff --git a/src/microhttpd/mhd_send.h b/src/microhttpd/mhd_send.h
index c01d9357..78edc9de 100644
--- a/src/microhttpd/mhd_send.h
+++ b/src/microhttpd/mhd_send.h
@@ -79,6 +79,12 @@ ssize_t
79MHD_sendfile_on_connection_ (struct MHD_Connection *connection); 79MHD_sendfile_on_connection_ (struct MHD_Connection *connection);
80 80
81void 81void
82MHD_setsockopt_ (struct MHD_Connection *connection,
83 int optname,
84 bool value,
85 bool state_store);
86
87void
82MHD_send_socket_state_nopush_ (struct MHD_Connection *connection, 88MHD_send_socket_state_nopush_ (struct MHD_Connection *connection,
83 bool value, 89 bool value,
84 bool state_store); 90 bool state_store);