163 Commits

Author SHA1 Message Date
Azat Khuzhin
7179ceddf0 Add -Wno-void-pointer-to-enum-cast (we use this hack in tests)
Refs: https://reviews.llvm.org/D75758
2021-09-19 13:47:32 +03:00
Paweł Wegner
087bbc572c cmake: don't override CMAKE_CONFIGURATION_TYPES.
Surprisingly this overrides configuration types for projects which embed libevent using cmake's add_subdirectory.
2021-05-14 14:07:30 +02:00
fanquake
78e8541a9e
build: remove no-longer used checks for vasprintf
From what I can tell the last usage was removed in
8d1317d71c46e27c5073d3429a64af69de0351a6.
2021-03-28 13:55:59 +08:00
fanquake
4c29b01c87
build: remove splice implementation fragments
Looks like a `splice` implementation was planned, but has clearly never
eventuated (the TODO comment is from ~12 years ago, in
8b5bd77415fb6634fadf08357676926fecf5f032). For now, it's probably better
to remove the unused code/correct the docs.
2021-03-28 10:57:11 +08:00
Azat Khuzhin
1a242e1c96 cmake: find openssl prefix via brew 2020-11-02 01:14:58 +03:00
okhowang(王沛文)
b45a02efab sample: add https-client-mbedtls 2020-09-16 11:57:52 +08:00
Azat Khuzhin
02428d9a2d build: fix building under windows with thread support
Fixes: 972289f3 ("Detect existence of pthread_mutexattr_setprotocol()")
2020-09-01 01:08:50 +03:00
Azat Khuzhin
972289f356 Detect existence of pthread_mutexattr_setprotocol()
Fixes: #1084
2020-08-29 01:15:20 +03:00
Gerry Garvey
eb7bed03c4 Convert from WinCrypt to Windows BCrypt
Fixes: #1069
2020-08-02 18:27:10 +03:00
okhowang(王沛文)
d095b834a9 Merge ssl implementations (openssl and mbedtls)
This patch splits common part out to avoid copy-paste from the
- bufferevent_openssl.c
- bufferevent_mbedtls.c

It uses VFS/bufferevent-like approach, i.e. structure of callbacks.
2020-07-22 23:03:17 +03:00
okhowang(王沛文)
028385f685 fix build system and add test and cleanup code 2020-07-22 22:53:23 +03:00
Jesse Fang
8218777d44 mbed TLS cmake support
FindMbedTLS.cmake is come from https://github.com/AVSystem/avs_commons/blob/master/cmake/FindMbedTLS.cmake, which is licensed under Apache 2.0

alternatives:
  https://github.com/curl/curl/blob/master/CMake/FindMbedTLS.cmake   without variable MBEDTLS_ROOT_DIR
  https://github.com/libgit2/libgit2/blob/master/cmake/Modules/FindmbedTLS.cmake  GPLv2 with a special Linking Exception
2020-07-22 22:53:23 +03:00
Pierce Lopez
b6497fa148 build: do not disable deprecation warnings on macOS
this was for using openssl-0.9.8 included in macOS 10.7 - 10.12,
but it is long since time you really should not use that openssl
2020-07-04 16:01:41 -04:00
Paul Osborne
26d5ff457c cmake: avoid problems from use of CMAKE_USE_PTHREADS_INIT
In some CMake integrations, portions of the toolchain may end up
defining CMAKE_USE_PTHREADS_INIT even when EVENT__DISABLE_THREAD_SUPPORT
is set for libevent.  Modify the build to not rely on this side effect
of find_package(Threads, ...) [which could be done elsewhere] but instead
to use EVENT__HAVE_PTHREADS which is defined only on the desired codepath.

Without this change, affected builds fail as a result of event_pthreads source
files being built but with build defines which cause the build to fail.

