]> granicus.if.org Git - libevent/log
libevent
5 years agoIgnore build files for autotools build in subfolder too
Azat Khuzhin [Sat, 13 Apr 2019 10:22:55 +0000 (13:22 +0300)]
Ignore build files for autotools build in subfolder too

5 years agoMerge branch '21_http_extended_method'
Azat Khuzhin [Thu, 11 Apr 2019 19:52:10 +0000 (22:52 +0300)]
Merge branch '21_http_extended_method'

* 21_http_extended_method:
  Added http method extending
  http: Update allowed_methods field from 16 to 32bits.

Fixes: #327
5 years agoAdded http method extending
Thomas Bernard [Fri, 8 Jan 2016 21:36:20 +0000 (13:36 -0800)]
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>

5 years agohttp: Update allowed_methods field from 16 to 32bits.
Thomas Bernard [Tue, 2 Apr 2019 13:43:35 +0000 (15:43 +0200)]
http: Update allowed_methods field from 16 to 32bits.

5 years agohttp: replace EVHTTP_REQ_UNKNOWN_ with 0
Azat Khuzhin [Mon, 8 Apr 2019 19:27:33 +0000 (22:27 +0300)]
http: replace EVHTTP_REQ_UNKNOWN_ with 0

From the server perspective the evhttp_response_phrase_internal() should
not be called with 0 before this patch, it will be called with
EVHTTP_REQ_UNKNOWN_ hence this patch should not change behavior.

Fixes: 68eb526d7b ("http: add WebDAV methods support")
Fixes: #789
Fixes: #796
Reported-by: Thomas Bernard <miniupnp@free.fr>
5 years agoRemove experimental note for finalizers API
Azat Khuzhin [Thu, 4 Apr 2019 06:09:09 +0000 (09:09 +0300)]
Remove experimental note for finalizers API

5 years agohttps-client: do not try to free not initialized base
Azat Khuzhin [Wed, 3 Apr 2019 20:22:54 +0000 (23:22 +0300)]
https-client: do not try to free not initialized base

Otherwise:
  $ https-client --help
  Syntax:
     https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-retries num] [-timeout sec] [-crt crt]
  Example:
     https-client -url https://ip.appspot.com/
  [warn] event_base_free_: no base to free

5 years agohttp: drop unused internal macros
Azat Khuzhin [Wed, 3 Apr 2019 20:20:06 +0000 (23:20 +0300)]
http: drop unused internal macros

5 years agoevwatch: Add "prepare" and "check" watchers.
Dan Rosen [Tue, 26 Mar 2019 17:33:57 +0000 (13:33 -0400)]
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
5 years agoDisable logging for tests that assume printing warnings
Azat Khuzhin [Wed, 3 Apr 2019 04:26:21 +0000 (07:26 +0300)]
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.

5 years agoRemove manually written nmake makefiles (cmake should be used instead)
Azat Khuzhin [Mon, 25 Mar 2019 08:13:03 +0000 (11:13 +0300)]
Remove manually written nmake makefiles (cmake should be used instead)

This nmake stuff is out dated, and nobody wants to support it anyway.

5 years agoappveyor: check intermediate powershell commands exit codes and terminate early
Azat Khuzhin [Tue, 2 Apr 2019 20:25:08 +0000 (23:25 +0300)]
appveyor: check intermediate powershell commands exit codes and terminate early

Otherwise build errors will be ignored, i.e. if build fails but regress
binary exists (copied from artifacts) it will be runned instead of newly
compiled.

5 years agoMerge branch 'fix-uchex-warnings'
Azat Khuzhin [Sun, 31 Mar 2019 23:42:55 +0000 (02:42 +0300)]
Merge branch 'fix-uchex-warnings'

There is one more report that is false positive, see [1]:
  "In bufferevent_openssl.c, pointer wm is dereferenced on line 871
before it is null checked on line 873."

  [1]: https://github.com/libevent/libevent/issues/382#issuecomment-238081938

* fix-uchex-warnings:
  evdns: do not check server_req twice
  evrpc: do not check req twice

Fixes: #382
5 years agoevdns: do not check server_req twice
Azat Khuzhin [Sun, 31 Mar 2019 23:41:17 +0000 (02:41 +0300)]
evdns: do not check server_req twice

Reported by µchex:
  "In evdns.c, pointer server_req is null checked on line 1289 after it
is dereferenced above. Since server_req was already null checked above
on line 1243, there is no risk of crashing and the only bug is the
redundant null check (and indentation) on line 1289.
"

