mhd_send.h (6627B)
1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 2 /* 3 This file is part of GNU libmicrohttpd. 4 Copyright (C) 2017-2025 Evgeny Grin (Karlson2k) 5 Copyright (C) 2019 ng0 6 7 GNU libmicrohttpd is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 GNU libmicrohttpd is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 Alternatively, you can redistribute GNU libmicrohttpd and/or 18 modify it under the terms of the GNU General Public License as 19 published by the Free Software Foundation; either version 2 of 20 the License, or (at your option) any later version, together 21 with the eCos exception, as follows: 22 23 As a special exception, if other files instantiate templates or 24 use macros or inline functions from this file, or you compile this 25 file and link it with other works to produce a work based on this 26 file, this file does not by itself cause the resulting work to be 27 covered by the GNU General Public License. However the source code 28 for this file must still be made available in accordance with 29 section (3) of the GNU General Public License v2. 30 31 This exception does not invalidate any other reasons why a work 32 based on this file might be covered by the GNU General Public 33 License. 34 35 You should have received copies of the GNU Lesser General Public 36 License and the GNU General Public License along with this library; 37 if not, see <https://www.gnu.org/licenses/>. 38 */ 39 40 /** 41 * @file src/mhd2/mhd_send.h 42 * @brief Declarations of send() wrappers. 43 * @author Karlson2k (Evgeny Grin) 44 * @author ng0 (N. Gillmann) 45 */ 46 47 #ifndef MHD_SEND_H 48 #define MHD_SEND_H 49 50 #include "mhd_sys_options.h" 51 52 #include "sys_base_types.h" 53 #include "sys_bool_type.h" 54 #include "mhd_socket_error.h" 55 56 struct MHD_Connection; /* forward declaration */ 57 struct mhd_iovec_track; /* forward declaration */ 58 59 /** 60 * Initialises static variables. 61 * Need to be called only once. 62 */ 63 void 64 mhd_send_init_once (void); 65 66 67 /** 68 * Send buffer to the client, push data from network buffer if requested 69 * and full buffer is sent. 70 * 71 * @param connection the MHD_Connection structure 72 * @param buf_size the size of the @a buf (in bytes) 73 * @param buf content of the buffer to send 74 * @param push_data set to true to force push the data to the network from 75 * system buffers (usually set for the last piece of data), 76 * set to false to prefer holding incomplete network packets 77 * (more data will be send for the same reply). 78 * @param[out] sent the pointer to get amount of actually sent bytes 79 * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets 80 * the sent size) or socket error 81 */ 82 MHD_INTERNAL enum mhd_SocketError 83 mhd_send_data (struct MHD_Connection *restrict connection, 84 size_t buf_size, 85 const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], 86 bool push_data, 87 size_t *restrict sent) 88 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5); 89 90 91 /** 92 * Send reply header with optional reply body. 93 * 94 * @param connection the MHD_Connection structure 95 * @param header content of header to send 96 * @param header_size the size of the @a header (in bytes) 97 * @param never_push_hdr set to true to disable internal algorithm 98 * that can push automatically header data 99 * alone to the network 100 * @param body content of the body to send (optional, may be NULL) 101 * @param body_size the size of the @a body (in bytes) 102 * @param complete_response set to true if complete response 103 * is provided by @a header and @a body, 104 * set to false if additional body data 105 * will be sent later 106 * @param[out] sent the pointer to get amount of actually sent bytes 107 * in total (from both buffers combined) 108 * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets 109 * the sent size) or socket error 110 */ 111 MHD_INTERNAL enum mhd_SocketError 112 mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, 113 size_t header_size, 114 const char *restrict header, 115 bool never_push_hdr, 116 size_t body_size, 117 const char *restrict body, 118 bool complete_response, 119 size_t *restrict sent) 120 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) 121 MHD_FN_PAR_NONNULL_IF_NONZERO_ (6, 5) 122 MHD_FN_PAR_NONNULL_ (8) MHD_FN_PAR_OUT_ (8) 123 MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (6, 5); 124 125 #if defined(mhd_USE_SENDFILE) 126 /** 127 * Function for sending responses backed by file FD. 128 * 129 * @param c the MHD connection structure 130 * @param[out] sent the pointer to get amount of actually sent bytes 131 * in total (from both buffers combined) 132 * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets 133 * the sent size) or socket error 134 */ 135 MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2) enum mhd_SocketError 136 mhd_send_sendfile (struct MHD_Connection *restrict c, 137 size_t *restrict sent) 138 MHD_FN_PAR_NONNULL_ALL_; 139 140 #endif 141 142 143 /** 144 * Function for sending responses backed by a an array of memory buffers. 145 * 146 * @param connection the MHD connection structure 147 * @param r_iov the pointer to iov response structure with tracking 148 * @param push_data set to true to force push the data to the network from 149 * system buffers (usually set for the last piece of data), 150 * set to false to prefer holding incomplete network packets 151 * (more data will be send for the same reply). 152 * @param[out] sent the pointer to get amount of actually sent bytes 153 * in total (from both buffers combined) 154 * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets 155 * the sent size) or socket error 156 */ 157 MHD_INTERNAL enum mhd_SocketError 158 mhd_send_iovec (struct MHD_Connection *restrict connection, 159 struct mhd_iovec_track *const restrict r_iov, 160 bool push_data, 161 size_t *restrict sent) 162 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (4); 163 164 165 #endif /* MHD_SEND_H */