diff options
author | ng0 <ng0@n0.is> | 2019-07-19 20:39:19 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-07-19 20:39:19 +0000 |
commit | b854bbba20255f77a681a4020191dc8b42e23049 (patch) | |
tree | 8a6107b0b59e5dd6b5badacc528f1dae3abd18bb | |
parent | 23a7502ef4edca9546a00ac3b9f88e126414aeb0 (diff) | |
download | libmicrohttpd-b854bbba20255f77a681a4020191dc8b42e23049.tar.gz libmicrohttpd-b854bbba20255f77a681a4020191dc8b42e23049.zip |
replace connection->send_cls()
-rw-r--r-- | src/microhttpd/connection.c | 58 | ||||
-rw-r--r-- | src/microhttpd/mhd_send.c | 53 |
2 files changed, 55 insertions, 56 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 877f514b..4d93acee 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -53,7 +53,7 @@ | |||
53 | /* For FreeBSD version identification */ | 53 | /* For FreeBSD version identification */ |
54 | #include <sys/param.h> | 54 | #include <sys/param.h> |
55 | #endif /* HAVE_SYS_PARAM_H */ | 55 | #endif /* HAVE_SYS_PARAM_H */ |
56 | 56 | #include "mhd_send.h" | |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Message to transmit when http 1.1 request is received | 59 | * Message to transmit when http 1.1 request is received |
@@ -3303,11 +3303,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3303 | case MHD_CONNECTION_HEADERS_PROCESSED: | 3303 | case MHD_CONNECTION_HEADERS_PROCESSED: |
3304 | return; | 3304 | return; |
3305 | case MHD_CONNECTION_CONTINUE_SENDING: | 3305 | case MHD_CONNECTION_CONTINUE_SENDING: |
3306 | ret = connection->send_cls (connection, | 3306 | ret = MHD_send_on_connection_ (connection, |
3307 | &HTTP_100_CONTINUE | 3307 | &HTTP_100_CONTINUE |
3308 | [connection->continue_message_write_offset], | 3308 | [connection->continue_message_write_offset], |
3309 | MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE) - | 3309 | MHD_STATICSTR_LEN_ (HTTP_100_CONTINUE) - |
3310 | connection->continue_message_write_offset); | 3310 | connection->continue_message_write_offset, |
3311 | MHD_SSO_NO_CORK); | ||
3311 | if (ret < 0) | 3312 | if (ret < 0) |
3312 | { | 3313 | { |
3313 | if (MHD_ERR_AGAIN_ == ret) | 3314 | if (MHD_ERR_AGAIN_ == ret) |
@@ -3337,11 +3338,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3337 | mhd_assert (0); | 3338 | mhd_assert (0); |
3338 | return; | 3339 | return; |
3339 | case MHD_CONNECTION_HEADERS_SENDING: | 3340 | case MHD_CONNECTION_HEADERS_SENDING: |
3340 | ret = connection->send_cls (connection, | 3341 | /* TODO: Maybe use MHD_send_on_connection2_()? */ |
3341 | &connection->write_buffer | 3342 | ret = MHD_send_on_connection_ (connection, |
3342 | [connection->write_buffer_send_offset], | 3343 | &connection->write_buffer |
3343 | connection->write_buffer_append_offset - | 3344 | [connection->write_buffer_send_offset], |
3344 | connection->write_buffer_send_offset); | 3345 | connection->write_buffer_append_offset - |
3346 | connection->write_buffer_send_offset, | ||
3347 | MHD_SSO_MAY_CORK); | ||
3345 | if (ret < 0) | 3348 | if (ret < 0) |
3346 | { | 3349 | { |
3347 | if (MHD_ERR_AGAIN_ == ret) | 3350 | if (MHD_ERR_AGAIN_ == ret) |
@@ -3389,11 +3392,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3389 | - response->data_start; | 3392 | - response->data_start; |
3390 | if (data_write_offset > (uint64_t)SIZE_MAX) | 3393 | if (data_write_offset > (uint64_t)SIZE_MAX) |
3391 | MHD_PANIC (_("Data offset exceeds limit")); | 3394 | MHD_PANIC (_("Data offset exceeds limit")); |
3392 | ret = connection->send_cls (connection, | 3395 | ret = MHD_send_on_connection_ (connection, |
3393 | &response->data | 3396 | &response->data |
3394 | [(size_t)data_write_offset], | 3397 | [(size_t)data_write_offset], |
3395 | response->data_size - | 3398 | response->data_size - |
3396 | (size_t)data_write_offset); | 3399 | (size_t)data_write_offset, |
3400 | MHD_SSO_NO_CORK); | ||
3397 | #if DEBUG_SEND_DATA | 3401 | #if DEBUG_SEND_DATA |
3398 | if (ret > 0) | 3402 | if (ret > 0) |
3399 | fprintf (stderr, | 3403 | fprintf (stderr, |
@@ -3432,11 +3436,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3432 | mhd_assert (0); | 3436 | mhd_assert (0); |
3433 | return; | 3437 | return; |
3434 | case MHD_CONNECTION_CHUNKED_BODY_READY: | 3438 | case MHD_CONNECTION_CHUNKED_BODY_READY: |
3435 | ret = connection->send_cls (connection, | 3439 | ret = MHD_send_on_connection_ (connection, |
3436 | &connection->write_buffer | 3440 | &connection->write_buffer |
3437 | [connection->write_buffer_send_offset], | 3441 | [connection->write_buffer_send_offset], |
3438 | connection->write_buffer_append_offset - | 3442 | connection->write_buffer_append_offset - |
3439 | connection->write_buffer_send_offset); | 3443 | connection->write_buffer_send_offset, |
3444 | MHD_SSO_NO_CORK); | ||
3440 | if (ret < 0) | 3445 | if (ret < 0) |
3441 | { | 3446 | { |
3442 | if (MHD_ERR_AGAIN_ == ret) | 3447 | if (MHD_ERR_AGAIN_ == ret) |
@@ -3460,11 +3465,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
3460 | mhd_assert (0); | 3465 | mhd_assert (0); |
3461 | return; | 3466 | return; |
3462 | case MHD_CONNECTION_FOOTERS_SENDING: | 3467 | case MHD_CONNECTION_FOOTERS_SENDING: |
3463 | ret = connection->send_cls (connection, | 3468 | ret = MHD_send_on_connection_ (connection, |
3464 | &connection->write_buffer | 3469 | &connection->write_buffer |
3465 | [connection->write_buffer_send_offset], | 3470 | [connection->write_buffer_send_offset], |
3466 | connection->write_buffer_append_offset - | 3471 | connection->write_buffer_append_offset - |
3467 | connection->write_buffer_send_offset); | 3472 | connection->write_buffer_send_offset, |
3473 | MHD_SSO_HDR_CORK); | ||
3468 | if (ret < 0) | 3474 | if (ret < 0) |
3469 | { | 3475 | { |
3470 | if (MHD_ERR_AGAIN_ == ret) | 3476 | if (MHD_ERR_AGAIN_ == ret) |
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index 18fa617f..36007929 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -24,37 +24,33 @@ | |||
24 | * @author ng0 <ng0@n0.is> | 24 | * @author ng0 <ng0@n0.is> |
25 | */ | 25 | */ |
26 | 26 | ||
27 | // to be used in: send_param_adapter, MHD_send_ | 27 | /* TODO: sendfile() wrappers. */ |
28 | // and every place where sendfile(), sendfile64(), setsockopt() | ||
29 | // are used. | ||
30 | // TODO: sendfile() wrappers. | ||
31 | 28 | ||
32 | #include "mhd_send.h" | 29 | #include "mhd_send.h" |
33 | 30 | ||
34 | // NOTE: TCP_CORK == TCP_NOPUSH in FreeBSD. | ||
35 | // TCP_CORK is Linux. | ||
36 | // TCP_CORK/TCP_NOPUSH: don't send out partial frames. | ||
37 | // TCP_NODELAY: disable Nagle (aggregate data based on | ||
38 | // buffer pressur). | ||
39 | // TODO: It is possible that Solaris/SunOS depending on | ||
40 | // the linked library needs a different setsockopt usage: | ||
41 | // https://stackoverflow.com/questions/48670299/setsockopt-usage-in-linux-and-solaris-invalid-argument-in-solaris | ||
42 | |||
43 | /* | 31 | /* |
44 | * https://svnweb.freebsd.org/base/head/sys/netinet/tcp_usrreq.c?view=markup&pathrev=346360 | 32 | * NOTE: |
33 | * It might be possible that Solaris/SunOS depending on the linked library needs a different setsockopt usage: | ||
34 | * https://stackoverflow.com/questions/48670299/setsockopt-usage-in-linux-and-solaris-invalid-argument-in-solaris | ||
35 | * | ||
45 | * Approximately in 2007 work began to make TCP_NOPUSH in FreeBSD | 36 | * Approximately in 2007 work began to make TCP_NOPUSH in FreeBSD |
46 | * behave like TCP_CORK in Linux. Thus we define them to be one and | 37 | * behave like TCP_CORK in Linux. Thus we define them to be one and |
47 | * the same, which again could be platform dependent (NetBSD does | 38 | * the same, which again could be platform dependent (NetBSD does |
48 | * (so far) only provide a FreeBSD compatibility here, for example). | 39 | * (so far) only provide a FreeBSD compatibility here, for example). |
49 | * Since we only deal with IPPROTO_TCP flags in this file and nowhere | 40 | * Since we only deal with IPPROTO_TCP flags in this file and nowhere |
50 | * else, we don't have to move this elsewhere for now. | 41 | * else, we don't have to move this elsewhere for now. |
51 | */ | 42 | * https://svnweb.freebsd.org/base/head/sys/netinet/tcp_usrreq.c?view=markup&pathrev=346360 |
52 | /* | 43 | * |
53 | #if ! defined(TCP_CORK) && defined(TCP_NOPUSH) | 44 | * verbose notes, remove when done: |
54 | #define TCP_CORK TCP_NOPUSH | 45 | * TCP_CORK == TCP_NOPUSH in FreeBSD. |
55 | #endif | 46 | * TCP_CORK is Linux. |
56 | */ | 47 | * TCP_CORK/TCP_NOPUSH: don't send out partial frames. |
57 | /* | 48 | * TCP_NODELAY: disable Nagle (aggregate data based on buffer pressur) |
49 | * | ||
50 | * to be used in: send_param_adapter, MHD_send_ | ||
51 | * and every place where sendfile(), sendfile64(), setsockopt() are used. | ||
52 | * | ||
53 | * Fix this up in doxygen style: | ||
58 | * -- OBJECTIVE: | 54 | * -- OBJECTIVE: |
59 | * connection: use member 'socket', and remember the | 55 | * connection: use member 'socket', and remember the |
60 | * current state of the socket-options (cork/nocork/nodelay/whatever) | 56 | * current state of the socket-options (cork/nocork/nodelay/whatever) |
@@ -152,17 +148,14 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
152 | { | 148 | { |
153 | connection->sk_tcp_nodelay = true; | 149 | connection->sk_tcp_nodelay = true; |
154 | } | 150 | } |
155 | //setsockopt (cork-on); // or nodelay on // + update connection->sk_tcp_nodelay_on | 151 | /* When we have CORK, we can have NODELAY on the same system, |
156 | // When we have CORK, we can have NODELAY on the same system, | 152 | * at least since Linux 2.2 and both can be combined since |
157 | // at least since Linux 2.2 and both can be combined since | 153 | * Linux 2.5.71. See tcp(7). No other system in 2019-06 has TCP_CORK. */ |
158 | // Linux 2.5.71. See tcp(7). No other system in 2019-06 has TCP_CORK. | ||
159 | } | 154 | } |
160 | #elif TCP_NOPUSH | 155 | #elif TCP_NOPUSH |
161 | /* | 156 | /* TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the |
162 | * TCP_NOPUSH on FreeBSD is equal to cork on Linux, with the | 157 | * exception that we know that TCP_NOPUSH will definitely |
163 | * exception that we know that TCP_NOPUSH will definitely | 158 | * exist and we can disregard TCP_NODELAY unless requested. */ |
164 | * exist and we can disregard TCP_NODELAY unless requested. | ||
165 | */ | ||
166 | if ((use_corknopush) && (have_cork && ! want_cork)) | 159 | if ((use_corknopush) && (have_cork && ! want_cork)) |
167 | { | 160 | { |
168 | if (0 == setsockopt (connection->socket_fd, | 161 | if (0 == setsockopt (connection->socket_fd, |