1361 Commits

Author SHA1 Message Date
Azat Khuzhin
4b72024b7f test: Use THREAD_* wrappers in del_notify/del_wait 2020-01-13 23:36:19 +03:00
Azat Khuzhin
e6285eed62 test: move threads created with THREAD_START() to realtime scheduling class too 2020-01-13 23:36:19 +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
nntrab
02905413fd Add callback support for error pages
The existing error pages are very basic and don't allow for
multi-lingual support or for conformity with other pages in a web site.
The aim of the callback functionality is to allow custom error pages to
be supported for calls to evhttp_send_error() by both calling
applications and Libevent itself.

A backward-incompatible change has been made to the title of error pages
sent by evhttp_send_error(). The original version of the function used
the reason argument as part of the title. That might have unforeseen
side-effects if it contains HTML tags. Therefore the title has been
changed to always use the standard status text.

An example of the error callback can be found in this
[version](https://github.com/libevent/libevent/files/123607/http-server.zip)
of the 'http-server' sample. It will output error pages with very bright
backgrounds, the error code using a very large font size and the reason.

Closes: #323 (cherr-picked from PR)
2020-01-13 00:50:14 +03:00
Azat Khuzhin
08981f8d75 Fix compilation without OPENSSL_API_COMPAT
Use the following for openssl 1.1+:
- X509_getm_notBefore over X509_get_notBefore
- X509_getm_notAfter  over X509_get_notAfter
- use OPENSSL_VERSION_NUMBER over SSLeay()
- add missing headers

Refs: openssl/openssl@0b7347effe
2020-01-07 22:15:08 +03:00
Andre Pereira Azevedo Pinto
f76456b0dc Add support for priority inheritance
Add support for posix mutex priority inheritance. This is important to
avoid priority inversion in systems running with threads with different
priorities.

Signed-off-by: Andre Azevedo <andre.azevedo@gmail.com>
2019-12-09 14:55:31 -08:00
Azat Khuzhin
8a34869984 test-ratelim: calculate timers bias (for slow CPUs) to avoid false-positive
This can be/should be done for regression tests too.

Refs: https://ci.appveyor.com/project/libevent/libevent/builds/28916689/job/kg621aa194a0qbym
Refs: https://github.com/libevent/libevent/pull/917#issuecomment-553811834
v2: EVENT_BASE_FLAG_PRECISE_TIMER
2019-11-17 20:52:28 +03:00
Philip Homburg
9fecb59a94 Parse IPv6 scope IDs. 2019-11-06 21:07:16 +03:00
Azat Khuzhin
4436287d12 Relax bufferevent_connect_hostname_emfile
Do not do any assumptions on the error for the EMFILE from
getaddrinfo(), expect just any error.

Fixes: #924
2019-10-31 09:20:49 +03:00
yuangongji
55d60c9258 test: add testcase for evutil_socketpair() 2019-10-19 13:07:04 +08:00
yuangongji
8d5c5650d2 tinytest: support timeout on Windows 2019-09-26 21:54:33 +08:00
yuangongji
6769f692d7 regress_buffer: improve testcase for evbuffer_freeze() 2019-09-22 22:57:21 +08:00
yuangongji
6f970267b6 eliminate some C4267 warnings in Windows 2019-08-28 11:41:53 +08:00
Jan Kasiak
445027a5dc Fix memory corruption in EV_CLOSURE_EVENT_FINALIZE with debug enabled
Call event_debug_note_teardown_ before evcb_evfinalize to avoid possible
UAF (if finalizer free's event).
2019-08-28 01:15:39 +03:00
Jan Kasiak
70daa93a51 test: prevent duplicate event_enable_debug_mode() for TT_ENABLE_DEBUG_MODE 2019-08-28 01:05:03 +03:00
Azat Khuzhin
6186d3126f
test: introduce TT_ENABLE_DEBUG_MODE flag 2019-08-26 22:43:51 +03:00
dota17
9c151f3c34
Fix typos in comments (sample/test/event-internal.h) 2019-08-09 12:34:46 +03:00
Azat Khuzhin
bdcade4722
buffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM
[ @azat:

  - add return heredoc for evbuffer_setcb()
  - add unit test with event_set_mem_functions()
  - look through the report from abi-compliance-checker/abi-dumper
]

Closes: #855
2019-07-31 10:43:57 +03:00
Azat Khuzhin
538141eb7e
evdns: add new options -- so-rcvbuf/so-sndbuf
This will allow to customize SO_RCVBUF/SO_SNDBUF for nameservers in this
evdns_base, you may want to adjust them if the kernel starts dropping
udp packages.
2019-06-15 23:32:39 +03:00
Azat Khuzhin
51ac04ac62
test: mark bev_connect_hostname() as static (to avoid prototype requirement) 2019-05-25 17:29:55 +03:00
Azat Khuzhin
244cacaf8c
test: regression for evbuffer_expand_fast_() with invalid last_with_datap
Before the fix:
  $ regress --no-fork evbuffer/reserve_invalid_last_with_datap
  evbuffer/empty_chain_expand: [err] ../buffer.c:2138: Assertion chain == buf->first failed in evbuffer_expand_fast_
  Aborted (core dumped)

This is the a shorter version of test from the #806 (with some
comments).
2019-05-16 10:16:21 +03:00
Azat Khuzhin
98ca307749
test: cover adjusting of last_with_datap in evbuffer_prepend()
Before the fix:
  $ regress evbuffer/empty_reference_prepend..
  evbuffer/empty_reference_prepend: [forking]
    FAIL ../test/regress_buffer.c:104: assert(chain == buf->first)
    FAIL ../test/regress_buffer.c:2291: Buffer format invalid
    [empty_reference_prepend FAILED]
  evbuffer/empty_reference_prepend_buffer: [forking] OK
  1/2 TESTS FAILED. (0 skipped)
2019-05-16 10:05:07 +03:00
Joseph Spadavecchia
5e137f3776
Implement bufferevent_socket_connect_hostname_hints()
So that ai_flags (such as AI_ADDRCONFIG) can be specified.

Closes: #193 (cherry-picked with conflicts resolved)
2019-05-13 11:13:04 +03:00
Tobias Stoeckmann
9b2060c97a Added test for evmap slot validations.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2019-04-27 11:47:23 +02:00
Thomas Bernard
8dcb94a4ca
Added http method extending
User can define his own response method by calling
evhttp_set_ext_method_cmp() on the struct http, or
evhttp_connection_set_ext_method_cmp() on the connection.

We expose a new stucture `evhttp_ext_method` which is passed to the
callback if it's set. So any field can be modified, with some exceptions
(in evhttp_method_):

If the cmp function is set, it has the ability to modify method, and
flags. Other fields will be ignored. Flags returned are OR'd with the
current flags.

Based on changes to the #282 from: Mark Ellzey <socket@gmail.com>
2019-04-11 22:48:01 +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
47d348a631
Disable logging for tests that assume printing warnings
To avoid possible confusion

But there is still one test that has some messages on windows:
  main/methods

Because this test needs >1 of avaiable methods, otherwise it will warn.
2019-04-03 08:00:12 +03:00
Azat Khuzhin
d4c7545017
Remove manually written nmake makefiles (cmake should be used instead)
This nmake stuff is out dated, and nobody wants to support it anyway.
2019-04-03 07:33:09 +03:00
Azat Khuzhin
e5b8f4c192
evdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT
- DNS_OPTION_NAMESERVERS_NO_DEFAULT
  Do not "default" nameserver (i.e. "127.0.0.1:53") if there is no nameservers
  in resolv.conf, (iff DNS_OPTION_NAMESERVERS is set)

- EVDNS_BASE_NAMESERVERS_NO_DEFAULT
  If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not add default
  nameserver if there are no nameservers in resolv.conf (just set
  DNS_OPTION_NAMESERVERS_NO_DEFAULT internally)

Fixes: #569
2019-04-01 02:18:59 +03:00
Azat Khuzhin
2ae875ed12
Link test/regress with event_core/event_extra over event
Due to regress linked with event and event_core (both of them includes
evthread.c) there will be two different evthread_id_fn_ variables under
mingw64:
  evthread_id_fn_: &0x5294f20a8
  evthread_id_fn_: &0x4ba0030a8

And because of this evthread_use_pthreads() can/will set one copy of
variables while evthread*() functions will access another, which will
break a lot of things (for example main/del_notify test).

Fixes: #792
2019-03-25 09:54:32 +03:00
Azat Khuzhin
8a674243b4
tinytest: fix parsing --timeout argument
Fixes: 15b2f41d ("tinytest: implement per-test timeout (via alarm() under !win32 only)")
2019-03-24 20:39:20 +03:00
Azat Khuzhin
15b2f41d74
tinytest: implement per-test timeout (via alarm() under !win32 only) 2019-03-24 16:56:01 +03:00
Azat Khuzhin
efcc18442b
bench: suppress int conversion warnings 2019-03-16 16:52:05 +03:00
Alexander Drozdov
68eb526d7b http: add WebDAV methods support
WebDAV introduced new HTTP methods (RFC4918):
PROPFIND, PROPPATCH, MKCOL, LOCK, UNLOCK, COPY, MOVE.

Add support of the methods.
2019-03-14 11:12:46 +03:00
Azat Khuzhin
5ee507c889
http: implement separate timeouts for read/write/connect phase
This patch allows to change timeout for next events read/write/connect
separatelly, using new API:

- client:
  evhttp_connection_set_connect_timeout_tv() -- for connect
  evhttp_connection_set_read_timeout_tv()    -- for read
  evhttp_connection_set_write_timeout_tv()   -- for write

- server:
  evhttp_set_read_timeout_tv()  -- for read
  evhttp_set_write_timeout_tv() -- for write

It also changes a logic a little, before there was next fallbacks which
does not handled in new API:
- HTTP_CONNECT_TIMEOUT
- HTTP_WRITE_TIMEOUT
- HTTP_READ_TIMEOUT

And introduce another internal flag (EVHTTP_CON_TIMEOUT_ADJUSTED) that
will be used in evrpc, which adjust evhttp_connection timeout only if it
is not default.

Fixes: #692
Fixes: #715
2019-03-05 00:33:46 +03:00
John Ohl
62df1301ca
Add support for EV_TIMEOUT to event_base_active_by_fd
Closes: #194 (cherry-pick)
2019-03-03 23:42:03 +03:00
Azat Khuzhin
5b19c9f62b
buffer: do not rely on ->off in advance_last_with_data()
advance_last_with_data() adjusts evbuffer.last_with_datap, and if we
will have empty chain in the middle advance_last_with_data() will stop,
while it should not, since while empty chains is not regular thing they
can pops up in various places like, and while I did not look through all
of them the most tricky I would say is:
  evbuffer_reverse_space()/evbuffer_commit_space()
  evbuffer_add_reference()

Test case from:
  https://github.com/envoyproxy/envoy/pull/6062

Fixes: #778

v2: keep last_with_datap really last with data, i.e. update only if
chain has data in it
2019-03-03 18:55:25 +03:00
Azat Khuzhin
fdfabbec00
buffer: fix evbuffer_remove_buffer() with empty chain in front
In case we have empty chain (chain that do not have any data, i.e. ->off
== 0) at the beginning of the buffer, and no more full chains to move to
the dst, we will skip moving of this empty chain, and hence
last_with_datap will not be adjusted, and things will be broken after.

Fix this by not relying on ->off, just count if we have something to
move that's it.

Test case from:
  https://github.com/envoyproxy/envoy/pull/6062

Fixes: #774
2019-03-03 18:00:37 +03:00
Azat Khuzhin
91acedcc97
test: verify content of the buffer in evbuffer/remove_buffer_with_empty*
And replace spaces with tab in remove_buffer_with_empty
2019-03-03 17:54:23 +03:00
Azat Khuzhin
14eb903ba3
Revert "test: avoid regress hanging in macOS"
After we started to use kill() over raise() everything should work just
fine.

This reverts commit a86f89d333d870e6714bd28c695ba1774df3d7f5.

Fixed-in: 728c5dc1 ("Use kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)")
Fixes: #747
2019-02-24 17:28:36 +03:00
Azat Khuzhin
728c5dc11f
Use kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)
On OSX 10.14+ the raise() uses pthread_kill() (verified with dtruss) and
by some reason signals that has been raised with pthread_kill() do not
received by kqueue EVFILT_SIGNAL.