5 years agoevrpc: do not check req twice
Azat Khuzhin [Sun, 31 Mar 2019 23:37:41 +0000 (02:37 +0300)]
evrpc: do not check req twice

reported by µchex:
  "In evrpc.c, pointer req is dereferenced on line 881 before it is null
checked on line 894."

5 years agoevdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT
Azat Khuzhin [Sun, 31 Mar 2019 22:47:00 +0000 (01:47 +0300)]
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
5 years agoevdns: add descriptions for DNS_OPTION_*/DNS_OPTIONS_ALL
Azat Khuzhin [Sun, 31 Mar 2019 22:40:18 +0000 (01:40 +0300)]
evdns: add descriptions for DNS_OPTION_*/DNS_OPTIONS_ALL

5 years agoLink test/regress with event_core/event_extra over event
Azat Khuzhin [Sun, 24 Mar 2019 22:40:46 +0000 (01:40 +0300)]
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
5 years agosignal: guard __cdecl definition with #ifdef
Azat Khuzhin [Sun, 24 Mar 2019 22:41:09 +0000 (01:41 +0300)]
signal: guard __cdecl definition with #ifdef

Under mingw64:
  ../signal.c:88:0: warning: "__cdecl" redefined
   #define __cdecl

  <built-in>: note: this is the location of the previous definition

https://ci.appveyor.com/project/azat/libevent/builds/23321613#L427

5 years agotinytest: fix parsing --timeout argument
Azat Khuzhin [Sun, 24 Mar 2019 17:36:16 +0000 (20:36 +0300)]
tinytest: fix parsing --timeout argument

Fixes: 15b2f41d ("tinytest: implement per-test timeout (via alarm() under !win32 only)")
5 years agotinytest: implement per-test timeout (via alarm() under !win32 only)
Azat Khuzhin [Sun, 24 Mar 2019 13:44:56 +0000 (16:44 +0300)]
tinytest: implement per-test timeout (via alarm() under !win32 only)

5 years agoMerge branch 'buffer-read-size'
Azat Khuzhin [Sat, 16 Mar 2019 14:41:09 +0000 (17:41 +0300)]
Merge branch 'buffer-read-size'

And after this patch set default evbuffer max read via bufferevent is
16K not 4K.

Here is some numbers for the single max read in evbuffer impact:
  function client() { becat "$@" | pv > /dev/null; }
  function server() { cat /dev/zero | becat -l "$@"; }

Plain bufferevent:

- 40K
  $ server -R $((40<<10)) & client -R $((40<<10))
  700MiB/s

- 16K *default now*
  $ server & client
  1.81GiB/s

- 4K
  $ server -R $((4<<10)) & client -R $((4<<10))
  1.05GiB/s

With OpenSSL (-S):

- 40K *default now*
  $ server -S -R $((40<<10)) & client -S -R $((40<<10))
  900MiB/s

- 16K *default now*
  $ server -S & client -S
  745MiB/s

- 4K
  $ server -S -R $((4<<10)) & client -S -R $((4<<10))
  593MiB/s

So as you can see without openssl 16K is faster then 40K/4K, while for
openssl 40K is still faster then 16K (I guess that this is due to with
openssl SSL_read() more at at time, while with plain we have some
allocations splits in evbuffer and maybe due to some buffer in openssl)

* buffer-read-size:
  sample/becat: bufferevent cat, ncat/nc/telnet analog
  Adjust evbuffer max read for bufferevents
  Maximum evbuffer read configuration
  Fix leaks in error path of the bufferevent_init_common_()

5 years agosample/becat: bufferevent cat, ncat/nc/telnet analog
Azat Khuzhin [Tue, 5 Mar 2019 18:34:31 +0000 (21:34 +0300)]
sample/becat: bufferevent cat, ncat/nc/telnet analog

5 years agoAdjust evbuffer max read for bufferevents
Azat Khuzhin [Sat, 16 Mar 2019 14:32:17 +0000 (17:32 +0300)]
Adjust evbuffer max read for bufferevents

5 years agoMaximum evbuffer read configuration
Azat Khuzhin [Sat, 16 Mar 2019 14:09:51 +0000 (17:09 +0300)]
Maximum evbuffer read configuration

Before this patch evbuffer always reads 4K at a time, while this is fine
most of time you can find an example when this will decrease throughput.

So add an API to change default limit:
- evbuffer_set_max_read()
- evbuffer_get_max_read()

And a notice that most of time default is sane.

5 years agoFix leaks in error path of the bufferevent_init_common_()
Azat Khuzhin [Sat, 16 Mar 2019 14:28:31 +0000 (17:28 +0300)]
Fix leaks in error path of the bufferevent_init_common_()

