3958 Commits

Author SHA1 Message Date
Azat Khuzhin
8483c5351a
evrpc: avoid NULL dereference on request is not EVHTTP_REQ_POST
Fixes: #660
2018-09-14 02:27:13 +03:00
Carlo Marcelo Arenas Belón
7af974eeaa
test: make sure pthread is defined
avoid warnings with any modern C99 compiler due to implicit function
declaration for pthread_create, as shown by the following :

test/regress_dns.c:2226:2: warning: implicit declaration of function
      'pthread_create' is invalid in C99 [-Wimplicit-function-declaration]
        THREAD_START(thread[0], race_base_run, &rp);
        ^
test/regress_thread.h:35:2: note: expanded from macro 'THREAD_START'
        pthread_create(&(threadvar), NULL, fn, arg)
        ^
test/regress_dns.c:2226:2: warning: this function declaration is not a prototype
      [-Wstrict-prototypes]
test/regress_thread.h:35:2: note: expanded from macro 'THREAD_START'
        pthread_create(&(threadvar), NULL, fn, arg)
        ^

$ clang --version
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Closes: #686 (cherry-picked)
2018-09-14 02:17:45 +03:00
Azat Khuzhin
29cc8386a2
appveyor: add all build tree into artifacts in case of failure
This will help in investigations of win32 failures...

P.S. looks like there is no better way, since
"artifacts.*.publish_on_failure" hadn't been implemented yet (while was
requiested in 2015).
2018-08-19 00:54:11 +03:00
Bogdan Harjoc
855f080430
dns-example: free result in getaddrinfo callback
According to evdns.c, the result not freed by libevent after
the callback runs:

evdns_getaddrinfo_gotresolve()
{
    ...
    data->user_cb(0, data->pending_result, data->user_data);
    data->pending_result = NULL;
    ...
}

To reproduce, build with -fsanitize=address, add -g to the getopt
list in dns-example.c like in the current commit and run

  dns-example -g google.com

Closes: #681 # cherry-picked
2018-08-17 03:22:28 +03:00
Philip Prindeville
be37116302
Eliminate compiler warnings (at least for gcc/linux)
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Closes: #646 # cherry-picked from the PR
2018-08-17 03:21:49 +03:00
Azat Khuzhin
ee12c516cf
Merge branch 'evdns_getaddrinfo-race-fix'
* evdns_getaddrinfo-race-fix:
  evdns: add regress test for getaddrinfo race
  evdns: fix race condition in evdns_getaddrinfo()