Signed-off-by: Paul Osborne <paul.osborne@smartthings.com>
2020-06-18 15:47:14 +00:00
Nick Grifka
83ef3216e4 Add wepoll support to light up the epoll backend on Windows
libevent is lacking a scalable backend on Windows. Let's leverage the wepoll
library until Windows comes up with an epoll/kqueue compete user mode API.

- All regress tests pass for standard wepoll
- These 2 tests fail intermittently for changelist wepoll, so disabling
  changelist wepoll for now
     http/cancel_inactive_server
     http/stream_in
- verify target on Windows runs tests for both wepoll and win32 backends
- wepoll backend preferred over win32 backend
- wepoll version 1.5.6

v2: cleaner backend abstraction. Disallow wepoll on MinGW/Cygwin.
v3: Add wepoll.h to dist
v4: Make sure wepoll source files are excluded from cygwin/mingw builds
v5: Keep win32 as default backend on windows.
v6: Include wepoll in mingw builds. Verified that regress tests pass w/ WEPOLL backend.
v7: Enable wepoll on mingw when building with cmake
v8: Add wepoll testrunner for autotools test target
2020-05-08 23:27:04 +03:00
Azat Khuzhin
7a465268b2 Pass --quiet to the event_rcpgen.py (autotools already does this) 2020-05-05 14:21:21 +03:00
Azat Khuzhin
5786290109 cmake: missing test-closed binary 2020-04-08 00:29:40 +03:00
yuangongji
41d1d75a84 cmake: replace CheckFunctionExists with CheckSymbolExists
Checking functions with `CheckFunctionExists` may
get wrong results, we should replace it with
`CheckSymbolExists`, which is recommended by the cmake
official documentation.
Before using `CheckSymbolExists`, we use
`CheckIncludeFiles` to check header files and save the
available header files in a variable that guarantees
`CheckSymbolExists` and `CheckTypeSize` to work correctly.
This approach is modeled after the cmake scripts of `curl`.

The following functions or files were not found before
modification, they can now be found:
- msys2 + mingw-8.1.0 on Windows10 or mingw-7.3.0 on Ubuntu-18.04
timerclear
timercmp
timerisset

- windows10
getaddrinfo
getnameinfo
getprotobynumber
getservbyname
putenv
strtoll
timerclear
timercmp
timerisset

- ubuntu-18.04
sys/sysctl.h
timeradd
timerclear
timercmp
timerisset

- MacOS 10.13
sys/random.h
timeradd
timerclear
timercmp
timerisset
2020-03-22 22:22:51 +08:00
yuangongji
503ba1d365 cmake: fix getaddrinfo checking error
Using `CheckFunctionExists` on Windows to check `getaddrinfo`
will get `not found`, but it actually exists. Using `CheckSymbolExists`
with headers will get correct results. Other functions such as
`getnameinfo`,`inet_ntop`,etc. have the same issue.
2020-03-17 21:43:39 +03:00
yuangongji
61c5c19bfd cmake: remove CheckFunctionExistsEx
`CheckFunctionExistsEx` is copied from the cmake modules before
3.1.2, which is the minimum required version of libevent.
The internal module `CheckFunctionExists`of cmake can completely
replace it.
2020-03-17 21:43:39 +03:00
Azat Khuzhin
b1e46c32db test: put thread into real time scheduling class on osx for better latencies 2020-01-13 23:36:19 +03:00
Azat Khuzhin
f8a6f12712 cmake: do not print used method (EVENT_SHOW_METHOD) while running tests
autotools don't, plus this will make CI logs cleaner
2020-01-13 22:26:37 +03:00
Azat Khuzhin
fa33819e3b cmake: run regress test quietly like autotools (makes CI logs cleaner) 2020-01-13 22:26:37 +03:00
Dimo Markov
f0e79bafd8 Added uninstall target check to cmakelists 2020-01-08 20:37:16 +02:00
Azat Khuzhin
8f13c170cf cmake: set CMAKE_{RUNTIME,LIBRARY,ARCHIVE}_OUTPUT_DIRECTORY they are not defined
This will allow overriding them in parent cmake rules, i.e. if libevent
is used via add_subdirectory().