5 years agobench: suppress int conversion warnings
Azat Khuzhin [Sat, 16 Mar 2019 13:52:05 +0000 (16:52 +0300)]
bench: suppress int conversion warnings

5 years agoSuppress int conversion warnings in getopt_long compatibility
Azat Khuzhin [Sat, 16 Mar 2019 13:37:38 +0000 (16:37 +0300)]
Suppress int conversion warnings in getopt_long compatibility

5 years agohttp: add WebDAV methods support
Alexander Drozdov [Wed, 13 Mar 2019 07:51:55 +0000 (10:51 +0300)]
http: add WebDAV methods support

WebDAV introduced new HTTP methods (RFC4918):
PROPFIND, PROPPATCH, MKCOL, LOCK, UNLOCK, COPY, MOVE.

Add support of the methods.

5 years agohttp: suppress -Wwrite-string in evhttp_parse_query_impl()
Azat Khuzhin [Tue, 12 Mar 2019 21:20:25 +0000 (00:20 +0300)]
http: suppress -Wwrite-string in evhttp_parse_query_impl()

5 years agocmake: sync warnings with autotools v2
Azat Khuzhin [Tue, 12 Mar 2019 21:02:39 +0000 (00:02 +0300)]
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

5 years agoUpdate documentation [ci skip]
Sayan Nandan [Sun, 10 Mar 2019 14:21:44 +0000 (19:51 +0530)]
Update documentation [ci skip]

The documentation for building and installing has been moved into a new
Documentation section

Closes: #788 (cherry-picked)
5 years agoMove list of contributors into separate file
Sayan Nandan [Fri, 8 Mar 2019 11:17:56 +0000 (16:47 +0530)]
Move list of contributors into separate file

Closes: #786 (cherry-picked)
5 years agohttp: implement separate timeouts for read/write/connect phase
Azat Khuzhin [Mon, 4 Mar 2019 03:53:42 +0000 (06:53 +0300)]
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
5 years agoAdd support for EV_TIMEOUT to event_base_active_by_fd
John Ohl [Wed, 10 Dec 2014 02:43:18 +0000 (21:43 -0500)]
Add support for EV_TIMEOUT to event_base_active_by_fd

Closes: #194 (cherry-pick)
5 years agobuffer: make evbuffer_prepend() of zero-length array no-op
Azat Khuzhin [Sun, 3 Mar 2019 16:03:29 +0000 (19:03 +0300)]
buffer: make evbuffer_prepend() of zero-length array no-op

Refs: #774

5 years agoMerge branch 'evbuffer-empty-chain-handling'
Azat Khuzhin [Sun, 3 Mar 2019 15:58:57 +0000 (18:58 +0300)]
Merge branch 'evbuffer-empty-chain-handling'

* evbuffer-empty-chain-handling:
  buffer: do not rely on ->off in advance_last_with_data()
  buffer: fix evbuffer_remove_buffer() with empty chain in front
  test: verify content of the buffer in evbuffer/remove_buffer_with_empty*

5 years agobuffer: do not rely on ->off in advance_last_with_data()
Azat Khuzhin [Sun, 3 Mar 2019 13:29:52 +0000 (16:29 +0300)]
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

5 years agobuffer: fix evbuffer_remove_buffer() with empty chain in front
Azat Khuzhin [Sat, 2 Mar 2019 19:50:00 +0000 (22:50 +0300)]
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
5 years agotest: verify content of the buffer in evbuffer/remove_buffer_with_empty*
Azat Khuzhin [Sun, 3 Mar 2019 14:43:37 +0000 (17:43 +0300)]
test: verify content of the buffer in evbuffer/remove_buffer_with_empty*

And replace spaces with tab in remove_buffer_with_empty

5 years agoRemove needless check for arc4_seeded_ok
Seong-Joong Kim [Thu, 21 Feb 2019 16:19:10 +0000 (16:19 +0000)]
Remove needless check for arc4_seeded_ok

5 years agoFix typos: warnigns -> warnings
Enji Cooper [Fri, 1 Mar 2019 01:47:51 +0000 (17:47 -0800)]
Fix typos: warnigns -> warnings

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
5 years agoFix typos in a comment describing the purpose of `VersionViaGit.cmake`
Enji Cooper [Fri, 1 Mar 2019 01:22:30 +0000 (17:22 -0800)]
Fix typos in a comment describing the purpose of `VersionViaGit.cmake`

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
5 years agoDefine `_GNU_SOURCE` properly/consistently per autoconf
Enji Cooper [Mon, 25 Feb 2019 19:59:15 +0000 (11:59 -0800)]
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>
5 years agoDon't loose top error in SSL
Yury Korzhetsky [Tue, 26 Feb 2019 09:33:49 +0000 (12:33 +0300)]
Don't loose top error in SSL