While on OSX 10.11 the raise()/pthread_kill() uses plain kill() and
everything work just fine (linux also does the same, but instead of
kill() it uses tgkill())

Here is a simple reproducer that installs alarm to show that the signal
does not received by the kqueue backend:
  https://gist.github.com/azat/73638b8e3b0fa563a20dadcca9e652a1

Refs: #747
Fixes: #765
2019-02-24 17:18:11 +03:00
Azat Khuzhin
6dbad0f671
test/dns: in solaris under EMFILE devpoll does not dispatch (due DP_POLL failure) 2019-02-04 22:43:47 +03:00
Azat Khuzhin
d234902da7
test/dns: in solaris under EMFILE the error is EAI_FAIL 2019-02-03 18:56:01 +03:00
Azat Khuzhin
ae9b285d2d
test/ssl/bufferevent_wm: explicitly break the loop once client/server received enough
There can be tricky cases (that can be reproduced by reducing
SO_RCVBUF/SO_SNDBUF to 6144, on linux, and be aware, since linux doubles
this const), when there is still write event pending, although we read
enough.

This should be fixed in a more sophisticated way, but to backport the
patch, let's simply break the loop manually.

The ssl/bufferevent_wm originally failed on solaris.
2019-02-03 18:51:28 +03:00
Azat Khuzhin
b29207dcee
Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)
windows has intptr_t instead of regular int.

