daemon_funcs.h (5553B)
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) 2024 Evgeny Grin (Karlson2k) 5 6 GNU libmicrohttpd 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 GNU libmicrohttpd 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 Alternatively, you can redistribute GNU libmicrohttpd and/or 17 modify it under the terms of the GNU General Public License as 18 published by the Free Software Foundation; either version 2 of 19 the License, or (at your option) any later version, together 20 with the eCos exception, as follows: 21 22 As a special exception, if other files instantiate templates or 23 use macros or inline functions from this file, or you compile this 24 file and link it with other works to produce a work based on this 25 file, this file does not by itself cause the resulting work to be 26 covered by the GNU General Public License. However the source code 27 for this file must still be made available in accordance with 28 section (3) of the GNU General Public License v2. 29 30 This exception does not invalidate any other reasons why a work 31 based on this file might be covered by the GNU General Public 32 License. 33 34 You should have received copies of the GNU Lesser General Public 35 License and the GNU General Public License along with this library; 36 if not, see <https://www.gnu.org/licenses/>. 37 */ 38 39 /** 40 * @file src/mhd2/daemon_funcs.h 41 * @brief The declarations of internal daemon-related functions 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #ifndef MHD_DAEMON_FUNCS_H 46 #define MHD_DAEMON_FUNCS_H 1 47 48 #include "mhd_sys_options.h" 49 50 #include "sys_bool_type.h" 51 52 #include "mhd_buffer.h" 53 54 struct MHD_Daemon; /* forward declaration */ 55 56 57 /** 58 * Get controlling daemon 59 * @param d the daemon to get controlling daemon 60 * @return the master daemon (possible the same as the @a d) 61 */ 62 MHD_INTERNAL struct MHD_Daemon * 63 mhd_daemon_get_master_daemon (struct MHD_Daemon *restrict d) 64 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_; 65 66 #ifdef MHD_SUPPORT_THREADS 67 68 /** 69 * Trigger daemon ITC. 70 * This should cause daemon's thread to stop waiting for the network events 71 * and process pending information 72 * @param d the daemon object, ITC should be initialised 73 * @return true if succeed, false otherwise 74 */ 75 MHD_INTERNAL bool 76 mhd_daemon_trigger_itc (struct MHD_Daemon *restrict d); 77 78 #else /* ! MHD_SUPPORT_THREADS */ 79 80 #define mhd_daemon_trigger_itc(d) ((void) d, ! 0) 81 #endif /* ! MHD_SUPPORT_THREADS */ 82 83 84 /** 85 * Request allocation of the large buffer 86 * @param d the daemon to use 87 * @param requested_size the requested size of allocation 88 * @return true if allocation allowed and counted, 89 * false otherwise 90 */ 91 MHD_INTERNAL bool 92 mhd_daemon_claim_lbuf (struct MHD_Daemon *restrict d, 93 size_t requested_size) 94 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_; 95 96 97 /** 98 * Reclaim the large buffer allocation. 99 * Must be called when the allocation has been already freed. 100 * @param d the daemon to use 101 * @param reclaimed_size the deallocated size 102 */ 103 MHD_INTERNAL void 104 mhd_daemon_reclaim_lbuf (struct MHD_Daemon *restrict d, 105 size_t reclaimed_size) 106 MHD_FN_PAR_NONNULL_ALL_; 107 108 /** 109 * Allocate the large buffer 110 * @param d the daemon to use 111 * @param requested_size the requested size of allocation 112 * @param[out] buf the buffer to allocate 113 * @return true if buffer is allocated, 114 * false otherwise 115 */ 116 MHD_INTERNAL bool 117 mhd_daemon_get_lbuf (struct MHD_Daemon *restrict d, 118 size_t requested_size, 119 struct mhd_Buffer *restrict buf) 120 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_ 121 MHD_FN_PAR_OUT_ (3); 122 123 /** 124 * Grow the large buffer, which previously was allocated 125 * @param d the daemon to use 126 * @param grow_size the requested size of grow 127 * @param[in,out] buf the buffer to grow 128 * @return true if buffer has been grown, 129 * false otherwise 130 */ 131 MHD_INTERNAL bool 132 mhd_daemon_grow_lbuf (struct MHD_Daemon *restrict d, 133 size_t grow_size, 134 struct mhd_Buffer *restrict buf) 135 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_ 136 MHD_FN_PAR_INOUT_ (3); 137 138 /** 139 * Grow or allocate the large buffer up to specified grow size. 140 * If the requested grow size is not possible, grow up to max possible size. 141 * @param d the daemon to use 142 * @param desired_grow_size the desired size of grow 143 * @param[in,out] buf the buffer to grow, must be allocated previously or 144 * zero-initialised 145 * @return the resulting grow size 146 */ 147 MHD_INTERNAL size_t 148 mhd_daemon_extend_lbuf_up_to (struct MHD_Daemon *restrict d, 149 size_t desired_grow_size, 150 struct mhd_Buffer *restrict buf) 151 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_ 152 MHD_FN_PAR_INOUT_ (3); 153 154 155 /** 156 * Free large buffer. 157 * @param d the daemon to use 158 * @param[in,out] buf the buffer to free 159 */ 160 MHD_INTERNAL void 161 mhd_daemon_free_lbuf (struct MHD_Daemon *restrict d, 162 struct mhd_Buffer *restrict buf) 163 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (2); 164 165 166 #endif /* ! MHD_DAEMON_FUNCS_H */