Merges: #673
2018-08-02 09:29:29 +03:00
Sergey Fionov
4802c132a2
evdns: add regress test for getaddrinfo race 2018-08-02 09:26:51 +03:00
Sergey Fionov
b59525ece4
evdns: fix race condition in evdns_getaddrinfo()
evdns_getaddrinfo() starts two parallel requests for A and AAAA record.
But if request is created from thread different from dns_base's, request of A record is
started immediately and may result in calling free_getaddrinfo_request() from
evdns_getaddrinfo_gotresolve() because `other_req' doesn't exist yet.

After that, request of AAAA record starts and finishes, and evdns_getaddrinfo_gotresolve()
is called again for structure that is already freed.

This commits adds locking into evdns_getaddrinfo() function.
2018-08-02 09:23:30 +03:00
Azat Khuzhin
e85818d248
Cleanup __func__ detection
First of all __func__ is not a macro, it is char[] array, so the code
that we had before in cmake, was incorrect, i.e.:
  #if defined (__func__)
  #define EVENT____func__ __func__
  #elif defined(__FUNCTION__)
  #define EVENT____func__  __FUNCTION__
  #else
  #define EVENT____func__ __FILE__
  #endif

So just detect do we have __func__/__FUNCTION__ in configure/cmake
before build and define EVENT__HAVE___func__/EVENT__HAVE___FUNCTION__
to use the later to choose which should be used as a __func__ (if it is
not presented).

Closes: #644
2018-08-02 02:50:48 +03:00
Azat Khuzhin
c3a6fe75e1
Merge branch 'official/pr/671' -- README cleanup
* official/pr/671:
  Capitalise project names consistently in README.md
  Indent configure flag section to make markdown format them as code
  Use https for resources that support it
  Rewords awkward sentences in README.md
  Fix typos in README.md
2018-08-01 09:48:42 +03:00
Azat Khuzhin
4728ffed86
autotools: include win32 specific headers for socklen_t detection on win32/mingw
The [1] removes EVENT__ prefix, and now if we will incorrectly detect
that "foobar" (or socklen_t in our case) type is not available, but
somewhere later it will be available then we will get next error [2]:
  error: two or more data types in declaration specifiers

According to [3]:
- Compile something in Cygwin and you are compiling it for Cygwin.
- Compile something in MinGW and you are compiling it for Windows.
  And I can confirm this, since there is _WIN32 defined (according to [4])

And since according to [5] our image in appveyour (Visual Studion 2015)
has mingw (and we use it, not cygwin) we need ws2tcpip.h (over
sys/socket.h -- which does not exist in win32) header to detect
socklen_t existence.

[1]: 587e9f5828c4eb3c6e79e9eb29f174e4ae0c05bd ("config.h can't be prefixed unconditionally")
[2]: https://ci.appveyor.com/project/nmathewson/libevent/build/job/yonukoc5q3tr3e5e#L372
[3]: https://stackoverflow.com/questions/771756/what-is-the-difference-between-cygwin-and-mingw
[4]: https://www.appveyor.com/docs/build-environment/#mingw-msys-cygwin
[5]: https://ci.appveyor.com/project/nmathewson/libevent/build/job/yonukoc5q3tr3e5e#L164

Fixes: #649
2018-08-01 09:30:54 +03:00
Aapeli
ee0c57993f
Capitalise project names consistently in README.md 2018-08-01 10:29:43 +10:00
Aapeli
72426ff433
Indent configure flag section to make markdown format them as code 2018-08-01 10:24:50 +10:00
Aapeli
a52bd1e37f
Use https for resources that support it 2018-08-01 10:21:57 +10:00
Aapeli
560d4f3296
Rewords awkward sentences in README.md 2018-08-01 10:20:28 +10:00
Aapeli
e5816df59e
Fix typos in README.md 2018-08-01 10:17:42 +10:00
Azat Khuzhin
bdd531288a
appveyor: disable almost all configurations (except autotools/cmake basic)
Since we have FREE plan, we have a lot of limits on our builds, so let's
reduce their amount to make them run/start faster (I hope).
2018-08-01 03:05:06 +03:00
Azat Khuzhin
0f04e9a401
vagrant/win32: reduce amount of threads
Otherwise I got:
    win:     855 [main] sh 840 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: /bin/sh: /usr/bin/sed: Input/output error
    win: /bin/sh: line 1: /bin/sh: Input/output error
    win:   CC       bufferevent_pair.lo
    win: /bin/sh: fork: Input/output error
    win: make[1]: *** [Makefile:1722: buffer.lo] Error 126
    win: make[1]: *** Waiting for unfinished jobs....
    win:   CC       bufferevent_ratelim.lo
    win:     176 [main] sh 2440 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: /bin/sh: fork: Input/output error
    win:       0 [main] sh 3684 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: ./libtool: fork: Input/output error
    win: make[1]: *** [Makefile:1722: bufferevent_filter.lo] Error 254
    win:       0 [main] sh 1356 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: ./libtool: fork: Input/output error
    win:       0 [main] sh 3640 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: ./libtool: line 922: /usr/bin/sed: Input/output error
    win: ./libtool: fork: Input/output error
    win:       0 [main] sh 3444 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win:       0 [main] sh 3796 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: ./libtool: fork: Input/output error
    win:     693 [main] sh 304 fork: child -1 - CreateProcessW failed for 'C:\tools\cygwin\bin\sh.exe', errno 5
    win: ./libtool: fork: Input/output error
    win: ./libtool: fork: Input/output error
    win: ./libtool: line 1377: /usr/bin/sed: Input/output error
    win: :   error: Failed to create '.libs'
2018-08-01 00:44:58 +03:00
Azat Khuzhin
9cd279c753
vagrant/win32: add missing aclocal 2018-08-01 00:28:48 +03:00
Xiaozhou Liu
30d77f1b59
Fix typo
Closes: #658
2018-07-30 00:50:32 +03:00
Nathan French
514dc7579c
[http] fix C90 warnings 2018-07-05 12:46:51 -04:00
Philip Prindeville
24236aed01
Tell Travis to use quiet git clone
Otherwise the logs show a bunch of pointless progress, which is
really only useful for interactive sessions.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Closes: #651 (cherry-picked)
2018-06-21 10:05:24 +03:00
Leo Zhang
d9ffd22137
test: make regress_dns C89 compatible
Closes: #635 (cherry-picked)
2018-06-21 03:07:55 +03:00
Azat Khuzhin
064a598716
Ignore evconfig-private.h for autotools
Fixes: e2874d95af584b3657eb5dc1d2e5404811dce117 ("Adopt ignore rules for
cmake + ninja")
2018-06-21 02:38:44 +03:00
Azat Khuzhin
35258a1f4e
Replace all EVENT_HAVE with EVENT__HAVE (EVENT__HAVE_USLEEP) 2018-06-19 10:19:40 +03:00
Philip Prindeville
d2acf67ec3
Add convenience macros for user-triggered events
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Closes: #647 (picked)
2018-06-18 03:13:12 +03:00
Philip Prindeville
755896efe2 Get rid of macros which are never used
There are no expansions of these macros or tests for their existence.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2018-06-16 17:04:05 -06:00
an-tao
0789bc5220
fix spelling mistakes
Closes: nmathewson/Libevent#162
2018-06-08 02:23:40 +03:00
Philip Prindeville
587e9f5828
config.h can't be prefixed unconditionally
The script make-event-config.sed was mangling all the symbols by
prefixing them with "EVENT__".  The problem here is that some
symbols aren't for local consumption within libevent, but rather
influence other system header files (ex: __USE_FILE_OFFSET64 is
used by dozens of header files including <sys/sendfile.h>).

As a workaround, all symbols starting with a capital letter only
(with the exception of STDC_HEADERS which must also be left
untouched) will be mangled.

Future contributors will need to be aware of this distinction.
2018-06-08 02:14:38 +03:00
Azat Khuzhin
c57f5c3490 Make rpc headers self-compilable
Fixes: #633
2018-05-07 02:40:16 +03:00
Nathan French
1619cc35e4
Merge pull request #632 from NathanFrench/realign_struct_event
Reorder fields in struct event for memory efficiency
2018-05-02 19:34:04 -04:00
Nathan French
1af8017648
[core] re-order fields in struct event for memory efficiency
The sizeof `struct event` can reduced on both 32 bit and 64 bit systems
by moving the 4 bytes that make up `ev_events` and `ev_res` below `ev_fd`,
before `struct event_base * ev_base;` since our compiler wouldn't dare do
such a thing (it instead will pad twice, whereas it only needs to be padded
once)

```C
struct event {
                                                         /*  OFFS |  SZ   Bytes  | Total Bytes | START - END  */
    struct event_callback ev_evcallback;                 /*   0x0 |  40          | 40          | 0x0   - 0x28 */