Also tt_fd_op() had been introduced, since we cannot use tt_int_op() for
comparing fd, since it is not always int.
2019-01-29 22:03:08 +03:00
Azat Khuzhin
0791a17204
test/et/et: use evutil_socket_t* over int* for pointer to the pair
Next code will not work correctly under win x64:
  evutil_socket_t very_long_pair_name[2];
  int *pair = very_long_pair_name; // <-- accessing the second word of the first element

Because sizeof(evutil_socket_t) == sizeof(intptr_t) == 8

P.S. in the 5334762f another test had been fixed instead of the one that
really fails.

Fixes: 5334762f ("test/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)")
Refs: #750
2019-01-29 21:11:27 +03:00
Azat Khuzhin
5334762fcf
test/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)
Fixes: #750
2019-01-29 10:54:22 +03:00
Azat Khuzhin
3e37fcd43c
test/et/et: verify return codes 2019-01-29 10:54:07 +03:00
Azat Khuzhin
b8ca5a6820
test: add logging for http/read_on_write_error and rearrange code 2019-01-29 00:51:46 +03:00
Azat Khuzhin
4ffc711617
test: adjust expecting error for getaddrinfo() under EMFILE
When getaddrinfo() cannot allocate file descriptor glibc/musl-libc on
linux report EAI_SYSTEM error. But this is not true for freebsd libc [1]
(and hence apple libc [2]), they report EAI_NONAME error instead, so
adjust expectation.

  [1]: https://github.com/freebsd/freebsd/blob/master/lib/libc/net/getaddrinfo.c
  [2]: https://opensource.apple.com/source/Libc/

Refs: #749
Refs: https://github.com/libevent/libevent/issues/749#issuecomment-457838159
2019-01-26 19:57:37 +03:00