libmicrohttpd2

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

sys_kqueue.h (4750B)


      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) 2026 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/sys_kqueue.h
     41  * @brief  The header for the system kqueue functions and related data types
     42  * @author Karlson2k (Evgeny Grin)
     43  *
     44  * This header includes system macros for kqueue and defines related
     45  * MHD macros.
     46  */
     47 
     48 #ifndef MHD_SYS_KQUEUE_H
     49 #define MHD_SYS_KQUEUE_H 1
     50 
     51 #include "mhd_sys_options.h"
     52 
     53 #ifdef MHD_SUPPORT_KQUEUE
     54 #  include "mhd_socket_type.h"
     55 #  ifndef MHD_SOCKETS_KIND_POSIX
     56 #error Only POSIX type sockets are supported
     57 #  endif
     58 #  ifdef HAVE_SYS_TYPES_H
     59 #    include <sys/types.h>
     60 #  endif /* HAVE_SYS_TYPES_H */
     61 
     62 #  ifdef HAVE_SYS_TIME_H
     63 #    include <sys/time.h>
     64 #  endif
     65 
     66 #  include <sys/event.h>
     67 
     68 #  ifdef HAVE_KQUEUEX
     69 #    ifdef KQUEUE_CLOEXEC
     70 #      define mhd_kqueue()                  kqueuex (KQUEUE_CLOEXEC)
     71 #      define mhd_KQUEUE_HAS_CLOEXEC_SET()  (! 0)
     72 #    else
     73 #      undef HAVE_KQUEUEX   /* No use for kqueuex() */
     74 #    endif
     75 #  endif
     76 
     77 #  ifdef HAVE_KQUEUE1
     78 #    ifdef mhd_kqueue
     79 #      undef HAVE_KQUEUE1   /* No use for kqueue1() */
     80 #    else
     81 #      include <fcntl.h>
     82 #      ifdef O_CLOEXEC
     83 #        define mhd_kqueue()                kqueue1 (O_CLOEXEC)
     84 #        define mhd_KQUEUE_HAS_CLOEXEC_SET()    (! 0)
     85 #      else
     86 #        undef HAVE_KQUEUE1
     87 #      endif
     88 #    endif
     89 #  endif
     90 
     91 #  ifndef mhd_kqueue
     92 #    define mhd_kqueue()                    kqueue ()
     93 #    define mhd_KQUEUE_HAS_CLOEXEC_SET()    (0)
     94 #  endif
     95 
     96 #  ifdef __NetBSD__
     97 #    include <sys/param.h>
     98 #    if __NetBSD_Version__ + 0 < 1000000000
     99 #      define mhd_KE_UDATA_IS_INTPTR    1
    100 #    endif
    101 #  endif
    102 
    103 #  ifndef mhd_KE_UDATA_IS_INTPTR
    104 typedef void *mhd_KE_UDATA_TYPE;
    105 #    define mhd_PTR_TO_KE_UDATA(ptr)    (ptr)
    106 #    define mhd_KE_UDATA_TO_PTR(ud)     (ud)
    107 #  else
    108 typedef intptr_t mhd_KE_UDATA_TYPE;
    109 #    define mhd_PTR_TO_KE_UDATA(ptr)    ((mhd_KE_UDATA_TYPE) (ptr))
    110 #    define mhd_KE_UDATA_TO_PTR(ud)     ((void*) (ud))
    111 #  endif
    112 
    113 #  define mhd_KE_GET_UDATA(ev_ptr)  mhd_KE_UDATA_TO_PTR ((ev_ptr)->udata)
    114 
    115 #  define mhd_KE_SET(ev_ptr,fd,evfltr,evflags,evudata_ptr) do { \
    116           struct kevent mhd__ke_tmp = {0u};                      \
    117           mhd__ke_tmp.ident = (unsigned int) (fd);                \
    118           mhd__ke_tmp.filter = (evfltr);                           \
    119           mhd__ke_tmp.flags = (evflags);                           \
    120           mhd__ke_tmp.udata = mhd_PTR_TO_KE_UDATA ((evudata_ptr)); \
    121           (*(ev_ptr)) = mhd__ke_tmp; } while (0)
    122 
    123 #  ifdef EV_KEEPUDATA
    124 #    define mhd_EV_KEEPUDATA_OR_ZERO    EV_KEEPUDATA
    125 #  else
    126 #    define mhd_EV_KEEPUDATA_OR_ZERO    (0)
    127 #  endif
    128 
    129 #  ifndef __NetBSD__
    130 #    define mhd_kevent(kqfd,chlist,nchs,evlist,nevs,tmout) \
    131         kevent ((kqfd),(chlist),(nchs),(evlist),(nevs),(tmout))
    132 #  else  /* ! __NetBSD__ */
    133 #    define mhd_kevent(kqfd,chlist,nchs,evlist,nevs,tmout) \
    134         kevent ((kqfd),(chlist),(size_t) (nchs),(evlist),(size_t) (nevs), \
    135                 (tmout))
    136 #  endif
    137 
    138 #endif /* MHD_SUPPORT_KQUEUE */
    139 
    140 #endif /* ! MHD_SYS_KQUEUE_H */