Closes: #775 (cherry-picked)
5 years agoIgnore bitrise branches for travis-ci/appvyeor [ci skip]
Azat Khuzhin [Sun, 24 Feb 2019 21:26:39 +0000 (00:26 +0300)]
Ignore bitrise branches for travis-ci/appvyeor [ci skip]

5 years agoUpdate link to the appveyor project
Azat Khuzhin [Sun, 24 Feb 2019 19:59:33 +0000 (22:59 +0300)]
Update link to the appveyor project

Since the migration request has been hanged for a while, let's switch it
for now without beauty API URL.

Fixes: #555
5 years agoMatch definition with prototype for bufferevent_socket_set_conn_address_fd_()
Azat Khuzhin [Sun, 24 Feb 2019 14:34:20 +0000 (17:34 +0300)]
Match definition with prototype for bufferevent_socket_set_conn_address_fd_()

Fixes: #772
Fixes: b29207dc ("Eliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)")
5 years agoRevert "test: avoid regress hanging in macOS"
Azat Khuzhin [Sun, 24 Feb 2019 14:25:31 +0000 (17:25 +0300)]
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
5 years agoUse kill() over raise() for raising the signal (fixes osx 10.14 with kqueue)
Azat Khuzhin [Sun, 24 Feb 2019 14:07:18 +0000 (17:07 +0300)]
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
5 years agoMerge pull request #769 from sungjungk/fix-return-handling
Nathan French [Thu, 21 Feb 2019 15:21:02 +0000 (10:21 -0500)]
Merge pull request #769 from sungjungk/fix-return-handling

Add error-handling routine for arc4_seed()

5 years agoAdd error-handling routine for arc4_seed()
Seong-Joong Kim [Thu, 21 Feb 2019 09:13:05 +0000 (18:13 +0900)]
Add error-handling routine for arc4_seed()

5 years agoAdded DNS header mask definitions.
Nathan French [Thu, 7 Feb 2019 16:43:14 +0000 (11:43 -0500)]
Added DNS header mask definitions.

Currently, we do a lot of data munging with manual hex. This is ugly
and can lead to bugs. I defined the following:

_QR_MASK    0x8000U
_OP_MASK    0x7800U
_AA_MASK    0x0400U
_TC_MASK    0x0200U
_RD_MASK    0x0100U
_RA_MASK    0x0080U
_Z_MASK     0x0040U
_AD_MASK    0x0020U
_CD_MASK    0x0010U
_RCODE_MASK 0x000fU

So that we can more easily twiddle flags.

v2: make evdns flag masks unsigned literal
Closes: #756 (cherry-picked)
5 years agoUse the logo from the libevent.org
Azat Khuzhin [Tue, 5 Feb 2019 21:12:35 +0000 (00:12 +0300)]
Use the logo from the libevent.org

5 years agotest/dns: in solaris under EMFILE devpoll does not dispatch (due DP_POLL failure)
Azat Khuzhin [Mon, 4 Feb 2019 19:34:10 +0000 (22:34 +0300)]
test/dns: in solaris under EMFILE devpoll does not dispatch (due DP_POLL failure)

5 years agocmake: fix checking of devpoll backend (like in autotools, by devpoll.h existence)
Azat Khuzhin [Mon, 4 Feb 2019 19:18:45 +0000 (22:18 +0300)]
cmake: fix checking of devpoll backend (like in autotools, by devpoll.h existence)

5 years agotest/dns: in solaris under EMFILE the error is EAI_FAIL
Azat Khuzhin [Sun, 3 Feb 2019 15:54:00 +0000 (18:54 +0300)]
test/dns: in solaris under EMFILE the error is EAI_FAIL

5 years agotest/ssl/bufferevent_wm: explicitly break the loop once client/server received enough
Azat Khuzhin [Sun, 3 Feb 2019 15:47:14 +0000 (18:47 +0300)]
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.

6 years agoEliminate fd conversion warnings and introduce EVUTIL_INVALID_SOCKET (windows)
Azat Khuzhin [Tue, 29 Jan 2019 18:12:33 +0000 (21:12 +0300)]
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.