Closes: #931
2019-11-30 15:58:17 +03:00
yuangongji
dc4be869d5 cmake: improve package config file 2019-11-14 18:09:31 +08:00
Philip Homburg
9fecb59a94 Parse IPv6 scope IDs. 2019-11-06 21:07:16 +03:00
yuangongji
5fe83d7433 cmake: eliminate duplicate installation of public headers 2019-10-25 21:54:13 +08:00
Michael Davidsaver
84affc1837 append to CMAKE_MODULE_PATH
Don't override any -DCMAKE_MODULE_PATH= passed from CLI
to eg. test custom Platform/ support.
2019-10-21 10:41:27 -07:00
Azat Khuzhin
b9b9f19058 Do not use sysctl.h on linux (it had been deprecated)
It had been deprecated for a long time (AFAIK), but since
glibc-2.29.9000-309-g744e829637 it produces a #warning
2019-10-16 01:11:51 +03:00
William A Rowe Jr
af4b07a55c Avoid transforming base C_FLAGS set deliberately
The CMAKE_C_FLAGS_DEBUG, CMAKE_C_FLAGS_RELEASE, CMAKE_C_FLAGS_MINSIZEREL
and CMAKE_C_FLAGS_RELWITHDEBINFO options are correctly and deliberately
toggled to use the libcmt (/MT) flag options in place of the usual
msvcrt (/MD) options, but this isn't necessarily desired by the user.
The default choice can be overriden with the EVENT__MSVC_STATIC_RUNTIME
cmake option.

However, the /MD flag that is the choice of CMake only enters into
play for the four types of builds above. If the user introduces another
CMAKE_BUILD_TYPE, the base CMAKE_C_FLAGS must not be manipulated, as
that value (and the CMAKE_C_FLAGS_{custom} value) have been explicitly
chosen by the user/developer deploying this library, and the mismatch
between these flags in different dependencies results in link errors.

The CMake build schema itself doesn't place an /MD flag in CMAKE_BUILD_TYPE
so any /M compile option in that variable needs to be retained.

Signed-off-by: William Rowe <wrowe@pivotal.io>
Signed-off-by: Yechiel Kalmenson <ykalmenson@pivotal.io>
2019-10-03 11:40:52 -07:00
yuangongji
148d12ad31 evutil_time: detect and use _gmtime64_s()/_gmtime64() 2019-09-19 15:52:49 +08:00
yuangongji
572a565130 https-client: load certificates from the system cert store on Windows 2019-09-17 20:57:01 +08:00
Azat Khuzhin
86f55b0420 arc4random: replace sysctl() with getrandom (on linux)
Since sysctl() is deprecated for a long-long time, according to
sysctl(2):

    Since Linux 2.6.24, uses of this system call result in warnings in the kernel log.

Fixes: #890
Suggested-by: Pierce Lopez
2019-09-03 00:50:10 +03:00
Boris.Dergachov
b5e1d91154 Fixes spelling 2019-09-02 11:11:58 +03:00
yuangongji
1d1c19091f cmake: attach doxygen target into all target
v2: Disable non-html generator for doxygen by default
v3: convert cmake option to doxygen config
2019-08-28 01:23:26 +03:00
yuangongji
669a53f341
cmake: set library names to be the same as with autotools
libtool has VERSION_INFO [1], cmake has SOVERSION/VERSION instead
(although it has different format). Also libtool has RELEASE [2] while
cmake do not have analog yet [3], hence manual symlinks should be
created.

  [1]: https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
  [2]: https://www.gnu.org/software/libtool/manual/html_node/Release-numbers.html
  [3]: https://gitlab.kitware.com/cmake/cmake/issues/17652