    union {                                              /*  0x28 |  ----------- | ----------- | ------------ */
        TAILQ_ENTRY(event) ev_next_with_common_timeout;  /*       |       ((16)) |             |              */
        int min_heap_idx;                                /*       |       ((04)) |             |              */
    }   ev_timeout_pos;                                  /*       |  16          | 56          | 0x28  - 0x38 */
    int ev_fd;                                           /*  0x38 |  04          | 60          | 0x38  - 0x3c */
```

Since the next field is 8 bytes in length, and we are up to 60 bytes, `ev_fd` ends up being padded (4 more bytes on 64b).

```C
                              /* --- 1 byte gap HERE --->            1           | <61>                      */
                              /* --- 1 byte gap HERE --->            1           | <62>                      */
                              /* --- 1 byte gap HERE --->            1           | <63>                      */
                              /* --- 1 byte gap HERE --->            1           | <64>                      */
    struct event_base * ev_base;                         /*  0x3c |  8           | 68         | 0x3c - 0x40  */
    union {                                              /*  0x40 | ------------ | ---------- | ------------ */
        struct {                                         /*       | ------------ |            |              */
            LIST_ENTRY (event) ev_io_next;               /*       |       ((16+  |            |              */
            struct timeval ev_timeout;                   /*       |         16)) |            |              */
        } ev_io;                                         /*       | ((32))       |            |              */
        struct {                                         /*       | ------------ |            |              */
            LIST_ENTRY (event) ev_signal_next;           /*       |      ((16+   |            |              */
            short   ev_ncalls;                           /*       |        02+   |            |              */
            short * ev_pncalls;                          /*       |        08))  |            |              */
        } ev_signal;                                     /*       | ((26))       |            |              */
    } ev_;                                               /*  0x60 | 32           | 100        | 0x40 - 0x60  */