6 years agoevmap: use approparite type for changes to avoid warnings under windows
Azat Khuzhin [Tue, 29 Jan 2019 18:31:19 +0000 (21:31 +0300)]
evmap: use approparite type for changes to avoid warnings under windows

6 years agotest/et/et: use evutil_socket_t* over int* for pointer to the pair
Azat Khuzhin [Tue, 29 Jan 2019 18:06:37 +0000 (21:06 +0300)]
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

6 years agoappveyor: disable verbosity of MSBuild
Azat Khuzhin [Tue, 29 Jan 2019 17:58:01 +0000 (20:58 +0300)]
appveyor: disable verbosity of MSBuild

6 years agoMerge branch 'win64-fixes'
Azat Khuzhin [Tue, 29 Jan 2019 07:54:39 +0000 (10:54 +0300)]
Merge branch 'win64-fixes'

* win64-fixes:
  test/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)
  test/et/et: verify return codes
  appveyor: switch to new VS/MinGW and x64

6 years agotest/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)
Azat Khuzhin [Tue, 29 Jan 2019 07:42:50 +0000 (10:42 +0300)]
test/et/et: fix it by using appropriate type for the SOCKET (evutil_socket_t)

Fixes: #750
6 years agotest/et/et: verify return codes
Azat Khuzhin [Mon, 28 Jan 2019 22:44:33 +0000 (01:44 +0300)]
test/et/et: verify return codes

6 years agoappveyor: switch to new VS/MinGW and x64
Azat Khuzhin [Sat, 24 Nov 2018 17:22:40 +0000 (20:22 +0300)]
appveyor: switch to new VS/MinGW and x64

The cache had been reseted with the following REST API requests:
  DELETE https://ci.appveyor.com/api/projects/nmathewson/libevent/buildCache
  DELETE https://ci.appveyor.com/api/projects/libevent/libevent/buildCache
  DELETE https://ci.appveyor.com/api/projects/azat/libevent/buildCache

6 years agowin32select: print an error in case of failure
Azat Khuzhin [Tue, 29 Jan 2019 04:56:21 +0000 (07:56 +0300)]
win32select: print an error in case of failure

6 years agoAdd OS-specific exclude patterns of the branch names for the CI
Azat Khuzhin [Tue, 29 Jan 2019 07:10:23 +0000 (10:10 +0300)]
Add OS-specific exclude patterns of the branch names for the CI

6 years agos/http-server: fix cleanup routines
Azat Khuzhin [Mon, 28 Jan 2019 22:23:02 +0000 (01:23 +0300)]
s/http-server: fix cleanup routines

Fixes: bdd71f18 ("s/http-server: graceful cleanup")
6 years agoMerge branch 'http-EVHTTP_CON_READ_ON_WRITE_ERROR-fixes-v2'
Azat Khuzhin [Mon, 28 Jan 2019 22:18:39 +0000 (01:18 +0300)]
Merge branch 'http-EVHTTP_CON_READ_ON_WRITE_ERROR-fixes-v2'

* http-EVHTTP_CON_READ_ON_WRITE_ERROR-fixes-v2:
  http: try to read existing data in buffer under EVHTTP_CON_READ_ON_WRITE_ERROR
  test: add logging for http/read_on_write_error and rearrange code
  http: do not call deferred readcb if readcb is not set

Refs: #749

6 years agohttp: try to read existing data in buffer under EVHTTP_CON_READ_ON_WRITE_ERROR
Azat Khuzhin [Mon, 28 Jan 2019 22:09:44 +0000 (01:09 +0300)]
http: try to read existing data in buffer under EVHTTP_CON_READ_ON_WRITE_ERROR

There are two possible ways of getting response from the server:
- processing existing bufferevent buffer
- reading from the socket (even after write() errored with -1, it is
still possible)

But we did not tried the first option, only the second one.

Fixes: http/read_on_write_error (on freebsd/osx)
6 years agotest: add logging for http/read_on_write_error and rearrange code
Azat Khuzhin [Sun, 27 Jan 2019 12:28:28 +0000 (15:28 +0300)]
test: add logging for http/read_on_write_error and rearrange code

6 years agohttp: do not call deferred readcb if readcb is not set
Azat Khuzhin [Sun, 27 Jan 2019 12:16:39 +0000 (15:16 +0300)]
http: do not call deferred readcb if readcb is not set

Otherwise evhttp_read_cb can be called with invalid connection state:
    http/read_on_write_error: [forking] [msg] libevent using: kqueue
      FAIL ../test/regress_http.c:4079: assert(req)
      FAIL ../test/regress_http.c:4087: assert(req)[err] evhttp_read_cb: illegal connection state 0