Plus osx has compatibility_version/current_version dylib properties and
cmake do not have separate properties for them [4], hence manual LINK_FLAGS.
And also there INSTALL_NAME_DIR property which should be adjusted too.

  [4]: https://public.kitware.com/Bug/view.php?id=4383

So after all changes, here is an example before/after for osx and linux:

  # osx
    # autotools
    .libs/libevent_pthreads-2.2.1.dylib
    .libs/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib
    /usr/local/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0)
    # cmake
      # before patch
      lib/libevent_pthreads.2.2.0.dylib
      lib/libevent_pthreads.dylib -> libevent_pthreads.2.2.0.dylib
      @rpath/libevent_pthreads.2.2.0.dylib (compatibility version 2.2.0, current version 0.0.0)
      # after patch
      lib/libevent_pthreads-2.2.1.dylib
      lib/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib
      /vagrant/.cmake/inst/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0)

  # linux
    # autotools
    .libs/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0
    .libs/libevent_pthreads-2.2.so.1.0.0
    .libs/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0
    # cmake
      # before patch
      lib/libevent_pthreads.so -> libevent_pthreads.so.2.2.0
      lib/libevent_pthreads.so.2.2.0
      # after patch
      lib/libevent_pthreads-2.2.so -> libevent_pthreads-2.2.so.1
      lib/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0
      lib/libevent_pthreads-2.2.so.1.0.0
      lib/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0

Closes: #838 (cherry-picked)
Closes: #760
2019-07-11 10:11:38 +03:00
Keith Smiley
41c95abb99 Enable _GNU_SOURCE for Android
When targeting the Android NDK _GNU_SOURCE is not enabled by default:

```
 /*
  * With bionic, you always get all C and POSIX API.
  *
  * If you want BSD and/or GNU extensions, _BSD_SOURCE and/or _GNU_SOURCE are
  * expected to be defined by callers before *any* standard header file is
  * included.
  *
  * In our header files we test against __USE_BSD and __USE_GNU.
  */
 #if defined(_GNU_SOURCE)
 #  define __USE_BSD 1
 #  define __USE_GNU 1
 #endif
```

Because of this `pipe2` is not available:

```
 #if defined(__USE_GNU)
 int pipe2(int __fds[2], int __flags) __INTRODUCED_IN(9);
 #endif
```

The function used to check if it does exist:

```
CHECK_FUNCTION_EXISTS_EX(pipe2 EVENT__HAVE_PIPE2)
```

Just check that the _linking_ succeeds, which it does, it's just not
visible in the import, leading to a warning (or error):

```
evutil.c:2637:6: error: implicit declaration of function 'pipe2' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0)
            ^
```

When targeting the NDK it should be safe to always opt into this. Clang
would pass the right flag for us automatically _if_ the source was C++
instead of C.
2019-07-08 14:09:15 -07:00
Keith Smiley
0d7d85c208 Enable kqueue for APPLE targets
The CMAKE_CROSSCOMPILING variable is not set for Apple targets seemingly
because of cmake implementation details (more info
https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html).
Since Apple targets have working kqueue implementations this check makes
sure we enable it always when those are the targets, without users
having to explicitly set EVENT__HAVE_WORKING_KQUEUE
2019-07-02 10:47:47 -07:00
Azat Khuzhin
69466cde03
cmake: link against shell32.lib/advapi32.lib
Fixes: #844
Refs: #760 (cmake-vs-autotools)
2019-06-26 01:27:20 +03:00
Azat Khuzhin
bd2de4836b
Require cmake >= 3.1.2 (for correct openssl 1.0.2 detection)
@ygj6 reported:
  "My platform is MacOS 10.13.5, This problem only happens on Mac.

   As written in the file CMakeLists.txt, the minimum required version of cmake is 3.1:
     cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
   So I built this project with cmake-3.1.0, but I got the following errors:

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:293 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:294 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:296 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

       CMake Error at /usr/local/cmake-3.1.0/share/cmake/Modules/FindOpenSSL.cmake:298 (list):
         list GET given empty list
       Call Stack (most recent call first):
         CMakeLists.txt:824 (find_package)

   I googled this error and got this answer:
     https://bugs.archlinux.org/task/43688

   It is a bug in FindOpenSSL.cmake on cmake-3.1.0 and fixed on cmake-3.1.2 .
   Of course, It was successful when rebuilding with cmake-3.1.2 .
   So I suggest setting the minimum version required for cmake to 3.1.2 or higher.
   "

