conn_mark_ready.h (6110B)
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/conn_mark_ready.h 41 * @brief The definition of static functions to mark/unmark connection as 42 * "process ready". 43 * @author Karlson2k (Evgeny Grin) 44 */ 45 46 #ifndef MHD_CONN_MARK_READY_H 47 #define MHD_CONN_MARK_READY_H 1 48 49 #include "mhd_sys_options.h" 50 51 #include "sys_null_macro.h" 52 53 #include "mhd_assert.h" 54 55 #include "mhd_connection.h" 56 #include "mhd_daemon.h" 57 #include "mhd_dlinked_list.h" 58 59 /** 60 * Mark connection as "ready to process" and add it to the end of the 61 * "process ready" list if connection is not in the list. 62 * @param c the connection to mark 63 * @param d the daemon for the connection 64 */ 65 mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void 66 mhd_conn_mark_ready (struct MHD_Connection *restrict c, 67 struct MHD_Daemon *restrict d) 68 { 69 mhd_assert (d == c->daemon); 70 if (c->in_proc_ready) 71 { 72 mhd_assert ((NULL != mhd_DLINKEDL_GET_NEXT (c, proc_ready)) || \ 73 (NULL != mhd_DLINKEDL_GET_PREV (c, proc_ready)) || \ 74 (c == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready))); 75 return; /* Already marked and in the list */ 76 } 77 mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, proc_ready)); 78 mhd_assert (NULL == mhd_DLINKEDL_GET_PREV (c, proc_ready)); 79 mhd_assert (c != mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready)); 80 mhd_assert (c != mhd_DLINKEDL_GET_LAST (&(d->events), proc_ready)); 81 82 mhd_DLINKEDL_INS_LAST (&(d->events), c, proc_ready); 83 c->in_proc_ready = true; 84 } 85 86 87 /** 88 * Mark connection as "not ready to process" and remove it from the "process 89 * ready" list if connection is in the list. 90 * @param c the connection to mark 91 * @param d the daemon for the connection 92 */ 93 mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void 94 mhd_conn_mark_unready (struct MHD_Connection *restrict c, 95 struct MHD_Daemon *restrict d) 96 { 97 mhd_assert (d == c->daemon); 98 if (! c->in_proc_ready) 99 { 100 mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, proc_ready)); 101 mhd_assert (NULL == mhd_DLINKEDL_GET_PREV (c, proc_ready)); 102 mhd_assert (c != mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready)); 103 mhd_assert (c != mhd_DLINKEDL_GET_LAST (&(d->events), proc_ready)); 104 return; /* Already unmarked and not in the list */ 105 } 106 mhd_assert ((NULL != mhd_DLINKEDL_GET_NEXT (c, proc_ready)) || \ 107 (NULL != mhd_DLINKEDL_GET_PREV (c, proc_ready)) || \ 108 (c == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready))); 109 110 mhd_DLINKEDL_DEL (&(d->events), c, proc_ready); 111 c->in_proc_ready = false; 112 } 113 114 115 /** 116 * Update "ready" mark on the connection, remove or add connection to 117 * the "process ready" list if necessary. 118 * @param c the connection to update 119 * @param force_ready ignore network states and mark the connection as "ready" 120 * @param d the daemon for the connection 121 */ 122 mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void 123 mhd_conn_mark_ready_update3 (struct MHD_Connection *restrict c, 124 bool force_ready, 125 struct MHD_Daemon *restrict d) 126 { 127 if (force_ready || 128 (0 != 129 ((((unsigned int) c->sk.ready) | mhd_C_HAS_TLS_DATA_IN (c)) 130 & ((unsigned int) c->event_loop_info) 131 & (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))) 132 mhd_conn_mark_ready (c, d); 133 else 134 mhd_conn_mark_unready (c, d); 135 } 136 137 138 /** 139 * Update "ready" mark on the connection, remove or add connection to 140 * the "process ready" list if necessary. 141 * This function could be used if the "daemon" handle is already extracted 142 * from the connection. 143 * @param c the connection to update 144 * @param d the daemon for the connection 145 */ 146 mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void 147 mhd_conn_mark_ready_update2 (struct MHD_Connection *restrict c, 148 struct MHD_Daemon *restrict d) 149 { 150 mhd_conn_mark_ready_update3 (c, 0, d); 151 } 152 153 154 /** 155 * Update "ready" mark on the connection, remove or add connection to 156 * the "process ready" list if necessary. 157 * This function could be used if the "daemon" handle has not been extracted 158 * from the connection. 159 * @param c the connection to update 160 */ 161 mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void 162 mhd_conn_mark_ready_update (struct MHD_Connection *restrict c) 163 { 164 mhd_conn_mark_ready_update2 (c, 165 c->daemon); 166 } 167 168 169 #endif /* ! MHD_CONN_MARK_READY_H */