6 years agoMerge branch 'travis-ci-osx-fixes'
Azat Khuzhin [Mon, 28 Jan 2019 19:19:20 +0000 (22:19 +0300)]
Merge branch 'travis-ci-osx-fixes'

* travis-ci-osx-fixes:
  travis-ci/osx: switch to xcode 10.1, since 9.4 is not compatible with gcc-8
  travis-ci/osx: install gcc and fix CC

6 years agotravis-ci/osx: switch to xcode 10.1, since 9.4 is not compatible with gcc-8
Azat Khuzhin [Mon, 28 Jan 2019 18:22:27 +0000 (21:22 +0300)]
travis-ci/osx: switch to xcode 10.1, since 9.4 is not compatible with gcc-8

Refs: travis-ci/travis-ci#9640

6 years agotravis-ci/osx: install gcc and fix CC
Azat Khuzhin [Mon, 28 Jan 2019 17:30:57 +0000 (20:30 +0300)]
travis-ci/osx: install gcc and fix CC

Since there is no gcc in osx_image [1]:
    ls: /usr/local/bin/gcc-?.?: No such file or directory

  [1]: https://travis-ci.org/libevent/libevent/jobs/484794192#L95

And use ls(1) over echo(1) to show an error if there is no such file.

6 years agotest: adjust expecting error for getaddrinfo() under EMFILE
Azat Khuzhin [Sat, 26 Jan 2019 15:52:33 +0000 (18:52 +0300)]
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

6 years agotest/nonpersist_readd: use assert helpers
Azat Khuzhin [Sat, 12 Jan 2019 10:58:50 +0000 (13:58 +0300)]
test/nonpersist_readd: use assert helpers

To debug failure under win32 in appveyor:
  https://ci.appveyor.com/project/nmathewson/libevent/builds/21559140/job/dn16qdo1j6sr497t#L1620

6 years agorpc: use *_new_with_arg() to match function prototype
Azat Khuzhin [Fri, 11 Jan 2019 18:52:11 +0000 (21:52 +0300)]
rpc: use *_new_with_arg() to match function prototype