    short ev_events;                                     /*  0x60 | 2            | 102        | 0x60 - 0x62  */
    short ev_res;                                        /*  0x62 | 2            | 104        | 0x62 - 0x64  */
```

We now hit another line, `struct timeval` is 16 bytes on 64b arch, so we have 4 more bytes
of padding on `ev_res`.

```C
    /* --- 1 byte gap HERE --- */
    /* --- 1 byte gap HERE --- */
    /* --- 1 byte gap HERE --- */
    /* --- 1 byte gap HERE --- */
    struct timeval ev_timeout;                           /*  0x64 | 16           | 120        | 0x64 - 0x74  */
};
```

After moving `ev_events` and `ev_res` below `ev_fd` we have something
a bit more optimal:

```C
struct event2 {
                                                         /*  OFFS |  SZ / Bytes  | RSUM Bytes | START - END  */
    struct event_callback ev_evcallback;                 /*   0x0 | 40           | 40         | 0x0   - 0x28 */
    union {                                              /*  0x28 | ------------ | ---------- | ------------ */
        TAILQ_ENTRY(event) ev_next_with_common_timeout;  /*       |       ((16)) |            |              */
        int min_heap_idx;                                /*       |       ((04)) |            |              */
    } ev_timeout_pos;                                    /*       | 16           | 56         | 0x28  - 0x38 */
    int ev_fd;                                           /*  0x38 | 4            | 60         | 0x38  - 0x3c */
    short ev_events;                                     /*  0x3c | 2            | 62         | 0x3c  - 0x3e */
    short ev_res;                                        /*  0x3e | 2            | 64         | 0x3e  - 0x40 */

    struct event_base * ev_base;                         /*  0x40 | 8            | 74         | 0x40  - 0x48 */
    union {                                              /*  0x48 | ------------ | ---------- | ------------ */
        struct {                                         /*       | ------------ |            |              */
            LIST_ENTRY (event) ev_io_next;               /*       |        ((16+ |            |              */
            struct timeval ev_timeout;                   /*       |         16)) |            |              */
        } ev_io;                                         /*       | ((32))       |            |              */
        struct {                                         /*       | ------------ |            |              */
            LIST_ENTRY (event) ev_signal_next;           /*       |       ((16+  |            |              */
            short   ev_ncalls;                           /*       |         02+  |            |              */
            short * ev_pncalls;                          /*       |         08)) |            |              */
        } ev_signal;                                     /*       | ((26))       |            |              */
    } ev_;                                               /*       | 32           | 106        | 0x48 - 0x68  */
    struct timeval ev_timeout;                           /* 0x68  | 16           | 120        | 0x68 - 0x78  */
};
```

We still have a gap here, but the first was removed.

Again, we can save 8 bytes on both 32 and 64 word sizes (32/64 byte cacheline).

Below are the results for testing v2.1.6 -> master -> master + this patch (Release/-O3)

Code:

```C
  #include <event2/event.h>

  int
  main(int argc, char ** argv) {
      printf("%zu\n", event_get_struct_event_size());
      return 0;
  }
```

Branch: `master` (2.2.x)

```
  $ gcc -O3 -Wall -Wl,-R/usr/local/lib bleh.c -L/usr/local/lib -o bleh  -levent
  $ ldd bleh
      linux-vdso.so.1 =>  (0x00007ffc3df50000)
      libevent.so.2.2.0 => /usr/local/lib/libevent.so.2.2.0 (0x00007f91fd781000)
      libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f91fd3a1000)
      libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f91fd182000)
      /lib64/ld-linux-x86-64.so.2 (0x00007f91fdbcc000)
  $ ./bleh
  128
```

Release: `2.1.6`

```
  $ gcc -O3 bleh.c -o bleh  -levent
  $ ldd bleh
      linux-vdso.so.1 =>  (0x00007ffd43773000)
      libevent-2.1.so.6 => /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6 (0x00007feb3add6000)
      libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007feb3a9f6000)
      libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007feb3a7d7000)
      /lib64/ld-linux-x86-64.so.2 (0x00007feb3b22a000)
  $ ./bleh
  128
```

Branch: `this one`

```
  $ gcc -O3 -Wl,-R./lib bleh.c -o bleh -L./lib -levent
  $ ldd bleh
      linux-vdso.so.1 =>  (0x00007ffff55f7000)
      libevent.so.2.2.0 => ./lib/libevent.so.2.2.0 (0x00007ff8e5c82000)
      libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff8e58a2000)
      libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff8e5683000)
      /lib64/ld-linux-x86-64.so.2 (0x00007ff8e60cd000)
  $ ./bleh
  120
