mhd_conn_socket.h (5733B)
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/mhd_conn_socket.h 41 * @brief The definition of the connection-specific socket data 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #ifndef MHD_CONN_SOCKET_H 46 #define MHD_CONN_SOCKET_H 1 47 48 #include "mhd_sys_options.h" 49 50 #include "sys_bool_type.h" 51 52 #include "mhd_socket_type.h" 53 #include "mhd_tristate.h" 54 #include "mhd_socket_error.h" 55 56 57 struct sockaddr_storage; /* Forward declaration */ 58 59 /** 60 * The network states for connected sockets 61 * An internal version of #MHD_FdState. Keep in sync! 62 */ 63 enum MHD_FIXED_FLAGS_ENUM_ mhd_SocketNetState 64 { 65 /** 66 * No active states of the socket 67 */ 68 mhd_SOCKET_NET_STATE_NOTHING = 0 69 , 70 /** 71 * The socket is ready for receiving 72 */ 73 mhd_SOCKET_NET_STATE_RECV_READY = 1 << 0 74 , 75 /** 76 * The socket is ready for sending 77 */ 78 mhd_SOCKET_NET_STATE_SEND_READY = 1 << 1 79 , 80 /** 81 * The socket has some unrecoverable error 82 */ 83 mhd_SOCKET_NET_STATE_ERROR_READY = 1 << 2 84 }; 85 86 87 #define mhd_SCKT_NET_ST_CLEAR_FLAG(p_scktns,flag) \ 88 ((*p_scktns) = \ 89 (enum mhd_SocketNetState) \ 90 ((~((unsigned int) ((enum mhd_SocketNetState) (flag)))) \ 91 & ((unsigned int) (*p_scktns))) ) 92 93 94 #define mhd_SCKT_NET_ST_SET_FLAG(p_scktns,flag) \ 95 ((*p_scktns) = \ 96 (enum mhd_SocketNetState) \ 97 (((unsigned int) (flag)) | ((unsigned int) (*p_scktns))) ) 98 99 100 #define mhd_SCKT_NET_ST_HAS_FLAG(scktns,flag) \ 101 (0 != (((unsigned int) (flag)) & ((unsigned int) (scktns))) ) 102 103 104 #define mhd_SCKT_NET_ST_HAS_FLAG_RECV(scktns) \ 105 mhd_SCKT_NET_ST_HAS_FLAG (scktns, mhd_SOCKET_NET_STATE_RECV_READY) 106 107 108 #define mhd_SCKT_NET_ST_HAS_FLAG_SEND(scktns) \ 109 mhd_SCKT_NET_ST_HAS_FLAG (scktns, mhd_SOCKET_NET_STATE_SEND_READY) 110 111 112 #define mhd_SCKT_NET_ST_HAS_FLAG_ERROR(scktns) \ 113 mhd_SCKT_NET_ST_HAS_FLAG (scktns, mhd_SOCKET_NET_STATE_ERROR_READY) 114 115 116 /** 117 * Connection-specific socket state data 118 */ 119 struct mhd_ConnSocketState 120 { 121 /** 122 * The current state of TCP_NODELAY socket setting 123 */ 124 enum mhd_Tristate nodelay; 125 126 // #ifndef MHD_SOCKETS_KIND_WINSOCK // TODO: conditionally use in the code 127 /** 128 * The current state of TCP_CORK / TCP_NOPUSH socket setting 129 */ 130 enum mhd_Tristate corked; 131 // #endif 132 133 /** 134 * Set to 'true' when the remote side shut down write/send and 135 * __the last byte from the remote has been read__. 136 */ 137 bool rmt_shut_wr; 138 139 /** 140 * The type of the error when the socket disconnected early 141 */ 142 enum mhd_SocketError discnt_err; 143 }; 144 145 /** 146 * Connection-specific socket properties 147 */ 148 struct mhd_ConnSocketProperties 149 { 150 /** 151 * The type of the socket: TCP/IP or non TCP/IP (a UNIX domain socket, a pipe) 152 */ 153 enum mhd_Tristate is_nonip; 154 155 /** 156 * true if the socket is non-blocking, false otherwise. 157 */ 158 bool is_nonblck; 159 160 /** 161 * true if the socket has set SIGPIPE suppression 162 */ 163 bool has_spipe_supp; 164 }; 165 166 167 /** 168 * The connection socket remote address information 169 */ 170 struct mhd_ConnSocketAddr 171 { 172 /** 173 * The remote address. 174 * Allocated by malloc() (not in the connection memory pool!). 175 * Could be NULL if the address is not known. 176 */ 177 struct sockaddr_storage *data; 178 179 /** 180 * The size of the address pointed by @a data. 181 * Zero is @a data is NULL. 182 */ 183 size_t size; 184 }; 185 186 /** 187 * Connection-specific socket data 188 */ 189 struct mhd_ConnSocket 190 { 191 /** 192 * The network socket. 193 */ 194 MHD_Socket fd; 195 196 /** 197 * Connection-specific socket state data 198 */ 199 struct mhd_ConnSocketState state; 200 201 /** 202 * The receive / send / error readiness of the socket 203 */ 204 enum mhd_SocketNetState ready; 205 206 /** 207 * Connection-specific socket properties 208 */ 209 struct mhd_ConnSocketProperties props; 210 211 /** 212 * The connection socket remote address information 213 */ 214 struct mhd_ConnSocketAddr addr; 215 }; 216 217 #endif /* ! MHD_CONN_SOCKET_H */