In 755fbf16c ("Add void* arguments to request_new and reply_new
evrpc hooks") this new functions had been introduced, but newer used,
what for? So let's use them.

6 years agohttp: Preserve socket error from listen across closesocket cleanup
Luke Dashjr [Fri, 28 Dec 2018 04:42:20 +0000 (04:42 +0000)]
http: Preserve socket error from listen across closesocket cleanup

Closes: #738 (cherry-picked)
6 years agocmake: support static runtime (MSVC)
Azat Khuzhin [Mon, 17 Dec 2018 18:31:54 +0000 (21:31 +0300)]
cmake: support static runtime (MSVC)

Fixes: #737
6 years agoappveyor: cover static libs for MSVC
Azat Khuzhin [Mon, 17 Dec 2018 18:41:32 +0000 (21:41 +0300)]
appveyor: cover static libs for MSVC

6 years agofix a comment error
baixiangcpp [Sat, 15 Dec 2018 13:45:36 +0000 (21:45 +0800)]
fix a comment error

Closes: #736 (cherry-picked)
6 years agocmake: Fix some typos in option descriptions
Fredrik Strupe [Sat, 15 Dec 2018 11:54:31 +0000 (12:54 +0100)]
cmake: Fix some typos in option descriptions

6 years agohttp: fix connection retries when there more then one request for connection
Azat Khuzhin [Fri, 7 Dec 2018 18:46:27 +0000 (21:46 +0300)]
http: fix connection retries when there more then one request for connection

We should not attemp to establishe the connection if there is retry
timer active, since otherwise there will be a bug.

Imagine next situation:
  con = evhttp_connection_base_new()
  evhttp_connection_set_retries(con, 2)
  req = evhttp_request_new()
  evhttp_make_request(con, req, ...)
  # failed during connecting, and timer for 2 second scheduler (retry_ev)

Then another request scheduled for this evcon:
  evhttp_make_request(con, req, ...)
  # got request from server,
  # and now it tries to read the response from the server
  # (req.kind == EVHTTP_RESPONSE)
  #
  # but at this point retry_ev scheduled,
  # and it schedules the connect again,
  # and after the connect will succeeed, it will pick request with
  # EVHTTP_RESPONSE for sending and this is completelly wrong and will
  # fail in evhttp_make_header_response() since there is no
  # "http_server" for this evcon

This was a long standing issue, that I came across few years ago
firstly, bad only now I had time to dig into it (but right now it was
pretty simple, by limiting amount of CPU for the process and using rr
for debug to go back and forth).

6 years agoDo not check O_NONBLOCK for invalid fds
Azat Khuzhin [Sun, 9 Dec 2018 11:48:44 +0000 (14:48 +0300)]
Do not check O_NONBLOCK for invalid fds

Fixes: 6f988ee1 ("Merge branch 'check-O_NONBLOCK-in-debug'")
6 years agotest-fdleak: fix memory leaks
Azat Khuzhin [Sat, 8 Dec 2018 14:35:53 +0000 (17:35 +0300)]
test-fdleak: fix memory leaks

Fixes: #726
6 years agotravis-ci: do not run coveralls with clang (SIGSEGV)
Azat Khuzhin [Wed, 5 Dec 2018 08:40:40 +0000 (11:40 +0300)]
travis-ci: do not run coveralls with clang (SIGSEGV)

This will fix coveralls badge

See: https://travis-ci.org/libevent/libevent/jobs/458590276#L1425

6 years agoAdd mailmap
Azat Khuzhin [Wed, 5 Dec 2018 08:46:30 +0000 (11:46 +0300)]
Add mailmap

6 years agotest: add TT_RETRIABLE for http/cancel_by_host_no_ns
Azat Khuzhin [Thu, 22 Nov 2018 21:42:46 +0000 (00:42 +0300)]
test: add TT_RETRIABLE for http/cancel_by_host_no_ns

Could fail from time to time in travis-ci:
  https://travis-ci.org/libevent/libevent/jobs/458554097#L1702

Follow-up-for: fe5b0719 ("Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)")

6 years agoappveyor: enable parallel build
Azat Khuzhin [Wed, 21 Nov 2018 04:04:33 +0000 (07:04 +0300)]
appveyor: enable parallel build

6 years agocmake: do not build both (SHARED and STATIC) for MSVC/win32
Azat Khuzhin [Thu, 22 Nov 2018 21:29:55 +0000 (00:29 +0300)]
cmake: do not build both (SHARED and STATIC) for MSVC/win32

MSVC does not support SHARED and STATIC libraries with the same name,
so let's just build SHARED libraries by default instead (yes we can add
prefix but let's stick with this).

The reason for this is that in windows shared libraries requires .lib
file too, but this is not static library it is imported library for
shared (doh...), for more info [1] and [2].

  [1]: https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-creation
  [2]: https://blogs.msdn.microsoft.com/oldnewthing/20091013-00/?p=16403

And when we build both static library can and will override shared
library imported part, let's take a look at event_extra.lib:

- before patch [3]:
  $ less libevent-fail/lib/Debug/event_extra.lib | head
  ==> use library:contained_file to view a file in the archive
  rw-rw-rw- 100666/100666  59568 Nov 21 23:55 2018 event_extra_static.dir/Debug/evrpc.obj
  rw-rw-rw- 100666/100666 252219 Nov 21 23:55 2018 event_extra_static.dir/Debug/evdns.obj
  rw-rw-rw- 100666/100666 203850 Nov 21 23:55 2018 event_extra_static.dir/Debug/http.obj
  rw-rw-rw- 100666/100666  25907 Nov 21 23:55 2018 event_extra_static.dir/Debug/event_tagging.obj

  [3]: https://ci.appveyor.com/project/azat/libevent/builds/20472024/job/t0o93v042jai0dj7

- "after patch" [4] (not after but the same effect):
  $ less libevent-ok/lib/Debug/event_extra.lib | head
  ==> use library:contained_file to view a file in the archive
  --------- 0/0    509 Nov 21 23:38 2018 event_extra.dll
  ...

  [4]: https://ci.appveyor.com/project/azat/libevent/builds/20478998/job/ca9k3c76amc4qr76

Refs: #691

6 years agocmake: introduce EVENT__LIBRARY_TYPE option
Azat Khuzhin [Thu, 22 Nov 2018 20:00:11 +0000 (23:00 +0300)]
cmake: introduce EVENT__LIBRARY_TYPE option

Long time ago in [1] cmake build was forced to compile both libraries
(SHARED and STATIC), since this is how our autotools build works.

  [1]: 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED and STATIC libraries (like autoconf does)")

And there is no way to configure this (and indeed you need to do this
for MSVC for example), so let's introduce option for this --
EVENT__LIBRARY_TYPE.

Plus now we have INTERFACE libraries, that we can use internally in
libevent's cmake rules to avoid strict to _shared/_static variant of the
libraries to link with samples/tests (we prefer SHARED over STATIC for
linking).

Also bump minimal cmake required version to 3.1 by the following
reasons:
- 3.1 is required for RPATH configuration under APPLE
- 3.0 is required for add_library(INTERFACE) (did not found it in 2.8.x
documentation)
- remove extra conditions
(anyway 3.1 was release 4 years ago, so I guess that most of the systems
will have it)

6 years agocmake: drop redundant add_dependencies()
Azat Khuzhin [Wed, 21 Nov 2018 04:31:57 +0000 (07:31 +0300)]
cmake: drop redundant add_dependencies()

6 years agoMerge branch 'TT_RETRIABLE'
Azat Khuzhin [Tue, 20 Nov 2018 21:10:43 +0000 (00:10 +0300)]
Merge branch 'TT_RETRIABLE'

* TT_RETRIABLE:
  Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)
  regress: introduce TT_RETRIABLE

