extr_events_funcs.h (5098B)
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) 2025 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/extr_events_funcs.h 41 * @brief The definition of the external events internal helper functions 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #ifndef MHD_EXTR_EVENTS_FUNCS_H 46 #define MHD_EXTR_EVENTS_FUNCS_H 1 47 48 #include "mhd_sys_options.h" 49 50 #ifdef mhd_DEBUG_POLLING_FDS 51 # include <stdio.h> 52 # include "mhd_daemon.h" 53 # include "mhd_assert.h" 54 # include "sys_null_macro.h" 55 #endif /* mhd_DEBUG_POLLING_FDS */ 56 57 #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY 58 59 struct MHD_Daemon; /* forward declaration */ 60 61 /** 62 * Log message about failed de-registration of FDs 63 */ 64 MHD_INTERNAL void 65 mhd_log_extr_event_dereg_failed (struct MHD_Daemon *restrict d); 66 67 #else /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ 68 69 /** 70 * Log message about failed de-registration of FDs (no-op implementation) 71 */ 72 #define mhd_log_extr_event_dereg_failed(d) ((void) 0) 73 74 #endif /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ 75 76 #ifdef mhd_DEBUG_POLLING_FDS 77 /** 78 * Call application event registration callback 79 * @param d the daemon to use 80 * @param fd the FD to register 81 * @param watch_for events/statuses to watch for 82 * @param app_cntx_old the previous application FD context 83 * @param ecb_cntx the MHD FD context 84 */ 85 mhd_static_inline 86 MHD_FN_PAR_NONNULL_ (1) void * 87 mhd_daemon_extr_event_reg (struct MHD_Daemon *d, 88 MHD_Socket fd, 89 enum MHD_FdState watch_for, 90 void *app_cntx_old, 91 struct MHD_EventUpdateContext *ecb_cntx) 92 { 93 void *res; 94 char state_str[] = "x:x:x"; 95 const char *reg_type; 96 const char *fd_rel; 97 98 mhd_assert (mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); 99 mhd_assert (mhd_POLL_TYPE_EXT == d->events.poll_type); 100 mhd_assert (mhd_SOCKET_REL_MARKER_EMPTY != (mhd_SockRelMarker) ecb_cntx); 101 102 res = 103 d->events.data.extr.cb_data.cb (d->events.data.extr.cb_data.cls, 104 fd, 105 watch_for, 106 app_cntx_old, 107 ecb_cntx); 108 109 if (NULL == app_cntx_old) 110 reg_type = " Registration"; 111 else if (MHD_FD_STATE_NONE == watch_for) 112 reg_type = "De-registration"; 113 else 114 reg_type = "Re-registration"; 115 116 state_str[0] = MHD_FD_STATE_IS_SET_RECV (watch_for) ? 'R' : '-'; 117 state_str[2] = MHD_FD_STATE_IS_SET_SEND (watch_for) ? 'W' : '-'; 118 state_str[4] = MHD_FD_STATE_IS_SET_EXCEPT (watch_for) ? 'E' : '-'; 119 120 switch ((mhd_SockRelMarker) ecb_cntx) 121 { 122 case mhd_SOCKET_REL_MARKER_ITC: 123 fd_rel = "ITC: "; 124 break; 125 case mhd_SOCKET_REL_MARKER_LISTEN: 126 fd_rel = "lstn:"; 127 break; 128 default: 129 fd_rel = "conn:"; 130 break; 131 } 132 fprintf (stderr, 133 "### %s callback (cls, [%s %2llu], %s, 0x%08llX, ptr) " 134 "-> 0x%08llX\n", 135 reg_type, 136 fd_rel, 137 (unsigned long long) fd, 138 state_str, 139 (unsigned long long) app_cntx_old, 140 (unsigned long long) res); 141 142 return res; 143 } 144 #else /* ! mhd_DEBUG_POLLING_FDS */ 145 # define mhd_daemon_extr_event_reg(d,fd,w_for,app_cntx_old,ecb_cntx) \ 146 d->events.data.extr.cb_data.cb (d->events.data.extr.cb_data.cls, \ 147 fd, w_for, app_cntx_old, ecb_cntx) 148 149 #endif /* ! mhd_DEBUG_POLLING_FDS */ 150 151 152 #endif /* ! MHD_EXTR_EVENTS_FUNCS_H */