176 Commits

Author SHA1 Message Date
Dmitry Antipov
117ee9a03f epoll: use epoll_pwait2() if available
On GNU/Linux with epoll backend, prefer epoll_pwait2() if available,
which is useful to support the timeout with microsecond precision.
2022-09-27 22:07:43 +03:00
Dmitry Ilyin
211c6653ae Add manual CMAKE_C_BYTE_ORDER set for old CMake 2022-09-26 21:42:02 +03:00
Dmitry Ilyin
e8313084f9
Add minimal WebSocket server implementation for evhttp (#1322)
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.

Implementation was inspired by modified Libevent source code in ipush project
[1].

  [1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable

Also, WebSocket-based chat server was added as a sample.
2022-09-12 22:16:56 +03:00
Azat Khuzhin
039e8d96a4 Add openssl-compat.h into HDR_PRIVATE
Fixes: #1334
2022-09-11 22:08:32 +02:00
Borys Smejda
86b5d2e951 Fixed CMake configuration failure (libevent#1321)
Deleted usage of CMake feature 'file(REAL_PATH'
which is available from version 3.19
with an old 'get_filename_component' so that
older version of CMake can still be used
to configure the project.
2022-08-13 20:15:06 +02:00
Dmitry Ilyin
99fd68abde Add check of mmap64 function and use it when available rather that mmap
There can be issues on 32-bit architectures to mmap 2+GiB file, and to
make this portable between different version of glibc, mmap64 was
prefered over _FILE_OFFSET_BITS
2022-08-09 00:18:10 +02:00
Haowei Hsu
dd610b7781 Add postfix for Debug configuration. 2022-08-07 11:14:40 +02:00
Azat Khuzhin
3960449374 Detech -Wno-unused-functions for GCC too
Otherwise build fails [1]:

    /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/minheap-internal.h:64:6: error: ‘min_heap_ctor_’ defined but not used [-Werror=unused-function]
     void min_heap_ctor_(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; }
          ^~~~~~~~~~~~~~
    In file included from /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/buffer.c:91:0:
    /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/bufferevent-internal.h:414:1: error: ‘bufferevent_trigger_nolock_’ defined but not used [-Werror=unused-function]
     bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/buffer.c:89:0:
    /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/evthread-internal.h:140:1: error: ‘EVLOCK_TRY_LOCK_’ defined but not used [-Werror=unused-function]
     EVLOCK_TRY_LOCK_(void *lock)

  [1]: https://github.com/libevent/libevent/runs/7263518180?check_suite_focus=true
2022-07-09 17:17:06 +03:00
Azat Khuzhin
92b73c7d55 cmake: add compiler version to the status message 2022-07-09 17:17:06 +03:00
Azat Khuzhin
f5ad737d73 Add -Wundef for cmake and fix EVENT__SIZEOF_TIME_T usage
Note, autotools already supports it.
2022-07-09 17:16:56 +03:00
fanquake
bf3ce77f6c build: only try silence options if they exist
Otherwise GCC will warn. i.e:
```bash
  CCLD     libevent_openssl.la
cc1: note: unrecognized command-line option ‘-Wno-void-pointer-to-enum-cast’
	may have been intended to silence earlier diagnostics
  CCLD     libevent_mbedtls.la
```
2022-06-30 22:06:51 +03:00
Azat Khuzhin
6349e94a0a Do not install RPATH for install tree by default
In ce8be2385b5fee16859a630fca0c98ad290c8e21 ("cmake: set rpath for
libraries on linux") RPATH was first instroduced.

Later in 6d09efe8686de824adf3d8810bbe0d5c386643e4 ("Set RPATH only if
installation is done into non system directory") it was set only if it
was installed to non system directory.

But absolute RPATH not a good default, let's change this.

Fixes: #920
2022-03-10 23:54:58 +03:00
Azat Khuzhin
6d09efe868 Set RPATH only if installation is done into non system directory
v2: use CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES

Fixes: #1245
2022-01-15 22:10:36 +03:00
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