aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_send.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-07-25 15:44:56 +0000
committerng0 <ng0@n0.is>2019-07-25 15:44:56 +0000
commit30c4d657ff18abf6e70e2149ad2a75cd9e95cd33 (patch)
treef833b4106643dc2a9b013c4da563892f6e6d9500 /src/microhttpd/mhd_send.c
parent9c8c1e7b4924395f5524e8b6c5023673d064d11f (diff)
downloadlibmicrohttpd-30c4d657ff18abf6e70e2149ad2a75cd9e95cd33.tar.gz
libmicrohttpd-30c4d657ff18abf6e70e2149ad2a75cd9e95cd33.zip
post_cork function first draft
Diffstat (limited to 'src/microhttpd/mhd_send.c')
-rw-r--r--src/microhttpd/mhd_send.c190
1 files changed, 181 insertions, 9 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index fe6360f3..74735cbe 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -38,6 +38,107 @@
38 38
39#include "mhd_send.h" 39#include "mhd_send.h"
40 40
41int
42post_cork_setsockopt (struct MHD_Connection *connection,
43 bool want_cork)
44{
45 int ret;
46 bool using_tls = false;
47 // const MHD_SCKT_OPT_BOOL_ state_val = val ? 1 : 0;
48 const MHD_SCKT_OPT_BOOL_ off_val = 0;
49 const MHD_SCKT_OPT_BOOL_ on_val = 1;
50#ifdef HTTPS_SUPPORT
51 using_tls = (0 != (connection->daemon->options & MHD_USE_TLS));
52#endif
53
54 if (using_tls)
55 {
56 // not sure.
57 return 0; // ? without a value I get a return type error.
58 }
59
60#if TCP_CORK
61 ret = setsockopt (connection->socket_fd,
62 IPPROTO_TCP,
63 TCP_CORK,
64 (const void *) &on_val,
65 sizeof (on_val));
66#elif TCP_NODELAY
67 ret = setsockopt (connection->socket_fd,
68 IPPROTO_TCP,
69 TCP_NODELAY,
70 (const void *) &off_val,
71 sizeof (off_val));
72#elif TCP_NOPUSH
73 ret = setsockopt (connection->socket_fd,
74 IPPROTO_TCP,
75 TCP_NOPUSH,
76 (const void *) &on_val,
77 sizeof (on_val));
78#else
79 ret = -1;
80#endif
81 if (0 == ret)
82 {
83 connection->sk_tcp_nodelay_on = false;
84 }
85 return ret;
86}
87
88int
89pre_cork_setsockopt (struct MHD_Connection *connection,
90 bool want_cork,
91 bool val)
92{
93 int ret;
94 bool using_tls = false;
95 const MHD_SCKT_OPT_BOOL_ state_val = val ? 1 : 0;
96 const MHD_SCKT_OPT_BOOL_ off_val = 0;
97 const MHD_SCKT_OPT_BOOL_ on_val = 1;
98#ifdef HTTPS_SUPPORT
99 using_tls = (0 != (connection->daemon->options & MHD_USE_TLS));
100#endif
101
102 if (using_tls)
103 {
104 // more gnutls work?
105 // or all of it because we want to somehow handle the tls and error handling for it here?
106 return 0; // return type error
107 }
108
109 // if sk_tcp_nodelay_on is already what we pass in, return.
110 if (connection->sk_tcp_nodelay_on == val)
111 {
112 return 0; // return type error
113 }
114
115#if TCP_CORK
116 ret = setsockopt (connection->socket_fd,
117 IPPROTO_TCP,
118 TCP_CORK,
119 (const void *) &off_val,
120 sizeof (off_val));
121#elif TCP_NODELAY
122 ret = setsockopt (connection->socket_fd,
123 IPPROTO_TCP,
124 TCP_NODELAY,
125 (const void *) &on_val,
126 sizeof (on_val));
127#elif TCP_NOPUSH
128 ret = setsockopt (connection->socket_fd,
129 IPPROTO_TCP,
130 TCP_NOPUSH,
131 (const void *) &on_val,
132 sizeof (on_val));
133#else
134 ret = -1;
135#endif
136 if (0 == ret)
137 {
138 connection->sk_tcp_nodelay_on = val;
139 }
140}
141
41/** 142/**
42 * Set TCP_NODELAY flag on socket and save the 143 * Set TCP_NODELAY flag on socket and save the
43 * #sk_tcp_nodelay_on state. 144 * #sk_tcp_nodelay_on state.
@@ -63,6 +164,75 @@ MHD_send_socket_state_nodelay_ (struct MHD_Connection *connection,
63#endif 164#endif
64} 165}
65 166
167/*
168void
169MHD_setsockopt_pre_ (struct MHD_Connection *connection,
170 bool value)
171{
172 bool using_tls = false;
173#ifdef HTTPS_SUPPORT
174 using_tls = (0 != (connection->daemon->options & MHD_USE_TLS));
175#endif
176 const MHD_SCKT_OPT_BOOL_ state_val = value ? 1 : 0;
177 const MHD_SCKT_OPT_BOOL_ off_val = 0;
178 const MHD_SCKT_OPT_BOOL_ on_val = 1;
179
180 if (connection->sk_tcp_nodelay_on == value)
181 {
182 return
183 }
184 if (0 == setsockopt (connection->socket_fd,
185 IPPROTO_TCP,
186#if TCP_CORK && (! using_tls)
187 TCP_CORK,
188 (const void *) &off_val,
189 sizeof (off_val)))
190 {
191 connection->sk_tcp_nodelay_on = on_val;
192 }
193#elif TCP_NODELAY
194 TCP_NODELAY,
195 (const void *) &off_val,
196 sizeof (off_val)))
197#endif
198#if TCP_NOPUSH
199#endif
200 (const void *) &state_val,
201 sizeof (state_val)))
202}
203*/
204/*
205void
206MHD_setsockopt_post_ (struct MHD_Connection *connection,
207 bool value)
208{
209 if (connection->sk_tcp_nodelay_on == value)
210 {
211 return
212 }
213 if (0 == setsockopt (connection->socket_fd,
214 IPPROTO_TCP,
215#if TCP_NODELAY
216 TCP_NODELAY,
217#endif
218#if TCP_NOPUSH
219 TCP_NOPUSH,
220#endif
221#if TCP_CORK
222 TCP_CORK,
223#endif
224
225
226 (const void *) &state_val,
227 sizeof (state_val)))
228 {
229 // When TRUE above, this is usually FALSE, but
230 // not always. We can't use the negation of
231 // value for that reason.
232 connection->sk_tcp_nodelay_on = state_store;
233 }
234}
235*/
66void 236void
67MHD_setsockopt_ (struct MHD_Connection *connection, 237MHD_setsockopt_ (struct MHD_Connection *connection,
68 int optname, 238 int optname,
@@ -264,7 +434,6 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
264#endif 434#endif
265 435
266#ifdef HTTPS_SUPPORT 436#ifdef HTTPS_SUPPORT
267
268 if (using_tls) 437 if (using_tls)
269 { 438 {
270 if (want_cork && ! have_cork) 439 if (want_cork && ! have_cork)
@@ -341,6 +510,9 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
341 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY; 510 connection->epoll_state &= ~MHD_EPOLL_STATE_WRITE_READY;
342#endif /* EPOLL_SUPPORT */ 511#endif /* EPOLL_SUPPORT */
343 } 512 }
513
514 post_cork_setsockopt (connection, want_cork);
515 /*
344#if TCP_CORK 516#if TCP_CORK
345 if ((! using_tls) && (use_corknopush) && (! have_cork && want_cork && ! have_more)) 517 if ((! using_tls) && (use_corknopush) && (! have_cork && want_cork && ! have_more))
346 { 518 {
@@ -351,12 +523,12 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
351 false); 523 false);
352 } 524 }
353#elif TCP_NOPUSH 525#elif TCP_NOPUSH
354 /* We don't have MSG_MORE. The OS which implement NOPUSH implement 526 // We don't have MSG_MORE. The OS which implement NOPUSH implement
355 * it in a similar way to TCP_CORK on Linux. This means we can just 527 // it in a similar way to TCP_CORK on Linux. This means we can just
356 * disregard the else branch for TCP_NODELAY which we had to use 528 // disregard the else branch for TCP_NODELAY which we had to use
357 * for the TCP_CORK case here. 529 // for the TCP_CORK case here.
358 * XXX: Verify this statement and finetune if necessary for 530 // XXX: Verify this statement and finetune if necessary for
359 * other systems, as only FreeBSD was checked. */ 531 // other systems, as only FreeBSD was checked.
360 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork)) 532 if ((! using_tls) && (use_corknopush) && (have_cork && ! want_cork))
361 { 533 {
362 MHD_send_socket_state_nopush_ (connection, true, false); 534 MHD_send_socket_state_nopush_ (connection, true, false);
@@ -369,7 +541,7 @@ MHD_send_on_connection_ (struct MHD_Connection *connection,
369 MHD_setsockopt_ (connection, TCP_NODELAY, true, true); 541 MHD_setsockopt_ (connection, TCP_NODELAY, true, true);
370 } 542 }
371#endif 543#endif
372 544 */
373 return ret; 545 return ret;
374} 546}
375 547
@@ -431,7 +603,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection,
431#if HAVE_SENDMSG 603#if HAVE_SENDMSG
432 struct msghdr msg; 604 struct msghdr msg;
433 msg.msg_iov = vector; 605 msg.msg_iov = vector;
434 memset(&msg, 0, sizeof(buffer + header)); 606 memset(&msg, 0, sizeof(msg));
435 ret = sendmsg (s, vector, MAYBE_MSG_NOSIGNAL); 607 ret = sendmsg (s, vector, MAYBE_MSG_NOSIGNAL);
436#elif HAVE_WRITEV 608#elif HAVE_WRITEV
437 iovcnt = sizeof (vector) / sizeof (struct iovec); 609 iovcnt = sizeof (vector) / sizeof (struct iovec);