Closes: #845
Refs: de4ccee75a
2019-06-26 01:01:46 +03:00
yuangongji
7201062f3e
cmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py)
Close: #832 (cherry-picked)
2019-06-13 21:57:39 +03:00
Jan Beich
236762a30d cmake: limit MSVC to Clang-CL 2019-05-28 12:45:59 +00:00
Azat Khuzhin
49a367e6cf
cmake: add -Wmissing-prototypes (like autotools has) 2019-05-25 17:28:53 +03:00
Azat Khuzhin
da11217544
build: struct sockaddr_un detection (sys/un.h, afunix.h)
- On UNIX:     sys/un.h
- Since win10: afunix.h

And windows has AF_UNIX but do not have sockaddr_un (before windows
build 17061 [1]), hence the sockaddr_un detection.

  [1]: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
2019-05-12 18:17:53 +03:00
Dan Rosen
2f184f8bbf evwatch: Add "prepare" and "check" watchers.
Adds two new callbacks: "prepare" watchers, which fire immediately
before we poll for I/O, and "check" watchers, which fire immediately
after we finish polling and before we process events. This allows other
event loops to be embedded into libevent's, and enables certain
performance monitoring.

Closes: #710
2019-04-03 12:44:50 -04:00
Azat Khuzhin
d5b24cc0c8
sample/becat: bufferevent cat, ncat/nc/telnet analog 2019-03-16 17:40:20 +03:00
Azat Khuzhin
42d5a36bd8
cmake: sync warnings with autotools v2
By some reason gcc reports next error:
  ../http.c:3330:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
       value = "";

Only under -Wwrite-strings, well this is logical, but this information
does not reflected in any documentation.

Follow-up: 8348b413 ("cmake: add various warning flags like autotools has")

f
2019-03-13 00:21:38 +03:00
Enji Cooper
5f87be42f0
Define _GNU_SOURCE properly/consistently per autoconf
Although `_GNU_SOURCE` can be defined as an arbitrary #define per the
glibc docs [1], it's best to define it in a manner consistent with the way
that autoconf defines it, i.e., `1`.

While this shouldn't matter in most cases, it does when the headers from
other projects follow the poorly defined GNU convention implemented by
autoconf and are included after the libevent's util.h header. An example
failure with clang, similar to the failure I encountered, is as follows:
```
$ printf "#define _GNU_SOURCE\n#define _GNU_SOURCE 1" | clang -c -x c -
<stdin>:2:9: warning: '_GNU_SOURCE' macro redefined [-Wmacro-redefined]
        ^
<stdin>:1:9: note: previous definition is here
        ^
1 warning generated.
```

This happened when compiling python [2] with a stale homebrew util.h file from
libevent (which admittedly would not happen in a correct libevent install, as the
header should be installed under /usr/local/include/event2/util.h). However, if
both headers had been combined (which is more likely), it would have failed as
shown above.

Removing the ad hoc definition unbreaks compiling python's pyconfig.h.in header
when included after util.h from libevent.

1. http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
2. https://github.com/python/cpython/blob/master/configure.ac#L126

Closes: #773 (cherry-picked)

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2019-02-27 23:18:12 +03:00
Azat Khuzhin
8e87de3c24
cmake: fix checking of devpoll backend (like in autotools, by devpoll.h existence) 2019-02-04 22:21:28 +03:00