Fixes: #704
6 years agoMark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)
Azat Khuzhin [Tue, 20 Nov 2018 08:46:44 +0000 (11:46 +0300)]
Mark a lot of flacky tests with TT_RETRIABLE (for linux/win32 only)

This patch mark testcases that only fail under travis-ci/appveyor with
TT_RETRIABLE, since otherwise there is too much noise, other issues
(like failures under vagrant boxes) would be investigated separatelly.

linux (from travis-ci only):
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_by_host_ns_timeout
- http/cancel_by_host_ns_timeout_inactive_server
- thread/conditions_simple
- util/monotonic_prc_precise
- util/usleep
- main/del_wait

vagrant/ubuntu box (this is the only exception):
- thread/no_events

win32 (from appveyor only):
- main/active_later
- main/persistent_active_timeout

And we should use TT_RETRIABLE over TT_OFF_BY_DEFAULT/TT_SKIP when it
make sense.

But there is still "test-ratelim__group_lim" left.

6 years agoregress: introduce TT_RETRIABLE
Azat Khuzhin [Mon, 19 Nov 2018 22:06:04 +0000 (01:06 +0300)]
regress: introduce TT_RETRIABLE

We have some tests that has false-positive due to real/CPU time bound,
but they are pretty generic and we do not want to skip them by default.

TT_RETRIABLE is the flag that will indicate tinytest to retry the test
in case of failure, use it to avoid next possible false-positives:
- real time-related
- CPU time-related
Since I guess it is better to see/grepping RETRYING messages over
ignoring completely failed builds.

No configuration switch for number of retries was done on purpose (only
3 retries and no more).

And this is how it looks BTW:
  $ gcc ../test/tinytest_demo.c ../test/tinytest.c
  $ ./a.out --verbose --no-fork
  demo/timeout_retry
  demo/timeout_retry:
    FAIL ../test/tinytest_demo.c:201: assert(i != 1): 1 vs 1
    [timeout_retry FAILED]

    [RETRYING timeout_retry (3)]
  demo/timeout_retry:
           OK ../test/tinytest_demo.c:201: assert(i != 1): 2 vs 1
           OK ../test/tinytest_demo.c:213: assert(t2-t1 >= 4): 5 vs 4
           OK ../test/tinytest_demo.c:215: assert(t2-t1 <= 6): 5 vs 6
  1 tests ok.  (0 skipped)

6 years agobufferevent: add debug messages when .setfd/.getfd/.enable/.disable failed
Azat Khuzhin [Mon, 19 Nov 2018 21:58:47 +0000 (00:58 +0300)]
bufferevent: add debug messages when .setfd/.getfd/.enable/.disable failed

6 years agohttp: improve error path for bufferevent_{setfd,enable,disable}()
Azat Khuzhin [Tue, 13 Nov 2018 21:20:20 +0000 (00:20 +0300)]
http: improve error path for bufferevent_{setfd,enable,disable}()

We have calls to the next functions but do not check return values,
though they can be invalid and it is better to show this somehow.

Also do bufferevent_setfd() first and only after it
bufferevent_enable()/bufferevent_disable() since:
a) it is more natural
b) it will avoid extra operations
c) it will not fail first bufferevent_enable() (this is the case for
   buffbufferevent_async at least)

In this case we could add more information for issues like #709

6 years agoregress_http: fix compilation with !EVENT__HAVE_OPENSSL
Azat Khuzhin [Tue, 20 Nov 2018 03:20:51 +0000 (06:20 +0300)]
regress_http: fix compilation with !EVENT__HAVE_OPENSSL

Fixes: 811c63f7 ("regress: test for HTTP/HTTPS with IOCP enabled")