libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

mhd_conn_socket.h (5356B)


      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 /**
    105  * Connection-specific socket state data
    106  */
    107 struct mhd_ConnSocketState
    108 {
    109   /**
    110    * The current state of TCP_NODELAY socket setting
    111    */
    112   enum mhd_Tristate nodelay;
    113 
    114 // #ifndef MHD_SOCKETS_KIND_WINSOCK // TODO: conditionally use in the code
    115   /**
    116    * The current state of TCP_CORK / TCP_NOPUSH socket setting
    117    */
    118   enum mhd_Tristate corked;
    119 // #endif
    120 
    121   /**
    122    * Set to 'true' when the remote side shut down write/send and
    123    * __the last byte from the remote has been read__.
    124    */
    125   bool rmt_shut_wr;
    126 
    127   /**
    128    * The type of the error when the socket disconnected early
    129    */
    130   enum mhd_SocketError discnt_err;
    131 };
    132 
    133 /**
    134  * Connection-specific socket properties
    135  */
    136 struct mhd_ConnSocketProperties
    137 {
    138   /**
    139    * The type of the socket: TCP/IP or non TCP/IP (a UNIX domain socket, a pipe)
    140    */
    141   enum mhd_Tristate is_nonip;
    142 
    143   /**
    144    * true if the socket is non-blocking, false otherwise.
    145    */
    146   bool is_nonblck;
    147 
    148   /**
    149    * true if the socket has set SIGPIPE suppression
    150    */
    151   bool has_spipe_supp;
    152 };
    153 
    154 
    155 /**
    156  * The connection socket remote address information
    157  */
    158 struct mhd_ConnSocketAddr
    159 {
    160   /**
    161    * The remote address.
    162    * Allocated by malloc() (not in the connection memory pool!).
    163    * Could be NULL if the address is not known.
    164    */
    165   struct sockaddr_storage *data;
    166 
    167   /**
    168    * The size of the address pointed by @a data.
    169    * Zero is @a data is NULL.
    170    */
    171   size_t size;
    172 };
    173 
    174 /**
    175  * Connection-specific socket data
    176  */
    177 struct mhd_ConnSocket
    178 {
    179   /**
    180    * The network socket.
    181    */
    182   MHD_Socket fd;
    183 
    184   /**
    185    * Connection-specific socket state data
    186    */
    187   struct mhd_ConnSocketState state;
    188 
    189   /**
    190    * The receive / send / error readiness of the socket
    191    */
    192   enum mhd_SocketNetState ready;
    193 
    194   /**
    195    * Connection-specific socket properties
    196    */
    197   struct mhd_ConnSocketProperties props;
    198 
    199   /**
    200    * The connection socket remote address information
    201    */
    202   struct mhd_ConnSocketAddr addr;
    203 };
    204 
    205 #endif /* ! MHD_CONN_SOCKET_H */