mhd_send.h (5413B)
1 /* 2 This file is part of libmicrohttpd 3 Copyright (C) 2017-2021 Karlson2k (Evgeny Grin) 4 Copyright (C) 2019 ng0 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 20 */ 21 22 /** 23 * @file mhd_send.h 24 * @brief Declarations of send() wrappers. 25 * @author ng0 26 * @author Karlson2k (Evgeny Grin) 27 */ 28 29 #ifndef MHD_SEND_H 30 #define MHD_SEND_H 31 32 #include "platform.h" 33 #include "internal.h" 34 #if defined(HAVE_STDBOOL_H) 35 #include <stdbool.h> 36 #endif /* HAVE_STDBOOL_H */ 37 #include <errno.h> 38 #include "mhd_sockets.h" 39 #include "connection.h" 40 #ifdef HTTPS_SUPPORT 41 #include "connection_https.h" 42 #endif 43 44 #if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) || \ 45 defined(MHD_WINSOCK_SOCKETS) 46 #define MHD_VECT_SEND 1 47 #endif /* HAVE_SENDMSG || HAVE_WRITEV || MHD_WINSOCK_SOCKETS */ 48 49 /** 50 * Initialises static variables 51 */ 52 void 53 MHD_send_init_static_vars_ (void); 54 55 56 /** 57 * Send buffer to the client, push data from network buffer if requested 58 * and full buffer is sent. 59 * 60 * @param connection the MHD_Connection structure 61 * @param buffer content of the buffer to send 62 * @param buffer_size the size of the @a buffer (in bytes) 63 * @param push_data set to true to force push the data to the network from 64 * system buffers (usually set for the last piece of data), 65 * set to false to prefer holding incomplete network packets 66 * (more data will be send for the same reply). 67 * @return sum of the number of bytes sent from both buffers or 68 * error code (negative) 69 */ 70 ssize_t 71 MHD_send_data_ (struct MHD_Connection *connection, 72 const char *buffer, 73 size_t buffer_size, 74 bool push_data); 75 76 77 /** 78 * Send reply header with optional reply body. 79 * 80 * @param connection the MHD_Connection structure 81 * @param header content of header to send 82 * @param header_size the size of the @a header (in bytes) 83 * @param never_push_hdr set to true to disable internal algorithm 84 * that can push automatically header data 85 * alone to the network 86 * @param body content of the body to send (optional, may be NULL) 87 * @param body_size the size of the @a body (in bytes) 88 * @param complete_response set to true if complete response 89 * is provided by @a header and @a body, 90 * set to false if additional body data 91 * will be sent later 92 * @return sum of the number of bytes sent from both buffers or 93 * error code (negative) 94 */ 95 ssize_t 96 MHD_send_hdr_and_body_ (struct MHD_Connection *connection, 97 const char *header, 98 size_t header_size, 99 bool never_push_hdr, 100 const char *body, 101 size_t body_size, 102 bool complete_response); 103 104 #if defined(_MHD_HAVE_SENDFILE) 105 /** 106 * Function for sending responses backed by file FD. 107 * 108 * @param connection the MHD connection structure 109 * @return actual number of bytes sent 110 */ 111 ssize_t 112 MHD_send_sendfile_ (struct MHD_Connection *connection); 113 114 #endif 115 116 117 /** 118 * Set required TCP_NODELAY state for connection socket 119 * 120 * The function automatically updates sk_nodelay state. 121 * @param connection the connection to manipulate 122 * @param nodelay_state the requested new state of socket 123 * @return true if succeed, false if failed or not supported 124 * by the current platform / kernel. 125 */ 126 bool 127 MHD_connection_set_nodelay_state_ (struct MHD_Connection *connection, 128 bool nodelay_state); 129 130 131 /** 132 * Set required cork state for connection socket 133 * 134 * The function automatically updates sk_corked state. 135 * 136 * @param connection the connection to manipulate 137 * @param cork_state the requested new state of socket 138 * @return true if succeed, false if failed or not supported 139 * by the current platform / kernel. 140 */ 141 bool 142 MHD_connection_set_cork_state_ (struct MHD_Connection *connection, 143 bool cork_state); 144 145 146 /** 147 * Function for sending responses backed by a an array of memory buffers. 148 * 149 * @param connection the MHD connection structure 150 * @param r_iov the pointer to iov response structure with tracking 151 * @param push_data set to true to force push the data to the network from 152 * system buffers (usually set for the last piece of data), 153 * set to false to prefer holding incomplete network packets 154 * (more data will be send for the same reply). 155 * @return actual number of bytes sent 156 */ 157 ssize_t 158 MHD_send_iovec_ (struct MHD_Connection *connection, 159 struct MHD_iovec_track_ *const r_iov, 160 bool push_data); 161 162 163 #endif /* MHD_SEND_H */