```
2018-04-30 18:13:45 -04:00
Azat Khuzhin
23c2914f6b Notify event base if there are no more events, so it can exit without delay
Fixes: #623
2018-04-26 01:14:49 +03:00
Azat Khuzhin
accf383e04 Fix CheckFunctionExistsEx() cmake macro on win32
For example under mingw64 it could not detect that strtok_r() exists,
because it checks with:
  void *p = func_name;

And for this you need the function to be defined, so just sync our
CheckFunctionExistsEx.c with CheckFunctionExists.c from cmake (and later
we should drop them out) since it does correct things to detech
functions existence.

Also for WIN32 there is -FIwinsock2.h -FIws2tcpip.h, and I guess that is
not works for mingw gcc (since -F in gcc is framework, and in windows
-FI is like -include in gcc). But looks like we do not need them
already (due to fixed CheckFunctionExistsEx()).

Refs: #605
2018-04-26 01:14:49 +03:00
Azat Khuzhin
d1c8993c3c test/dns: install correct RLIMIT_NOFILE in bufferevent_connect_hostname_emfile
Otherwise poll() will fail with EINVAL:
       EINVAL The nfds value exceeds the RLIMIT_NOFILE value.

P.S. and cleanup this test a little, with early-return.

CI: https://travis-ci.org/libevent/libevent/jobs/370350426
2018-04-24 14:47:58 +03:00
Azat Khuzhin
da028dec49 travis-ci: allow tests under osx to fail (temporary, until we will fix them) 2018-04-24 02:56:42 +03:00
Azat Khuzhin
e4edc7fc27 test/http: cover evhttp_connection_get_addr() for incomming connections
Refs: #510
2018-04-24 02:46:39 +03:00
Greg Hazel
367cd9e5c2 Fix evhttp_connection_get_addr() fox incomming http connections
Install conn_address of the bufferevent on incomping http connections
(even though this is kind of subsytem violation, so let's fix it in a
simplest way and thinkg about long-term solution).

Fixes: #510
Closes: #595 (pick)
2018-04-24 02:29:17 +03:00
Azat Khuzhin
a3d8f2e093 test/dns: verify bufferevent_socket_connect() errorcb invoking if socket() fails
Refs: #600
2018-04-24 02:05:30 +03:00
Jesse Fang
f7bc133797 bufferevent_socket_connect{,_hostname}() missing event callback and use ret code
- When socket() failed in bufferevent_socket_connect() , the event
  callback should be called also in
  bufferevent_socket_connect_hostname().  eg. when use
  bufferevent_socket_connect_hostname() to resolve and connect an IP
  address but process have a smaller ulimit open files, socket() fails
  always but caller is not notified.

- Make bufferevent_socket_connect()'s behavior more consistent: function
  return error then no callback, function return ok then error passed by
  event callback.

Fixes: #597
Closes: #599
Closes: #600
2018-04-24 02:05:30 +03:00
Azat Khuzhin
623ef3ccdc test/dns: cleanup test_bufferevent_connect_hostname() 2018-04-24 02:05:30 +03:00
Azat Khuzhin
a5f19422fd Merge branch 'pull-628'
* pull-628:
  Give priority to the build directory headers
  Do not ship evconfig-private.h in dist archive

Closes: #628
2018-04-23 00:52:57 +03:00
Cristian Morales Vega
5d74565a96 Give priority to the build directory headers
Not changing anything right now AFAIK. But if for any reason in the
future we end up with two headers with the same name in the source and
build directories, chances are we want to use the one in the build
directory.
2018-04-23 00:52:10 +03:00
Cristian Morales Vega
0379eb4b5d Do not ship evconfig-private.h in dist archive
It will be generated by autotools, so there is not reason to include it.
And infact this breaks compilation with out-of-tree builds (VPATH),
since, for the quote form of the include directive, headers in the
directory of the file with the #include line have priority over those
named in -I options, the copy of evconfig-private.h from the source
directory had priority over the one in the build directory.
2018-04-23 00:52:10 +03:00
Azat Khuzhin
e2874d95af Adopt ignore rules for cmake + ninja
In case we have build directory differs from source directory there will be
bunch of files we should ignore, so just remove leading "/" for some or rules.
And fix others.
2018-04-23 00:38:19 +03:00
SuckShit
ab3224c3e6 Fix assert() condition in evbuffer_drain() for IOCP
In the case of iocp, in the for loop above, there is a situation where:
  remaining == chain->off == 0

And this happens due to CHAIN_PINNED_R() case (that is used only in
buffer_iocp.c)

Closes: #630 (picked)
2018-04-22 13:27:40 +03:00
The Gitter Badger
ba78ba9e8b Add Gitter badge 2018-04-16 02:10:59 +03:00
Philip Herron
0fa43c99fb cmake: ensure windows dll's are installed as well as lib files
Closes: #621
2018-04-09 00:15:03 +03:00
dpayne
791e3de0c3 Generating evdns_base_config_windows_nameservers docs on all platforms 2018-04-03 15:43:22 -07:00
dpayne
2c1562949c Fixing doxygen docs for evdns_base_search_clear when generated on non-windows machines 2018-04-03 15:17:51 -07:00