diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-12-13 14:02:51 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-12-13 14:25:07 +0300 |
commit | cd8294e59dc3d32062c8a3ddd6e5a203f746958d (patch) | |
tree | 6f762c6bffa464497026e48975c6cb00d86444dd /src/microhttpd/mhd_send.c | |
parent | 275990c32ffd8591f9b346c0d69fdd5cbd6eb7b1 (diff) | |
download | libmicrohttpd-cd8294e59dc3d32062c8a3ddd6e5a203f746958d.tar.gz libmicrohttpd-cd8294e59dc3d32062c8a3ddd6e5a203f746958d.zip |
MHD_send: renamed function for clarity, moved doxy
Renamed MHD_send_on_connection2_ to MHD_send_hdr_and_body_ to reflect
function action. Doxy moved to the header and fixed.
Diffstat (limited to 'src/microhttpd/mhd_send.c')
-rw-r--r-- | src/microhttpd/mhd_send.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c index f0cdfb58..e54a251c 100644 --- a/src/microhttpd/mhd_send.c +++ b/src/microhttpd/mhd_send.c | |||
@@ -807,29 +807,12 @@ MHD_send_on_connection_ (struct MHD_Connection *connection, | |||
807 | } | 807 | } |
808 | 808 | ||
809 | 809 | ||
810 | /** | ||
811 | * Send header followed by buffer on connection. | ||
812 | * Uses writev if possible to send both at once | ||
813 | * and returns the sum of the number of bytes sent from | ||
814 | * both buffers, or -1 on error; | ||
815 | * if writev is unavailable, this call MUST only send from 'header' | ||
816 | * (as we cannot handle the case that the first write | ||
817 | * succeeds and the 2nd fails!). | ||
818 | * | ||
819 | * @param connection the MHD_Connection structure | ||
820 | * @param header content of header to send | ||
821 | * @param header_size the size of the header (in bytes) | ||
822 | * @param buffer content of the buffer to send | ||
823 | * @param buffer_size the size of the buffer (in bytes) | ||
824 | * @return sum of the number of bytes sent from both buffers or | ||
825 | * -1 on error | ||
826 | */ | ||
827 | ssize_t | 810 | ssize_t |
828 | MHD_send_on_connection2_ (struct MHD_Connection *connection, | 811 | MHD_send_hdr_and_body_ (struct MHD_Connection *connection, |
829 | const char *header, | 812 | const char *header, |
830 | size_t header_size, | 813 | size_t header_size, |
831 | const char *buffer, | 814 | const char *body, |
832 | size_t buffer_size) | 815 | size_t body_size) |
833 | { | 816 | { |
834 | ssize_t ret; | 817 | ssize_t ret; |
835 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) | 818 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) |
@@ -841,12 +824,12 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
841 | const bool no_vec = false; | 824 | const bool no_vec = false; |
842 | #endif /* ! HTTPS_SUPPORT */ | 825 | #endif /* ! HTTPS_SUPPORT */ |
843 | #endif /* HAVE_SENDMSG || HAVE_WRITEV */ | 826 | #endif /* HAVE_SENDMSG || HAVE_WRITEV */ |
844 | mhd_assert ( (NULL != buffer) || (0 == buffer_size) ); | 827 | mhd_assert ( (NULL != body) || (0 == body_size) ); |
845 | 828 | ||
846 | if ( | 829 | if ( |
847 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) | 830 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) |
848 | (no_vec) || | 831 | (no_vec) || |
849 | (0 == buffer_size) || | 832 | (0 == body_size) || |
850 | ((size_t) SSIZE_MAX <= header_size) | 833 | ((size_t) SSIZE_MAX <= header_size) |
851 | #else /* ! (HAVE_SENDMSG || HAVE_WRITEV) */ | 834 | #else /* ! (HAVE_SENDMSG || HAVE_WRITEV) */ |
852 | true | 835 | true |
@@ -859,19 +842,19 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
859 | MHD_SSO_HDR_CORK); | 842 | MHD_SSO_HDR_CORK); |
860 | if ( ((size_t) header_size == ret) && | 843 | if ( ((size_t) header_size == ret) && |
861 | (((size_t) SSIZE_MAX > header_size)) && | 844 | (((size_t) SSIZE_MAX > header_size)) && |
862 | (0 != buffer_size) ) | 845 | (0 != body_size) ) |
863 | { | 846 | { |
864 | int ret2; | 847 | int ret2; |
865 | /* The header has been sent completely. | 848 | /* The header has been sent completely. |
866 | * Try to send the reply body without waiting for | 849 | * Try to send the reply body without waiting for |
867 | * the next round. */ | 850 | * the next round. */ |
868 | /* Make sure that sum of ret + ret2 will not exceed SSIZE_MAX. */ | 851 | /* Make sure that sum of ret + ret2 will not exceed SSIZE_MAX. */ |
869 | if ( (((size_t) SSIZE_MAX) - ((size_t) ret)) < buffer_size) | 852 | if ( (((size_t) SSIZE_MAX) - ((size_t) ret)) < body_size) |
870 | buffer_size = (((size_t) SSIZE_MAX) - ((size_t) ret)); | 853 | body_size = (((size_t) SSIZE_MAX) - ((size_t) ret)); |
871 | 854 | ||
872 | ret2 = MHD_send_on_connection_ (connection, | 855 | ret2 = MHD_send_on_connection_ (connection, |
873 | buffer, | 856 | body, |
874 | buffer_size, | 857 | body_size, |
875 | MHD_SSO_PUSH_DATA); | 858 | MHD_SSO_PUSH_DATA); |
876 | if (0 < ret2) | 859 | if (0 < ret2) |
877 | return ret + ret2; /* Total data sent */ | 860 | return ret + ret2; /* Total data sent */ |
@@ -884,9 +867,9 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
884 | } | 867 | } |
885 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) | 868 | #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) |
886 | 869 | ||
887 | if ( ((size_t) SSIZE_MAX <= buffer_size) || | 870 | if ( ((size_t) SSIZE_MAX <= body_size) || |
888 | ((size_t) SSIZE_MAX < (header_size + buffer_size)) ) | 871 | ((size_t) SSIZE_MAX < (header_size + body_size)) ) |
889 | buffer_size = SSIZE_MAX - header_size; | 872 | body_size = SSIZE_MAX - header_size; |
890 | 873 | ||
891 | /* Since we generally give the fully answer, we do not want | 874 | /* Since we generally give the fully answer, we do not want |
892 | corking to happen */ | 875 | corking to happen */ |
@@ -900,8 +883,8 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
900 | 883 | ||
901 | vector[0].iov_base = (void *) header; | 884 | vector[0].iov_base = (void *) header; |
902 | vector[0].iov_len = header_size; | 885 | vector[0].iov_len = header_size; |
903 | vector[1].iov_base = (void *) buffer; | 886 | vector[1].iov_base = (void *) body; |
904 | vector[1].iov_len = buffer_size; | 887 | vector[1].iov_len = body_size; |
905 | 888 | ||
906 | #if HAVE_SENDMSG | 889 | #if HAVE_SENDMSG |
907 | { | 890 | { |
@@ -935,7 +918,7 @@ MHD_send_on_connection2_ (struct MHD_Connection *connection, | |||
935 | * it's unknown whether sendfile() will be used or not so | 918 | * it's unknown whether sendfile() will be used or not so |
936 | * assume that next final send() will be the same, like for | 919 | * assume that next final send() will be the same, like for |
937 | * this response. */ | 920 | * this response. */ |
938 | if ((header_size + buffer_size) == (size_t) ret) | 921 | if ((header_size + body_size) == (size_t) ret) |
939 | post_send_setopt (connection, | 922 | post_send_setopt (connection, |
940 | #if HAVE_SENDMSG | 923 | #if HAVE_SENDMSG |
941 | true, | 924 | true, |