diff options
author | kikht <kikht@yandex-team.ru> | 2022-02-10 16:45:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:14 +0300 |
commit | 194cae0e8855b11be2005e1eff12c660c3ee9774 (patch) | |
tree | ed29c437b616690880c017855ebe0be34fdf81a2 /contrib/libs/libevent | |
parent | 49116032d905455a7b1c994e4a696afc885c1e71 (diff) | |
download | ydb-194cae0e8855b11be2005e1eff12c660c3ee9774.tar.gz |
Restoring authorship annotation for <kikht@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/libevent')
105 files changed, 18185 insertions, 18185 deletions
diff --git a/contrib/libs/libevent/ChangeLog b/contrib/libs/libevent/ChangeLog index 17874b14b9..180832cabe 100644 --- a/contrib/libs/libevent/ChangeLog +++ b/contrib/libs/libevent/ChangeLog @@ -79,1312 +79,1312 @@ Changes in version 2.1.12-stable (05 Jul 2020) o Change the minimum version of automake to 1.13 and autoconf to 2.67 (fdb8fb66 ygj6) o Add Uninstall.cmake.in into dist archive (877f2355 Azat Khuzhin) -Changes in version 2.1.11-stable (01 Aug 2019) - - This release contains one ABI breakage fix (that had been introduced in - 2.1.10, and strictly speaking this release breaks ABI again to make it - compatible with 2.1.9 and less, please take a look at 18104973 for more - details). Apart from that it contains some bug fixes, that grouped below. - - And even though the return value for evbuffer_setcb() had been changed it - should ABI compatible (anyway that function is in -compat.h header). - - There is also one patch that introduce new functionality, this is 546a366c, - to tune SO_RCVBUF/SO_SNDBUF in evdns, but one can count it as a bug-fix on - the application level, since before you cannot tune this settings and hence - you could stumble on problems. - - ABI breakage: - o Protect min_heap_push_ against integer overflow. (8c899768 Tobias Stoeckmann) - o Revert "Protect min_heap_push_ against integer overflow." (18104973 Azat Khuzhin) - - functionality: - o evdns: add new options -- so-rcvbuf/so-sndbuf (546a366c Azat Khuzhin) - - build: - o Change autoconf version to 2.62 and automake version to 1.11.2 (2a333008 yuangongji) - o cmake: install shared library only if it was requested (596855f7 Azat Khuzhin) - o Missing <winerror.h> on win7/MinGW(MINGW32_NT-6.1)/MSYS (9559349c yuangongji) - o cmake: set library names to be the same as with autotools (305251b9 yuangongji) - o Enable _GNU_SOURCE for Android (f013fc7d Keith Smiley) - o Enable kqueue for APPLE targets (3aa68a82 Keith Smiley) - o autotools: do not install bufferevent_ssl.h under --disable-openssl (5349a07e Azat Khuzhin) - o cmake: link against shell32.lib/advapi32.lib (c9ce638c Azat Khuzhin) - o Add README.md into dist archive (3660a4cc Azat Khuzhin) - o cmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py) (2d65071c yuangongji) - o m4/libevent_openssl.m4: fix detection of openssl (d4056e59 Fabrice Fontaine) - o Fix detection of the __has_attribute() for apple clang [ci skip] (7fd7c5ef Azat Khuzhin) - - lib: - o buffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM (598f247d Azat Khuzhin) - o Warn if forked from the event loop during event_reinit() (b75922ae Azat Khuzhin) - o evutil: set the have_checked_interfaces in evutil_check_interfaces() - (ef498aa2, a09265ac jeremyerb) - - samples: - o https-client: correction error checking (a8a04565 wenyg) - - -Changes in version 2.1.10-stable (26 May 2019) - - This release contains mostly fixes (some evbuffer oddity, AF_UNIX handling in - http server, some UB fixes and others) but also some new functionality - (without ABI breakage as usual) and now dist archive can be used for building - on windows (getopt had been added into it). - - Above you will find changelog for this particular release (but with some - trivial fixes pruned out from it - to make it a little bit more informative). - - To view full changelog please use git: - git log --format=' o %s (%h %aN)' release-2.1.9-beta...release-2.1.10-stable - - dist: - o Add getopt into dist archive (7042ff24 Azat Khuzhin) - - functionality: - o evdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT - (58e81106 Azat Khuzhin) - o Add support for EV_TIMEOUT to event_base_active_by_fd (3f893f0a John Ohl) - - fixes: - o Merge branch 'evbuffer-fixes-806-v2' (2fea04b3 Azat Khuzhin) - o Merge branch 'issue-807-accept4-getnameinfo-AF_UNIX' (7c4da937, e2790a7f - Azat Khuzhin) - o kqueue: Avoid undefined behaviour. (e70e18e9 Tobias Stoeckmann) - o Prevent integer overflow in kq_build_changes_list. (43a55a23 Tobias Stoeckmann) - o evdns: fix lock/unlock mismatch in evdns_close_server_port() (54103883 zhuizhuhaomeng) - o Merge remote-tracking branch 'official/pr/804' -- Enforce limit of NSIG - signals (87fa93a8 Tobias Stoeckmann) - o Protect min_heap_push_ against integer overflow. (0b46bb8c Tobias Stoeckmann) - o le-proxy: initiate use of the Winsock DLL (2a1e1530 linxiaohui) - o Fix leaks in error path of the bufferevent_init_common_() (bb0f8fe7 Azat Khuzhin) - o buffer: make evbuffer_prepend() of zero-length array no-op (61fa7b7d Azat Khuzhin) - o Merge branch 'evbuffer-empty-chain-handling' (6a3dd717 Azat Khuzhin) - o Don't loose top error in SSL (3d1a7a1d Yury Korzhetsky) - o Remove needless check for arc4_seeded_ok (6602a97d Seong-Joong Kim) - o Merge pull request #769 from sungjungk/fix-return-handling (91084140 Nathan French) - - build: - o Define `_GNU_SOURCE` properly/consistently per autoconf (00ba9fa2 Enji Cooper) - o signal: guard __cdecl definition with #ifdef (d89045a6 Azat Khuzhin) - o Link test/regress with event_core/event_extra over event (22380996 Azat Khuzhin) - - tests: - o Use kill() over raise() for raising the signal (fixes osx 10.14 with - kqueue) (3db5296b, a45f6733 Azat Khuzhin) - o tinytest: implement per-test timeout (via alarm() under !win32 only) - (b64dbfb6, 75d7e1ff Azat Khuzhin) - -Changes in version 2.1.9-beta (10 February 2019) - - This changelog will differs from other releases in the next few clauses: - - contains only highlighted changes (so now it will not contains a lot of - patches that fixes some stuff in regression tests, typos, leaks fixes in - samples and so forth) - - no authors (since merge commits breaks them anyway, but AUTHORS sections in - README will be kept up to date) - - group name trimmed from commit subjects trimmed - - it's been 2 years since the previoius release, so it is pretty huge - - And I think that this is more useful, so from now on it will always has the - same look (until there will too many objections of course). - - To view full changelog please use git: - git log --format=' o %s (%h %aN)' release-2.1.8-stable...release-2.1.9-beta - - - dist archive: - o Add cmake rules into dist archive (bf3a67cf) - o Add missing print-winsock-errors.c into dist archive (822d6462) - o Include openssl-compat.h into dist archive (08658136) - - core: - o Merge branch 'check-O_NONBLOCK-in-debug' (a39898f3, a8155c62) - o Merge branch 'event-ET-#636-v2' (ca4b6404) - o Fix visibility issues under (mostly on win32) - (349081e1g, 802be13ag, a1f28e2f) - o Define __EXT_POSIX2 for QNX (a2176f2c) - o Cleanup __func__ detection (b3af7bdd) - o Add convenience macros for user-triggered events (06ec5de6) - o Notify event base if there are no more events, so it can exit without delay (d9d1c09e) - o Fix base unlocking in event_del() if event_base_set() runned in another thread (4f0f40e3) - o If precise_time is false, we should not set EVENT_BASE_FLAG_PRECISE_TIMER (27dee54d) - o Fix race in access to ev_res from event loop with event_active() (43d92a6d) - o Return from event_del() after the last event callback termination (876c7ac7) - - http: - o Merge branch 'http-EVHTTP_CON_READ_ON_WRITE_ERROR-fixes-v2' (eb7b472b) - o Preserve socket error from listen across closesocket cleanup (2ccd00a6) - o fix connection retries when there more then one request for connection (d30e7bba) - o improve error path for bufferevent_{setfd,enable,disable}() (a8cc449e) - o Fix conceivable UAF of the bufferevent in evhttp_connection_free() (6ac2ec25) - o Merge branch 'http-request-line-parsing' (cdcfbafe) - o Fix evhttp_connection_get_addr() fox incomming http connections (4215c003) - o fix leaks in evhttp_uriencode() (123362e9) - o CONNECT method only takes an authority (7d1ffe64) - o Allow bodies for GET/DELETE/OPTIONS/CONNECT (23eb38b9) - o Do not crash when evhttp_send_reply_start() is called after a timeout. (826f1134) - o Fix crashing http server when callback do not reply in place (5b40744d, b2581380) - o fix handling of close_notify (ssl) in http with openssl bufferevents (7e91622b) - - evrpc: - o use *_new_with_arg() to match function prototype (a95cc9e3) - o avoid NULL dereference on request is not EVHTTP_REQ_POST (e05136c7) - - regression tests: - o Merge branch 'TT_RETRIABLE' (6ea1ec68, f9b592aa) - - bufferevent: - o Merge branch 'iocp-fixes' (6bfac964) - o Merge branch 'be-wm-overrun-v2' (3f692fff) - o bufferevent_socket_connect{,_hostname}() missing event callback and use ret code (1dde74ef) - o don't fail be_null_filter if bytes are copied (b92b0792) - o Call underlying bev ctrl GET_FD on filtered bufferevents (ebfac517) - - bufferevent_openssl/openssl: - o Merge branch 'ssl_bufferevent_wm_filter-fix' (30020a35) - o be_openssl: avoid leaking of SSL structure (e86ccfe5) - o Fix build with LibreSSL 2.7 (894ca48a) - o Add missing includes into openssl-compat.h (01bc36c1) - o Explicitly call SSL_clear when reseting the fd. (29b7a516) - o Unbreak build with LibreSSL after openssl 1.1 support added (230af9f0) - - samples: - o Merge branch 'sample-http-server' (b6309bcc) - o sample/https-client: use host SSL certificate store by default (5c0132f3) - - listener: - o ipv6only socket bind support (ba148796) - o Merge branch 'listener-immediate-close' (df2ed13f) - o Merge branch 'evconnlistener-do-not-close-client-fd' (42e851bb) - - evdns: - o evdns: handle NULL filename explicitly (0033f5cc) - o Merge branch 'evdns_getaddrinfo-race-fix' (3237d697) - o Generating evdns_base_config_windows_nameservers docs on all platforms (3bd2ce43) - - utils: - o Merge branch 'evutil_found_ifaddr-dev' (b07e43e6) - o Avoid possible SEGVs in select() (in unit tests) (8818c86c) - o Port `event_rpcgen.py` and `test/check-dumpevents.py` to Python 3. (532a8cc3) - - buffer: - o Fix assert() condition in evbuffer_drain() for IOCP (d6326104) - o fix incorrect unlock of the buffer mutex (for deferred callbacks) (2b4d127d) - o Fix wrong assert in evbuffer_drain() (9f4d0dce) - - cmake: - o fix checking of devpoll backend (like in autotools, by devpoll.h existence) (7f161902) - o support static runtime (MSVC) (c8b3ec17, 61fb055a) - o do not build both (SHARED and STATIC) for MSVC/win32 (bc7f2fd9) - o introduce EVENT__LIBRARY_TYPE option (eb10a738) - o ensure windows dll's are installed as well as lib files (29590718) - o Fix generation of LibeventConfig.cmake for the installation tree (7fa08c4b) - o fix pkgconfig generation (copy-paste typo) (cc554d87) - o Merge branch 'cmake-missing-bits' (9806b126) - o Fix detection of timerfd_create() in CMake. (e50af331) - o Merge branch 'cmake-configure-fixes-v2' (a0bfe2c4) - o Do not add epoll_sub (syscall wrappers) for epoll in cmake (cea61de6) - o Fix RPATH for APPLE (45b1f379) - - autotools: - o include win32 specific headers for socklen_t detection on win32/mingw (d7579fb9) - o Ignore evconfig-private.h for autotools (37423849) - o config.h can't be prefixed unconditionally (63a054f8) - o Merge branch 'pull-628' (7e56c8b2) - o Provide Makefile variables LIBEVENT_{CFLAGS,CPPFLAGS,LDFLAGS} (2f060c5f) - o confirm openssl is working before using (b39ccf8e) - o pass $(OPENSSL_INCS) for samples (FTBFS macOS) (c2495265) - o Add configure check for midipix (d433201e) - o Fix tests with detached builds (c46ff439) - - build: - o Fix arc4random_addrandom() detecting and fallback (regression) (303d6d77) - o Merge branch 'win32-fixes' (ebd12e6d) - o Merge branch 'fix-openssl-linking' (e7bd9e03) - o Merge branch 'fix-struct-linger' (8567f2f5) - - CI: - o travis-ci/appveyor now uses fast_finish+allow_failures - (5e97b6e6, dd472e7d, dfb5fc167) - o Merge branch 'travis-ci-osx-fixes' (9f02b39c) - o Merge branch 'win64-fixes' (aee0fcd5) - - -Changes in version 2.1.8-stable (22 January 2017) - - Libevent 2.1.8-stable, it contains openssl fixes for resetting fd and using - bufferevent_openssl_filter_new(). vagrant fixes, some build fixes, increased - timeout for some tests (to reduce number of failures due to timing issues), - date in RFC1123 format and running tests in parallel. - - There are highlighted changes above. - - Build fixes: - o Fix _FILE_OFFSET_BITS redinition (solaris/autotools) (336f3b11 Azat Khuzhin) - o util-internal: fix __func__ redefinition (netbsd) (253e7fa9 Azat Khuzhin) - o Fix signedness differ for iov_base (solaris) (2c62062e Azat Khuzhin) - o evutil_time: include <unistd.h> when there is only sleep()/usleep() (3e75194c Azat Khuzhin) - o http: fix formatter for pritnf for req->ntoread (osx) (1cbf26f6 Azat Khuzhin) - Testing environment: - o Merge branch 'automake-tests-parallel-v4' (*includes ci bits also*) (59e217df Azat Khuzhin) - Vagrant env fixes: - o vagrant/netbsd: missing libtool (9c9be399 Azat Khuzhin) - o vagrant/netbsd: more reliable way of installing packages (36da6877 Azat Khuzhin) - o vagrant/osx: use make instead of gmake (there is no gmake) (f7c70aef Azat Khuzhin) - o vagrant: add centos box (ca591c5b Azat Khuzhin) - Tests: - o test/dns: replace servname since solaris does not have "http" (d6bafbbe Azat Khuzhin) - o test/thread: netbsd is too slow, increase timeout for conditions_simple (3c7422fc Azat Khuzhin) - o test/dns: run async resolving after sync one (to avoid timeouts) (07862531 Azat Khuzhin) - o test/http: turn off some tests that based on backlog filling (falky) (26f416c1 Azat Khuzhin) - Bugfixes: - o Merge branch 'openssl-filter-fixes-v4' (83e0f43b Azat Khuzhin) - o Merge branch 'date-rfc1123' (68def435,4798de6c,4545807d Azat Khuzhin) - o Merge branch 'be-openssl-fd-reset-fix-v2' (86fa0070,32adf434 Azat Khuzhin) - o Merge branch 'openssl-1.1-init-fixes-v2' (18a161f0 Azat Khuzhin) - o Fix incorrect MIME type (23f9a20e johnsonlee) - Trivial fixes: - Documentation updates: - o Update README.md (3821cca1 Breaker) - - -Changes in version 2.1.7-rc (2 Novemer 2016) - - Libevent 2.1.7-rc contains openssl 1.1 support, build fixes, CI improvements - and plus Vagrantfile for testing under multiple OS'es. - - - Continious Integration: - o Use coveralls.io via travis (9ac000c Azat Khuzhin) - o travis-ci: use container-based infrastructure (7e12e96 Azat Khuzhin) - o travis-ci/osx: fix compiling/linking openssl libraries (9d2f8d4 Azat Khuzhin) - o travis-ci: use gcc-5 (fixes osx|gcc failures) (d7ceae5 Azat Khuzhin) - o Testing with vagrant for 6 OS and cmake+autoconf (9585338 Azat Khuzhin) - o travis-ci/osx: install lcov (e4e099b Azat Khuzhin) - - Build Improvements/Fixes: - o Fix cmake -DEVENT__COVERAGE=ON (40fbffc Azat Khuzhin) - o autogen.sh: learn about gmake (9376ac4 Azat Khuzhin) - o autogen.sh: remove all autoconf/automake caches, if any (69cce25 Azat Khuzhin) - o cmake: fix finding python2, and check that it is really 2 (3453c08 Azat Khuzhin) - o cmake: fix CheckFunctionExistsEx/CheckPrototypeDefinition (CMP0054) (43b69b2 Azat Khuzhin) - o cmake: cleanup (dc624ad Zonr Chang) - o cmake/win32: fix running regress, but fixing finding python2 interpreter (bcb990a Azat Khuzhin) - o cmake: use PYTHON_EXECUTABLE to find python2 (a4d044c Azat Khuzhin) - o Merge branch 'force-disable-clockgettime' (83c7cdf Azat Khuzhin) - - Code Improvements (core) - o use ev_uint16_t instead of unsigned short for port (e983712 Thomas Bernard) - o Merge branch 'contrib-guide-v2' (b9c5077 Azat Khuzhin) - o poll: Prevent libevent from spinning if POLLNVAL occurs (675974c Tim Hentenaar) - - Testing: - o test/regress: cover a polling of invalid fd (cb0df5c Tim Hentenaar) - - Code Improvements (bufferevent_openssl) - o Make it build using OpenSSL 1.1.0 (3e9e0a0 Kurt Roeckx) - o Don't call BIO_number_{read|written} on NULL BIOs. (6702da1 Adam Langley) - o Switch from a 512 to 2048-bit RSA key. (f9803a6 Adam Langley) - - Trivial fixes: - o Ignore temporary configure files (8fb08ae Azat Khuzhin) - o README.md: fix typo: ar -> are (2361616 Simone Basso) - o be: just a simple mistake, reinclude the <errno.h> (7521664 Seven) - -Changes in version 2.1.6-beta (4 July 2016) - - Libevent 2.1.6-beta contains mostly bug fixes (evbuffers, evthread, evdns, - bufferevents, core, http, samples), improvements but mostly to fix some - possible issues (EVHTTP_CON_LINGERING_CLOSE), a lot of new unit tests and new - appveyor integration. - - Security Fixes (utils) - o evutil_parse_sockaddr_port(): fix buffer overflow (329acc1 Azat Khuzhin) - - Security Fixes (evdns) - o evdns: name_parse(): fix remote stack overread (96f64a0 Azat Khuzhin) - o evdns: fix searching empty hostnames (ec65c42 Azat Khuzhin) - - New APIs (evdns) - o New function to get address for nameserver. (537177d Nick Mathewson) - - New APIs (bufferevents) - o expose bufferevent_incref/decref (with fewer modifications) (1ed6718 Mark Ellzey) - - New APIs (internal) - o evdns: export cancel via callbacks in util (like async lib core/extra issues) (8cbe65d Azat Khuzhin) - - New APIs/Improvements (http) - o http: take EVHTTP_CON_LINGERING_CLOSE into account for "Expect: 100-Continue" (ac448a7 Azat Khuzhin) - o http: lingering close (like nginx have) for entity-too-large (9fde518 Azat Khuzhin) - o http: read server response even after server closed the connection (680742e Azat Khuzhin) - o http: export evhttp_connection_set_family() (714fc70 Azat Khuzhin) - o http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR (a50f5f0 Azat Khuzhin) - o http: use IP address that we got before (if any) during retrying (54c887d Azat Khuzhin) - - Bugfixes (core) - o Fix getaddrinfo under solaris (for multiprotocol case) (40730ae Azat Khuzhin) - o Check for Mac OS X 10.4 kqueue bug properly (df6f99e Mark Mentovai) - o event_reinit: make signals works after fork() without evsig_add() (88640aa Nicholas Marriott) - o event_reinit: always re-init signal's socketpair (ad0c237 Nicholas Marriott) - o Free event queues even for recursive finalizers (7c8d015 Azat Khuzhin) - o Fix checking for make_base_notifiable() (f337296 Azat Khuzhin) - o Set correct socklen for PF_INET6 sockaddr len (3499ad9 Mark Ellzey) - o Fix garbage value in socketpair util function, stdint? (043ae74 Mark Ellzey) - o fix the return value of event_deferred_cb_schedule_ (38cef64 Greg Hazel) - o event_free_debug_globals_locks(): disable lock debugging (e5c87d1 Azat Khuzhin) - o event: call event_disable_debug_mode() in libevent_global_shutdown() (941faae Azat Khuzhin) - o ht-internal: don't reset hth_table_length explicitly in name_##HT_CLEAR (597c7b2 Azat Khuzhin) - - Bugfixes (evthread) - o evthread: fix evthread_setup_global_lock_() for debug-lock with a real-lock case (e4556fc Azat Khuzhin) - o evthread: evthreadimpl_disable_lock_debugging_() for libevent_global_shutdown() (ccc5593 Azat Khuzhin) - - Bugfixes (evdns) - o evdns: avoid double-free in evdns_base_free() for probing requests (4db15e0 Azat Khuzhin) - o evdns: evdns_base_free(): fix UAF of evdns_base with @fail_requests (00313c5 Azat Khuzhin) - o evdns: evdns_base_free(): free requests before namservers (14f84bb Azat Khuzhin) - o evdns: fix randomize-case by make case-insensitive as required (9c238de Azat Khuzhin) - - Bugfixes (bufferevents) - o be_sock: handle readv() returns ECONNREFUSED (freebsd 9.2) (3189eb0 Azat Khuzhin) - o be_filter: avoid data stuck under active watermarks (b627ad8 Eduardo Panisset) - o Fix bufferevent_pair to properly set BEV_EVENT_{READING,WRITING} on flush. (2851889 David Paschich) - o be_openssl: clear all pending errors before SSL_*() calls (38e0f4a Azat Khuzhin) - o be_sock: cancel in-progress dns requests (86dfd2c Azat Khuzhin) - o be_sock: unfreeze buffers on fd changing (255525d Azat Khuzhin) - o be_sock: bufferevent_socket_connect_hostname(): make it thread-safe (809bb39 Azat Khuzhin) - o be_openssl: don't call do_write() directly from outbuf_cb (da52933 Azat Khuzhin) - o be_openssl: use bufferevent_enable() instead of bufferevent_add_event_() (0c66d32 Azat Khuzhin) - o be_openssl: don't add events during bev creation (like be_sock) (f4b6284 Azat Khuzhin) - o Fix lock leak in be_pair_flush() if flush type is BEV_NORMAL (f45d39d Bill Vaughan) - o be_openssl: don't use *_auto() in do_handshake() we can't have fd == -1 there (877280d Azat Khuzhin) - o be_openssl: don't call set_open_callbacks() if fd == -1 (e8a2da9 Azat Khuzhin) - o be_openssl: get rid off hackish "fd_is_set", to fix some corner cases (40b0379 Azat Khuzhin) - o be: we don't need to use getpeername() we we have conn_address (2c271e2 Azat Khuzhin) - o Call underlying bev ctrl SET_FD on filtered bufferevents (c2aa7dc Mark Ellzey) - o be_pair: release shared lock with the latest of bufferevent_pair (92a359e Azat Khuzhin) - - Bugfixes (http) - o [Issue #313] set method to ASCII "NULL" if evhttp_method() returns NULL (17cc636 Mark Ellzey) - o evhttp_have_expect(): fix -Wlogical-not-parentheses (24b5214 Azat Khuzhin) - o http: set fd to -1 unconditioally, to avoid leaking of DNS requests (7a4b472 Azat Khuzhin) - o http: avoid leaking of fd in evhttp_connection_free() (f0e1341 Azat Khuzhin) - o http: get fd from be layer during connection reset (4a53c54 Azat Khuzhin) - o http: fix EVHTTP_CON_READ_ON_WRITE_ERROR when it doesn't supported by OS (2ff164a Azat Khuzhin) - o http: do not do function calls under EVUTIL_ASSERT() to fix NDEBUG builds (7c89999 Azat Khuzhin) - o http: fix leaking of response_code_line (8f18a62 Azat Khuzhin) - o http: fix "Expect: 100-continue" client side (0b46b39 Azat Khuzhin) - o http: fix conflicts EVHTTP_CON_AUTOFREE and EVHTTP_CON_REUSE_CONNECTED_ADDR (4dc0979 Azat Khuzhin) - o http: avoid epoll_ctl() on already closed fd (triggers by http/chunk_out) (ab3bc69 Azat Khuzhin) - o http: install timeout for read too during connect for ssl (040000d Azat Khuzhin) - o http: fix evhttp_request_own() by checking EVHTTP_USER_OWNED in more cases (b0d3964 Azat Khuzhin) - o http: fix detecting EOF without write (7ed02ac Azat Khuzhin) - o evhttp: Fix failure to send all output data for POST/PUT requests (24eea0d John Ohl) - o Fix evhttp_uriencode() regression. (c6b1ec1 Mark Ellzey) - o removed unused vars (e94250c Mark Ellzey) - o pointer overflow checks for evhttp_uriencode (72afe4c Zonr Chang) - - Bugfixes (evbuffers) - o buffer: fix overflow check in evbuffer_expand_singlechain() (a3f4ccd Azat Khuzhin) - o buffer: evbuffer_add_buffer(): clean empty chains from destination buffer (26fd932 Azat Khuzhin) - o Fix n_add_for_cb in evbuffer_prepend() in case of new buffer required (0abd039 Azat Khuzhin) - o be_filter: actually disable output_filter during processing output (c031215 Simon Perreault) - o evbuffer_add: Use last_with_datap if set, not last. (a8769ef Marcus Sundberg) - o EVBUFFER_PTR_SET -> EVBUFFER_PTR_ADD (8674e4f jer-gentoo) - - Bugfixes (evconnlistener) - o listener: unlock lev on error in listener_read_cb() (2a71b33 Azat Khuzhin) - o Fix potential fd leak in listener_read_cb() (a695a72 Mark Ellzey) - - Testing - o tests: use waitpid(..., WNOWAIT) to fix failing of main/fork under solaris (43eb56c Azat Khuzhin) - o test: replace sleeping with syncing pair in main/fork (16d220c Azat Khuzhin) - o test/http: do not run tests that based on backlog filling (freebsd) (500b6b7 Azat Khuzhin) - o test/bufferevent/iocp: fix test name for "bufferevent_connect_fail_eventcb" (4410e9d Azat Khuzhin) - o test/ssl: use send()/recv()/EVUTIL_ERR_RW_RETRIABLE()/EVUTIL_SOCKET_ERROR() to fix win32 (a9e8cd6 Azat Khuzhin) - o test/https_basic: increase timeout for complete write (fixes win32) (d5a2f2f Azat Khuzhin) - o test: fix building with --disable-thread-support under win32 (a487706 Azat Khuzhin) - o test/buffer: evbuffer_add_buffer() with empty chains (a272bc4 Azat Khuzhin) - o test/buffer: evbuffer_remove_buffer() with empty chains (prepend) (f0cfa14 Azat Khuzhin) - o test/buffer: evbuffer_remove_buffer() with empty chains (evbuffer_add_buffer()) (2880ce6 Azat Khuzhin) - o test/buffer: cover evbuffer_expand() for overflow (48dab7a Azat Khuzhin) - o test/be_filter: creating test case for data stuck with active watermarks (766194b Eduardo Panisset) - o test/http: avoid using conditionals with omitted operands (fixes VS2015) (2a4bf29 Azat Khuzhin) - o test/http: don't mix declarations and code (fixes -Wdeclaration-after-statement) (aabf1c2 Azat Khuzhin) - o test/buffer: fix leak in test_evbuffer_prepend() (c08d90b Azat Khuzhin) - o test/buffer: avoid errors with --no-fork (reinitialize static vars) (e7d1e39 Azat Khuzhin) - o test/buffer: cover n_add_for_cb when evbuffer_prepend() need to allocate buffer (e77ff41 Azat Khuzhin) - o test/tinytest_macros: add new one tt_nstr_op() (bd19a28 Azat Khuzhin) - o test/bufferevent: check that output_filter disabled during processing output (ae28812 Azat Khuzhin) - o test/listener: regression for missing unlock in listener_read_cb() (7d85651 Azat Khuzhin) - o test/regress: add tests for evbuffer_add() breakage on empty last chain (d5ee739 Marcus Sundberg) - o test/http: fix running some tests sequential (with --no-fork) (bddad71 Azat Khuzhin) - o test/http: localize evhttp server structure (cbc3209 Azat Khuzhin) - o test/dns: regression for empty hostname (d7348ba Azat Khuzhin) - o test/http: fix SERVER_TIMEOUT tests under win32 (d49a658 Azat Khuzhin) - o test/http: add a helper for creating timedout/failed request (376f107 Azat Khuzhin) - o test/http: adopt for C90 (mixed code and declarations) (d02a285 Azat Khuzhin) - o test/http: cover NS timed out during request cancellations separatelly (0c343af Azat Khuzhin) - o test/http: request cancellation with resolving/{conn,write}-timeouts in progress (334340d Azat Khuzhin) - o test/http: exit from the loop in the errorcb to wait cancellation (927ab33 Azat Khuzhin) - o regress_clean_dnsserver(): reset global port vars (351207f Azat Khuzhin) - o test/http: read_on_write_error: fix it for win32 (3b58169 Azat Khuzhin) - o test/http: separate coverage for EVHTTP_CON_READ_ON_WRITE_ERROR (5c2b4c1 Azat Khuzhin) - o test/http: cover "Expect: 100-continue" client-server interaction (31d8116 Azat Khuzhin) - o test/http: *lingering tests shouldn't have "Expect: 100-continue" (ed469ab Azat Khuzhin) - o test: use EVUTIL_SHUT_WR (04fc82f Azat Khuzhin) - o test/http: avoid huge stack allocations to fix win32 builds (3166765 Azat Khuzhin) - o test: http/lingering_close: cover EVHTTP_SERVER_LINGERING_CLOSE (e122ca1 Azat Khuzhin) - o test: http/non_lingering_close: cover ~EVHTTP_SERVER_LINGERING_CLOSE (f41e1b0 Azat Khuzhin) - o test: http/*: update expected HTTP codes for body exceeds `max_body_size` (addf2b9 Azat Khuzhin) - o test: http/data_length_constrains: set EVHTTP_CON_READ_ON_WRITE_ERROR (d38a723 Azat Khuzhin) - o test: increase buffer size for http/data_length_constraints to trigger EPIPE (0792e1e Azat Khuzhin) - o test/tinytest_demo: include <windows.h> for win32 to fix tdm-gcc (f062bbe Azat Khuzhin) - o test/regress: cover event_del() waiting mechanism (5b58b70 Azat Khuzhin) - o test/regress: cover existing signal callbacks and fork() + event_reinit() (ceddc60 Azat Khuzhin) - o test/regress: cover signals after fork() + event_reinit() (b075b81 Azat Khuzhin) - o test/regress: main/fork: rewrite assertions by just removing event in callback (088d8b3 Azat Khuzhin) - o test/dns: check exit code of evdns_getaddrinfo() (0b9d432 Azat Khuzhin) - o test/dns: cover evdns_getaddrinfo() and evdns_base_free() with @fail_requests (4ad3483 Azat Khuzhin) - o test/dns: cover @fail_requests for evdns_base_free() (d6c6fb4 Azat Khuzhin) - o test/dns: more graceful coverage of @fail_requests (123d372 Azat Khuzhin) - o test/ssl: cover busy-loop (i.e. {read,write}-blocked-on-{write,read} stuff) (da0ea7a Azat Khuzhin) - o test/http: write_during_read for https (23c77b6 Azat Khuzhin) - o test/http: connection_fail for https (7ea26f7 Azat Khuzhin) - o test/http: stream_out for https (ac04968 Azat Khuzhin) - o test/http: chunk_out for https (a71ffb9 Azat Khuzhin) - o test/regress: fix ssl-less builds (need to make this prettier) (3160716 Azat Khuzhin) - o test/http: allow dirty shutdown for ssl to fix https_incomplete (1ede326 Azat Khuzhin) - o test/http: https basic (59714b4 Azat Khuzhin) - o test/http: incomplete{,_timeout} for https (615490d Azat Khuzhin) - o test/http: add simplest test for http/https/https_dirty_shutdown (93b19dc Azat Khuzhin) - o test/http: https: retry coverage (7c2d24a Azat Khuzhin) - o test/http: https server support (plus some helpers) (a7088ad Azat Khuzhin) - o test/http: more sanity checks (a27c53c Azat Khuzhin) - o test/ssl: export getkey()/getcert()/get_ssl_ctx()/init_ssl() for https (0c4c387 Azat Khuzhin) - o test/regress_be: basic coverage bufferevent_flush() for pair/sock layers (ad52602 Azat Khuzhin) - o test/regress_be: socket_filter_inactive: check bufferevent after creation (f8081af Azat Khuzhin) - o test/regress_be: cover finalizers from inactive to active queue (337684b Azat Khuzhin) - o test/regress_buffer: fix clang compilation warnings (d8fd4c0 Azat Khuzhin) - o test/regress_http: fix compilation warnings (-Wmissing-field-initializers) (cd422e0 Azat Khuzhin) - o test/regress_dns: fix compilation warnings (-Wmissing-field-initializers/for) (f55db98 Azat Khuzhin) - o tests/regress_dns: cover that randomize-case works case-insensitive (1e8bfbc Azat Khuzhin) - o test: fix bufferevent/bufferevent_pair_release_lock in debug mode (3f749e9 Azat Khuzhin) - o test: fix bufferevent/bufferevent_pair_release_lock for freebsd (79f9ace Azat Khuzhin) - o test/regress_be: bufferevent_enable() shouldn't call eventcb by it's own (a0f308d Azat Khuzhin) - o test/regress_be: introduce fake_listener_create() (37dc9e0 Azat Khuzhin) - o test/regress_http: cover evhttp_request_own() (6f6fa0d Azat Khuzhin) - o test/regress_http: cover write during read (3d15aeb Azat Khuzhin) - o test/regress_http: verify that closecb will be called without multiple write (4be6c70 Azat Khuzhin) - o test/regress: fix bufferevent_pair_release_lock with EVENT_DEBUG_MODE (6ea6655 Azat Khuzhin) - o test/regress_ssl: check events fd/pending after timeout triggered (cdafdf0 Azat Khuzhin) - o test/regress_ssl: cover case when server didn't up (failed with timeout) (74845f1 Azat Khuzhin) - o test/regress_ssl: covert that we can't change fd with underlying (df507af Azat Khuzhin) - o test/regress_ssl: cover that events (read/write) at finish not pending (762edb4 Azat Khuzhin) - o test/regress_ssl: cover fd manipulations (b78a829 Azat Khuzhin) - o test/regress_ssl: convert open_ssl_bufevs() to mask (46bba73 Azat Khuzhin) - o test/regress_ssl: convert client/server to mask too (3455991 Azat Khuzhin) - o test/regress_ssl: cover "allow_dirty_shutdown" (0430327 Azat Khuzhin) - o test/regress_ssl: convert regress_bufferevent_openssl() to bitmask (342e116 Azat Khuzhin) - o tests/regress_ssl: drop duplicated assert (25e56fd Azat Khuzhin) - o test/regress_http: initialize "dns_base" to avoid reading trash (9f0bff3 Azat Khuzhin) - o test/http: cover retrying with saved conn_address by shutting down dns server (f4874d8 Azat Khuzhin) - o be_pair/regress: cover use of shared lock (lock/unlock/free) (a558fcd Azat Khuzhin) - o regress_dns: drop hack for event_debug_map_HT_GROW in leak tests (3540a19 Azat Khuzhin) - - Sample code - o Fix memory leak in signal-test.c (666db91 basavesh.as) - o sample/hello-world: exAmple, not eXMple (2d3cd35 kirillDanshin) - o dns-example: allow to set ns from args (df19a97 Azat Khuzhin) - o dns-example: convert to getopt() (32f8592 Azat Khuzhin) - o http-connect: make it win32 compilable (1bf7595 Azat Khuzhin) - o sample/https-client: allow to change path to ca-certificates (fdf713a Azat Khuzhin) - o sample/https-client: check for ERR_remove_thread_state() existence (c4e9d9b Azat Khuzhin) - o sample/https-client: replace ERR_remove_state() by ERR_remove_thread_state() (77ad68a Azat Khuzhin) - o sample/https-client: add -timeout option (4637aa8 Azat Khuzhin) - o sample/https-client: don't try to free uninitialized SSL (f3d7ff5 Azat Khuzhin) - o sample/https-client: graceful exit with freeing memory (to make valgrind happy) (24a1f25 Azat Khuzhin) - o https-client: correctly handle URLs with no path (like "https://host:port") (29a0482 Andrey Skriabin) - o sample/http-connect: don't use assert() to make it work with NDEBUG (6dc71e7 Azat Khuzhin) - o sample/http-connect: made it compatible with C90 (f976d43 Azat Khuzhin) - o sample: add HTTP CONNECT tunnelling example using libevent http layer (1d34498 Azat Khuzhin) - o Update dns-example. (620ff24 Mark Ellzey) - - Documentation - o Update README.md (b8ec70c Mark Ellzey) - o Update README.md (80faee9 Mark Ellzey) - o Update README.md (ad4a897 Mark Ellzey) - o Update README.md (a2b2e1e Mark Ellzey) - o Update README.md (0dfa5dc Mark Ellzey) - - Code Improvements (evthread) - o evthread: add evthread_get_{lock,condition}_callbacks() helpers (c0b34f6 Azat Khuzhin) - - Code Improvements (core) - o util: make @sa const for evutil_socket_connect_() (a8d32c2 Azat Khuzhin) - - Code Improvements (http) - o http: assert's that evbuffer_drain() success on connection reset (2185e63 Azat Khuzhin) - o http: introduce evhttp_request_free_() helper (22061ac Azat Khuzhin) - o http: introduce evhttp_is_request_connection_close() helper (6540da3 Azat Khuzhin) - - Code Improvements (bufferevents) - o be_sock: bufferevent_socket_set_conn_address(): assert instead of silent no-op (0ab88c2 Azat Khuzhin) - o be_sock: sanity check in bufferevent_socket_set_conn_address() (eedbeff Azat Khuzhin) - o be: replace sockaddr_storage with sockaddr_in6 for conn_address (3889612 Azat Khuzhin) - o be: replace conn_address by full struct instead of pointer (e5615aa Azat Khuzhin) - o bufferevent: move conn_address out from http into bufferevent (8bb3842 Azat Khuzhin) - o be: make @sa const for bufferevent_socket_connect() (dc33c78 Azat Khuzhin) - - Cleanups (core) - o Refactoring conditional directives that break parts of statements. (4b41eeb lzmths) - o epoll: introduce PRINT_CHANGES() macro to avoid copy-pasting (a1b142b Azat Khuzhin) - o tab (6e7a580 Greg Hazel) - - Cleanups (evbuffers) - o buffer_compat: fix comment -- we have EVBUFFER_EOL_ANY not EOL_STYLE_ANY (575ff67 Azat Khuzhin) - - Cleanups (bufferevents) - o be_sock: evutil_getaddrinfo_async_() always return 0 (dbff101 Azat Khuzhin) - o be_sock: drop be_sock_add() macro (useless and debug unfriendly) (fad5fe2 Azat Khuzhin) - o be: introduce bufferevent_generic_adj_existing_timeouts_() (3c1f58f Azat Khuzhin) - o be: add_event: use evutil_timerisset() (a96b73b Azat Khuzhin) - o be_openssl: introduce be_openssl_auto_fd() helper (2a8a711 Azat Khuzhin) - o be_openssl: introduce set_open_callbacks_auto() (510da71 Azat Khuzhin) - - Cleanups (http) - o http: make fallback for EVHTTP_CON_READ_ON_WRITE_ERROR more cleaner (d405492 Azat Khuzhin) - o http: coding style issue (365f181 Azat Khuzhin) - - Cleanups (evdns) - o evnds: inline TEST_NAME macro to make debuggin easier (0c615f4 Azat Khuzhin) - - Portability Fixes - o [#372] check for errno.h (3031617 Mark Ellzey) - o Fixed Unicode issue in error messages. (e8b7895 Mattes D) - o Assume that ke_udata is an integer type on CloudABI. (5602e45 Ed Schouten) - o Add missing include of <netinet/in.h>. (b2c68bc Ed Schouten) - o Include <sys/ioctl.h>, <sys/resource.h> and <sys/wait.h> optionally. (c1404b5 Ed Schouten) - o Test against SO_REUSEADDR (along with _WIN32). (ce1776c Ed Schouten) - o Always define missing TAILQ functions from sys/queue.h (2828bdb Christopher Wiley) - o Don't use BSD u_* types. (fd36647 Ed Schouten) - o Remove BSD-ism: TIMEVAL_TO_TIMESPEC(). (193c7de Ed Schouten) - o be: include all variations of headers for sockaddr_in6 struct (c212291 Azat Khuzhin) - o be: fix sockaddr_in6 type definition for win32 (c42bc6b Azat Khuzhin) - - Continious Integration: - o travis: split long lines, and make it cleaner (685a6a1 Azat Khuzhin) - o travis: fix autotools on osx by reinstalling libtool (088ea5e Azat Khuzhin) - o appveyor/autotools: link with openssl by passing LDFLAGS/CFLAGS (6fcfa25 Azat Khuzhin) - o appveyor: image already had openssl installed (4634b85 Azat Khuzhin) - o appveyor: check -DUNICODE -D_UNICODE according to ReleaseChecklist (cmake only) (e9acc44 Azat Khuzhin) - o appveyor: ignore failure of mingw-get (1810857 Azat Khuzhin) - o appveyor: drop shallow_clone, since we use tags for detecting version in cmake (ac90133 Azat Khuzhin) - o appveyor: support cmake & autotools using build matrix (like travis-ci has) (8f95015 Azat Khuzhin) - o travis-ci/osx: relink gcc/g++ instead of clang (481481d Azat Khuzhin) - o travis-ci: enable multi-os mode (osx, linux) (79917e4 Azat Khuzhin) - o travis-ci: increase matrix (--disable-foo) (59649f7 Azat Khuzhin) - o travis-ci: adjust alignment (c8be339 Azat Khuzhin) - o travis: add builds without debug mode into matrix (3e56da2 Azat Khuzhin) - o test: run regress with EVENT_DEBUG_MODE=1 and without (cf2cf2a Azat Khuzhin) - o Update travis config for status updates (37453ab Mark Ellzey) - o Use autotools for appveyor until cmake is fixed. (1cc2e29 Mark Ellzey) - o Fix the link for appveyor OpenSSL installer (WIN32) (107d565 Mark Ellzey) - o Forgot to install OpenSSL for appveyor (26164a5 Joakim Söderberg) - o Add support for appveyor.com windows CI (5f89c37 Joakim Söderberg) - - Build Improvements/Fixes: - o evutil: mark ai_find_protocol() static (prototype-less) (5a157c8 Azat Khuzhin) - o cmake/solaris: set CMAKE_REQUIRED_LIBRARIES to fix functions detections (dc95823 Azat Khuzhin) - o cmake/solaris: fix building (link with socket,nsl) (050bfc7 Azat Khuzhin) - o cmake: check for ZLIB_INCLUDE_DIR, since we can have only library without headers (c4dfb93 Azat Khuzhin) - o autotools/win32: fix searching ssl library (671a24f Azat Khuzhin) - o cmake/win32: do not compile regress_thread on -DEVENT__DISABLE_THREAD_SUPPORT=ON (de0c196 Azat Khuzhin) - o cmake/win32: do not compile evthread_win32 on -DEVENT__DISABLE_THREAD_SUPPORT=ON (ecb0ec8 Azat Khuzhin) - o cmake: fix -DEVENT__ENABLE_VERBOSE_DEBUG (typo on -DUSE_DEBUG) (e35f224 Azat Khuzhin) - o cmake: do not use stderr for notifications/version-info (38716c6 Azat Khuzhin) - o autoconf: fix --disable-thread-support build under win32 (bb09535 Azat Khuzhin) - o buffer: don't mix code and declarations (8892f4c Azat Khuzhin) - o Update gitignore file to ignore cscope gen'ed files (0aaa4fb Neeraj Badlani) - o For non GCC/clang on OSX the -Wno-deprecated-declarations may not be valid (b5ca365 Rainer Keller) - o automake: define serial-tests only if automake have this option (61179de Azat Khuzhin) - o test/automake: don't use paralell test harness (since automake 1.12) (44d755e Azat Khuzhin) - o Ignore all pkgconfig generated stuff (ce38993 Azat Khuzhin) - o libevent_core and libevent_extra also deserve a pkgconfig file (b8d7c62 Jan Heylen) - o Ignore verify_tests.bat (win32 version) (0f2de10 Azat Khuzhin) - o cmake: require 3.1 only for win32 to make it work under ubunty precise (87f7238 Azat Khuzhin) - o cmake: require at least 3.1 for target_sources() (c46ead5 Azat Khuzhin) - o cmake: fix adding of compiler flags, and now it will (36588e1 Azat Khuzhin) - o Replace -Wswitch-enum with -Wswitch, and add it into cmake rules too (f29f59e Azat Khuzhin) - o test/regress_ssl: Fix compile problems for win32 (73d0360 Trond Norbye) - o util: fix "%zu" format on TDM-gcc/MinGW-w64 (79b69d8 Azat Khuzhin) - o cmake: don't define EVENT__NEED_DLLIMPORT always (fixes VS2013 static build) (49bd790 Azat Khuzhin) - o Add missing return statement to del_wait_thread so libevent can build. (4f778ab Nick Mathewson) - o cmake: fix building dns-example under win32 (missing getopt) (a1609a8 Azat Khuzhin) - o visibility: align it to make it more readable (bb6b53d Azat Khuzhin) - o cmake: Fix detection of ssize_t/SSIZE_T (7707f6b Azat Khuzhin) - o Ignore more configure stuff (configure.lineno) (8d34302 Azat Khuzhin) - o Fixed issue with cmake version generation (d56efd9 Mark Ellzey) - o Cmake is now officially working. (7f9646d Mark Ellzey) - o More cmake updates, lot's of missing definitions (49a5381 Mark Ellzey) - o CMake syntax fixes fo .in files (6aad23d Mark Ellzey) - o Revert "The Windows socket type is defined as SOCKET." (a264da8 Mark Ellzey) - o CMAKE CMAKE CMAKE CLEANUPS (a9db46a Mark Ellzey) - o Lot's of cmake updates (8b228e2 Mark Ellzey) - o Provide a mechanism for building the library on Windows with different compiler flags. Add a batch file that builds it for the M[DT][d] options and performs a hunt and gather of the different output libraries. (ded8086 billsegall) - o The Windows socket type is defined as SOCKET. (c9e6c3d billsegall) - o autotools: fix getservbyname() detection (959a4c2 Azat Khuzhin) - o Add missing <string.h> for openssl_hostname_validation module (3316a21 Azat Khuzhin) - o make test/regress_ssl.c compile without warnings (9f02a44 Thomas Bernard) - o test/regress_be: drop debug __asm__(int3) to fix arm build (8240379 Azat Khuzhin) - o event_debug_created_threadable_ctx_: fix compilation without debug mode (a068f2e Azat Khuzhin) - o Add a prototype for event_disable_debug_mode() (bfcedee Sebastian Hahn) - o http: eliminate warning about "socklen" in evhttp_connection_connect_() (dfad1a4 Azat Khuzhin) - o Updated gitignore (1dbb55d Mark Ellzey) - o Update bench_httpclient.c (cb96931 Seungmo Koo) - o *fix: bench_httpclient to support win32 (4e9325e zeliard) - o Commented out a WIN32 threading / timing test for now (e84e269 Mark Ellzey) - o Fix mixed declarations and code (forbidden by ISO C90) (0c7f217 Thomas Bernard) - o Fix "function declaration isn’t a prototype" (746d2c5 Thomas Bernard) - o This fixes a bug introduced in 27bd9faf498b91923296cc91643e03ec4055c230 (19ba454 Joakim Söderberg) - o changed strtotimeval signature as per #211 (bdbc823 Xiao Bao Clark) - o Added cmake-generated files to ignore list. (6c12bfe Matyas Dolak) - o Ignore `make dist` generated files (8a2c6c7 Azat Khuzhin) - - Debugging - o Debug mode option to error on evthread init AFTER other event calls. (dcfb19a Mark Ellzey) - - - -Changes in version 2.1.5-beta (5 January 2015) - - Security Fixes (evbuffers) - o Avoid integer overflow bugs in evbuffer_add() and related functions. See CVE-2014-6272 advisory for more information. (d49bc0e88b81a5812116074dc007f1db0ca1eecd) - - New APIs (evconnlistener) - o Provide support for SO_REUSEPORT through LEV_OPT_REUSABLE_PORT (b625361 Maciej Soltysiak) - - Bugfixes (core) - o Fix use-after-free error in EV_CLOSURE_EVENT callback (3cc0eac John Ohl) - o Fix race caused by event_active (3c7d6fc vjpai) - - Bugfixes (evbuffer) - o Fix evbuffer_peek() with len==-1 and start_at non-NULL. (ba59923) - o Consistently check for failure from evbuffer_pullup() (60f8f72) - o Fix evbuffer_peek() with len==-1 and start_at non-NULL. (fb7e76a) - - Bugfixes (windows, IOCP) - o be async: avoid double close() (f133b86 Azat Khuzhin) - - Bugfixes (bufferevents) - o Fix issue #127, double free for filterevents that use BEV_OPT_CLOSE_ON_FREE (2c82aa0 John Ohl) - o make bufferevent_getwatermark api more robust (a21e510 ufo2243) - o [Bugfix] fix bufferevent setwatermark suspend_read (b34e4ac ufo2243) - o bufferevent_openssl: reset fd_is_set when setfd with -1 is called (3da84c2 Azat Khuzhin) - o Fix compilation for older OpenSSL versions. (5c7282f Joakim Soderberg) - - New APIs (evhttp) - o Add evhttp_connection_set_family() to set addrinfo->family for DNS requests (12c29b0 Azat Khuzhin) - o Implement interface that provides the ability to have an outbound evhttp_connection free itself once all requests have completed (2b9ec4c,10fe4f John Ohl) - - New APIs (core) - o Implement new/free for struct evutil_monotonic_timer and export monotonic time functions (f2645f8 Andrea Shepard) - - Bugfixes (evdns) - o Load hosts file on Windows. (a0b247c Vilmos Nebehaj) - o Don't truncate hosts file path on Windows. (d0dc861 Vilmos Nebehaj) - o Fix a crash in evdns related to shutting down evdns (9f39c88,e8fe749) - o evdns: avoid read-after-free in evdns_request_timeout_callback() (61262a0 Azat Khuzhin) - o Correctly handle allocation failures in evdns_getaddrinfo (6a53d15) - o evdns: fix EVDNS_BASE_DISABLE_WHEN_INACTIVE in case retransmit/retry (74d0eee Azat Khuzhin) - o evdns: add retry/reissue tests for EVDNS_BASE_DISABLE_WHEN_INACTIVE (3ca9d43 Azat Khuzhin) - o evdns: fail ns after we are failing/retrasmitting request (97c750d Azat Khuzhin) - - Bugfixes (evhttp) - o http: reset connection before installing retry timer (fix http retries handling) (bc79cc5 Azat Khuzhin) - - - Testing - o regress_dns: fix leaks in getaddrinfo_async{,_cancel_stress} tests (2fdc5f2 Azat Khuzhin) - o test: add family argument for http_connection_test_() (177b8a7 Azat Khuzhin) - o test: add regress for evhttp_connection_set_family() with AF_INET and AF_UNSPEC (42aefeb Azat Khuzhin) - o test/http: add regress test for set family to AF_INET6 (3fbf3cc Azat Khuzhin) - o Update to a more recent tinytest_macros. (8da5a18) - o test/regress: add simplestsignal: to track reorder bugs separately (b897bef Azat Khuzhin) - o test/evbuffer_peek: add regress in case we have first buffer greater (e2d139d Azat Khuzhin) - o More evbuffer_peek() test cases (154006a) - o use correct tt macro for pointer compare (08c88ea) - o regress_buffer: fix 'memcmp' compare size (79800df Maks Naumov) - o Fix a use-after-free in unit tests. CID 752027 (3739057) - o Fix a dead-code warning in unit tests. CID 1193548 (c119f24) - o Use evutil_weakrand() in unit tests. (a677b72, 364c110) - o Use a more precise calculation for max in time-ratelim.c (ca5b5c7) - o Make a buffer larger in the tests to avoid a scary evbuffer_copyout_from() (fb57b8b) - o Fix several memory leaks in the unit tests. (89c1a3b) - o Add test for evhttp_connection_free_on_completion (b0e9924 John Ohl) - o Fix annoying heisenbug in test-time.c (cb73704) - - Sample code - o Make http-server.c output into good html5 (6d72bdc) - o Use FindClose for handle from FindFirstFile in http-server.c (6466e88) - o https-client: add -retries argument, for connection retries (d9da844 Azat Khuzhin) - - Bugfixes (build) - o Add missing headerfile for cmake (15d90cc Trond Norbye) - o ignore one more test binary (b6593aa Michael Richardson) - o ignore config.cache/test-driver files (c83f333 Mike Frysinger) - o add a --disable-samples configure flag (0c492b3 Mike Frysinger) - o Add a few files created by "make verify" to .gitignore. (1a8295a Pierre Phaneuf) - o updates in cmake build (27bd9fa Sergey Nikulov) - o Fix cmake error when the Module path has more than one entry. (befbd13 Acer Yang) - o Fix CMake shared library build (e69d910 Nobuaki Sukegawa) - o Fix warnings when compiling with clang 3.5 (f5b4765 John Ohl) - o Fix mixed declarations and code (forbidden by ISO C90) (8afbdbc Thomas Bernard) - - Bugfixes (miscellaneous) - o tree.h: drop duplicated content of tree.h (6193187 Azat Khuzhin) - o evdns: disable probing with EVDNS_BASE_DISABLE_WHEN_INACTIVE (610410b,ad0493e,fea86a6,d83b337,5ca9e97 Azat Khuzhin) - o [Bugfix] fix grammer error (3a4d249 ufo2243) - o Change return type of evutil_load_windows_system_library_ to HMODULE (f691389) - o Fix a c90 warning (76643dd) - o Fix a typo in a doxygen comment. Reported by 亦得. (be1aeff) - o remove trailing comma from enum (b361b8a Jean-Philippe Ouellet) - - Bugfixes (FreeBSD) - o Handle ENOTCAPABLE from FreeBSD - this is returned if an event in the changelist is for an FD that has been closed. (6fd7394 Adrian Chadd) - - - -Changes in version 2.1.4-alpha (21 Mar 2014) - - Libevent 2.1.4-alpha adds a number of new miscellaneous APIs to make - Libevent more useful, including support for early close detection with - epoll via EPOLLRDHUP, triggering bufferevent callbacks, adding more - evhttp callbacks, and more. There are also numerous bugfixes, including - a number for finalize-related issues from 2.1.3-alpha; and an - alternative (non-primary!) cmake-based build mechanism. - - New APIs (core) - o Added event_base_get_num_events() (0fa107d Mobai Zhang) - o New event_base_active_by_fd API (865a142 Greg Hazel, 5c9da9a, 87fa2b0) - o Add event_base_active_by_signal by analogy (4865943) - o Add access to max event count stats (5173bef, efbd3dc, 26230a2 - Andrew Sweeney) - o Implemented EV_CLOSED event for epoll backend - (EPOLLRDHUP). (b1b69ac Diego Giagio, 53d2793, 43ffcf6, dfe1e52 - Marcin Juszkiewicz, ff26633 Joakim Soderberg, 3908a5e) - - New APIs (evutil_secure_rng) - o Add evutil_secure_rng_set_urandom_device_file (2bbb5d7) - - New APIs (bufferevents) - o Add function to fetch underlying ratelimit cfg (4b3d5af Mark Ellzey) - o Pass and return const for bufferevent_get_token_bucket_cfg (1c77fbb - Mark Ellzey) - o Add watermark introspection (4ce242b OndÅ™ej KuznÃk) - o Add an option to trigger bufferevent I/O callbacks (61ee18b OndÅ™ej KuznÃk) - o Add an option to trigger bufferevent event callbacks (a7384c7 - OndÅ™ej KuznÃk) - o Clarifications in response to merge req. comments (bd41947 OndÅ™ej - KuznÃk) - o Minor optimizations on bufferevent_trigger options (a3172a4) - - New APIs (evhttp) - o Add evhttp_connection_get_server(). (a7f82a3 Maxime Henrion) - o add a http default content type option (5a5acd9 Nicolas Martyanoff) - o http: implement new evhttp_connection_get_addr() api. (0c7f040 Azat - Khuzhin) - o Add a variant of evhttp_send_reply_chunk() with a callback on - evhttp_write_buffer() (8d8decf Julien BLACHE) - o Allow registering callback for parsing HTTP headers (b0bd7fe Balint Reczey) - o Provide on request complete callback facility (b083ca0 Andrew Sweeney) - o evhttp_request_set_on_complete_cb to be more specific about what - the function actually does and usage (da86dda Andrew Sweeney) - o Update unit test to make sure that the callback happens after the - output data is written (b85f398 Andrew Sweeney) - - Features (evdns) - o bug fix for issues #293 evdns_base_load_hosts doesn't remove - outdated addresses (954d2f9, f03d353, 45eba6f Kuldeep Gupta) - - Features: (cmake build support) - o Initial CMake commit. (e415196 Joakim Soderberg) - o Add all tests and benchmarks to CMake project. (e9fc014 Joakim Soderberg) - o More work on adding tests to CMake project (99c1dc3 Joakim Soderberg) - o Generate a dummy evconfig-private.h so things build - properly. (ce14def Joakim Soderberg) - o Link libm on unix platforms. (58fcd42 Joakim Soderberg) - o Added some GCC specific options. (19222e5 Joakim Soderberg) - o Use evutil_closesocket instead. (dbf2b51 Joakim Soderberg) - o Add copyright and licensing files for CMake modules. (c259d53 - Joakim Soderberg) - o Only include WIN32 getopt where it is used. (9bbce0b Joakim Soderberg) - o Fix bench_cascade program on Windows. (78da644 Joakim Soderberg) - o Don't segfault on no found event backend. (8f2af50 Joakim Soderberg) - o Only test the event backends available on the system. (7ea4159 - Joakim Soderberg) - o Added a "make verify" target. (e053c4f Joakim Soderberg) - o Fix the make "verify" target on Windows. (67e5d74 Joakim Soderberg) - o Get rid of deprecation warnings for OpenSSL on OSX 10.7+ (69c3516 - Joakim Söderberg) - o Fix kqueue support. (a831f2f Joakim Söderberg) - o Added a test for testing if kqueue works with pipes. (2799b35 - Joakim Söderberg) - o Change the BSD license from 4 to 3-clause. (86df3ed Joakim Soderberg) - o Minimum required python version is 2.4. (968e97b Joakim Soderberg) - o Get rid of unknown pragma warnings. (0ef1d04 Joakim Soderberg) - o Add a "make verify_coverage" target generation coverage - info. (f2483f8 Joakim Soderberg) - o Fix the "make verify" target on NetBSD (4ac086a Joakim Soderberg) - o Only look for ZLib when it is used (if tests are - included). (f780593 Joakim Soderberg) - o Added EVENT__ENABLE_GCC_WARNINGS, turns all warnings into - errors. (dd413bd Joakim Soderberg) - o Add CMake config and install targets. (f3446ed Joakim Soderberg) - o Fix typo (4b754df Joakim Soderberg) - o Some work on making it possible to simply do add_subdirectory() on - the project. (49ab363 Joakim Soderberg) - o Set USE_DEBUG=1 on EVENT__ENABLE_VERBOSE_DEBUG (fd42e70 Joakim Soderberg) - o Fix so that old nmake project still builds. (24d6466 Joakim - Soderberg) - o Rename README to README.md and use markdown to format. (d2bc39a - Joakim Soderberg) - o Update README with CMake build instructions. (604b8cc Joakim Soderberg) - o Clean up the README some. (8d4cb35 JoakimSoderberg) - o Forgotten headers for old nmake project compatability. (8697b99 - Joakim Soderberg) - o Change all uses of WIN32 to _WIN32 (4e14395 Joakim Söderberg) - o Fix include bug. (2024467 Joakim Söderberg) - o Check if we're on OSX before disabling deprecation in le-proxy - (8b40a5b Joakim Söderberg) - o Fix broken autotools build. (ae1bd82 Joakim Söderberg) - o Disclaimerize cmake a little in the README (d03b5bf) - o Fix CMake compile when OpenSSL is disabled. (e423d42 Joakim - Söderberg) - o CMake: Get rid of python not found warning when regress tests - turned off. (d38d798 Joakim Söderberg) - o Fix https-client compilation on Windows. (d7be788 Joakim Soderberg) - o Guard against EVENT_NOWIN32 being set during testing. (f1715b4 - Joakim Soderberg) - o Check for OSX when checking for clang. (e212c54 Joakim Soderberg) - o Added a Travis-CI configuration file. (8c0f0a9 Joakim Soderberg) - o Added -Qunused-arguments for clang on macosx (ed99d92 Trond Norbye) - o Rename event_extras to event_extra (a0dd5df Trond Norbye) - o Add option to build shared library (4545fa9 Trond Norbye) - o Add -Qunused-arguments for clang on macos (b56611d Trond Norbye) - o Add cmake-related files to .gitignore (e061321 Trond Norbye) - o Export event_extra not event_extras. (2b41bcf Joakim Söderberg) - - Bugfixes (core) - o If evsel->del() fails, don't leave the evmap in an inconsistent - state (9b5a527 Maxime Henrion) - o Move event_debug_note_teardown_ before mm_free. (69b5c64) - o Check CLOCK_MONOTONIC_* at runtime if needed. (911abf3) - o Fix reinit of fds with EV_WRITE but not EV_READ. (ebfd8a8 maksqwe) - o Tweaked callbacks to prevent race condition - (https://github.com/libevent/libevent/issues/104) (40830f1, 2ea15ed - John Ohl) - o Move assert(ev) to before we use ev in EV_CLOSURE_EVENT_FINALIZE - case (9805972) - - Bugfixes (evhttp) - o Fix a double close() bug in evhttp when the underlying bufferevent uses - BEV_OPT_CLOSE_ON_FREE. (31db8a0 Maxime Henrion) - o Fix an unlikely but possible error case for http connections (f22049e) - o Avoid racy bufferevent activation (5eb1788 Nate Rosenblum) - - Bugfixes on 2.0 (Windows) - o Use windows vsnprintf fixup logic on all windows environments (e826f19) - o libevent/win32_dealloc() : fix sizeof(pointer) vs sizeof(*pointer) - (b8f5980 Frank Denis) - - Bugfixes (evutil_secure_rng) - o When we seed from /proc/sys/kernel/random/uuid, count it as success - (e35b540) - o We should return after arc4random_buf() (1ea1f26 Makoto Kato) - o Avoid other RNG initialization FS reads when urandom file is - specified (9695e9c) - o Really remove RNG seeds from the stack (f5ced88) - o Fix another arc4random_buf-related warning (e64a2b0) - - Bugfixes (bufferevents) - o Initialize async bufferevent timeout CBs unconditionally (af9b2a7) - - Bugfixes (evdns) - o Checking request nameserver for NULL, before using it. (5c710c0 - Belobrov Andrey) - o Fix SEGFAULT after evdns_base_resume if no nameservers - installed. (14971a8 Azat Khuzhin) - o Actually use the log facility for reporting evdns problems. (e1766a1) - o Fix SEGFAULT after evdns_base_resume if no nameservers - installed. (f8d7df8 Azat Khuzhin) - o fix for ServFail from RIPE Atlas release (62f596b Antony Antony) - - Bugfixes (compilation) - o Fix test compilation with nmake: add the gdi.lib dependency (5ba8ab7) - o Whoops. It is gdi.lib, not gdi32.lib. (github issue #61) (8ab612e) - o Don't use return since return type is void and build error occurs - using clang (838161d Makoto Kato) - o Use void casts to suppress some "unchecked return value" warns (7080d55) - o rpcgen: Generate regress.gen.[c,h] in build rather than src dir - (243386c Ross Lagerwall) - o Fix a compiler warning when checking for arc4random_buf linker - breakage. (5cb3865) - o Fix 'make distcheck' by adding regress.gen.[ch] to DISTCLEANFILES - (239d834) - - o Fix a c90 warning (c207682) - o Fix consts in WIN32-Code/getopt*.[ch] (57abb35) - - Bugfixes (locks, synchronization) - o Missed lock acquire/release in event_base_cancel_single_callback_() - (d3d999a Azat Khuzhin) - o Fix locking in bufferevent_get_options_(). (dbc9cd4 Maxime Henrion) - - Bugfixes (leaks) - o Avoid leaking segment mappings when offset is not a page multiple (d409514) - - Testing - o Add tests for evdns_base_resume(). (1cd9ff5 Azat Khuzhin) - o Fix dns/leak_resume_send_err test. (7e876df Azat Khuzhin) - o Add checks for evhttp_connection_get_server() in unit - tests. (fbc323b Maxime Henrion) - o Fix a (failure-only) null dereference in the unit tests (1104d0b) - o Fix a logic error in test_evbuffer_freeze (7765884) - o Add missing check to test_evbuffer_file_segment_add_cleanup_cb (eba4506) - o Fix some crash-on-fail cases in DNS regression tests (87cd6f0) - o DNS tests: add a missing check (f314900) - o Finalize tests: add a missing check (82b6956) - o test_evutil_rtrim: add another missing check. (e193c95) - o regress_main: logging all if env EVENT_DEBUG_LOGGING_ALL isset - (611e28b Azat Khuzhin) - o regress_http: add tests for evhttp_connection_get_addr() (4dd500c - Azat Khuzhin) - o Update to the latest version of tinytest (7a80476) - o Heap-allocate zlib data structure in regress_zlib tests (4947c18) - - Performance tweaks (core) - o Avoid redundant syscall to make a nonblocking socket nonblocking - (42c03da Maxime Henrion) - o Avoid redundant syscall if making a socket cloexec twice (1f29b18) - o Avoid redundant invocations of init_extension_functions for IOCP (3b77d62) - - Documentation - o Document that arc4random is not a great cryptographic PRNG. (6e49696) - o Small doxygen tweaks (6e67b51) - o Try another doxygen tweak (ccf432b) - o Clarify event_base_loop exit conditions (031a803) - o Fix a typo (be7bf2c OndÅ™ej KuznÃk) - o Document deferred eventcb behaviour (13a9a02 OndÅ™ej KuznÃk) - o Typo fixes from Linus Nordberg (cec62cb, 8cd695b) - o Fix duplicate paragraph in evbuffer_ptr documentation (58408ee) - - Code Improvements (coverity) - o Fix a pile of coverity warnings in the unit tests (867f401) - o Fix coverity warnings in benchmark tools. (ff7f739) - o Whoops; fix compilation in bench.c (544cf88) - o Remove spurious checks in evrpc.c error cases (coverity) (991b362) - o Fix a couple of compilation warnings in regress_http.c (860767e) - o Fix even more coverity warnings. (d240328) - o Stop checking for inet_aton; we don't use it. (f665d5c) - o Add an include to evrpc-internal to fix openbsd compilation warning - (5e161c6) - - Cleanups - o Remove an unreachable return statement in minheap-internal.h (e639a9e) - o Refactor evmap_{io,signal}_active_() to tolerate bad inputs (974c60e) - o Fix needless bufferevent includes in evdns.c (254c04e) - o Fix a couple of "#ifdef WIN32" instances (88ecda3) - o Remove unneeded declaration in bufferevent-internal.h (4c8ebcd) - - Sample code - o le-proxy: Fail more gracefully if opening listener fails (44b2491) - o http-server: drop uri_root from base_url in http-server. (6171e1c Azat Khuzhin) - o https-client: POST supported, args supported (c5887f7 Alexey Ozeritsky) - o https-client: code cleanup (29af65e Alexey Ozeritsky) - o https-client: Small tweaks to https-client.c (90786eb) - o https-client: Set hostname for SNI extension (by f69m) (d1976f8) - o https-client: add a cast to https-client.c (462e6b6) - - - -Changes in version 2.1.3-alpha (1 May 2013) - - Libevent 2.1.3-alpha fixes various bugs, adds new unit tests, and cleans - up the code in a couple of places. It has a new callback in evhttp for - reporting errors during a request, a new feature for allowing evdns to - not keep the event_base looping when there are no requests inflight, and - example code for writing an https client. - - Libevent 2.1.3-alpha also has an important new (experimental) event - finalization feature to allow safe event teardown in multithreaded - programs. This ought to fix the longstanding bug with deadlocks in - multithreaded use of SSL-based bufferevents that some people have been - experiencing since Libevent 2.0. - - - Core (event finalization) - o Implement event_finalize() and related functions to avoid certain - deadlocks (8eedeab) - o Use finalization feature so bufferevents can avoid deadlocks (02fbf68) - o Always run pending finalizers when event_base_free() is called (e9ebef8) - o Remove bufferevent_del_generic_timeout_cbs as now unused (4ea4c6a) - o More documentation for finalization feature (a800b91) - o Make the event_finalize* functions return an error code (5d11f4f) - o Mark the finalize stuff as experiemental in case it needs to - change (23e2e29) - - Evdns - o evdns: New flag to make evdns not prevent the event loop from - exiting (6b7fa62 Azat Khuzhin) - - Bugfixes (Core) - o Make event_remove_timer behave correctly with persistent timers (5623e80) - o Unit test for event_remove_timer with EV_PERSIST. (96150dd) - o Double-check next timeout when adding events (9443868 Nate Rosenblum) - o event_base_update_cache_time should be a no-op if the loop isn't - running (5e6fa2a) - - Bugfixes (evhttp, crash fix, from 2.0) - o fix #73 and fix http_connection_fail_test to catch it (b618204 Greg Hazel) - - Bugfixes (compilation and portability, from 2.0) - o Fix compilation with WIN32_HAVE_CONDITION_VARIABLES enabled (7e45739) - o Fix missing AC_PROG_SED on older Autoconfs (9ab2b3f Tay Ray Chuan) - o Backport libevent to vanilla Autoconf 2.59 (as used in RHEL5) - (74d4c44 Kevin Bowling) - o Use AC_CONFIG_HEADERS in place of AM_CONFIG_HEADERS for autmake - 1.13 compat (817ea36) - o Rename configure.in to configure.ac to appease newer autoconfs (0c79787) - o Avoid using top_srcdir in TESTS: new automakes do not like this (a55514e) - - Bugfixes (resource leaks/lock errors on error, from 2.0) - o Avoid leaking fds on evconnlistener with no callback set (69db261) - o Avoid double-close on getsockname error in evutil_ersatz_socketpair - (0a822a6) - o Fix a locking error in bufferevent_socket_get_dns_error. (0a5eb2e) - - Documentation Fixes (from 2.0) - o Fix a mistake in evbuffer_remove() arguments in example http server code - (c322c20 Gyepi Sam) - o Fix a typo in a comment in buffer.h. Spotted by Alt_F4 (773b0a5) - - Documentation Fixes - o minor documentation typos (809586a Patrick Pelletier) - o Fix cut-and-paste err in whatsnew-2.1 (49905ac) - o Fix comment to refer to sample/include.am correctly (9e8cdf3 Sebastian - Hahn) - o Fix typo : Dispatching instead of Dispaching (0c2bacc Volker Lendecke) - o fix some hinky indentation in evhttp_make_request (80e220e Patrick - Pelletier) - o "buffer" spelling (a452811 Patrick Pelletier) - o Specify return behavior in header for evbuffer_pullup() in corner case - (cf8d1cd Dan Petro) - o Clarify an important point about event_base_foreach_event() (920a5e6) - - Compilation Fixes/Tool Support - o avoid valgrind false positive by zeroing epoll_event (1258614 Patrick - Pelletier) - o Fix harmless clang enum warning (b452a43 Sebastian Hahn) - o remove all exes on "make clean", not just regress.exe (974bfa0 Patrick - Pelletier) - o Make --disable-libevent-regress work again (787fd74) - o Do not build strlcpy.c when it will have no code. (4914620) - - Portability Fixes - o When EWOULDBLOCK is not EAGAIN, treat it as equivalent to it (bf7a0ff) - o Preliminary changes for Minix3. (0dda56a Nicholas Heath) - o Use AC_CONFIG_HEADERS in place of AM_CONFIG_HEADERS for autmake 1.13 - compat (bf278b) - o Avoid using $(top_srcdir) in TESTS. (2863c83) - o build test/test-script.sh on systems with a less-featureful $< (f935e21) - o Implement EVUTIL_ERR_IS_EAGAIN on windows. (42aaf4d) - - Evhttp changes: - o Fix ipv6 support for http. When URL contain domain, not IP - address. (71e709c Azat Khuzhin) - o uri decode: fix for warning "use of uninitialised value" (64b6ece Azat - Khuzhin) - o uri decode: changed the test for the existence of the next character - (e1903e3 Azat Khuzhin) - o Move prototype of evhttp_decode_uri_internal() to http-internal.h - (de8101a Azat Khuzhin) - o Test: decoding just part of string with evhttp_decode_uri_internal() - (1367653 Azat Khuzhin) - o Add new error_cb for actual reporting of HTTP request errors. (7b07719 - Azat Khuzhin) - o Add test for EVREQ_HTTP_REQUEST_CANCEL into http_cancel_test() (862c217 - Azat Khuzhin) - o Drop extra header http_struct.h from regress_http.c (54cc800 Azat Khuzhin) - - Testing - o Add regress test ipv6_for_domain. (9ec88bd Azat Khuzhin) - o Add an environment variable (EVENT_DEBUG_MODE) to run unit tests in debug - mode (2fad0f3) - o Add a test with an active_later event at event_base_free time. (1c3147f) - o Make all tests pass under EVENT_DEBUG_MODE=1 (b1b054f) - o Add some verbose notes to bufferevent unit tests (9d893c9) - o New test for active_later->active transition on event_active (a153874) - o New tests for event_base_foreach_event() (0b096ef) - o Unit tests for event_base_gettimeofday_cached() and - event_base_update_cache_time() (30ea291) - o A test for event_get_assignment() (f09629e) - o More unit tests for initializing common timeouts. (d596739) - o Fix a bug in the new main/event_foreach test (702c9aa) - - Windows: - o use FormatMessage for winsock errors (0c6ec5d, 2078e9b, 4ccdd53, c9ad3af - Patrick Pelletier) - o a program to print out the error strings for winsock errors (7296512 - Patrick Pelletier) - o Fix a warning introduced in 0c6ec5d8 (eeb700c) - o Fix another warning introduced in 0c6ec5d8 (ed26561) - - Examples (http) - o Add sample/https-client.c, an example of stacking evhttp as a client on - top of bufferevent_ssl. (be46c99 Catalin Patulea) - o use ${OPENSSL_LIBS} instead of -lssl -lcrypto (bf31fa5 Patrick Pelletier) - o https-client was putting newlines at 256-byte boundaries (42d7441 Patrick - Pelletier) - o better handling of OpenSSL errors (5754d96 Patrick Pelletier) - o use Debian's default root certificate location (aacd674 Patrick Pelletier) - o use iSECPartners code to validate hostname in certificate (64d9f16 - Patrick Pelletier) - o avoid sign mismatch warning in openssl_hostname_validation.c (6021cb5 - Patrick Pelletier) - o pull in wildcard matching code from cURL (4db9da6 Patrick Pelletier) - o Another tweak to https-client.c (95acdaa) - o Remove http_struct.h usage in sample/https-client.c (8a90a85) - - - -Changes in version 2.1.2-alpha (18 Nov 2012) - - Libevent 2.1.2-alpha includes more portable for monotonic timers, - refactors much of Libevent's internal and external infrastructure, - closes some longstanding gaps in the interface, makde other - improvements. Ths log below tries to organize features by rough area of - effect. It omits a few commits which were pure bugfixes on other commits - listed below. For more detail, see the git changelogs. For more - insight, see the "whatsnew-2.1.txt" document included in the Libevent - 2.1.2-alpha distribution. - - Libevent 2.1.2-alpha also includes all changes made in 2.0.19-stable - through 2.0.21-stable inclusive. - - Performance (core): - o Replace pipe-based notification with EVFILT_USER where possible. This - should make multithreaded programs on OSX and *BSD alert the main thread a - little faster. (53a07fe) - o Make th_base_lock nonrecursive. (9cd5acb) - - New/Changed API Functions: - o New event_get_priority() function to return an event's priority (f90e255) - o Add a bufferevent_get_priority() function (bd39554) - o Add an event_base_loopcontinue() to tell Libevent to rescan for more - events right away (7d6aa5e) - o Add a new callback to get called on evbuffer_file_segment free - (e9f8feb yangacer, 64051b9) - o Expose event_base_foreach_event() as a public API. (84fd6d7 Roman - Puls, 232055e, ffe1643) - o Add an event_remove_timer() to remove timer on an event without - deleting it (e3b2e08) - o Make bufferevent_set_timeouts(bev, NULL, NULL) have plausible - semantics (9dee36b) - o Rename event_enable_lock_debuging() to ..._debugging(). (The old name - should still work.) (07e132e) - o Add missing implementation for event_enable_debug_logging (3b3e21d) - - PORTABLE MONOTONIC TIMERS: - - Libevent 2.1.2 includes internal support for monotonic timers on - (nearly) all supported platforms, including Windows, and OSX. Libevent - applications should now be more resilient to jumps forwards or backwards - in the system clock. Also, on Linux systems with epoll, we now - optionally support microsecond-level timeouts (whereas epoll only - supports millisecond-precision timeouts). - - o Use mach_absolute_time() for monotonic clock support on OSX. (b8fd6f9) - o Do not track use_monotonic field when is no monotonic clock (cb653a0) - o EVENT_BASE_FLAG_PRECISE_TIMER indicates we want fine timer precision - (ddd69d3) - o On Linux, use CLOCK_MONOTONIC_COARSE by default (55780a7) - o Implement a GetTickCount-based monotonic timer for Windows (d5e1d5a) - o Refactor monotonic timer handling into a new type and set of - functions; add a gettimeofday-based ratcheting implementation (f5e4eb0) - o Add EVENT_PRECISE_TIMER environment var for selecting precise-but-slow - timer (a2598ec) - o Implement fast/precise monotonic clocks on Windows (2c47045) - o Simple unit tests for monotonic timers (630f077) - o Improve the monotonic-time unit test: make it check the step size (7428c78) - o When PRECISE_TIMERS is set with epoll, use timerfd for microsecond - precision (26c7582) - o Split out time-related evutil functions into a new evutil_time.c (c419485) - o Split out time-related prototypes into time-internal.h (71bca50) - o Add evutil_time.obj to Makefile.nmake (0ba0683) - o Avoid giving a spurious warning when timerfd support is unavailable - (1aaf9f0 Dave Hart) - o Make test_evutil_monotonic a little more tolerant (def3b83) - o Avoid unused-var warning on systems with clock_gettime but without - CLOCK_MONOTONIC_COARSE (9be5468) - -EVENT_BASE_ONCE LEAKS: - If a callback added by event_base_once() is never invoked, Libevent no - longer leaks internal memory. - - o Free dangling event_once objects on event_base_free() (c17dd59) - o Add a unit test in which an event is created with event_base_once() - but never fires (4343edf) - -TESTING SUPPORT, FIXES AND IMPROVEMENTS: - - Libevent now disables by default its unit tests that would touch the - network, or that tend to fail on heavily-loaded systems. To re-enable - them, invoke the ./test/regress program with the @all alias. - - o Simplify test.sh code significantly. (9b856fd Ross Lagerwall) - o Make all tests that hit the network disabled by default (f2cea87) - o Avoid a resource leak on error in http client benchmark (ea92fba) - o Update to latest tinytest (911b4f0349377) (ef7c4f7) - o Avoid (unlikely) overflow in bench_httpclient.c (5671033) - o Shave 700 msec off the persistent_timeout_jump test (21205b8) - o Check return value of write() in regress.c (c8009d2) - o Make load-dependent monotonic timer tests off-by-default (2b6fe8b) - o Add deferred_cb_skew to list of timing-dependent tests (34c8f31) - o Avoid test -e; older shs don't have one. (f1bd938) - o Fix renegotiation test to work around openssl 1.0.1 bug (c2f3086) - o Fix a couple of compile warnings in the unit tests (5a9a014) - -MISC: - o Change evutil_weakrand_() to avoid platform random() (e86af4b Nicholas - Marriott, 3aa4415) - -INFRASTRUCTURE (Active-later events): - As a simplification and optimization to Libevent's "deferred callback" - logic (introduced in 2.0 to avoid callback recursion), Libevent now - treats all of its deferrable callback types using the same logic it uses - for active events. Now deferred events no longer cause priority - inversion, no longer require special code to cancel them, and so on. - - o Refactor the callback part of an event into its own event_callback - type (cba59e5) - o Add "active later" event_callbacks to supersede deferred (745a63d) - o event_base_assert_ok: check value of event_active_count for - correctness (fec8bae) - o Replace deferred_cbs with event_callback-based implementation. (ae2b84b) - o Replace more deferred_cb names with event_callback (a4079aa) - o Give event_base_process_active a single exit path (581b5be) - o Restore our priority-inversion-prevention code with deferreds (c0e425a) - o Refactor event_persist_closure: raise and extract some common logic - (bec22b4) - o Remove the unused bits from EVLIST_ALL (9889a3d) -||||||| merged common ancestors -Changes in version 2.0.22-stable (?? Dec 2013) - - (As of 3b77d62829c4393bda6f9105a5d3b73b48a64b71.) - +Changes in version 2.1.11-stable (01 Aug 2019) + + This release contains one ABI breakage fix (that had been introduced in + 2.1.10, and strictly speaking this release breaks ABI again to make it + compatible with 2.1.9 and less, please take a look at 18104973 for more + details). Apart from that it contains some bug fixes, that grouped below. + + And even though the return value for evbuffer_setcb() had been changed it + should ABI compatible (anyway that function is in -compat.h header). + + There is also one patch that introduce new functionality, this is 546a366c, + to tune SO_RCVBUF/SO_SNDBUF in evdns, but one can count it as a bug-fix on + the application level, since before you cannot tune this settings and hence + you could stumble on problems. + + ABI breakage: + o Protect min_heap_push_ against integer overflow. (8c899768 Tobias Stoeckmann) + o Revert "Protect min_heap_push_ against integer overflow." (18104973 Azat Khuzhin) + + functionality: + o evdns: add new options -- so-rcvbuf/so-sndbuf (546a366c Azat Khuzhin) + + build: + o Change autoconf version to 2.62 and automake version to 1.11.2 (2a333008 yuangongji) + o cmake: install shared library only if it was requested (596855f7 Azat Khuzhin) + o Missing <winerror.h> on win7/MinGW(MINGW32_NT-6.1)/MSYS (9559349c yuangongji) + o cmake: set library names to be the same as with autotools (305251b9 yuangongji) + o Enable _GNU_SOURCE for Android (f013fc7d Keith Smiley) + o Enable kqueue for APPLE targets (3aa68a82 Keith Smiley) + o autotools: do not install bufferevent_ssl.h under --disable-openssl (5349a07e Azat Khuzhin) + o cmake: link against shell32.lib/advapi32.lib (c9ce638c Azat Khuzhin) + o Add README.md into dist archive (3660a4cc Azat Khuzhin) + o cmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py) (2d65071c yuangongji) + o m4/libevent_openssl.m4: fix detection of openssl (d4056e59 Fabrice Fontaine) + o Fix detection of the __has_attribute() for apple clang [ci skip] (7fd7c5ef Azat Khuzhin) + + lib: + o buffer: fix possible NULL dereference in evbuffer_setcb() on ENOMEM (598f247d Azat Khuzhin) + o Warn if forked from the event loop during event_reinit() (b75922ae Azat Khuzhin) + o evutil: set the have_checked_interfaces in evutil_check_interfaces() + (ef498aa2, a09265ac jeremyerb) + + samples: + o https-client: correction error checking (a8a04565 wenyg) + + +Changes in version 2.1.10-stable (26 May 2019) + + This release contains mostly fixes (some evbuffer oddity, AF_UNIX handling in + http server, some UB fixes and others) but also some new functionality + (without ABI breakage as usual) and now dist archive can be used for building + on windows (getopt had been added into it). + + Above you will find changelog for this particular release (but with some + trivial fixes pruned out from it - to make it a little bit more informative). + + To view full changelog please use git: + git log --format=' o %s (%h %aN)' release-2.1.9-beta...release-2.1.10-stable + + dist: + o Add getopt into dist archive (7042ff24 Azat Khuzhin) + + functionality: + o evdns: add DNS_OPTION_NAMESERVERS_NO_DEFAULT/EVDNS_BASE_NAMESERVERS_NO_DEFAULT + (58e81106 Azat Khuzhin) + o Add support for EV_TIMEOUT to event_base_active_by_fd (3f893f0a John Ohl) + + fixes: + o Merge branch 'evbuffer-fixes-806-v2' (2fea04b3 Azat Khuzhin) + o Merge branch 'issue-807-accept4-getnameinfo-AF_UNIX' (7c4da937, e2790a7f + Azat Khuzhin) + o kqueue: Avoid undefined behaviour. (e70e18e9 Tobias Stoeckmann) + o Prevent integer overflow in kq_build_changes_list. (43a55a23 Tobias Stoeckmann) + o evdns: fix lock/unlock mismatch in evdns_close_server_port() (54103883 zhuizhuhaomeng) + o Merge remote-tracking branch 'official/pr/804' -- Enforce limit of NSIG + signals (87fa93a8 Tobias Stoeckmann) + o Protect min_heap_push_ against integer overflow. (0b46bb8c Tobias Stoeckmann) + o le-proxy: initiate use of the Winsock DLL (2a1e1530 linxiaohui) + o Fix leaks in error path of the bufferevent_init_common_() (bb0f8fe7 Azat Khuzhin) + o buffer: make evbuffer_prepend() of zero-length array no-op (61fa7b7d Azat Khuzhin) + o Merge branch 'evbuffer-empty-chain-handling' (6a3dd717 Azat Khuzhin) + o Don't loose top error in SSL (3d1a7a1d Yury Korzhetsky) + o Remove needless check for arc4_seeded_ok (6602a97d Seong-Joong Kim) + o Merge pull request #769 from sungjungk/fix-return-handling (91084140 Nathan French) + + build: + o Define `_GNU_SOURCE` properly/consistently per autoconf (00ba9fa2 Enji Cooper) + o signal: guard __cdecl definition with #ifdef (d89045a6 Azat Khuzhin) + o Link test/regress with event_core/event_extra over event (22380996 Azat Khuzhin) + + tests: + o Use kill() over raise() for raising the signal (fixes osx 10.14 with + kqueue) (3db5296b, a45f6733 Azat Khuzhin) + o tinytest: implement per-test timeout (via alarm() under !win32 only) + (b64dbfb6, 75d7e1ff Azat Khuzhin) + +Changes in version 2.1.9-beta (10 February 2019) + + This changelog will differs from other releases in the next few clauses: + - contains only highlighted changes (so now it will not contains a lot of + patches that fixes some stuff in regression tests, typos, leaks fixes in + samples and so forth) + - no authors (since merge commits breaks them anyway, but AUTHORS sections in + README will be kept up to date) + - group name trimmed from commit subjects trimmed + - it's been 2 years since the previoius release, so it is pretty huge + + And I think that this is more useful, so from now on it will always has the + same look (until there will too many objections of course). + + To view full changelog please use git: + git log --format=' o %s (%h %aN)' release-2.1.8-stable...release-2.1.9-beta + + + dist archive: + o Add cmake rules into dist archive (bf3a67cf) + o Add missing print-winsock-errors.c into dist archive (822d6462) + o Include openssl-compat.h into dist archive (08658136) + + core: + o Merge branch 'check-O_NONBLOCK-in-debug' (a39898f3, a8155c62) + o Merge branch 'event-ET-#636-v2' (ca4b6404) + o Fix visibility issues under (mostly on win32) + (349081e1g, 802be13ag, a1f28e2f) + o Define __EXT_POSIX2 for QNX (a2176f2c) + o Cleanup __func__ detection (b3af7bdd) + o Add convenience macros for user-triggered events (06ec5de6) + o Notify event base if there are no more events, so it can exit without delay (d9d1c09e) + o Fix base unlocking in event_del() if event_base_set() runned in another thread (4f0f40e3) + o If precise_time is false, we should not set EVENT_BASE_FLAG_PRECISE_TIMER (27dee54d) + o Fix race in access to ev_res from event loop with event_active() (43d92a6d) + o Return from event_del() after the last event callback termination (876c7ac7) + + http: + o Merge branch 'http-EVHTTP_CON_READ_ON_WRITE_ERROR-fixes-v2' (eb7b472b) + o Preserve socket error from listen across closesocket cleanup (2ccd00a6) + o fix connection retries when there more then one request for connection (d30e7bba) + o improve error path for bufferevent_{setfd,enable,disable}() (a8cc449e) + o Fix conceivable UAF of the bufferevent in evhttp_connection_free() (6ac2ec25) + o Merge branch 'http-request-line-parsing' (cdcfbafe) + o Fix evhttp_connection_get_addr() fox incomming http connections (4215c003) + o fix leaks in evhttp_uriencode() (123362e9) + o CONNECT method only takes an authority (7d1ffe64) + o Allow bodies for GET/DELETE/OPTIONS/CONNECT (23eb38b9) + o Do not crash when evhttp_send_reply_start() is called after a timeout. (826f1134) + o Fix crashing http server when callback do not reply in place (5b40744d, b2581380) + o fix handling of close_notify (ssl) in http with openssl bufferevents (7e91622b) + + evrpc: + o use *_new_with_arg() to match function prototype (a95cc9e3) + o avoid NULL dereference on request is not EVHTTP_REQ_POST (e05136c7) + + regression tests: + o Merge branch 'TT_RETRIABLE' (6ea1ec68, f9b592aa) + + bufferevent: + o Merge branch 'iocp-fixes' (6bfac964) + o Merge branch 'be-wm-overrun-v2' (3f692fff) + o bufferevent_socket_connect{,_hostname}() missing event callback and use ret code (1dde74ef) + o don't fail be_null_filter if bytes are copied (b92b0792) + o Call underlying bev ctrl GET_FD on filtered bufferevents (ebfac517) + + bufferevent_openssl/openssl: + o Merge branch 'ssl_bufferevent_wm_filter-fix' (30020a35) + o be_openssl: avoid leaking of SSL structure (e86ccfe5) + o Fix build with LibreSSL 2.7 (894ca48a) + o Add missing includes into openssl-compat.h (01bc36c1) + o Explicitly call SSL_clear when reseting the fd. (29b7a516) + o Unbreak build with LibreSSL after openssl 1.1 support added (230af9f0) + + samples: + o Merge branch 'sample-http-server' (b6309bcc) + o sample/https-client: use host SSL certificate store by default (5c0132f3) + + listener: + o ipv6only socket bind support (ba148796) + o Merge branch 'listener-immediate-close' (df2ed13f) + o Merge branch 'evconnlistener-do-not-close-client-fd' (42e851bb) + + evdns: + o evdns: handle NULL filename explicitly (0033f5cc) + o Merge branch 'evdns_getaddrinfo-race-fix' (3237d697) + o Generating evdns_base_config_windows_nameservers docs on all platforms (3bd2ce43) + + utils: + o Merge branch 'evutil_found_ifaddr-dev' (b07e43e6) + o Avoid possible SEGVs in select() (in unit tests) (8818c86c) + o Port `event_rpcgen.py` and `test/check-dumpevents.py` to Python 3. (532a8cc3) + + buffer: + o Fix assert() condition in evbuffer_drain() for IOCP (d6326104) + o fix incorrect unlock of the buffer mutex (for deferred callbacks) (2b4d127d) + o Fix wrong assert in evbuffer_drain() (9f4d0dce) + + cmake: + o fix checking of devpoll backend (like in autotools, by devpoll.h existence) (7f161902) + o support static runtime (MSVC) (c8b3ec17, 61fb055a) + o do not build both (SHARED and STATIC) for MSVC/win32 (bc7f2fd9) + o introduce EVENT__LIBRARY_TYPE option (eb10a738) + o ensure windows dll's are installed as well as lib files (29590718) + o Fix generation of LibeventConfig.cmake for the installation tree (7fa08c4b) + o fix pkgconfig generation (copy-paste typo) (cc554d87) + o Merge branch 'cmake-missing-bits' (9806b126) + o Fix detection of timerfd_create() in CMake. (e50af331) + o Merge branch 'cmake-configure-fixes-v2' (a0bfe2c4) + o Do not add epoll_sub (syscall wrappers) for epoll in cmake (cea61de6) + o Fix RPATH for APPLE (45b1f379) + + autotools: + o include win32 specific headers for socklen_t detection on win32/mingw (d7579fb9) + o Ignore evconfig-private.h for autotools (37423849) + o config.h can't be prefixed unconditionally (63a054f8) + o Merge branch 'pull-628' (7e56c8b2) + o Provide Makefile variables LIBEVENT_{CFLAGS,CPPFLAGS,LDFLAGS} (2f060c5f) + o confirm openssl is working before using (b39ccf8e) + o pass $(OPENSSL_INCS) for samples (FTBFS macOS) (c2495265) + o Add configure check for midipix (d433201e) + o Fix tests with detached builds (c46ff439) + + build: + o Fix arc4random_addrandom() detecting and fallback (regression) (303d6d77) + o Merge branch 'win32-fixes' (ebd12e6d) + o Merge branch 'fix-openssl-linking' (e7bd9e03) + o Merge branch 'fix-struct-linger' (8567f2f5) + + CI: + o travis-ci/appveyor now uses fast_finish+allow_failures + (5e97b6e6, dd472e7d, dfb5fc167) + o Merge branch 'travis-ci-osx-fixes' (9f02b39c) + o Merge branch 'win64-fixes' (aee0fcd5) + + +Changes in version 2.1.8-stable (22 January 2017) + + Libevent 2.1.8-stable, it contains openssl fixes for resetting fd and using + bufferevent_openssl_filter_new(). vagrant fixes, some build fixes, increased + timeout for some tests (to reduce number of failures due to timing issues), + date in RFC1123 format and running tests in parallel. + + There are highlighted changes above. + + Build fixes: + o Fix _FILE_OFFSET_BITS redinition (solaris/autotools) (336f3b11 Azat Khuzhin) + o util-internal: fix __func__ redefinition (netbsd) (253e7fa9 Azat Khuzhin) + o Fix signedness differ for iov_base (solaris) (2c62062e Azat Khuzhin) + o evutil_time: include <unistd.h> when there is only sleep()/usleep() (3e75194c Azat Khuzhin) + o http: fix formatter for pritnf for req->ntoread (osx) (1cbf26f6 Azat Khuzhin) + Testing environment: + o Merge branch 'automake-tests-parallel-v4' (*includes ci bits also*) (59e217df Azat Khuzhin) + Vagrant env fixes: + o vagrant/netbsd: missing libtool (9c9be399 Azat Khuzhin) + o vagrant/netbsd: more reliable way of installing packages (36da6877 Azat Khuzhin) + o vagrant/osx: use make instead of gmake (there is no gmake) (f7c70aef Azat Khuzhin) + o vagrant: add centos box (ca591c5b Azat Khuzhin) + Tests: + o test/dns: replace servname since solaris does not have "http" (d6bafbbe Azat Khuzhin) + o test/thread: netbsd is too slow, increase timeout for conditions_simple (3c7422fc Azat Khuzhin) + o test/dns: run async resolving after sync one (to avoid timeouts) (07862531 Azat Khuzhin) + o test/http: turn off some tests that based on backlog filling (falky) (26f416c1 Azat Khuzhin) + Bugfixes: + o Merge branch 'openssl-filter-fixes-v4' (83e0f43b Azat Khuzhin) + o Merge branch 'date-rfc1123' (68def435,4798de6c,4545807d Azat Khuzhin) + o Merge branch 'be-openssl-fd-reset-fix-v2' (86fa0070,32adf434 Azat Khuzhin) + o Merge branch 'openssl-1.1-init-fixes-v2' (18a161f0 Azat Khuzhin) + o Fix incorrect MIME type (23f9a20e johnsonlee) + Trivial fixes: + Documentation updates: + o Update README.md (3821cca1 Breaker) + + +Changes in version 2.1.7-rc (2 Novemer 2016) + + Libevent 2.1.7-rc contains openssl 1.1 support, build fixes, CI improvements + and plus Vagrantfile for testing under multiple OS'es. + + + Continious Integration: + o Use coveralls.io via travis (9ac000c Azat Khuzhin) + o travis-ci: use container-based infrastructure (7e12e96 Azat Khuzhin) + o travis-ci/osx: fix compiling/linking openssl libraries (9d2f8d4 Azat Khuzhin) + o travis-ci: use gcc-5 (fixes osx|gcc failures) (d7ceae5 Azat Khuzhin) + o Testing with vagrant for 6 OS and cmake+autoconf (9585338 Azat Khuzhin) + o travis-ci/osx: install lcov (e4e099b Azat Khuzhin) + + Build Improvements/Fixes: + o Fix cmake -DEVENT__COVERAGE=ON (40fbffc Azat Khuzhin) + o autogen.sh: learn about gmake (9376ac4 Azat Khuzhin) + o autogen.sh: remove all autoconf/automake caches, if any (69cce25 Azat Khuzhin) + o cmake: fix finding python2, and check that it is really 2 (3453c08 Azat Khuzhin) + o cmake: fix CheckFunctionExistsEx/CheckPrototypeDefinition (CMP0054) (43b69b2 Azat Khuzhin) + o cmake: cleanup (dc624ad Zonr Chang) + o cmake/win32: fix running regress, but fixing finding python2 interpreter (bcb990a Azat Khuzhin) + o cmake: use PYTHON_EXECUTABLE to find python2 (a4d044c Azat Khuzhin) + o Merge branch 'force-disable-clockgettime' (83c7cdf Azat Khuzhin) + + Code Improvements (core) + o use ev_uint16_t instead of unsigned short for port (e983712 Thomas Bernard) + o Merge branch 'contrib-guide-v2' (b9c5077 Azat Khuzhin) + o poll: Prevent libevent from spinning if POLLNVAL occurs (675974c Tim Hentenaar) + + Testing: + o test/regress: cover a polling of invalid fd (cb0df5c Tim Hentenaar) + + Code Improvements (bufferevent_openssl) + o Make it build using OpenSSL 1.1.0 (3e9e0a0 Kurt Roeckx) + o Don't call BIO_number_{read|written} on NULL BIOs. (6702da1 Adam Langley) + o Switch from a 512 to 2048-bit RSA key. (f9803a6 Adam Langley) + + Trivial fixes: + o Ignore temporary configure files (8fb08ae Azat Khuzhin) + o README.md: fix typo: ar -> are (2361616 Simone Basso) + o be: just a simple mistake, reinclude the <errno.h> (7521664 Seven) + +Changes in version 2.1.6-beta (4 July 2016) + + Libevent 2.1.6-beta contains mostly bug fixes (evbuffers, evthread, evdns, + bufferevents, core, http, samples), improvements but mostly to fix some + possible issues (EVHTTP_CON_LINGERING_CLOSE), a lot of new unit tests and new + appveyor integration. + + Security Fixes (utils) + o evutil_parse_sockaddr_port(): fix buffer overflow (329acc1 Azat Khuzhin) + + Security Fixes (evdns) + o evdns: name_parse(): fix remote stack overread (96f64a0 Azat Khuzhin) + o evdns: fix searching empty hostnames (ec65c42 Azat Khuzhin) + + New APIs (evdns) + o New function to get address for nameserver. (537177d Nick Mathewson) + + New APIs (bufferevents) + o expose bufferevent_incref/decref (with fewer modifications) (1ed6718 Mark Ellzey) + + New APIs (internal) + o evdns: export cancel via callbacks in util (like async lib core/extra issues) (8cbe65d Azat Khuzhin) + + New APIs/Improvements (http) + o http: take EVHTTP_CON_LINGERING_CLOSE into account for "Expect: 100-Continue" (ac448a7 Azat Khuzhin) + o http: lingering close (like nginx have) for entity-too-large (9fde518 Azat Khuzhin) + o http: read server response even after server closed the connection (680742e Azat Khuzhin) + o http: export evhttp_connection_set_family() (714fc70 Azat Khuzhin) + o http: reuse connected address only with EVHTTP_CON_REUSE_CONNECTED_ADDR (a50f5f0 Azat Khuzhin) + o http: use IP address that we got before (if any) during retrying (54c887d Azat Khuzhin) + + Bugfixes (core) + o Fix getaddrinfo under solaris (for multiprotocol case) (40730ae Azat Khuzhin) + o Check for Mac OS X 10.4 kqueue bug properly (df6f99e Mark Mentovai) + o event_reinit: make signals works after fork() without evsig_add() (88640aa Nicholas Marriott) + o event_reinit: always re-init signal's socketpair (ad0c237 Nicholas Marriott) + o Free event queues even for recursive finalizers (7c8d015 Azat Khuzhin) + o Fix checking for make_base_notifiable() (f337296 Azat Khuzhin) + o Set correct socklen for PF_INET6 sockaddr len (3499ad9 Mark Ellzey) + o Fix garbage value in socketpair util function, stdint? (043ae74 Mark Ellzey) + o fix the return value of event_deferred_cb_schedule_ (38cef64 Greg Hazel) + o event_free_debug_globals_locks(): disable lock debugging (e5c87d1 Azat Khuzhin) + o event: call event_disable_debug_mode() in libevent_global_shutdown() (941faae Azat Khuzhin) + o ht-internal: don't reset hth_table_length explicitly in name_##HT_CLEAR (597c7b2 Azat Khuzhin) + + Bugfixes (evthread) + o evthread: fix evthread_setup_global_lock_() for debug-lock with a real-lock case (e4556fc Azat Khuzhin) + o evthread: evthreadimpl_disable_lock_debugging_() for libevent_global_shutdown() (ccc5593 Azat Khuzhin) + + Bugfixes (evdns) + o evdns: avoid double-free in evdns_base_free() for probing requests (4db15e0 Azat Khuzhin) + o evdns: evdns_base_free(): fix UAF of evdns_base with @fail_requests (00313c5 Azat Khuzhin) + o evdns: evdns_base_free(): free requests before namservers (14f84bb Azat Khuzhin) + o evdns: fix randomize-case by make case-insensitive as required (9c238de Azat Khuzhin) + + Bugfixes (bufferevents) + o be_sock: handle readv() returns ECONNREFUSED (freebsd 9.2) (3189eb0 Azat Khuzhin) + o be_filter: avoid data stuck under active watermarks (b627ad8 Eduardo Panisset) + o Fix bufferevent_pair to properly set BEV_EVENT_{READING,WRITING} on flush. (2851889 David Paschich) + o be_openssl: clear all pending errors before SSL_*() calls (38e0f4a Azat Khuzhin) + o be_sock: cancel in-progress dns requests (86dfd2c Azat Khuzhin) + o be_sock: unfreeze buffers on fd changing (255525d Azat Khuzhin) + o be_sock: bufferevent_socket_connect_hostname(): make it thread-safe (809bb39 Azat Khuzhin) + o be_openssl: don't call do_write() directly from outbuf_cb (da52933 Azat Khuzhin) + o be_openssl: use bufferevent_enable() instead of bufferevent_add_event_() (0c66d32 Azat Khuzhin) + o be_openssl: don't add events during bev creation (like be_sock) (f4b6284 Azat Khuzhin) + o Fix lock leak in be_pair_flush() if flush type is BEV_NORMAL (f45d39d Bill Vaughan) + o be_openssl: don't use *_auto() in do_handshake() we can't have fd == -1 there (877280d Azat Khuzhin) + o be_openssl: don't call set_open_callbacks() if fd == -1 (e8a2da9 Azat Khuzhin) + o be_openssl: get rid off hackish "fd_is_set", to fix some corner cases (40b0379 Azat Khuzhin) + o be: we don't need to use getpeername() we we have conn_address (2c271e2 Azat Khuzhin) + o Call underlying bev ctrl SET_FD on filtered bufferevents (c2aa7dc Mark Ellzey) + o be_pair: release shared lock with the latest of bufferevent_pair (92a359e Azat Khuzhin) + + Bugfixes (http) + o [Issue #313] set method to ASCII "NULL" if evhttp_method() returns NULL (17cc636 Mark Ellzey) + o evhttp_have_expect(): fix -Wlogical-not-parentheses (24b5214 Azat Khuzhin) + o http: set fd to -1 unconditioally, to avoid leaking of DNS requests (7a4b472 Azat Khuzhin) + o http: avoid leaking of fd in evhttp_connection_free() (f0e1341 Azat Khuzhin) + o http: get fd from be layer during connection reset (4a53c54 Azat Khuzhin) + o http: fix EVHTTP_CON_READ_ON_WRITE_ERROR when it doesn't supported by OS (2ff164a Azat Khuzhin) + o http: do not do function calls under EVUTIL_ASSERT() to fix NDEBUG builds (7c89999 Azat Khuzhin) + o http: fix leaking of response_code_line (8f18a62 Azat Khuzhin) + o http: fix "Expect: 100-continue" client side (0b46b39 Azat Khuzhin) + o http: fix conflicts EVHTTP_CON_AUTOFREE and EVHTTP_CON_REUSE_CONNECTED_ADDR (4dc0979 Azat Khuzhin) + o http: avoid epoll_ctl() on already closed fd (triggers by http/chunk_out) (ab3bc69 Azat Khuzhin) + o http: install timeout for read too during connect for ssl (040000d Azat Khuzhin) + o http: fix evhttp_request_own() by checking EVHTTP_USER_OWNED in more cases (b0d3964 Azat Khuzhin) + o http: fix detecting EOF without write (7ed02ac Azat Khuzhin) + o evhttp: Fix failure to send all output data for POST/PUT requests (24eea0d John Ohl) + o Fix evhttp_uriencode() regression. (c6b1ec1 Mark Ellzey) + o removed unused vars (e94250c Mark Ellzey) + o pointer overflow checks for evhttp_uriencode (72afe4c Zonr Chang) + + Bugfixes (evbuffers) + o buffer: fix overflow check in evbuffer_expand_singlechain() (a3f4ccd Azat Khuzhin) + o buffer: evbuffer_add_buffer(): clean empty chains from destination buffer (26fd932 Azat Khuzhin) + o Fix n_add_for_cb in evbuffer_prepend() in case of new buffer required (0abd039 Azat Khuzhin) + o be_filter: actually disable output_filter during processing output (c031215 Simon Perreault) + o evbuffer_add: Use last_with_datap if set, not last. (a8769ef Marcus Sundberg) + o EVBUFFER_PTR_SET -> EVBUFFER_PTR_ADD (8674e4f jer-gentoo) + + Bugfixes (evconnlistener) + o listener: unlock lev on error in listener_read_cb() (2a71b33 Azat Khuzhin) + o Fix potential fd leak in listener_read_cb() (a695a72 Mark Ellzey) + + Testing + o tests: use waitpid(..., WNOWAIT) to fix failing of main/fork under solaris (43eb56c Azat Khuzhin) + o test: replace sleeping with syncing pair in main/fork (16d220c Azat Khuzhin) + o test/http: do not run tests that based on backlog filling (freebsd) (500b6b7 Azat Khuzhin) + o test/bufferevent/iocp: fix test name for "bufferevent_connect_fail_eventcb" (4410e9d Azat Khuzhin) + o test/ssl: use send()/recv()/EVUTIL_ERR_RW_RETRIABLE()/EVUTIL_SOCKET_ERROR() to fix win32 (a9e8cd6 Azat Khuzhin) + o test/https_basic: increase timeout for complete write (fixes win32) (d5a2f2f Azat Khuzhin) + o test: fix building with --disable-thread-support under win32 (a487706 Azat Khuzhin) + o test/buffer: evbuffer_add_buffer() with empty chains (a272bc4 Azat Khuzhin) + o test/buffer: evbuffer_remove_buffer() with empty chains (prepend) (f0cfa14 Azat Khuzhin) + o test/buffer: evbuffer_remove_buffer() with empty chains (evbuffer_add_buffer()) (2880ce6 Azat Khuzhin) + o test/buffer: cover evbuffer_expand() for overflow (48dab7a Azat Khuzhin) + o test/be_filter: creating test case for data stuck with active watermarks (766194b Eduardo Panisset) + o test/http: avoid using conditionals with omitted operands (fixes VS2015) (2a4bf29 Azat Khuzhin) + o test/http: don't mix declarations and code (fixes -Wdeclaration-after-statement) (aabf1c2 Azat Khuzhin) + o test/buffer: fix leak in test_evbuffer_prepend() (c08d90b Azat Khuzhin) + o test/buffer: avoid errors with --no-fork (reinitialize static vars) (e7d1e39 Azat Khuzhin) + o test/buffer: cover n_add_for_cb when evbuffer_prepend() need to allocate buffer (e77ff41 Azat Khuzhin) + o test/tinytest_macros: add new one tt_nstr_op() (bd19a28 Azat Khuzhin) + o test/bufferevent: check that output_filter disabled during processing output (ae28812 Azat Khuzhin) + o test/listener: regression for missing unlock in listener_read_cb() (7d85651 Azat Khuzhin) + o test/regress: add tests for evbuffer_add() breakage on empty last chain (d5ee739 Marcus Sundberg) + o test/http: fix running some tests sequential (with --no-fork) (bddad71 Azat Khuzhin) + o test/http: localize evhttp server structure (cbc3209 Azat Khuzhin) + o test/dns: regression for empty hostname (d7348ba Azat Khuzhin) + o test/http: fix SERVER_TIMEOUT tests under win32 (d49a658 Azat Khuzhin) + o test/http: add a helper for creating timedout/failed request (376f107 Azat Khuzhin) + o test/http: adopt for C90 (mixed code and declarations) (d02a285 Azat Khuzhin) + o test/http: cover NS timed out during request cancellations separatelly (0c343af Azat Khuzhin) + o test/http: request cancellation with resolving/{conn,write}-timeouts in progress (334340d Azat Khuzhin) + o test/http: exit from the loop in the errorcb to wait cancellation (927ab33 Azat Khuzhin) + o regress_clean_dnsserver(): reset global port vars (351207f Azat Khuzhin) + o test/http: read_on_write_error: fix it for win32 (3b58169 Azat Khuzhin) + o test/http: separate coverage for EVHTTP_CON_READ_ON_WRITE_ERROR (5c2b4c1 Azat Khuzhin) + o test/http: cover "Expect: 100-continue" client-server interaction (31d8116 Azat Khuzhin) + o test/http: *lingering tests shouldn't have "Expect: 100-continue" (ed469ab Azat Khuzhin) + o test: use EVUTIL_SHUT_WR (04fc82f Azat Khuzhin) + o test/http: avoid huge stack allocations to fix win32 builds (3166765 Azat Khuzhin) + o test: http/lingering_close: cover EVHTTP_SERVER_LINGERING_CLOSE (e122ca1 Azat Khuzhin) + o test: http/non_lingering_close: cover ~EVHTTP_SERVER_LINGERING_CLOSE (f41e1b0 Azat Khuzhin) + o test: http/*: update expected HTTP codes for body exceeds `max_body_size` (addf2b9 Azat Khuzhin) + o test: http/data_length_constrains: set EVHTTP_CON_READ_ON_WRITE_ERROR (d38a723 Azat Khuzhin) + o test: increase buffer size for http/data_length_constraints to trigger EPIPE (0792e1e Azat Khuzhin) + o test/tinytest_demo: include <windows.h> for win32 to fix tdm-gcc (f062bbe Azat Khuzhin) + o test/regress: cover event_del() waiting mechanism (5b58b70 Azat Khuzhin) + o test/regress: cover existing signal callbacks and fork() + event_reinit() (ceddc60 Azat Khuzhin) + o test/regress: cover signals after fork() + event_reinit() (b075b81 Azat Khuzhin) + o test/regress: main/fork: rewrite assertions by just removing event in callback (088d8b3 Azat Khuzhin) + o test/dns: check exit code of evdns_getaddrinfo() (0b9d432 Azat Khuzhin) + o test/dns: cover evdns_getaddrinfo() and evdns_base_free() with @fail_requests (4ad3483 Azat Khuzhin) + o test/dns: cover @fail_requests for evdns_base_free() (d6c6fb4 Azat Khuzhin) + o test/dns: more graceful coverage of @fail_requests (123d372 Azat Khuzhin) + o test/ssl: cover busy-loop (i.e. {read,write}-blocked-on-{write,read} stuff) (da0ea7a Azat Khuzhin) + o test/http: write_during_read for https (23c77b6 Azat Khuzhin) + o test/http: connection_fail for https (7ea26f7 Azat Khuzhin) + o test/http: stream_out for https (ac04968 Azat Khuzhin) + o test/http: chunk_out for https (a71ffb9 Azat Khuzhin) + o test/regress: fix ssl-less builds (need to make this prettier) (3160716 Azat Khuzhin) + o test/http: allow dirty shutdown for ssl to fix https_incomplete (1ede326 Azat Khuzhin) + o test/http: https basic (59714b4 Azat Khuzhin) + o test/http: incomplete{,_timeout} for https (615490d Azat Khuzhin) + o test/http: add simplest test for http/https/https_dirty_shutdown (93b19dc Azat Khuzhin) + o test/http: https: retry coverage (7c2d24a Azat Khuzhin) + o test/http: https server support (plus some helpers) (a7088ad Azat Khuzhin) + o test/http: more sanity checks (a27c53c Azat Khuzhin) + o test/ssl: export getkey()/getcert()/get_ssl_ctx()/init_ssl() for https (0c4c387 Azat Khuzhin) + o test/regress_be: basic coverage bufferevent_flush() for pair/sock layers (ad52602 Azat Khuzhin) + o test/regress_be: socket_filter_inactive: check bufferevent after creation (f8081af Azat Khuzhin) + o test/regress_be: cover finalizers from inactive to active queue (337684b Azat Khuzhin) + o test/regress_buffer: fix clang compilation warnings (d8fd4c0 Azat Khuzhin) + o test/regress_http: fix compilation warnings (-Wmissing-field-initializers) (cd422e0 Azat Khuzhin) + o test/regress_dns: fix compilation warnings (-Wmissing-field-initializers/for) (f55db98 Azat Khuzhin) + o tests/regress_dns: cover that randomize-case works case-insensitive (1e8bfbc Azat Khuzhin) + o test: fix bufferevent/bufferevent_pair_release_lock in debug mode (3f749e9 Azat Khuzhin) + o test: fix bufferevent/bufferevent_pair_release_lock for freebsd (79f9ace Azat Khuzhin) + o test/regress_be: bufferevent_enable() shouldn't call eventcb by it's own (a0f308d Azat Khuzhin) + o test/regress_be: introduce fake_listener_create() (37dc9e0 Azat Khuzhin) + o test/regress_http: cover evhttp_request_own() (6f6fa0d Azat Khuzhin) + o test/regress_http: cover write during read (3d15aeb Azat Khuzhin) + o test/regress_http: verify that closecb will be called without multiple write (4be6c70 Azat Khuzhin) + o test/regress: fix bufferevent_pair_release_lock with EVENT_DEBUG_MODE (6ea6655 Azat Khuzhin) + o test/regress_ssl: check events fd/pending after timeout triggered (cdafdf0 Azat Khuzhin) + o test/regress_ssl: cover case when server didn't up (failed with timeout) (74845f1 Azat Khuzhin) + o test/regress_ssl: covert that we can't change fd with underlying (df507af Azat Khuzhin) + o test/regress_ssl: cover that events (read/write) at finish not pending (762edb4 Azat Khuzhin) + o test/regress_ssl: cover fd manipulations (b78a829 Azat Khuzhin) + o test/regress_ssl: convert open_ssl_bufevs() to mask (46bba73 Azat Khuzhin) + o test/regress_ssl: convert client/server to mask too (3455991 Azat Khuzhin) + o test/regress_ssl: cover "allow_dirty_shutdown" (0430327 Azat Khuzhin) + o test/regress_ssl: convert regress_bufferevent_openssl() to bitmask (342e116 Azat Khuzhin) + o tests/regress_ssl: drop duplicated assert (25e56fd Azat Khuzhin) + o test/regress_http: initialize "dns_base" to avoid reading trash (9f0bff3 Azat Khuzhin) + o test/http: cover retrying with saved conn_address by shutting down dns server (f4874d8 Azat Khuzhin) + o be_pair/regress: cover use of shared lock (lock/unlock/free) (a558fcd Azat Khuzhin) + o regress_dns: drop hack for event_debug_map_HT_GROW in leak tests (3540a19 Azat Khuzhin) + + Sample code + o Fix memory leak in signal-test.c (666db91 basavesh.as) + o sample/hello-world: exAmple, not eXMple (2d3cd35 kirillDanshin) + o dns-example: allow to set ns from args (df19a97 Azat Khuzhin) + o dns-example: convert to getopt() (32f8592 Azat Khuzhin) + o http-connect: make it win32 compilable (1bf7595 Azat Khuzhin) + o sample/https-client: allow to change path to ca-certificates (fdf713a Azat Khuzhin) + o sample/https-client: check for ERR_remove_thread_state() existence (c4e9d9b Azat Khuzhin) + o sample/https-client: replace ERR_remove_state() by ERR_remove_thread_state() (77ad68a Azat Khuzhin) + o sample/https-client: add -timeout option (4637aa8 Azat Khuzhin) + o sample/https-client: don't try to free uninitialized SSL (f3d7ff5 Azat Khuzhin) + o sample/https-client: graceful exit with freeing memory (to make valgrind happy) (24a1f25 Azat Khuzhin) + o https-client: correctly handle URLs with no path (like "https://host:port") (29a0482 Andrey Skriabin) + o sample/http-connect: don't use assert() to make it work with NDEBUG (6dc71e7 Azat Khuzhin) + o sample/http-connect: made it compatible with C90 (f976d43 Azat Khuzhin) + o sample: add HTTP CONNECT tunnelling example using libevent http layer (1d34498 Azat Khuzhin) + o Update dns-example. (620ff24 Mark Ellzey) + + Documentation + o Update README.md (b8ec70c Mark Ellzey) + o Update README.md (80faee9 Mark Ellzey) + o Update README.md (ad4a897 Mark Ellzey) + o Update README.md (a2b2e1e Mark Ellzey) + o Update README.md (0dfa5dc Mark Ellzey) + + Code Improvements (evthread) + o evthread: add evthread_get_{lock,condition}_callbacks() helpers (c0b34f6 Azat Khuzhin) + + Code Improvements (core) + o util: make @sa const for evutil_socket_connect_() (a8d32c2 Azat Khuzhin) + + Code Improvements (http) + o http: assert's that evbuffer_drain() success on connection reset (2185e63 Azat Khuzhin) + o http: introduce evhttp_request_free_() helper (22061ac Azat Khuzhin) + o http: introduce evhttp_is_request_connection_close() helper (6540da3 Azat Khuzhin) + + Code Improvements (bufferevents) + o be_sock: bufferevent_socket_set_conn_address(): assert instead of silent no-op (0ab88c2 Azat Khuzhin) + o be_sock: sanity check in bufferevent_socket_set_conn_address() (eedbeff Azat Khuzhin) + o be: replace sockaddr_storage with sockaddr_in6 for conn_address (3889612 Azat Khuzhin) + o be: replace conn_address by full struct instead of pointer (e5615aa Azat Khuzhin) + o bufferevent: move conn_address out from http into bufferevent (8bb3842 Azat Khuzhin) + o be: make @sa const for bufferevent_socket_connect() (dc33c78 Azat Khuzhin) + + Cleanups (core) + o Refactoring conditional directives that break parts of statements. (4b41eeb lzmths) + o epoll: introduce PRINT_CHANGES() macro to avoid copy-pasting (a1b142b Azat Khuzhin) + o tab (6e7a580 Greg Hazel) + + Cleanups (evbuffers) + o buffer_compat: fix comment -- we have EVBUFFER_EOL_ANY not EOL_STYLE_ANY (575ff67 Azat Khuzhin) + + Cleanups (bufferevents) + o be_sock: evutil_getaddrinfo_async_() always return 0 (dbff101 Azat Khuzhin) + o be_sock: drop be_sock_add() macro (useless and debug unfriendly) (fad5fe2 Azat Khuzhin) + o be: introduce bufferevent_generic_adj_existing_timeouts_() (3c1f58f Azat Khuzhin) + o be: add_event: use evutil_timerisset() (a96b73b Azat Khuzhin) + o be_openssl: introduce be_openssl_auto_fd() helper (2a8a711 Azat Khuzhin) + o be_openssl: introduce set_open_callbacks_auto() (510da71 Azat Khuzhin) + + Cleanups (http) + o http: make fallback for EVHTTP_CON_READ_ON_WRITE_ERROR more cleaner (d405492 Azat Khuzhin) + o http: coding style issue (365f181 Azat Khuzhin) + + Cleanups (evdns) + o evnds: inline TEST_NAME macro to make debuggin easier (0c615f4 Azat Khuzhin) + + Portability Fixes + o [#372] check for errno.h (3031617 Mark Ellzey) + o Fixed Unicode issue in error messages. (e8b7895 Mattes D) + o Assume that ke_udata is an integer type on CloudABI. (5602e45 Ed Schouten) + o Add missing include of <netinet/in.h>. (b2c68bc Ed Schouten) + o Include <sys/ioctl.h>, <sys/resource.h> and <sys/wait.h> optionally. (c1404b5 Ed Schouten) + o Test against SO_REUSEADDR (along with _WIN32). (ce1776c Ed Schouten) + o Always define missing TAILQ functions from sys/queue.h (2828bdb Christopher Wiley) + o Don't use BSD u_* types. (fd36647 Ed Schouten) + o Remove BSD-ism: TIMEVAL_TO_TIMESPEC(). (193c7de Ed Schouten) + o be: include all variations of headers for sockaddr_in6 struct (c212291 Azat Khuzhin) + o be: fix sockaddr_in6 type definition for win32 (c42bc6b Azat Khuzhin) + + Continious Integration: + o travis: split long lines, and make it cleaner (685a6a1 Azat Khuzhin) + o travis: fix autotools on osx by reinstalling libtool (088ea5e Azat Khuzhin) + o appveyor/autotools: link with openssl by passing LDFLAGS/CFLAGS (6fcfa25 Azat Khuzhin) + o appveyor: image already had openssl installed (4634b85 Azat Khuzhin) + o appveyor: check -DUNICODE -D_UNICODE according to ReleaseChecklist (cmake only) (e9acc44 Azat Khuzhin) + o appveyor: ignore failure of mingw-get (1810857 Azat Khuzhin) + o appveyor: drop shallow_clone, since we use tags for detecting version in cmake (ac90133 Azat Khuzhin) + o appveyor: support cmake & autotools using build matrix (like travis-ci has) (8f95015 Azat Khuzhin) + o travis-ci/osx: relink gcc/g++ instead of clang (481481d Azat Khuzhin) + o travis-ci: enable multi-os mode (osx, linux) (79917e4 Azat Khuzhin) + o travis-ci: increase matrix (--disable-foo) (59649f7 Azat Khuzhin) + o travis-ci: adjust alignment (c8be339 Azat Khuzhin) + o travis: add builds without debug mode into matrix (3e56da2 Azat Khuzhin) + o test: run regress with EVENT_DEBUG_MODE=1 and without (cf2cf2a Azat Khuzhin) + o Update travis config for status updates (37453ab Mark Ellzey) + o Use autotools for appveyor until cmake is fixed. (1cc2e29 Mark Ellzey) + o Fix the link for appveyor OpenSSL installer (WIN32) (107d565 Mark Ellzey) + o Forgot to install OpenSSL for appveyor (26164a5 Joakim Söderberg) + o Add support for appveyor.com windows CI (5f89c37 Joakim Söderberg) + + Build Improvements/Fixes: + o evutil: mark ai_find_protocol() static (prototype-less) (5a157c8 Azat Khuzhin) + o cmake/solaris: set CMAKE_REQUIRED_LIBRARIES to fix functions detections (dc95823 Azat Khuzhin) + o cmake/solaris: fix building (link with socket,nsl) (050bfc7 Azat Khuzhin) + o cmake: check for ZLIB_INCLUDE_DIR, since we can have only library without headers (c4dfb93 Azat Khuzhin) + o autotools/win32: fix searching ssl library (671a24f Azat Khuzhin) + o cmake/win32: do not compile regress_thread on -DEVENT__DISABLE_THREAD_SUPPORT=ON (de0c196 Azat Khuzhin) + o cmake/win32: do not compile evthread_win32 on -DEVENT__DISABLE_THREAD_SUPPORT=ON (ecb0ec8 Azat Khuzhin) + o cmake: fix -DEVENT__ENABLE_VERBOSE_DEBUG (typo on -DUSE_DEBUG) (e35f224 Azat Khuzhin) + o cmake: do not use stderr for notifications/version-info (38716c6 Azat Khuzhin) + o autoconf: fix --disable-thread-support build under win32 (bb09535 Azat Khuzhin) + o buffer: don't mix code and declarations (8892f4c Azat Khuzhin) + o Update gitignore file to ignore cscope gen'ed files (0aaa4fb Neeraj Badlani) + o For non GCC/clang on OSX the -Wno-deprecated-declarations may not be valid (b5ca365 Rainer Keller) + o automake: define serial-tests only if automake have this option (61179de Azat Khuzhin) + o test/automake: don't use paralell test harness (since automake 1.12) (44d755e Azat Khuzhin) + o Ignore all pkgconfig generated stuff (ce38993 Azat Khuzhin) + o libevent_core and libevent_extra also deserve a pkgconfig file (b8d7c62 Jan Heylen) + o Ignore verify_tests.bat (win32 version) (0f2de10 Azat Khuzhin) + o cmake: require 3.1 only for win32 to make it work under ubunty precise (87f7238 Azat Khuzhin) + o cmake: require at least 3.1 for target_sources() (c46ead5 Azat Khuzhin) + o cmake: fix adding of compiler flags, and now it will (36588e1 Azat Khuzhin) + o Replace -Wswitch-enum with -Wswitch, and add it into cmake rules too (f29f59e Azat Khuzhin) + o test/regress_ssl: Fix compile problems for win32 (73d0360 Trond Norbye) + o util: fix "%zu" format on TDM-gcc/MinGW-w64 (79b69d8 Azat Khuzhin) + o cmake: don't define EVENT__NEED_DLLIMPORT always (fixes VS2013 static build) (49bd790 Azat Khuzhin) + o Add missing return statement to del_wait_thread so libevent can build. (4f778ab Nick Mathewson) + o cmake: fix building dns-example under win32 (missing getopt) (a1609a8 Azat Khuzhin) + o visibility: align it to make it more readable (bb6b53d Azat Khuzhin) + o cmake: Fix detection of ssize_t/SSIZE_T (7707f6b Azat Khuzhin) + o Ignore more configure stuff (configure.lineno) (8d34302 Azat Khuzhin) + o Fixed issue with cmake version generation (d56efd9 Mark Ellzey) + o Cmake is now officially working. (7f9646d Mark Ellzey) + o More cmake updates, lot's of missing definitions (49a5381 Mark Ellzey) + o CMake syntax fixes fo .in files (6aad23d Mark Ellzey) + o Revert "The Windows socket type is defined as SOCKET." (a264da8 Mark Ellzey) + o CMAKE CMAKE CMAKE CLEANUPS (a9db46a Mark Ellzey) + o Lot's of cmake updates (8b228e2 Mark Ellzey) + o Provide a mechanism for building the library on Windows with different compiler flags. Add a batch file that builds it for the M[DT][d] options and performs a hunt and gather of the different output libraries. (ded8086 billsegall) + o The Windows socket type is defined as SOCKET. (c9e6c3d billsegall) + o autotools: fix getservbyname() detection (959a4c2 Azat Khuzhin) + o Add missing <string.h> for openssl_hostname_validation module (3316a21 Azat Khuzhin) + o make test/regress_ssl.c compile without warnings (9f02a44 Thomas Bernard) + o test/regress_be: drop debug __asm__(int3) to fix arm build (8240379 Azat Khuzhin) + o event_debug_created_threadable_ctx_: fix compilation without debug mode (a068f2e Azat Khuzhin) + o Add a prototype for event_disable_debug_mode() (bfcedee Sebastian Hahn) + o http: eliminate warning about "socklen" in evhttp_connection_connect_() (dfad1a4 Azat Khuzhin) + o Updated gitignore (1dbb55d Mark Ellzey) + o Update bench_httpclient.c (cb96931 Seungmo Koo) + o *fix: bench_httpclient to support win32 (4e9325e zeliard) + o Commented out a WIN32 threading / timing test for now (e84e269 Mark Ellzey) + o Fix mixed declarations and code (forbidden by ISO C90) (0c7f217 Thomas Bernard) + o Fix "function declaration isn’t a prototype" (746d2c5 Thomas Bernard) + o This fixes a bug introduced in 27bd9faf498b91923296cc91643e03ec4055c230 (19ba454 Joakim Söderberg) + o changed strtotimeval signature as per #211 (bdbc823 Xiao Bao Clark) + o Added cmake-generated files to ignore list. (6c12bfe Matyas Dolak) + o Ignore `make dist` generated files (8a2c6c7 Azat Khuzhin) + + Debugging + o Debug mode option to error on evthread init AFTER other event calls. (dcfb19a Mark Ellzey) + + + +Changes in version 2.1.5-beta (5 January 2015) + + Security Fixes (evbuffers) + o Avoid integer overflow bugs in evbuffer_add() and related functions. See CVE-2014-6272 advisory for more information. (d49bc0e88b81a5812116074dc007f1db0ca1eecd) + + New APIs (evconnlistener) + o Provide support for SO_REUSEPORT through LEV_OPT_REUSABLE_PORT (b625361 Maciej Soltysiak) + + Bugfixes (core) + o Fix use-after-free error in EV_CLOSURE_EVENT callback (3cc0eac John Ohl) + o Fix race caused by event_active (3c7d6fc vjpai) + + Bugfixes (evbuffer) + o Fix evbuffer_peek() with len==-1 and start_at non-NULL. (ba59923) + o Consistently check for failure from evbuffer_pullup() (60f8f72) + o Fix evbuffer_peek() with len==-1 and start_at non-NULL. (fb7e76a) + + Bugfixes (windows, IOCP) + o be async: avoid double close() (f133b86 Azat Khuzhin) + + Bugfixes (bufferevents) + o Fix issue #127, double free for filterevents that use BEV_OPT_CLOSE_ON_FREE (2c82aa0 John Ohl) + o make bufferevent_getwatermark api more robust (a21e510 ufo2243) + o [Bugfix] fix bufferevent setwatermark suspend_read (b34e4ac ufo2243) + o bufferevent_openssl: reset fd_is_set when setfd with -1 is called (3da84c2 Azat Khuzhin) + o Fix compilation for older OpenSSL versions. (5c7282f Joakim Soderberg) + + New APIs (evhttp) + o Add evhttp_connection_set_family() to set addrinfo->family for DNS requests (12c29b0 Azat Khuzhin) + o Implement interface that provides the ability to have an outbound evhttp_connection free itself once all requests have completed (2b9ec4c,10fe4f John Ohl) + + New APIs (core) + o Implement new/free for struct evutil_monotonic_timer and export monotonic time functions (f2645f8 Andrea Shepard) + + Bugfixes (evdns) + o Load hosts file on Windows. (a0b247c Vilmos Nebehaj) + o Don't truncate hosts file path on Windows. (d0dc861 Vilmos Nebehaj) + o Fix a crash in evdns related to shutting down evdns (9f39c88,e8fe749) + o evdns: avoid read-after-free in evdns_request_timeout_callback() (61262a0 Azat Khuzhin) + o Correctly handle allocation failures in evdns_getaddrinfo (6a53d15) + o evdns: fix EVDNS_BASE_DISABLE_WHEN_INACTIVE in case retransmit/retry (74d0eee Azat Khuzhin) + o evdns: add retry/reissue tests for EVDNS_BASE_DISABLE_WHEN_INACTIVE (3ca9d43 Azat Khuzhin) + o evdns: fail ns after we are failing/retrasmitting request (97c750d Azat Khuzhin) + + Bugfixes (evhttp) + o http: reset connection before installing retry timer (fix http retries handling) (bc79cc5 Azat Khuzhin) + + + Testing + o regress_dns: fix leaks in getaddrinfo_async{,_cancel_stress} tests (2fdc5f2 Azat Khuzhin) + o test: add family argument for http_connection_test_() (177b8a7 Azat Khuzhin) + o test: add regress for evhttp_connection_set_family() with AF_INET and AF_UNSPEC (42aefeb Azat Khuzhin) + o test/http: add regress test for set family to AF_INET6 (3fbf3cc Azat Khuzhin) + o Update to a more recent tinytest_macros. (8da5a18) + o test/regress: add simplestsignal: to track reorder bugs separately (b897bef Azat Khuzhin) + o test/evbuffer_peek: add regress in case we have first buffer greater (e2d139d Azat Khuzhin) + o More evbuffer_peek() test cases (154006a) + o use correct tt macro for pointer compare (08c88ea) + o regress_buffer: fix 'memcmp' compare size (79800df Maks Naumov) + o Fix a use-after-free in unit tests. CID 752027 (3739057) + o Fix a dead-code warning in unit tests. CID 1193548 (c119f24) + o Use evutil_weakrand() in unit tests. (a677b72, 364c110) + o Use a more precise calculation for max in time-ratelim.c (ca5b5c7) + o Make a buffer larger in the tests to avoid a scary evbuffer_copyout_from() (fb57b8b) + o Fix several memory leaks in the unit tests. (89c1a3b) + o Add test for evhttp_connection_free_on_completion (b0e9924 John Ohl) + o Fix annoying heisenbug in test-time.c (cb73704) + + Sample code + o Make http-server.c output into good html5 (6d72bdc) + o Use FindClose for handle from FindFirstFile in http-server.c (6466e88) + o https-client: add -retries argument, for connection retries (d9da844 Azat Khuzhin) + + Bugfixes (build) + o Add missing headerfile for cmake (15d90cc Trond Norbye) + o ignore one more test binary (b6593aa Michael Richardson) + o ignore config.cache/test-driver files (c83f333 Mike Frysinger) + o add a --disable-samples configure flag (0c492b3 Mike Frysinger) + o Add a few files created by "make verify" to .gitignore. (1a8295a Pierre Phaneuf) + o updates in cmake build (27bd9fa Sergey Nikulov) + o Fix cmake error when the Module path has more than one entry. (befbd13 Acer Yang) + o Fix CMake shared library build (e69d910 Nobuaki Sukegawa) + o Fix warnings when compiling with clang 3.5 (f5b4765 John Ohl) + o Fix mixed declarations and code (forbidden by ISO C90) (8afbdbc Thomas Bernard) + + Bugfixes (miscellaneous) + o tree.h: drop duplicated content of tree.h (6193187 Azat Khuzhin) + o evdns: disable probing with EVDNS_BASE_DISABLE_WHEN_INACTIVE (610410b,ad0493e,fea86a6,d83b337,5ca9e97 Azat Khuzhin) + o [Bugfix] fix grammer error (3a4d249 ufo2243) + o Change return type of evutil_load_windows_system_library_ to HMODULE (f691389) + o Fix a c90 warning (76643dd) + o Fix a typo in a doxygen comment. Reported by 亦得. (be1aeff) + o remove trailing comma from enum (b361b8a Jean-Philippe Ouellet) + + Bugfixes (FreeBSD) + o Handle ENOTCAPABLE from FreeBSD - this is returned if an event in the changelist is for an FD that has been closed. (6fd7394 Adrian Chadd) + + + +Changes in version 2.1.4-alpha (21 Mar 2014) + + Libevent 2.1.4-alpha adds a number of new miscellaneous APIs to make + Libevent more useful, including support for early close detection with + epoll via EPOLLRDHUP, triggering bufferevent callbacks, adding more + evhttp callbacks, and more. There are also numerous bugfixes, including + a number for finalize-related issues from 2.1.3-alpha; and an + alternative (non-primary!) cmake-based build mechanism. + + New APIs (core) + o Added event_base_get_num_events() (0fa107d Mobai Zhang) + o New event_base_active_by_fd API (865a142 Greg Hazel, 5c9da9a, 87fa2b0) + o Add event_base_active_by_signal by analogy (4865943) + o Add access to max event count stats (5173bef, efbd3dc, 26230a2 + Andrew Sweeney) + o Implemented EV_CLOSED event for epoll backend + (EPOLLRDHUP). (b1b69ac Diego Giagio, 53d2793, 43ffcf6, dfe1e52 + Marcin Juszkiewicz, ff26633 Joakim Soderberg, 3908a5e) + + New APIs (evutil_secure_rng) + o Add evutil_secure_rng_set_urandom_device_file (2bbb5d7) + + New APIs (bufferevents) + o Add function to fetch underlying ratelimit cfg (4b3d5af Mark Ellzey) + o Pass and return const for bufferevent_get_token_bucket_cfg (1c77fbb + Mark Ellzey) + o Add watermark introspection (4ce242b OndÅ™ej KuznÃk) + o Add an option to trigger bufferevent I/O callbacks (61ee18b OndÅ™ej KuznÃk) + o Add an option to trigger bufferevent event callbacks (a7384c7 + OndÅ™ej KuznÃk) + o Clarifications in response to merge req. comments (bd41947 OndÅ™ej + KuznÃk) + o Minor optimizations on bufferevent_trigger options (a3172a4) + + New APIs (evhttp) + o Add evhttp_connection_get_server(). (a7f82a3 Maxime Henrion) + o add a http default content type option (5a5acd9 Nicolas Martyanoff) + o http: implement new evhttp_connection_get_addr() api. (0c7f040 Azat + Khuzhin) + o Add a variant of evhttp_send_reply_chunk() with a callback on + evhttp_write_buffer() (8d8decf Julien BLACHE) + o Allow registering callback for parsing HTTP headers (b0bd7fe Balint Reczey) + o Provide on request complete callback facility (b083ca0 Andrew Sweeney) + o evhttp_request_set_on_complete_cb to be more specific about what + the function actually does and usage (da86dda Andrew Sweeney) + o Update unit test to make sure that the callback happens after the + output data is written (b85f398 Andrew Sweeney) + + Features (evdns) + o bug fix for issues #293 evdns_base_load_hosts doesn't remove + outdated addresses (954d2f9, f03d353, 45eba6f Kuldeep Gupta) + + Features: (cmake build support) + o Initial CMake commit. (e415196 Joakim Soderberg) + o Add all tests and benchmarks to CMake project. (e9fc014 Joakim Soderberg) + o More work on adding tests to CMake project (99c1dc3 Joakim Soderberg) + o Generate a dummy evconfig-private.h so things build + properly. (ce14def Joakim Soderberg) + o Link libm on unix platforms. (58fcd42 Joakim Soderberg) + o Added some GCC specific options. (19222e5 Joakim Soderberg) + o Use evutil_closesocket instead. (dbf2b51 Joakim Soderberg) + o Add copyright and licensing files for CMake modules. (c259d53 + Joakim Soderberg) + o Only include WIN32 getopt where it is used. (9bbce0b Joakim Soderberg) + o Fix bench_cascade program on Windows. (78da644 Joakim Soderberg) + o Don't segfault on no found event backend. (8f2af50 Joakim Soderberg) + o Only test the event backends available on the system. (7ea4159 + Joakim Soderberg) + o Added a "make verify" target. (e053c4f Joakim Soderberg) + o Fix the make "verify" target on Windows. (67e5d74 Joakim Soderberg) + o Get rid of deprecation warnings for OpenSSL on OSX 10.7+ (69c3516 + Joakim Söderberg) + o Fix kqueue support. (a831f2f Joakim Söderberg) + o Added a test for testing if kqueue works with pipes. (2799b35 + Joakim Söderberg) + o Change the BSD license from 4 to 3-clause. (86df3ed Joakim Soderberg) + o Minimum required python version is 2.4. (968e97b Joakim Soderberg) + o Get rid of unknown pragma warnings. (0ef1d04 Joakim Soderberg) + o Add a "make verify_coverage" target generation coverage + info. (f2483f8 Joakim Soderberg) + o Fix the "make verify" target on NetBSD (4ac086a Joakim Soderberg) + o Only look for ZLib when it is used (if tests are + included). (f780593 Joakim Soderberg) + o Added EVENT__ENABLE_GCC_WARNINGS, turns all warnings into + errors. (dd413bd Joakim Soderberg) + o Add CMake config and install targets. (f3446ed Joakim Soderberg) + o Fix typo (4b754df Joakim Soderberg) + o Some work on making it possible to simply do add_subdirectory() on + the project. (49ab363 Joakim Soderberg) + o Set USE_DEBUG=1 on EVENT__ENABLE_VERBOSE_DEBUG (fd42e70 Joakim Soderberg) + o Fix so that old nmake project still builds. (24d6466 Joakim + Soderberg) + o Rename README to README.md and use markdown to format. (d2bc39a + Joakim Soderberg) + o Update README with CMake build instructions. (604b8cc Joakim Soderberg) + o Clean up the README some. (8d4cb35 JoakimSoderberg) + o Forgotten headers for old nmake project compatability. (8697b99 + Joakim Soderberg) + o Change all uses of WIN32 to _WIN32 (4e14395 Joakim Söderberg) + o Fix include bug. (2024467 Joakim Söderberg) + o Check if we're on OSX before disabling deprecation in le-proxy + (8b40a5b Joakim Söderberg) + o Fix broken autotools build. (ae1bd82 Joakim Söderberg) + o Disclaimerize cmake a little in the README (d03b5bf) + o Fix CMake compile when OpenSSL is disabled. (e423d42 Joakim + Söderberg) + o CMake: Get rid of python not found warning when regress tests + turned off. (d38d798 Joakim Söderberg) + o Fix https-client compilation on Windows. (d7be788 Joakim Soderberg) + o Guard against EVENT_NOWIN32 being set during testing. (f1715b4 + Joakim Soderberg) + o Check for OSX when checking for clang. (e212c54 Joakim Soderberg) + o Added a Travis-CI configuration file. (8c0f0a9 Joakim Soderberg) + o Added -Qunused-arguments for clang on macosx (ed99d92 Trond Norbye) + o Rename event_extras to event_extra (a0dd5df Trond Norbye) + o Add option to build shared library (4545fa9 Trond Norbye) + o Add -Qunused-arguments for clang on macos (b56611d Trond Norbye) + o Add cmake-related files to .gitignore (e061321 Trond Norbye) + o Export event_extra not event_extras. (2b41bcf Joakim Söderberg) + + Bugfixes (core) + o If evsel->del() fails, don't leave the evmap in an inconsistent + state (9b5a527 Maxime Henrion) + o Move event_debug_note_teardown_ before mm_free. (69b5c64) + o Check CLOCK_MONOTONIC_* at runtime if needed. (911abf3) + o Fix reinit of fds with EV_WRITE but not EV_READ. (ebfd8a8 maksqwe) + o Tweaked callbacks to prevent race condition + (https://github.com/libevent/libevent/issues/104) (40830f1, 2ea15ed + John Ohl) + o Move assert(ev) to before we use ev in EV_CLOSURE_EVENT_FINALIZE + case (9805972) + + Bugfixes (evhttp) + o Fix a double close() bug in evhttp when the underlying bufferevent uses + BEV_OPT_CLOSE_ON_FREE. (31db8a0 Maxime Henrion) + o Fix an unlikely but possible error case for http connections (f22049e) + o Avoid racy bufferevent activation (5eb1788 Nate Rosenblum) + + Bugfixes on 2.0 (Windows) + o Use windows vsnprintf fixup logic on all windows environments (e826f19) + o libevent/win32_dealloc() : fix sizeof(pointer) vs sizeof(*pointer) + (b8f5980 Frank Denis) + + Bugfixes (evutil_secure_rng) + o When we seed from /proc/sys/kernel/random/uuid, count it as success + (e35b540) + o We should return after arc4random_buf() (1ea1f26 Makoto Kato) + o Avoid other RNG initialization FS reads when urandom file is + specified (9695e9c) + o Really remove RNG seeds from the stack (f5ced88) + o Fix another arc4random_buf-related warning (e64a2b0) + + Bugfixes (bufferevents) + o Initialize async bufferevent timeout CBs unconditionally (af9b2a7) + + Bugfixes (evdns) + o Checking request nameserver for NULL, before using it. (5c710c0 + Belobrov Andrey) + o Fix SEGFAULT after evdns_base_resume if no nameservers + installed. (14971a8 Azat Khuzhin) + o Actually use the log facility for reporting evdns problems. (e1766a1) + o Fix SEGFAULT after evdns_base_resume if no nameservers + installed. (f8d7df8 Azat Khuzhin) + o fix for ServFail from RIPE Atlas release (62f596b Antony Antony) + + Bugfixes (compilation) + o Fix test compilation with nmake: add the gdi.lib dependency (5ba8ab7) + o Whoops. It is gdi.lib, not gdi32.lib. (github issue #61) (8ab612e) + o Don't use return since return type is void and build error occurs + using clang (838161d Makoto Kato) + o Use void casts to suppress some "unchecked return value" warns (7080d55) + o rpcgen: Generate regress.gen.[c,h] in build rather than src dir + (243386c Ross Lagerwall) + o Fix a compiler warning when checking for arc4random_buf linker + breakage. (5cb3865) + o Fix 'make distcheck' by adding regress.gen.[ch] to DISTCLEANFILES + (239d834) + + o Fix a c90 warning (c207682) + o Fix consts in WIN32-Code/getopt*.[ch] (57abb35) + + Bugfixes (locks, synchronization) + o Missed lock acquire/release in event_base_cancel_single_callback_() + (d3d999a Azat Khuzhin) + o Fix locking in bufferevent_get_options_(). (dbc9cd4 Maxime Henrion) + + Bugfixes (leaks) + o Avoid leaking segment mappings when offset is not a page multiple (d409514) + + Testing + o Add tests for evdns_base_resume(). (1cd9ff5 Azat Khuzhin) + o Fix dns/leak_resume_send_err test. (7e876df Azat Khuzhin) + o Add checks for evhttp_connection_get_server() in unit + tests. (fbc323b Maxime Henrion) + o Fix a (failure-only) null dereference in the unit tests (1104d0b) + o Fix a logic error in test_evbuffer_freeze (7765884) + o Add missing check to test_evbuffer_file_segment_add_cleanup_cb (eba4506) + o Fix some crash-on-fail cases in DNS regression tests (87cd6f0) + o DNS tests: add a missing check (f314900) + o Finalize tests: add a missing check (82b6956) + o test_evutil_rtrim: add another missing check. (e193c95) + o regress_main: logging all if env EVENT_DEBUG_LOGGING_ALL isset + (611e28b Azat Khuzhin) + o regress_http: add tests for evhttp_connection_get_addr() (4dd500c + Azat Khuzhin) + o Update to the latest version of tinytest (7a80476) + o Heap-allocate zlib data structure in regress_zlib tests (4947c18) + + Performance tweaks (core) + o Avoid redundant syscall to make a nonblocking socket nonblocking + (42c03da Maxime Henrion) + o Avoid redundant syscall if making a socket cloexec twice (1f29b18) + o Avoid redundant invocations of init_extension_functions for IOCP (3b77d62) + + Documentation + o Document that arc4random is not a great cryptographic PRNG. (6e49696) + o Small doxygen tweaks (6e67b51) + o Try another doxygen tweak (ccf432b) + o Clarify event_base_loop exit conditions (031a803) + o Fix a typo (be7bf2c OndÅ™ej KuznÃk) + o Document deferred eventcb behaviour (13a9a02 OndÅ™ej KuznÃk) + o Typo fixes from Linus Nordberg (cec62cb, 8cd695b) + o Fix duplicate paragraph in evbuffer_ptr documentation (58408ee) + + Code Improvements (coverity) + o Fix a pile of coverity warnings in the unit tests (867f401) + o Fix coverity warnings in benchmark tools. (ff7f739) + o Whoops; fix compilation in bench.c (544cf88) + o Remove spurious checks in evrpc.c error cases (coverity) (991b362) + o Fix a couple of compilation warnings in regress_http.c (860767e) + o Fix even more coverity warnings. (d240328) + o Stop checking for inet_aton; we don't use it. (f665d5c) + o Add an include to evrpc-internal to fix openbsd compilation warning + (5e161c6) + + Cleanups + o Remove an unreachable return statement in minheap-internal.h (e639a9e) + o Refactor evmap_{io,signal}_active_() to tolerate bad inputs (974c60e) + o Fix needless bufferevent includes in evdns.c (254c04e) + o Fix a couple of "#ifdef WIN32" instances (88ecda3) + o Remove unneeded declaration in bufferevent-internal.h (4c8ebcd) + + Sample code + o le-proxy: Fail more gracefully if opening listener fails (44b2491) + o http-server: drop uri_root from base_url in http-server. (6171e1c Azat Khuzhin) + o https-client: POST supported, args supported (c5887f7 Alexey Ozeritsky) + o https-client: code cleanup (29af65e Alexey Ozeritsky) + o https-client: Small tweaks to https-client.c (90786eb) + o https-client: Set hostname for SNI extension (by f69m) (d1976f8) + o https-client: add a cast to https-client.c (462e6b6) + + + +Changes in version 2.1.3-alpha (1 May 2013) + + Libevent 2.1.3-alpha fixes various bugs, adds new unit tests, and cleans + up the code in a couple of places. It has a new callback in evhttp for + reporting errors during a request, a new feature for allowing evdns to + not keep the event_base looping when there are no requests inflight, and + example code for writing an https client. + + Libevent 2.1.3-alpha also has an important new (experimental) event + finalization feature to allow safe event teardown in multithreaded + programs. This ought to fix the longstanding bug with deadlocks in + multithreaded use of SSL-based bufferevents that some people have been + experiencing since Libevent 2.0. + + + Core (event finalization) + o Implement event_finalize() and related functions to avoid certain + deadlocks (8eedeab) + o Use finalization feature so bufferevents can avoid deadlocks (02fbf68) + o Always run pending finalizers when event_base_free() is called (e9ebef8) + o Remove bufferevent_del_generic_timeout_cbs as now unused (4ea4c6a) + o More documentation for finalization feature (a800b91) + o Make the event_finalize* functions return an error code (5d11f4f) + o Mark the finalize stuff as experiemental in case it needs to + change (23e2e29) + + Evdns + o evdns: New flag to make evdns not prevent the event loop from + exiting (6b7fa62 Azat Khuzhin) + + Bugfixes (Core) + o Make event_remove_timer behave correctly with persistent timers (5623e80) + o Unit test for event_remove_timer with EV_PERSIST. (96150dd) + o Double-check next timeout when adding events (9443868 Nate Rosenblum) + o event_base_update_cache_time should be a no-op if the loop isn't + running (5e6fa2a) + + Bugfixes (evhttp, crash fix, from 2.0) + o fix #73 and fix http_connection_fail_test to catch it (b618204 Greg Hazel) + + Bugfixes (compilation and portability, from 2.0) + o Fix compilation with WIN32_HAVE_CONDITION_VARIABLES enabled (7e45739) + o Fix missing AC_PROG_SED on older Autoconfs (9ab2b3f Tay Ray Chuan) + o Backport libevent to vanilla Autoconf 2.59 (as used in RHEL5) + (74d4c44 Kevin Bowling) + o Use AC_CONFIG_HEADERS in place of AM_CONFIG_HEADERS for autmake + 1.13 compat (817ea36) + o Rename configure.in to configure.ac to appease newer autoconfs (0c79787) + o Avoid using top_srcdir in TESTS: new automakes do not like this (a55514e) + + Bugfixes (resource leaks/lock errors on error, from 2.0) + o Avoid leaking fds on evconnlistener with no callback set (69db261) + o Avoid double-close on getsockname error in evutil_ersatz_socketpair + (0a822a6) + o Fix a locking error in bufferevent_socket_get_dns_error. (0a5eb2e) + + Documentation Fixes (from 2.0) + o Fix a mistake in evbuffer_remove() arguments in example http server code + (c322c20 Gyepi Sam) + o Fix a typo in a comment in buffer.h. Spotted by Alt_F4 (773b0a5) + + Documentation Fixes + o minor documentation typos (809586a Patrick Pelletier) + o Fix cut-and-paste err in whatsnew-2.1 (49905ac) + o Fix comment to refer to sample/include.am correctly (9e8cdf3 Sebastian + Hahn) + o Fix typo : Dispatching instead of Dispaching (0c2bacc Volker Lendecke) + o fix some hinky indentation in evhttp_make_request (80e220e Patrick + Pelletier) + o "buffer" spelling (a452811 Patrick Pelletier) + o Specify return behavior in header for evbuffer_pullup() in corner case + (cf8d1cd Dan Petro) + o Clarify an important point about event_base_foreach_event() (920a5e6) + + Compilation Fixes/Tool Support + o avoid valgrind false positive by zeroing epoll_event (1258614 Patrick + Pelletier) + o Fix harmless clang enum warning (b452a43 Sebastian Hahn) + o remove all exes on "make clean", not just regress.exe (974bfa0 Patrick + Pelletier) + o Make --disable-libevent-regress work again (787fd74) + o Do not build strlcpy.c when it will have no code. (4914620) + + Portability Fixes + o When EWOULDBLOCK is not EAGAIN, treat it as equivalent to it (bf7a0ff) + o Preliminary changes for Minix3. (0dda56a Nicholas Heath) + o Use AC_CONFIG_HEADERS in place of AM_CONFIG_HEADERS for autmake 1.13 + compat (bf278b) + o Avoid using $(top_srcdir) in TESTS. (2863c83) + o build test/test-script.sh on systems with a less-featureful $< (f935e21) + o Implement EVUTIL_ERR_IS_EAGAIN on windows. (42aaf4d) + + Evhttp changes: + o Fix ipv6 support for http. When URL contain domain, not IP + address. (71e709c Azat Khuzhin) + o uri decode: fix for warning "use of uninitialised value" (64b6ece Azat + Khuzhin) + o uri decode: changed the test for the existence of the next character + (e1903e3 Azat Khuzhin) + o Move prototype of evhttp_decode_uri_internal() to http-internal.h + (de8101a Azat Khuzhin) + o Test: decoding just part of string with evhttp_decode_uri_internal() + (1367653 Azat Khuzhin) + o Add new error_cb for actual reporting of HTTP request errors. (7b07719 + Azat Khuzhin) + o Add test for EVREQ_HTTP_REQUEST_CANCEL into http_cancel_test() (862c217 + Azat Khuzhin) + o Drop extra header http_struct.h from regress_http.c (54cc800 Azat Khuzhin) + + Testing + o Add regress test ipv6_for_domain. (9ec88bd Azat Khuzhin) + o Add an environment variable (EVENT_DEBUG_MODE) to run unit tests in debug + mode (2fad0f3) + o Add a test with an active_later event at event_base_free time. (1c3147f) + o Make all tests pass under EVENT_DEBUG_MODE=1 (b1b054f) + o Add some verbose notes to bufferevent unit tests (9d893c9) + o New test for active_later->active transition on event_active (a153874) + o New tests for event_base_foreach_event() (0b096ef) + o Unit tests for event_base_gettimeofday_cached() and + event_base_update_cache_time() (30ea291) + o A test for event_get_assignment() (f09629e) + o More unit tests for initializing common timeouts. (d596739) + o Fix a bug in the new main/event_foreach test (702c9aa) + + Windows: + o use FormatMessage for winsock errors (0c6ec5d, 2078e9b, 4ccdd53, c9ad3af + Patrick Pelletier) + o a program to print out the error strings for winsock errors (7296512 + Patrick Pelletier) + o Fix a warning introduced in 0c6ec5d8 (eeb700c) + o Fix another warning introduced in 0c6ec5d8 (ed26561) + + Examples (http) + o Add sample/https-client.c, an example of stacking evhttp as a client on + top of bufferevent_ssl. (be46c99 Catalin Patulea) + o use ${OPENSSL_LIBS} instead of -lssl -lcrypto (bf31fa5 Patrick Pelletier) + o https-client was putting newlines at 256-byte boundaries (42d7441 Patrick + Pelletier) + o better handling of OpenSSL errors (5754d96 Patrick Pelletier) + o use Debian's default root certificate location (aacd674 Patrick Pelletier) + o use iSECPartners code to validate hostname in certificate (64d9f16 + Patrick Pelletier) + o avoid sign mismatch warning in openssl_hostname_validation.c (6021cb5 + Patrick Pelletier) + o pull in wildcard matching code from cURL (4db9da6 Patrick Pelletier) + o Another tweak to https-client.c (95acdaa) + o Remove http_struct.h usage in sample/https-client.c (8a90a85) + + + +Changes in version 2.1.2-alpha (18 Nov 2012) + + Libevent 2.1.2-alpha includes more portable for monotonic timers, + refactors much of Libevent's internal and external infrastructure, + closes some longstanding gaps in the interface, makde other + improvements. Ths log below tries to organize features by rough area of + effect. It omits a few commits which were pure bugfixes on other commits + listed below. For more detail, see the git changelogs. For more + insight, see the "whatsnew-2.1.txt" document included in the Libevent + 2.1.2-alpha distribution. + + Libevent 2.1.2-alpha also includes all changes made in 2.0.19-stable + through 2.0.21-stable inclusive. + + Performance (core): + o Replace pipe-based notification with EVFILT_USER where possible. This + should make multithreaded programs on OSX and *BSD alert the main thread a + little faster. (53a07fe) + o Make th_base_lock nonrecursive. (9cd5acb) + + New/Changed API Functions: + o New event_get_priority() function to return an event's priority (f90e255) + o Add a bufferevent_get_priority() function (bd39554) + o Add an event_base_loopcontinue() to tell Libevent to rescan for more + events right away (7d6aa5e) + o Add a new callback to get called on evbuffer_file_segment free + (e9f8feb yangacer, 64051b9) + o Expose event_base_foreach_event() as a public API. (84fd6d7 Roman + Puls, 232055e, ffe1643) + o Add an event_remove_timer() to remove timer on an event without + deleting it (e3b2e08) + o Make bufferevent_set_timeouts(bev, NULL, NULL) have plausible + semantics (9dee36b) + o Rename event_enable_lock_debuging() to ..._debugging(). (The old name + should still work.) (07e132e) + o Add missing implementation for event_enable_debug_logging (3b3e21d) + + PORTABLE MONOTONIC TIMERS: + + Libevent 2.1.2 includes internal support for monotonic timers on + (nearly) all supported platforms, including Windows, and OSX. Libevent + applications should now be more resilient to jumps forwards or backwards + in the system clock. Also, on Linux systems with epoll, we now + optionally support microsecond-level timeouts (whereas epoll only + supports millisecond-precision timeouts). + + o Use mach_absolute_time() for monotonic clock support on OSX. (b8fd6f9) + o Do not track use_monotonic field when is no monotonic clock (cb653a0) + o EVENT_BASE_FLAG_PRECISE_TIMER indicates we want fine timer precision + (ddd69d3) + o On Linux, use CLOCK_MONOTONIC_COARSE by default (55780a7) + o Implement a GetTickCount-based monotonic timer for Windows (d5e1d5a) + o Refactor monotonic timer handling into a new type and set of + functions; add a gettimeofday-based ratcheting implementation (f5e4eb0) + o Add EVENT_PRECISE_TIMER environment var for selecting precise-but-slow + timer (a2598ec) + o Implement fast/precise monotonic clocks on Windows (2c47045) + o Simple unit tests for monotonic timers (630f077) + o Improve the monotonic-time unit test: make it check the step size (7428c78) + o When PRECISE_TIMERS is set with epoll, use timerfd for microsecond + precision (26c7582) + o Split out time-related evutil functions into a new evutil_time.c (c419485) + o Split out time-related prototypes into time-internal.h (71bca50) + o Add evutil_time.obj to Makefile.nmake (0ba0683) + o Avoid giving a spurious warning when timerfd support is unavailable + (1aaf9f0 Dave Hart) + o Make test_evutil_monotonic a little more tolerant (def3b83) + o Avoid unused-var warning on systems with clock_gettime but without + CLOCK_MONOTONIC_COARSE (9be5468) + +EVENT_BASE_ONCE LEAKS: + If a callback added by event_base_once() is never invoked, Libevent no + longer leaks internal memory. + + o Free dangling event_once objects on event_base_free() (c17dd59) + o Add a unit test in which an event is created with event_base_once() + but never fires (4343edf) + +TESTING SUPPORT, FIXES AND IMPROVEMENTS: + + Libevent now disables by default its unit tests that would touch the + network, or that tend to fail on heavily-loaded systems. To re-enable + them, invoke the ./test/regress program with the @all alias. + + o Simplify test.sh code significantly. (9b856fd Ross Lagerwall) + o Make all tests that hit the network disabled by default (f2cea87) + o Avoid a resource leak on error in http client benchmark (ea92fba) + o Update to latest tinytest (911b4f0349377) (ef7c4f7) + o Avoid (unlikely) overflow in bench_httpclient.c (5671033) + o Shave 700 msec off the persistent_timeout_jump test (21205b8) + o Check return value of write() in regress.c (c8009d2) + o Make load-dependent monotonic timer tests off-by-default (2b6fe8b) + o Add deferred_cb_skew to list of timing-dependent tests (34c8f31) + o Avoid test -e; older shs don't have one. (f1bd938) + o Fix renegotiation test to work around openssl 1.0.1 bug (c2f3086) + o Fix a couple of compile warnings in the unit tests (5a9a014) + +MISC: + o Change evutil_weakrand_() to avoid platform random() (e86af4b Nicholas + Marriott, 3aa4415) + +INFRASTRUCTURE (Active-later events): + As a simplification and optimization to Libevent's "deferred callback" + logic (introduced in 2.0 to avoid callback recursion), Libevent now + treats all of its deferrable callback types using the same logic it uses + for active events. Now deferred events no longer cause priority + inversion, no longer require special code to cancel them, and so on. + + o Refactor the callback part of an event into its own event_callback + type (cba59e5) + o Add "active later" event_callbacks to supersede deferred (745a63d) + o event_base_assert_ok: check value of event_active_count for + correctness (fec8bae) + o Replace deferred_cbs with event_callback-based implementation. (ae2b84b) + o Replace more deferred_cb names with event_callback (a4079aa) + o Give event_base_process_active a single exit path (581b5be) + o Restore our priority-inversion-prevention code with deferreds (c0e425a) + o Refactor event_persist_closure: raise and extract some common logic + (bec22b4) + o Remove the unused bits from EVLIST_ALL (9889a3d) +||||||| merged common ancestors +Changes in version 2.0.22-stable (?? Dec 2013) + + (As of 3b77d62829c4393bda6f9105a5d3b73b48a64b71.) + BUGFIXES (evhttp) o fix #73 and fix http_connection_fail_test to catch it (crash fix) (b618204 Greg Hazel) o Avoid racy bufferevent activation (5eb1788 Nate Rosenblum) @@ -1407,7 +1407,7 @@ BUGFIXES (resource leaks/lock errors on error) o libevent/win32_dealloc() : fix sizeof(pointer) vs sizeof(*pointer) (b8f5980 Frank Denis) BUGFIXES (miscellaneous) - o Avoid other RNG initialization FS reads when urandom file is specified (9695e9c, bb52471) + o Avoid other RNG initialization FS reads when urandom file is specified (9695e9c, bb52471) o Avoid redundant invocations of init_extension_functions for IOCP (3b77d62) BUFGIXES (evdns) @@ -1426,7 +1426,7 @@ DOCUMENTATION FIXES o Fix a typo in a comment in buffer.h. Spotted by Alt_F4 (773b0a5) - + Changes in version 2.0.21-stable (18 Nov 2012) BUGFIXES: o ssl: Don't discard SSL read event when timeout and read come close together (576b29f) @@ -1804,358 +1804,358 @@ DOCUMENTATION: -BUILD IMPROVEMENTS: - Libevent 2.1.2-alpha modernizes Libevent's use of autotools, and makes - numerous other build system. Parallel builds should be faster, and all - builds should be quieter. - - o Split long lists in Makefile.am into one-item-per-line (2711cda) - o Remove unnecessary code in configure.in. (e65914f Ross Lagerwall) - o attempt to support OpenSSL in Makefile.nmake (eba0eb2 Patrick Pelletier) - o Use newer syntax for autoconf/automake init (7d60ba8) - o Enable silent build rules by default. Override with V=1 (7b18e5c) - o Switch to non-recursive makefiles (7092f3b) - o Rename subordinate Makefile.ams to include.am (6cdfeeb) - o Make quiet build even quieter (371a123) - o New --quiet option for event_rpcgen.py (aa59c1e) - o Be quiet when making regress.gen.[ch] (607a8ff) - o Fix handling of no-python case for nonrecursive make (1e3123d) - o We now require automake 1.9 or later. Modernize! (b7f6e89) - o Rename configure.in to configure.ac. (b3fea67 Ross Lagerwall) - o Use correct openssl libs and includes in pkgconfig file (d70af27) - o Use the same CFLAGS for openssl when building unit tests as with - libevent (1d9d511) +BUILD IMPROVEMENTS: + Libevent 2.1.2-alpha modernizes Libevent's use of autotools, and makes + numerous other build system. Parallel builds should be faster, and all + builds should be quieter. + + o Split long lists in Makefile.am into one-item-per-line (2711cda) + o Remove unnecessary code in configure.in. (e65914f Ross Lagerwall) + o attempt to support OpenSSL in Makefile.nmake (eba0eb2 Patrick Pelletier) + o Use newer syntax for autoconf/automake init (7d60ba8) + o Enable silent build rules by default. Override with V=1 (7b18e5c) + o Switch to non-recursive makefiles (7092f3b) + o Rename subordinate Makefile.ams to include.am (6cdfeeb) + o Make quiet build even quieter (371a123) + o New --quiet option for event_rpcgen.py (aa59c1e) + o Be quiet when making regress.gen.[ch] (607a8ff) + o Fix handling of no-python case for nonrecursive make (1e3123d) + o We now require automake 1.9 or later. Modernize! (b7f6e89) + o Rename configure.in to configure.ac. (b3fea67 Ross Lagerwall) + o Use correct openssl libs and includes in pkgconfig file (d70af27) + o Use the same CFLAGS for openssl when building unit tests as with + libevent (1d9d511) DOCUMENTATION - o Note that make_base_notifiable should not be necessary (26ee5f9) - o Be more clear that LEV_OPT_DEFERRED_ACCEPT has tricky prereqs (371efeb) - o Add caveat to docs about bufferevent_free() with data in outbuf (6fab9ee) - o Make it more clear that NOLOCK means "I promise, no multithreading" - (9444524) - o Fix a comment in test-fdleak after 077c7e949. (3881d8f Ross Lagerwall) - o Make the Makefile.nmake warning slightly less dire (e7bf4c8) - o Fix typo : events instead of evets (05f1aca Azat Khuzhin) - o Additional comments about OPENSSL_DIR variable, prompted by Dave Hart - (6bde2ef Patrick Pelletier) - -EVHTTP: - o ignore LWS after field-content in headers (370a2c0 Artem Germanov) - o Clean up rtrim implementation (aa59d80) - o Remove trailing tabs in HTTP headers as well. (ac42519) - o Remove internal ws from multiline http headers correctly (c6ff381) - o Move evutil_rtrim_lws_ to evutil.c where it belongs (61b93af) - o add evhttp_request_get_response_code_line (4f4d0c9 Jay R. Wren) - o Use EVUTIL_SOCKET_ERROR() wrapper to save/restore errno in - evhttp_connection_fail_ (7afbd60) - o preserve errno in evhttp_connection_fail_ for inspection by the - callback (36d0ee5 Patrick Pelletier) - -BUGFIXES: - o Correctly handle running on a system where accept4 doesn't work. (9fbfe9b) - o Avoid double-free on error in evbuffer_add_file. Found by - coverity. (6a81b1f) - o Fix another possible uninitialized read in dns regression tests. Found - by coverity. (13525c5) - o Add checks for functions in test-ratelim.c; found by Coverity (aa501e1) - o Avoid memory leak in test_event_calloc unit test; found by coverity - (92817a1) - o Fix a shadowed variable in addfile_test_readcb; found by coverity - (225344c) - o Check return value when using LEV_OPT_DEFERRED_ACCEPT. Found by - coverity (6487f63) - o Prevent reference leak of bufferevent if getaddrinfo fails. (b757786 - Joachim Bauch) - o Make event_base_getnpriorities work with old "implicit base" code - (c46cb9c) - o Simplify and correct evutil_open_closeonexec_ (0de587f) - o Fix event_dlist definition when sys/queue not included (81b6209 - Derrick Pallas) - - - -Changes in version 2.1.1-alpha (4 Apr 2012) - - Libevent 2.1.1-alpha includes a number of new features and performance - improvements. The log below tries to organize them by rough area of - effect. It omits some commits which were pure bugfixes on other commits - listed below. For more detail, see the git changelogs. For more - insight, see the "whatsnew-2.1.txt" document included in the Libevent - 2.1.1-alpha distribution. - - Performance: Core - o Replace several TAILQ users with LIST. LIST can be a little faster than - TAILQ for cases where we don't need queue-like behavior. (f9db33d, - 6494772, d313c29, 974d004) - o Disabled code to optimize the case where we reinsert an existing - timeout (e47042f, 09cbc3d) - o Remove a needless base-notify when rescheduling the first timeout (77a96fd) - o Save a needless comparison when removing/adjusting timeouts (dd5189b) - o Possible optimization: split event_queue_insert/remove into - separate functions. needs testing (efc4dc5) - o Make event_count maintenance branchless at the expense of an - extra shift. Needs benchmarking (d1cee3b) - o In the 2.1 branch, let's try out lazy gettimeofday/clock_gettime - comparison (2a83ecc) - o Optimization in event_process_active(): ignore maxcb & endtime - for highest priority events. (a9866aa Alexander Drozdov) - o Bypass event_add when using event_base_once() for a 0-sec timeout (35c5c95) - o Remove the eventqueue list and the ev_next pointers. (604569b 066775e) - - Performance: Evbuffers - o Roughly 20% speed increase when line-draining a buffer using - EVBUFFER_EOL_CRLF (5dde0f0 Mina Naguib) - o Try to squeeze a little more speed out of EVBUFFER_EOL_CRLF (7b9d139) - o Fix a bug in the improved EOL_CRLF code (d927965) - o Remove a needless branch in evbuffer_drain() (d19a326) - - Performance: Linux - o Infrastructure for using faster/fewer syscalls when creating - sockets (a1c042b) - o Minimize syscalls during socket creation in listener.c (7e9e289) - o Use a wrapper function to create the notification - pipe/socketpair/eventfd (ca76cd9) - o Use pipes for telling signals to main thread when possible (a35f396) - o Save syscalls when constructing listener sockets for evhttp (af6c9d8) - o Save some syscalls when creating evdns sockets (713e570) - o Save some syscalls when constructing a socket for a bufferevent (33fca62) - o Prefer epoll_create1 on Linuxen that have it (bac906c) - - Performance: Epoll backend - o Use current event set rather than current pending change when - deciding whether to no-op a del (04ba27e Mike Smellie) - o Replace big chain of if/thens in epoll.c with a table lookup (8c83eb6) - o Clean up error handling in epoll_apply_one_change() a little (2d55a19) - - Performance: Evport backend - o evport: use evmap_io to track fdinfo status. Should save time and - RAM. (4687ce4) - o evport: Remove a linear search over recent events when - reactivating them (0f77efe) - o evport: Use portev_user to remember fdinfo struct (276ec0e) - o evport: don't scan more events in ed_pending than needed (849a5cf) - o evport: Remove artificial low limit on max events per getn call (c04d927) - o Reenable main/many_events_slow_add for evport in 2.1 (e903db3) - - Performance: Windows - o Use GetSystemTimeAsFileTime to implement gettimeofday on - win32. It's faster and more accurate than our old - approach. (b8b8aa5) - - New functions and features: debugging - o Add event_enable_debug_logging() to control use of debug logs (e30a82f) - - New functions and features: core - o Add event_config function to limit time/callbacks between calls - to dispatch (fd4de1e, 9fa56bd, a37a0c0, 3c63edd) - o New EVLOOP_NO_EXIT_ON_EMPTY option to keep looping even when no - events are pending (084e68f) - o Add event_base_get_npriorities() function. (ee3a4ee Alexander Drozdov) - o Make evbase_priority_init() and evbase_get_npriorities() - threadsafe (3c55b5e) - o New event_base_update_cache_time() to set cached_tv to current - time (212533e Abel Mathew) - o Add event_self_cbarg() to be used in conjunction with - event_new(). (ed36e6a Ross Lagerwall, fa931bb, 09a1906, 1338e6c, - 33e43ef) - o Add a new libevent_global_shutdown() to free all globals before - exiting. (041ca00 Mark Ellzey, f98c158, 15296d0, 55e991b) - o Use getifaddrs to detect our interfaces if possible (7085a45) - o Add event_base_get_running_event() to get the event* whose cb we - are in (c5732fd, 13dad99) - - New functions and features: building - o Implement --enable-gcc-hardening configure option (7550267 Sebastian Hahn) - - New functions and features: evbuffers - o Add evbuffer_add_file_segment() so one fd can be used efficiently - in more than one evbuffer_add_file at a time (e72afae, c2d9884, - 3f405d2, 0aad014) - o Fix windows file segment mappings (8254de7) - o Allow evbuffer_ptr_set to yield a point just after the end of the - buffer. (e6fe1da) - o Allow evbuffer_ptr to point to position 0 in an empty evbuffer - (7aeb2fd Nir Soffer) - o Set the special "not found" evbuffer_ptr consistently. (e3e97ae Nir Soffer) - o support adding buffers to other buffers non-destructively - (9d7368a Joachim Bauch) - o prevent nested multicast references, reworked locking (26041a8 - Joachim Bauch) - o New EVBUFFER_EOL_NUL to read NUL-terminated strings from an - evbuffer (d7a8b36 Andrea Montefusco, 54142c9) - o Make evbuffer_file_segment_types adaptable (c6bbbf1) - o Added evbuffer_add_iovec and unit tests. (aaec5ac Mark Ellzey, 27b5398) - o Add evbuffer_copyout_from to copy data from the middle of a - buffer (27e2225) - - New functions and features: bufferevents - o Allow users to set allow_dirty_shutdown (099d27d Catalin Patulea) - o Tweak allow_dirty_shutdown documentation (a44cd2b) - o Fix two issues in the allow_dirty_shutdown code. (f3b89de) - o Add a bufferevent_getcb() to find a bufferevent's current - callbacks (a650394) - o bufferevent: Add functions to set/get max_single_read/write - values. (998c813 Alexander Drozdov) - o bev_ssl: Be more specific in event callbacks. evhttp in particular gets - confused without at least one of BEV_EVENT_{READING|WRITING}. (f7eb69a - Catalin Patulea) - - New functions and features: evconnlisteners - o Support TCP_DEFER_ACCEPT sockopts for listeners (5880e4a Mark Ellzey, - a270728) - o Add another caveat to the TCP_DEFER_ACCEPT documentation (a270728) - o Allow evconnlistener to be created in disabled state. (9593a33 - Alexander Drozdov) - o The LEV_OPT_CLOSE_ON_EXEC flag now applies to accepted listener - sockets too (4970329) - - Evhttp: - o Add new evhttp_{connection_}set_timeout_tv() functions to set - finger-grained http timeouts (6350e6c Constantine Verutin) - o Performance tweak to evhttp_parse_request_line. (aee1a97 Mark Ellzey) - o Add missing break to evhttp_parse_request_line (0fcc536) - o Add evhttp callback for bufferevent creation; this lets evhttp - support SSL. (8d3a850) - o Remove calls to deprecated bufferevent functions from evhttp.c (4d63758) - o evhttp: Add evhttp_foreach_bound_socket. (a2c48e3 Samy Al Bahra) - - Build improvements: - o Add AC_USE_SYSTEM_EXTENSIONS to configure.in. Requires follow on - patches for correctness and robustness. (1fa7dbe Kevin Bowling) - o Filter '# define' statements from autoconf and generate - event-private.h (321b558 Kevin Bowling) - o Remove internal usage of _GNU_SOURCE (3b26541 Kevin Bowling) - o Eliminate a couple more manual internal _GNU_SOURCE defines (c51ef93 - Kevin Bowling) - o Add AC_GNU_SOURCE to the fallback case. (ea8fa4c Kevin Bowling) - o Use a Configuration Header Template for evconfig-private.h (868f888 - Kevin Bowling) - o Fix a comment warning and add evconfig-private.h to .gitignore - (f6d66bc Kevin Bowling) - o Include evconfig-private.h in internal files for great good. (0915ca0 - Kevin Bowling) - o Backport libevent to vanilla Autoconf 2.59 (as used in RHEL5) - (ad03952 Kevin Bowling) - o Prefer the ./configure evconfig-private.h in MinGW, just in - case. (f964b72 Kevin Bowling) - o Shell hack for weird mkdir -p commands (fd7b5a8 Kevin Bowling) - o Add evconfig-private to remaining files (ded0a09 Kevin Bowling) - o Allow use of --enable-silent-rules for quieter compilation with - automake 1.11 (f1f8514 Dave Hart) - o Use "_WIN32", not WIN32: it's standard and we don't need to fake it - (9f560b) - o In configure, test for _WIN32 not WIN32. (85078b1 Peter Rosin) - o Do not define WIN32 in Makefile.nmake (d41f3ea Peter Rosin) - o Provide the autoconf m4 macros for the new OpenSSL via pkg-config - stuff. (674dc3d Harlan Stenn) - o Use pkg-config (if available) to handle OpenSSL. (1c63860 Harlan Stenn) - o We need AM_CPPFLAGS when compiling bufferevent_openssl.c (6d2613b - Harlan Stenn) - o Fix OSX build: $(OPENSSL_INCS) needs to be after - $(AM_CPPFLAGS). (46f1769 Zack Weinberg) - o Make gcc warnings on by default, and --enable-gcc-warnings only add - -Werror (d46517e Sebastian Hahn) - o Split up extra-long AC_CHECK_FUNCS/HEADERS lines in configure.in (88a30ad) - o Move libevent 1.x headers to include/, to put all public headers in - one place. (bbea8d6) - o Put #ifdef around some files to support alternate build - systems. (76d4c92 Ross Lagerwall) - o Also make win32select.c conditional for IDE users (bf2c5a7) - - Debugging: - o Add a magic number to debug_locks to better catch lock-coding - errors. (b4a29c0 Dave Hart) - o munge the debug_lock signature before freeing it: it might help us - catch use-after-free (f28084d) - o Added --enable-event-debugging in configure (bc7b4e4, a9c2c9a Mark Ellzey) - o Debug addition for printing usec on TIMEOUT debugging. (ac43ce0 Mark Ellzey) - o Added usec debug in another area for debug (3baab0d Mark Ellzey) - o added timeout debug logs to include event ptr. (4b7d298 Mark Ellzey) - o more event dbg updates (6727543 Mark Ellzey) - o Clarify event_enable_debug_logging a little (6207826) - o Make --enable-verbose-debug option match its help text (10c3450) - o Add argument checks to some memory functions in `event.c'. (c8953d1 - Mansour Moufid) - - Testing: - o More abstraction in test.sh (cd74c4e) - o Add failing test for evbuffer_search_range. (8e26154 Nir Soffer) - o Tweaks to return types with end-of-buf ptrs (9ab8ab8) - o Add an (internal) usleep function for use by unit tests (f25d9d3) - o Synchronize with upstream tinytest (6c81be7) - o Make test-changelist faster (7622d26) - o Reduce the timeout in the main/fork test. (ab14f7c) - o New evhttp function to adjust initial retry timeout (350a3c4) - o Make regression tests run over 3x faster. (67a1763) - o Use test_timeval_diff_eq more consistently (b77b43f) - o Allow more slop in deferred_cb_skew test; freebsd needs it (b9f7e5f) - o When including an -internal.h header outside the main tree, do so - early (95e2455) - o Add a new test: test-fdleak which tests for fd leaks by creating many - sockets. (2ef9278 Ross Lagerwall, f7af194, 1c4288f, etc) - o Add a unit test for event_base_dump_events() (7afe48a, 8d08cce) - o Test more bufferevent_ratelim features (c24f91a) - - Documentation: - o Improve evbuffer_ptr documentation (261ba63) - o added comments to describe refcounting of multicast chains (ba24f61 - Joachim Bauch) - o Add doxygen for event_base_dump_events (cad5753) - - OSX: - o Use "unlimited select" on OSX so that we can have more than - FD_SETSIZE fds (1fb5cc6) - - KQueue: - o Use SIG_IGN instead of a do-nothing handler for signal events with - kqueue (148458e Zack Weinberg) - - evprc: - o event_rpcgen.py now prints status information to stdout and errors to - stderr. (ffb0ba0 Ross Lagerwall) - - Code improvement and refactoring: - o Make event_reinit() more robust and maintainable (272033e) - o Restore fast-path event_reinit() for slower backends (2c4b5de) - o Check changelist as part of checking representational integrity (39b3f38) - o Fix a compile warning in event_reinit (e4a56ed Sebastian Hahn) - o Refactor the functions that run over every event. (c89b4e6) - o Remove the last vestiges of _EVENT_USE_EVENTLIST (a3cec90) - o Make event-config.h depend on Makefile.am (2958a5c) - - Build fixes: - o Don't do clang version detection when disabling some flags (083296b - Sebastian Hahn) - - C standards conformance: - o Check for NULL return on win32 mm_calloc, and set ENOMEM. (af7ba69) - o Convert event-config.h macros to avoid reserved identifiers (68120d9) - o Generate event-config.h using the correct macros. (f82c57e) - o Convert include-guard macro convention to avoid reserved identifiers - (3f8c7cd) - o Make event_rpcgen.py output conform to identifier conventions (372bff1) - o Stop referring to an obsolete include guard in bench_http.h (5c0f7e0) - o Make the generated event-config.h use correct include guards (639383a) - o Fix all identifiers with names beginning with underscore. (cb9da0b) - o Make event_rpcgen.py output conform to identifier conventions, more - (bcefd24) - o Fix some problems introduced by automated identifier cleanup script - (c963534) - o Have all visible internal function names end with an underscore. (8ac3c4c) - o Apply the naming convention to our EVUTIL_IS* functions (c7848fa) - o Clean up lingering _identifiers. (946b584) - o Fix doxygen to use new macro conventions (da455e9) - - Bugfixes: - o Do not use system EAI/AI values if we are not using the system - getaddrinfo. (7bcac07) - - Sample Code: - o Fix up sample/event-test.c to use newer interfaces and make it - actually work. (19bab4f Ross Lagerwall) - o On Unix, remove event.fifo left by sample/event-test.c. (c0dacd2 Ross - Lagerwall) - o Rename event-test.c to event-read-fifo.c. (a5b370a Ross Lagerwall) - o event-read-fifo: Use EV_PERSIST appropriately (24dab0b) + o Note that make_base_notifiable should not be necessary (26ee5f9) + o Be more clear that LEV_OPT_DEFERRED_ACCEPT has tricky prereqs (371efeb) + o Add caveat to docs about bufferevent_free() with data in outbuf (6fab9ee) + o Make it more clear that NOLOCK means "I promise, no multithreading" + (9444524) + o Fix a comment in test-fdleak after 077c7e949. (3881d8f Ross Lagerwall) + o Make the Makefile.nmake warning slightly less dire (e7bf4c8) + o Fix typo : events instead of evets (05f1aca Azat Khuzhin) + o Additional comments about OPENSSL_DIR variable, prompted by Dave Hart + (6bde2ef Patrick Pelletier) + +EVHTTP: + o ignore LWS after field-content in headers (370a2c0 Artem Germanov) + o Clean up rtrim implementation (aa59d80) + o Remove trailing tabs in HTTP headers as well. (ac42519) + o Remove internal ws from multiline http headers correctly (c6ff381) + o Move evutil_rtrim_lws_ to evutil.c where it belongs (61b93af) + o add evhttp_request_get_response_code_line (4f4d0c9 Jay R. Wren) + o Use EVUTIL_SOCKET_ERROR() wrapper to save/restore errno in + evhttp_connection_fail_ (7afbd60) + o preserve errno in evhttp_connection_fail_ for inspection by the + callback (36d0ee5 Patrick Pelletier) + +BUGFIXES: + o Correctly handle running on a system where accept4 doesn't work. (9fbfe9b) + o Avoid double-free on error in evbuffer_add_file. Found by + coverity. (6a81b1f) + o Fix another possible uninitialized read in dns regression tests. Found + by coverity. (13525c5) + o Add checks for functions in test-ratelim.c; found by Coverity (aa501e1) + o Avoid memory leak in test_event_calloc unit test; found by coverity + (92817a1) + o Fix a shadowed variable in addfile_test_readcb; found by coverity + (225344c) + o Check return value when using LEV_OPT_DEFERRED_ACCEPT. Found by + coverity (6487f63) + o Prevent reference leak of bufferevent if getaddrinfo fails. (b757786 + Joachim Bauch) + o Make event_base_getnpriorities work with old "implicit base" code + (c46cb9c) + o Simplify and correct evutil_open_closeonexec_ (0de587f) + o Fix event_dlist definition when sys/queue not included (81b6209 + Derrick Pallas) + + + +Changes in version 2.1.1-alpha (4 Apr 2012) + + Libevent 2.1.1-alpha includes a number of new features and performance + improvements. The log below tries to organize them by rough area of + effect. It omits some commits which were pure bugfixes on other commits + listed below. For more detail, see the git changelogs. For more + insight, see the "whatsnew-2.1.txt" document included in the Libevent + 2.1.1-alpha distribution. + + Performance: Core + o Replace several TAILQ users with LIST. LIST can be a little faster than + TAILQ for cases where we don't need queue-like behavior. (f9db33d, + 6494772, d313c29, 974d004) + o Disabled code to optimize the case where we reinsert an existing + timeout (e47042f, 09cbc3d) + o Remove a needless base-notify when rescheduling the first timeout (77a96fd) + o Save a needless comparison when removing/adjusting timeouts (dd5189b) + o Possible optimization: split event_queue_insert/remove into + separate functions. needs testing (efc4dc5) + o Make event_count maintenance branchless at the expense of an + extra shift. Needs benchmarking (d1cee3b) + o In the 2.1 branch, let's try out lazy gettimeofday/clock_gettime + comparison (2a83ecc) + o Optimization in event_process_active(): ignore maxcb & endtime + for highest priority events. (a9866aa Alexander Drozdov) + o Bypass event_add when using event_base_once() for a 0-sec timeout (35c5c95) + o Remove the eventqueue list and the ev_next pointers. (604569b 066775e) + + Performance: Evbuffers + o Roughly 20% speed increase when line-draining a buffer using + EVBUFFER_EOL_CRLF (5dde0f0 Mina Naguib) + o Try to squeeze a little more speed out of EVBUFFER_EOL_CRLF (7b9d139) + o Fix a bug in the improved EOL_CRLF code (d927965) + o Remove a needless branch in evbuffer_drain() (d19a326) + + Performance: Linux + o Infrastructure for using faster/fewer syscalls when creating + sockets (a1c042b) + o Minimize syscalls during socket creation in listener.c (7e9e289) + o Use a wrapper function to create the notification + pipe/socketpair/eventfd (ca76cd9) + o Use pipes for telling signals to main thread when possible (a35f396) + o Save syscalls when constructing listener sockets for evhttp (af6c9d8) + o Save some syscalls when creating evdns sockets (713e570) + o Save some syscalls when constructing a socket for a bufferevent (33fca62) + o Prefer epoll_create1 on Linuxen that have it (bac906c) + + Performance: Epoll backend + o Use current event set rather than current pending change when + deciding whether to no-op a del (04ba27e Mike Smellie) + o Replace big chain of if/thens in epoll.c with a table lookup (8c83eb6) + o Clean up error handling in epoll_apply_one_change() a little (2d55a19) + + Performance: Evport backend + o evport: use evmap_io to track fdinfo status. Should save time and + RAM. (4687ce4) + o evport: Remove a linear search over recent events when + reactivating them (0f77efe) + o evport: Use portev_user to remember fdinfo struct (276ec0e) + o evport: don't scan more events in ed_pending than needed (849a5cf) + o evport: Remove artificial low limit on max events per getn call (c04d927) + o Reenable main/many_events_slow_add for evport in 2.1 (e903db3) + + Performance: Windows + o Use GetSystemTimeAsFileTime to implement gettimeofday on + win32. It's faster and more accurate than our old + approach. (b8b8aa5) + + New functions and features: debugging + o Add event_enable_debug_logging() to control use of debug logs (e30a82f) + + New functions and features: core + o Add event_config function to limit time/callbacks between calls + to dispatch (fd4de1e, 9fa56bd, a37a0c0, 3c63edd) + o New EVLOOP_NO_EXIT_ON_EMPTY option to keep looping even when no + events are pending (084e68f) + o Add event_base_get_npriorities() function. (ee3a4ee Alexander Drozdov) + o Make evbase_priority_init() and evbase_get_npriorities() + threadsafe (3c55b5e) + o New event_base_update_cache_time() to set cached_tv to current + time (212533e Abel Mathew) + o Add event_self_cbarg() to be used in conjunction with + event_new(). (ed36e6a Ross Lagerwall, fa931bb, 09a1906, 1338e6c, + 33e43ef) + o Add a new libevent_global_shutdown() to free all globals before + exiting. (041ca00 Mark Ellzey, f98c158, 15296d0, 55e991b) + o Use getifaddrs to detect our interfaces if possible (7085a45) + o Add event_base_get_running_event() to get the event* whose cb we + are in (c5732fd, 13dad99) + + New functions and features: building + o Implement --enable-gcc-hardening configure option (7550267 Sebastian Hahn) + + New functions and features: evbuffers + o Add evbuffer_add_file_segment() so one fd can be used efficiently + in more than one evbuffer_add_file at a time (e72afae, c2d9884, + 3f405d2, 0aad014) + o Fix windows file segment mappings (8254de7) + o Allow evbuffer_ptr_set to yield a point just after the end of the + buffer. (e6fe1da) + o Allow evbuffer_ptr to point to position 0 in an empty evbuffer + (7aeb2fd Nir Soffer) + o Set the special "not found" evbuffer_ptr consistently. (e3e97ae Nir Soffer) + o support adding buffers to other buffers non-destructively + (9d7368a Joachim Bauch) + o prevent nested multicast references, reworked locking (26041a8 + Joachim Bauch) + o New EVBUFFER_EOL_NUL to read NUL-terminated strings from an + evbuffer (d7a8b36 Andrea Montefusco, 54142c9) + o Make evbuffer_file_segment_types adaptable (c6bbbf1) + o Added evbuffer_add_iovec and unit tests. (aaec5ac Mark Ellzey, 27b5398) + o Add evbuffer_copyout_from to copy data from the middle of a + buffer (27e2225) + + New functions and features: bufferevents + o Allow users to set allow_dirty_shutdown (099d27d Catalin Patulea) + o Tweak allow_dirty_shutdown documentation (a44cd2b) + o Fix two issues in the allow_dirty_shutdown code. (f3b89de) + o Add a bufferevent_getcb() to find a bufferevent's current + callbacks (a650394) + o bufferevent: Add functions to set/get max_single_read/write + values. (998c813 Alexander Drozdov) + o bev_ssl: Be more specific in event callbacks. evhttp in particular gets + confused without at least one of BEV_EVENT_{READING|WRITING}. (f7eb69a + Catalin Patulea) + + New functions and features: evconnlisteners + o Support TCP_DEFER_ACCEPT sockopts for listeners (5880e4a Mark Ellzey, + a270728) + o Add another caveat to the TCP_DEFER_ACCEPT documentation (a270728) + o Allow evconnlistener to be created in disabled state. (9593a33 + Alexander Drozdov) + o The LEV_OPT_CLOSE_ON_EXEC flag now applies to accepted listener + sockets too (4970329) + + Evhttp: + o Add new evhttp_{connection_}set_timeout_tv() functions to set + finger-grained http timeouts (6350e6c Constantine Verutin) + o Performance tweak to evhttp_parse_request_line. (aee1a97 Mark Ellzey) + o Add missing break to evhttp_parse_request_line (0fcc536) + o Add evhttp callback for bufferevent creation; this lets evhttp + support SSL. (8d3a850) + o Remove calls to deprecated bufferevent functions from evhttp.c (4d63758) + o evhttp: Add evhttp_foreach_bound_socket. (a2c48e3 Samy Al Bahra) + + Build improvements: + o Add AC_USE_SYSTEM_EXTENSIONS to configure.in. Requires follow on + patches for correctness and robustness. (1fa7dbe Kevin Bowling) + o Filter '# define' statements from autoconf and generate + event-private.h (321b558 Kevin Bowling) + o Remove internal usage of _GNU_SOURCE (3b26541 Kevin Bowling) + o Eliminate a couple more manual internal _GNU_SOURCE defines (c51ef93 + Kevin Bowling) + o Add AC_GNU_SOURCE to the fallback case. (ea8fa4c Kevin Bowling) + o Use a Configuration Header Template for evconfig-private.h (868f888 + Kevin Bowling) + o Fix a comment warning and add evconfig-private.h to .gitignore + (f6d66bc Kevin Bowling) + o Include evconfig-private.h in internal files for great good. (0915ca0 + Kevin Bowling) + o Backport libevent to vanilla Autoconf 2.59 (as used in RHEL5) + (ad03952 Kevin Bowling) + o Prefer the ./configure evconfig-private.h in MinGW, just in + case. (f964b72 Kevin Bowling) + o Shell hack for weird mkdir -p commands (fd7b5a8 Kevin Bowling) + o Add evconfig-private to remaining files (ded0a09 Kevin Bowling) + o Allow use of --enable-silent-rules for quieter compilation with + automake 1.11 (f1f8514 Dave Hart) + o Use "_WIN32", not WIN32: it's standard and we don't need to fake it + (9f560b) + o In configure, test for _WIN32 not WIN32. (85078b1 Peter Rosin) + o Do not define WIN32 in Makefile.nmake (d41f3ea Peter Rosin) + o Provide the autoconf m4 macros for the new OpenSSL via pkg-config + stuff. (674dc3d Harlan Stenn) + o Use pkg-config (if available) to handle OpenSSL. (1c63860 Harlan Stenn) + o We need AM_CPPFLAGS when compiling bufferevent_openssl.c (6d2613b + Harlan Stenn) + o Fix OSX build: $(OPENSSL_INCS) needs to be after + $(AM_CPPFLAGS). (46f1769 Zack Weinberg) + o Make gcc warnings on by default, and --enable-gcc-warnings only add + -Werror (d46517e Sebastian Hahn) + o Split up extra-long AC_CHECK_FUNCS/HEADERS lines in configure.in (88a30ad) + o Move libevent 1.x headers to include/, to put all public headers in + one place. (bbea8d6) + o Put #ifdef around some files to support alternate build + systems. (76d4c92 Ross Lagerwall) + o Also make win32select.c conditional for IDE users (bf2c5a7) + + Debugging: + o Add a magic number to debug_locks to better catch lock-coding + errors. (b4a29c0 Dave Hart) + o munge the debug_lock signature before freeing it: it might help us + catch use-after-free (f28084d) + o Added --enable-event-debugging in configure (bc7b4e4, a9c2c9a Mark Ellzey) + o Debug addition for printing usec on TIMEOUT debugging. (ac43ce0 Mark Ellzey) + o Added usec debug in another area for debug (3baab0d Mark Ellzey) + o added timeout debug logs to include event ptr. (4b7d298 Mark Ellzey) + o more event dbg updates (6727543 Mark Ellzey) + o Clarify event_enable_debug_logging a little (6207826) + o Make --enable-verbose-debug option match its help text (10c3450) + o Add argument checks to some memory functions in `event.c'. (c8953d1 + Mansour Moufid) + + Testing: + o More abstraction in test.sh (cd74c4e) + o Add failing test for evbuffer_search_range. (8e26154 Nir Soffer) + o Tweaks to return types with end-of-buf ptrs (9ab8ab8) + o Add an (internal) usleep function for use by unit tests (f25d9d3) + o Synchronize with upstream tinytest (6c81be7) + o Make test-changelist faster (7622d26) + o Reduce the timeout in the main/fork test. (ab14f7c) + o New evhttp function to adjust initial retry timeout (350a3c4) + o Make regression tests run over 3x faster. (67a1763) + o Use test_timeval_diff_eq more consistently (b77b43f) + o Allow more slop in deferred_cb_skew test; freebsd needs it (b9f7e5f) + o When including an -internal.h header outside the main tree, do so + early (95e2455) + o Add a new test: test-fdleak which tests for fd leaks by creating many + sockets. (2ef9278 Ross Lagerwall, f7af194, 1c4288f, etc) + o Add a unit test for event_base_dump_events() (7afe48a, 8d08cce) + o Test more bufferevent_ratelim features (c24f91a) + + Documentation: + o Improve evbuffer_ptr documentation (261ba63) + o added comments to describe refcounting of multicast chains (ba24f61 + Joachim Bauch) + o Add doxygen for event_base_dump_events (cad5753) + + OSX: + o Use "unlimited select" on OSX so that we can have more than + FD_SETSIZE fds (1fb5cc6) + + KQueue: + o Use SIG_IGN instead of a do-nothing handler for signal events with + kqueue (148458e Zack Weinberg) + + evprc: + o event_rpcgen.py now prints status information to stdout and errors to + stderr. (ffb0ba0 Ross Lagerwall) + + Code improvement and refactoring: + o Make event_reinit() more robust and maintainable (272033e) + o Restore fast-path event_reinit() for slower backends (2c4b5de) + o Check changelist as part of checking representational integrity (39b3f38) + o Fix a compile warning in event_reinit (e4a56ed Sebastian Hahn) + o Refactor the functions that run over every event. (c89b4e6) + o Remove the last vestiges of _EVENT_USE_EVENTLIST (a3cec90) + o Make event-config.h depend on Makefile.am (2958a5c) + + Build fixes: + o Don't do clang version detection when disabling some flags (083296b + Sebastian Hahn) + + C standards conformance: + o Check for NULL return on win32 mm_calloc, and set ENOMEM. (af7ba69) + o Convert event-config.h macros to avoid reserved identifiers (68120d9) + o Generate event-config.h using the correct macros. (f82c57e) + o Convert include-guard macro convention to avoid reserved identifiers + (3f8c7cd) + o Make event_rpcgen.py output conform to identifier conventions (372bff1) + o Stop referring to an obsolete include guard in bench_http.h (5c0f7e0) + o Make the generated event-config.h use correct include guards (639383a) + o Fix all identifiers with names beginning with underscore. (cb9da0b) + o Make event_rpcgen.py output conform to identifier conventions, more + (bcefd24) + o Fix some problems introduced by automated identifier cleanup script + (c963534) + o Have all visible internal function names end with an underscore. (8ac3c4c) + o Apply the naming convention to our EVUTIL_IS* functions (c7848fa) + o Clean up lingering _identifiers. (946b584) + o Fix doxygen to use new macro conventions (da455e9) + + Bugfixes: + o Do not use system EAI/AI values if we are not using the system + getaddrinfo. (7bcac07) + + Sample Code: + o Fix up sample/event-test.c to use newer interfaces and make it + actually work. (19bab4f Ross Lagerwall) + o On Unix, remove event.fifo left by sample/event-test.c. (c0dacd2 Ross + Lagerwall) + o Rename event-test.c to event-read-fifo.c. (a5b370a Ross Lagerwall) + o event-read-fifo: Use EV_PERSIST appropriately (24dab0b) diff --git a/contrib/libs/libevent/ChangeLog-1.4 b/contrib/libs/libevent/ChangeLog-1.4 index d7f6517b2b..aa6e69b83d 100644 --- a/contrib/libs/libevent/ChangeLog-1.4 +++ b/contrib/libs/libevent/ChangeLog-1.4 @@ -1,231 +1,231 @@ -Changes in 1.4.14b-stable - o Set the VERSION_INFO correctly for 1.4.14 - -Changes in 1.4.14-stable - o Add a .gitignore file for the 1.4 branch. (d014edb) - o Backport evbuffer_readln(). (b04cc60 Nicholas Marriott) - o Make the evbuffer_readln backport follow the current API (c545485) - o Valgrind fix: Clear struct kevent before checking for OSX bug. (5713d5d William Ahern) - o Fix a crash when reading badly formatted resolve.conf (5b10d00 Yasuoka Masahiko) - o Fix memory-leak of signal handler array with kqueue. [backport] (01f3775) - o Update sample/signal-test.c to use newer APIs and not leak. (891765c Evan Jones) - o Correct all versions in 1.4 branch (ac0d213) - o Make evutil_make_socket_nonblocking() leave any other flags alone. (81c26ba Jardel Weyrich) - o Adjusted fcntl() retval comparison on evutil_make_socket_nonblocking(). (5f2e250 Jardel Weyrich) - o Correct a debug message in evhttp_parse_request_line (35df59e) - o Merge branch 'readln-backport' into patches-1.4 (8771d5b) - o Do not send an HTTP error when we've already closed or responded. (4fd2dd9 Pavel Plesov) - o Re-add event_siglcb; some old code _was_ still using it. :( (bd03d06) - o Make Libevent 1.4 build on win32 with Unicode enabled. (bce58d6 Brodie Thiesfield) - o Distribute nmake makefile for 1.4 (20d706d) - o do not fail while sending on http connections the client closed. (5c8b446) - o make evhttp_send() safe against terminated connections, too (01ea0c5) - o Fix a free(NULL) in min_heap.h (2458934) - o Fix memory leak when setting up priorities; reported by Alexander Drozdov (cb1a722) - o Clean up properly when adding a signal handler fails. (ae6ece0 Gilad Benjamini) - o Do not abort HTTP requests missing a reason string. (29d7b32 Pierre Phaneuf) - o Fix compile warning in http.c (906d573) - o Define _REENTRANT as needed on Solaris, elsewhere (6cbea13) - - -Changes in 1.4.13-stable: - o If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it. Fixes bug 2841177; found by Alexander Pronchenkov. - o Do not allocate the maximum event queue and fd array for the epoll backend at startup. Instead, start out accepting 32 events at a time, and double the queue's size when it seems that the OS is generating events faster than we're requesting them. Saves up to 512K per epoll-based event_base. Resolves bug 2839240. - o Fix compilation on Android, which forgot to define fd_mask in its sys/select.h - o Do not drop data from evbuffer when out of memory; reported by Jacek Masiulaniec - o Rename our replacement compat/sys/_time.h header to avoid build a conflict on HPUX; reported by Kathryn Hogg. - o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian. - o Fix a problem with excessive memory allocation when using multiple event priorities. - o When running set[ug]id, don't check the environment. Based on a patch from OpenBSD. - - -Changes in 1.4.12-stable: - o Try to contain degree of failure when running on a win32 version so heavily firewalled that we can't fake a socketpair. - o Fix an obscure timing-dependent, allocator-dependent crash in the evdns code. - o Use __VA_ARGS__ syntax for varargs macros in event_rpcgen when compiler is not GCC. - o Activate fd events in a pseudorandom order with O(N) backends, so that we don't systematically favor low fds (select) or earlier-added fds (poll, win32). - o Fix another pair of fencepost bugs in epoll.c. [Patch from Adam Langley.] - o Do not break evdns connections to nameservers when our IP changes. - o Set truncated flag correctly in evdns server replies. - o Disable strict aliasing with GCC: our code is not compliant with it. - -Changes in 1.4.11-stable: - o Fix a bug when removing a timeout from the heap. [Patch from Marko Kreen] - o Remove the limit on size of HTTP headers by removing static buffers. - o Fix a nasty dangling pointer bug in epoll.c that could occur after epoll_recalc(). [Patch from Kevin Springborn] - o Distribute Win32-Code/event-config.h, not ./event-config.h - -Changes in 1.4.10-stable: - o clean up buffered http connection data on reset; reported by Brian O'Kelley - o bug fix and potential race condition in signal handling; from Alexander Drozdov - o rename the Solaris event ports backend to evport - o support compilation on Haiku - o fix signal processing when a signal callback delivers a signal; from Alexander Drozdov - o const-ify some arguments to evdns functions. - o off-by-one error in epoll_recalc; reported by Victor Goya - o include Doxyfile in tar ball; from Jeff Garzik - o correctly parse queries with encoded \r, \n or + characters - -Changes in 1.4.9-stable: - o event_add would not return error for some backends; from Dean McNamee - o Clear the timer cache on entering the event loop; reported by Victor Chang - o Only bind the socket on connect when a local address has been provided; reported by Alejo Sanchez - o Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones. - o Clear the timer cache when leaving the event loop; reported by Robin Haberkorn - o Fix a typo in setting the global event base; reported by lance. - o Fix a memory leak when reading multi-line headers - o Fix a memory leak by not running explicit close detection for server connections - -Changes in 1.4.8-stable: - o Match the query in DNS replies to the query in the request; from Vsevolod Stakhov. - o Fix a merge problem in which name_from_addr returned pointers to the stack; found by Jiang Hong. - o Do not remove Accept-Encoding header - -Changes in 1.4.7-stable: - o Fix a bug where headers arriving in multiple packets were not parsed; fix from Jiang Hong; test by me. - -Changes in 1.4.6-stable: - o evutil.h now includes <stdarg.h> directly - o switch all uses of [v]snprintf over to evutil - o Correct handling of trailing headers in chunked replies; from Scott Lamb. - o Support multi-line HTTP headers; based on a patch from Moshe Litvin - o Reject negative Content-Length headers; anonymous bug report - o Detect CLOCK_MONOTONIC at runtime for evdns; anonymous bug report - o Fix a bug where deleting signals with the kqueue backend would cause subsequent adds to fail - o Support multiple events listening on the same signal; make signals regular events that go on the same event queue; problem report by Alexander Drozdov. - o Deal with evbuffer_read() returning -1 on EINTR|EAGAIN; from Adam Langley. - o Fix a bug in which the DNS server would incorrectly set the type of a cname reply to a. - o Fix a bug where setting the timeout on a bufferevent would take not effect if the event was already pending. - o Fix a memory leak when using signals for some event bases; reported by Alexander Drozdov. - o Add libevent.vcproj file to distribution to help with Windows build. - o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov. - o Fix off-by-one errors in devpoll; from Ian Bell - o Make event_add not change any state if it fails; reported by Ian Bell. - o Do not warn on accept when errno is either EAGAIN or EINTR - -Changes in 1.4.5-stable: - o Fix connection keep-alive behavior for HTTP/1.0 - o Fix use of freed memory in event_reinit; pointed out by Peter Postma - o Constify struct timeval * where possible; pointed out by Forest Wilkinson - o allow min_heap_erase to be called on removed members; from liusifan. - o Rename INPUT and OUTPUT to EVRPC_INPUT and EVRPC_OUTPUT. Retain INPUT/OUTPUT aliases on on-win32 platforms for backwards compatibility. - o Do not use SO_REUSEADDR when connecting - o Fix Windows build - o Fix a bug in event_rpcgen when generated fixed-sized entries - -Changes in 1.4.4-stable: - o Correct the documentation on buffer printf functions. - o Don't warn on unimplemented epoll_create(): this isn't a problem, just a reason to fall back to poll or select. - o Correctly handle timeouts larger than 35 minutes on Linux with epoll.c. This is probably a kernel defect, but we'll have to support old kernels anyway even if it gets fixed. - o Fix a potential stack corruption bug in tagging on 64-bit CPUs. - o expose bufferevent_setwatermark via header files and fix high watermark on read - o fix a bug in bufferevent read water marks and add a test for them - o introduce bufferevent_setcb and bufferevent_setfd to allow better manipulation of bufferevents - o use libevent's internal timercmp on all platforms, to avoid bugs on old platforms where timercmp(a,b,<=) is buggy. - o reduce system calls for getting current time by caching it. - o fix evhttp_bind_socket() so that multiple sockets can be bound by the same http server. - o Build test directory correctly with CPPFLAGS set. - o Fix build under Visual C++ 2005. - o Expose evhttp_accept_socket() API. - o Merge windows gettimeofday() replacement into a new evutil_gettimeofday() function. - o Fix autoconf script behavior on IRIX. - o Make sure winsock2.h include always comes before windows.h include. - -Changes in 1.4.3-stable: - o include Content-Length in reply for HTTP/1.0 requests with keep-alive - o Patch from Tani Hosokawa: make some functions in http.c threadsafe. - o Do not free the kqop file descriptor in other processes, also allow it to be 0; from Andrei Nigmatulin - o make event_rpcgen.py generate code include event-config.h; reported by Sam Banks. - o make event methods static so that they are not exported; from Andrei Nigmatulin - o make RPC replies use application/octet-stream as mime type - o do not delete uninitialized timeout event in evdns - -Changes in 1.4.2-rc: - o remove pending timeouts on event_base_free() - o also check EAGAIN for Solaris' event ports; from W.C.A. Wijngaards - o devpoll and evport need reinit; tested by W.C.A Wijngaards - o event_base_get_method; from Springande Ulv - o Send CRLF after each chunk in HTTP output, for compliance with RFC2626. Patch from "propanbutan". Fixes bug 1894184. - o Add a int64_t parsing function, with unit tests, so we can apply Scott Lamb's fix to allow large HTTP values. - o Use a 64-bit field to hold HTTP content-lengths. Patch from Scott Lamb. - o Allow regression code to build even without Python installed - o remove NDEBUG ifdefs from evdns.c - o update documentation of event_loop and event_base_loop; from Tani Hosokawa. - o detect integer types properly on platforms without stdint.h - o Remove "AM_MAINTAINER_MODE" declaration in configure.in: now makefiles and configure should get re-generated automatically when Makefile.am or configure.in chanes. - o do not insert event into list when evsel->add fails - -Changes in 1.4.1-beta: - o free minheap on event_base_free(); from Christopher Layne - o debug cleanups in signal.c; from Christopher Layne - o provide event_base_new() that does not set the current_base global - o bufferevent_write now uses a const source argument; report from Charles Kerr - o better documentation for event_base_loopexit; from Scott Lamb. - o Make kqueue have the same behavior as other backends when a signal is caught between event_add() and event_loop(). Previously, it would catch and ignore such signals. - o Make kqueue restore signal handlers correctly when event_del() is called. - o provide event_reinit() to reintialize an event_base after fork - o small improvements to evhttp documentation - o always generate Date and Content-Length headers for HTTP/1.1 replies - o set the correct event base for HTTP close events - o New function, event_{base_}loopbreak. Like event_loopexit, it makes an event loop stop executing and return. Unlike event_loopexit, it keeps subsequent pending events from getting executed. Patch from Scott Lamb - o Removed obsoleted recalc code - o pull setters/getters out of RPC structures into a base class to which we just need to store a pointer; this reduces the memory footprint of these structures. - o fix a bug with event_rpcgen for integers - o move EV_PERSIST handling out of the event backends - o support for 32-bit tag numbers in rpc structures; this is wire compatible, but changes the API slightly. - o prefix {encode,decode}_tag functions with evtag to avoid collisions - o Correctly handle DNS replies with no answers set (Fixes bug 1846282) - o The configure script now takes an --enable-gcc-warnings option that turns on many optional gcc warnings. (Nick has been building with these for a while, but they might be useful to other developers.) - o When building with GCC, use the "format" attribute to verify type correctness of calls to printf-like functions. - o removed linger from http server socket; reported by Ilya Martynov - o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. - o demote most http warnings to debug messages - o Fix Solaris compilation; from Magne Mahre - o Add a "Date" header to HTTP responses, as required by HTTP 1.1. - o Support specifying the local address of an evhttp_connection using set_local_address - o Fix a memory leak in which failed HTTP connections would not free the request object - o Make adding of array members in event_rpcgen more efficient, but doubling memory allocation - o Fix a memory leak in the DNS server - o Fix compilation when DNS_USE_OPENSSL_FOR_ID is enabled - o Fix buffer size and string generation in evdns_resolve_reverse_ipv6(). - o Respond to nonstandard DNS queries with "NOTIMPL" rather than by ignoring them. - o In DNS responses, the CD flag should be preserved, not the TC flag. - o Fix http.c to compile properly with USE_DEBUG; from Christopher Layne - o Handle NULL timeouts correctly on Solaris; from Trond Norbye - o Recalculate pending events properly when reallocating event array on Solaris; from Trond Norbye - o Add Doxygen documentation to header files; from Mark Heily - o Add a evdns_set_transaction_id_fn() function to override the default - transaction ID generation code. - o Add an evutil module (with header evutil.h) to implement our standard cross-platform hacks, on the theory that somebody else would like to use them too. - o Fix signals implementation on windows. - o Fix http module on windows to close sockets properly. - o Make autogen.sh script run correctly on systems where /bin/sh isn't bash. (Patch from Trond Norbye, rewritten by Hagne Mahre and then Hannah Schroeter.) - o Skip calling gettime() in timeout_process if we are not in fact waiting for any events. (Patch from Trond Norbye) - o Make test subdirectory compile under mingw. - o Fix win32 buffer.c behavior so that it is correct for sockets (which do not like ReadFile and WriteFile). - o Make the test.sh script run unit tests for the evpoll method. - o Make the entire evdns.h header enclosed in "extern C" as appropriate. - o Fix implementation of strsep on platforms that lack it - o Fix implementation of getaddrinfo on platforms that lack it; mainly, this will make Windows http.c work better. Original patch by Lubomir Marinov. - o Fix evport implementation: port_disassociate called on unassociated events resulting in bogus errors; more efficient memory management; from Trond Norbye and Prakash Sangappa - o support for hooks on rpc input and output; can be used to implement rpc independent processing such as compression or authentication. - o use a min heap instead of a red-black tree for timeouts; as a result finding the min is a O(1) operation now; from Maxim Yegorushkin - o associate an event base with an rpc pool - o added two additional libraries: libevent_core and libevent_extra in addition to the regular libevent. libevent_core contains only the event core whereas libevent_extra contains dns, http and rpc support - o Begin using libtool's library versioning support correctly. If we don't mess up, this will more or less guarantee binaries linked against old versions of libevent continue working when we make changes to libevent that do not break backward compatibility. - o Fix evhttp.h compilation when TAILQ_ENTRY is not defined. - o Small code cleanups in epoll_dispatch(). - o Increase the maximum number of addresses read from a packet in evdns to 32. - o Remove support for the rtsig method: it hasn't compiled for a while, and nobody seems to miss it very much. Let us know if there's a good reason to put it back in. - o Rename the "class" field in evdns_server_request to dns_question_class, so that it won't break compilation under C++. Use a macro so that old code won't break. Mark the macro as deprecated. - o Fix DNS unit tests so that having a DNS server with broken IPv6 support is no longer cause for aborting the unit tests. - o Make event_base_free() succeed even if there are pending non-internal events on a base. This may still leak memory and fds, but at least it no longer crashes. - o Post-process the config.h file into a new, installed event-config.h file that we can install, and whose macros will be safe to include in header files. - o Remove the long-deprecated acconfig.h file. - o Do not require #include <sys/types.h> before #include <event.h>. - o Add new evutil_timer* functions to wrap (or replace) the regular timeval manipulation functions. - o Fix many build issues when using the Microsoft C compiler. - o Remove a bash-ism in autogen.sh - o When calling event_del on a signal, restore the signal handler's previous value rather than setting it to SIG_DFL. Patch from Christopher Layne. - o Make the logic for active events work better with internal events; patch from Christopher Layne. - o We do not need to specially remove a timeout before calling event_del; patch from Christopher Layne. +Changes in 1.4.14b-stable + o Set the VERSION_INFO correctly for 1.4.14 + +Changes in 1.4.14-stable + o Add a .gitignore file for the 1.4 branch. (d014edb) + o Backport evbuffer_readln(). (b04cc60 Nicholas Marriott) + o Make the evbuffer_readln backport follow the current API (c545485) + o Valgrind fix: Clear struct kevent before checking for OSX bug. (5713d5d William Ahern) + o Fix a crash when reading badly formatted resolve.conf (5b10d00 Yasuoka Masahiko) + o Fix memory-leak of signal handler array with kqueue. [backport] (01f3775) + o Update sample/signal-test.c to use newer APIs and not leak. (891765c Evan Jones) + o Correct all versions in 1.4 branch (ac0d213) + o Make evutil_make_socket_nonblocking() leave any other flags alone. (81c26ba Jardel Weyrich) + o Adjusted fcntl() retval comparison on evutil_make_socket_nonblocking(). (5f2e250 Jardel Weyrich) + o Correct a debug message in evhttp_parse_request_line (35df59e) + o Merge branch 'readln-backport' into patches-1.4 (8771d5b) + o Do not send an HTTP error when we've already closed or responded. (4fd2dd9 Pavel Plesov) + o Re-add event_siglcb; some old code _was_ still using it. :( (bd03d06) + o Make Libevent 1.4 build on win32 with Unicode enabled. (bce58d6 Brodie Thiesfield) + o Distribute nmake makefile for 1.4 (20d706d) + o do not fail while sending on http connections the client closed. (5c8b446) + o make evhttp_send() safe against terminated connections, too (01ea0c5) + o Fix a free(NULL) in min_heap.h (2458934) + o Fix memory leak when setting up priorities; reported by Alexander Drozdov (cb1a722) + o Clean up properly when adding a signal handler fails. (ae6ece0 Gilad Benjamini) + o Do not abort HTTP requests missing a reason string. (29d7b32 Pierre Phaneuf) + o Fix compile warning in http.c (906d573) + o Define _REENTRANT as needed on Solaris, elsewhere (6cbea13) + + +Changes in 1.4.13-stable: + o If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it. Fixes bug 2841177; found by Alexander Pronchenkov. + o Do not allocate the maximum event queue and fd array for the epoll backend at startup. Instead, start out accepting 32 events at a time, and double the queue's size when it seems that the OS is generating events faster than we're requesting them. Saves up to 512K per epoll-based event_base. Resolves bug 2839240. + o Fix compilation on Android, which forgot to define fd_mask in its sys/select.h + o Do not drop data from evbuffer when out of memory; reported by Jacek Masiulaniec + o Rename our replacement compat/sys/_time.h header to avoid build a conflict on HPUX; reported by Kathryn Hogg. + o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian. + o Fix a problem with excessive memory allocation when using multiple event priorities. + o When running set[ug]id, don't check the environment. Based on a patch from OpenBSD. + + +Changes in 1.4.12-stable: + o Try to contain degree of failure when running on a win32 version so heavily firewalled that we can't fake a socketpair. + o Fix an obscure timing-dependent, allocator-dependent crash in the evdns code. + o Use __VA_ARGS__ syntax for varargs macros in event_rpcgen when compiler is not GCC. + o Activate fd events in a pseudorandom order with O(N) backends, so that we don't systematically favor low fds (select) or earlier-added fds (poll, win32). + o Fix another pair of fencepost bugs in epoll.c. [Patch from Adam Langley.] + o Do not break evdns connections to nameservers when our IP changes. + o Set truncated flag correctly in evdns server replies. + o Disable strict aliasing with GCC: our code is not compliant with it. + +Changes in 1.4.11-stable: + o Fix a bug when removing a timeout from the heap. [Patch from Marko Kreen] + o Remove the limit on size of HTTP headers by removing static buffers. + o Fix a nasty dangling pointer bug in epoll.c that could occur after epoll_recalc(). [Patch from Kevin Springborn] + o Distribute Win32-Code/event-config.h, not ./event-config.h + +Changes in 1.4.10-stable: + o clean up buffered http connection data on reset; reported by Brian O'Kelley + o bug fix and potential race condition in signal handling; from Alexander Drozdov + o rename the Solaris event ports backend to evport + o support compilation on Haiku + o fix signal processing when a signal callback delivers a signal; from Alexander Drozdov + o const-ify some arguments to evdns functions. + o off-by-one error in epoll_recalc; reported by Victor Goya + o include Doxyfile in tar ball; from Jeff Garzik + o correctly parse queries with encoded \r, \n or + characters + +Changes in 1.4.9-stable: + o event_add would not return error for some backends; from Dean McNamee + o Clear the timer cache on entering the event loop; reported by Victor Chang + o Only bind the socket on connect when a local address has been provided; reported by Alejo Sanchez + o Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones. + o Clear the timer cache when leaving the event loop; reported by Robin Haberkorn + o Fix a typo in setting the global event base; reported by lance. + o Fix a memory leak when reading multi-line headers + o Fix a memory leak by not running explicit close detection for server connections + +Changes in 1.4.8-stable: + o Match the query in DNS replies to the query in the request; from Vsevolod Stakhov. + o Fix a merge problem in which name_from_addr returned pointers to the stack; found by Jiang Hong. + o Do not remove Accept-Encoding header + +Changes in 1.4.7-stable: + o Fix a bug where headers arriving in multiple packets were not parsed; fix from Jiang Hong; test by me. + +Changes in 1.4.6-stable: + o evutil.h now includes <stdarg.h> directly + o switch all uses of [v]snprintf over to evutil + o Correct handling of trailing headers in chunked replies; from Scott Lamb. + o Support multi-line HTTP headers; based on a patch from Moshe Litvin + o Reject negative Content-Length headers; anonymous bug report + o Detect CLOCK_MONOTONIC at runtime for evdns; anonymous bug report + o Fix a bug where deleting signals with the kqueue backend would cause subsequent adds to fail + o Support multiple events listening on the same signal; make signals regular events that go on the same event queue; problem report by Alexander Drozdov. + o Deal with evbuffer_read() returning -1 on EINTR|EAGAIN; from Adam Langley. + o Fix a bug in which the DNS server would incorrectly set the type of a cname reply to a. + o Fix a bug where setting the timeout on a bufferevent would take not effect if the event was already pending. + o Fix a memory leak when using signals for some event bases; reported by Alexander Drozdov. + o Add libevent.vcproj file to distribution to help with Windows build. + o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov. + o Fix off-by-one errors in devpoll; from Ian Bell + o Make event_add not change any state if it fails; reported by Ian Bell. + o Do not warn on accept when errno is either EAGAIN or EINTR + +Changes in 1.4.5-stable: + o Fix connection keep-alive behavior for HTTP/1.0 + o Fix use of freed memory in event_reinit; pointed out by Peter Postma + o Constify struct timeval * where possible; pointed out by Forest Wilkinson + o allow min_heap_erase to be called on removed members; from liusifan. + o Rename INPUT and OUTPUT to EVRPC_INPUT and EVRPC_OUTPUT. Retain INPUT/OUTPUT aliases on on-win32 platforms for backwards compatibility. + o Do not use SO_REUSEADDR when connecting + o Fix Windows build + o Fix a bug in event_rpcgen when generated fixed-sized entries + +Changes in 1.4.4-stable: + o Correct the documentation on buffer printf functions. + o Don't warn on unimplemented epoll_create(): this isn't a problem, just a reason to fall back to poll or select. + o Correctly handle timeouts larger than 35 minutes on Linux with epoll.c. This is probably a kernel defect, but we'll have to support old kernels anyway even if it gets fixed. + o Fix a potential stack corruption bug in tagging on 64-bit CPUs. + o expose bufferevent_setwatermark via header files and fix high watermark on read + o fix a bug in bufferevent read water marks and add a test for them + o introduce bufferevent_setcb and bufferevent_setfd to allow better manipulation of bufferevents + o use libevent's internal timercmp on all platforms, to avoid bugs on old platforms where timercmp(a,b,<=) is buggy. + o reduce system calls for getting current time by caching it. + o fix evhttp_bind_socket() so that multiple sockets can be bound by the same http server. + o Build test directory correctly with CPPFLAGS set. + o Fix build under Visual C++ 2005. + o Expose evhttp_accept_socket() API. + o Merge windows gettimeofday() replacement into a new evutil_gettimeofday() function. + o Fix autoconf script behavior on IRIX. + o Make sure winsock2.h include always comes before windows.h include. + +Changes in 1.4.3-stable: + o include Content-Length in reply for HTTP/1.0 requests with keep-alive + o Patch from Tani Hosokawa: make some functions in http.c threadsafe. + o Do not free the kqop file descriptor in other processes, also allow it to be 0; from Andrei Nigmatulin + o make event_rpcgen.py generate code include event-config.h; reported by Sam Banks. + o make event methods static so that they are not exported; from Andrei Nigmatulin + o make RPC replies use application/octet-stream as mime type + o do not delete uninitialized timeout event in evdns + +Changes in 1.4.2-rc: + o remove pending timeouts on event_base_free() + o also check EAGAIN for Solaris' event ports; from W.C.A. Wijngaards + o devpoll and evport need reinit; tested by W.C.A Wijngaards + o event_base_get_method; from Springande Ulv + o Send CRLF after each chunk in HTTP output, for compliance with RFC2626. Patch from "propanbutan". Fixes bug 1894184. + o Add a int64_t parsing function, with unit tests, so we can apply Scott Lamb's fix to allow large HTTP values. + o Use a 64-bit field to hold HTTP content-lengths. Patch from Scott Lamb. + o Allow regression code to build even without Python installed + o remove NDEBUG ifdefs from evdns.c + o update documentation of event_loop and event_base_loop; from Tani Hosokawa. + o detect integer types properly on platforms without stdint.h + o Remove "AM_MAINTAINER_MODE" declaration in configure.in: now makefiles and configure should get re-generated automatically when Makefile.am or configure.in chanes. + o do not insert event into list when evsel->add fails + +Changes in 1.4.1-beta: + o free minheap on event_base_free(); from Christopher Layne + o debug cleanups in signal.c; from Christopher Layne + o provide event_base_new() that does not set the current_base global + o bufferevent_write now uses a const source argument; report from Charles Kerr + o better documentation for event_base_loopexit; from Scott Lamb. + o Make kqueue have the same behavior as other backends when a signal is caught between event_add() and event_loop(). Previously, it would catch and ignore such signals. + o Make kqueue restore signal handlers correctly when event_del() is called. + o provide event_reinit() to reintialize an event_base after fork + o small improvements to evhttp documentation + o always generate Date and Content-Length headers for HTTP/1.1 replies + o set the correct event base for HTTP close events + o New function, event_{base_}loopbreak. Like event_loopexit, it makes an event loop stop executing and return. Unlike event_loopexit, it keeps subsequent pending events from getting executed. Patch from Scott Lamb + o Removed obsoleted recalc code + o pull setters/getters out of RPC structures into a base class to which we just need to store a pointer; this reduces the memory footprint of these structures. + o fix a bug with event_rpcgen for integers + o move EV_PERSIST handling out of the event backends + o support for 32-bit tag numbers in rpc structures; this is wire compatible, but changes the API slightly. + o prefix {encode,decode}_tag functions with evtag to avoid collisions + o Correctly handle DNS replies with no answers set (Fixes bug 1846282) + o The configure script now takes an --enable-gcc-warnings option that turns on many optional gcc warnings. (Nick has been building with these for a while, but they might be useful to other developers.) + o When building with GCC, use the "format" attribute to verify type correctness of calls to printf-like functions. + o removed linger from http server socket; reported by Ilya Martynov + o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. + o demote most http warnings to debug messages + o Fix Solaris compilation; from Magne Mahre + o Add a "Date" header to HTTP responses, as required by HTTP 1.1. + o Support specifying the local address of an evhttp_connection using set_local_address + o Fix a memory leak in which failed HTTP connections would not free the request object + o Make adding of array members in event_rpcgen more efficient, but doubling memory allocation + o Fix a memory leak in the DNS server + o Fix compilation when DNS_USE_OPENSSL_FOR_ID is enabled + o Fix buffer size and string generation in evdns_resolve_reverse_ipv6(). + o Respond to nonstandard DNS queries with "NOTIMPL" rather than by ignoring them. + o In DNS responses, the CD flag should be preserved, not the TC flag. + o Fix http.c to compile properly with USE_DEBUG; from Christopher Layne + o Handle NULL timeouts correctly on Solaris; from Trond Norbye + o Recalculate pending events properly when reallocating event array on Solaris; from Trond Norbye + o Add Doxygen documentation to header files; from Mark Heily + o Add a evdns_set_transaction_id_fn() function to override the default + transaction ID generation code. + o Add an evutil module (with header evutil.h) to implement our standard cross-platform hacks, on the theory that somebody else would like to use them too. + o Fix signals implementation on windows. + o Fix http module on windows to close sockets properly. + o Make autogen.sh script run correctly on systems where /bin/sh isn't bash. (Patch from Trond Norbye, rewritten by Hagne Mahre and then Hannah Schroeter.) + o Skip calling gettime() in timeout_process if we are not in fact waiting for any events. (Patch from Trond Norbye) + o Make test subdirectory compile under mingw. + o Fix win32 buffer.c behavior so that it is correct for sockets (which do not like ReadFile and WriteFile). + o Make the test.sh script run unit tests for the evpoll method. + o Make the entire evdns.h header enclosed in "extern C" as appropriate. + o Fix implementation of strsep on platforms that lack it + o Fix implementation of getaddrinfo on platforms that lack it; mainly, this will make Windows http.c work better. Original patch by Lubomir Marinov. + o Fix evport implementation: port_disassociate called on unassociated events resulting in bogus errors; more efficient memory management; from Trond Norbye and Prakash Sangappa + o support for hooks on rpc input and output; can be used to implement rpc independent processing such as compression or authentication. + o use a min heap instead of a red-black tree for timeouts; as a result finding the min is a O(1) operation now; from Maxim Yegorushkin + o associate an event base with an rpc pool + o added two additional libraries: libevent_core and libevent_extra in addition to the regular libevent. libevent_core contains only the event core whereas libevent_extra contains dns, http and rpc support + o Begin using libtool's library versioning support correctly. If we don't mess up, this will more or less guarantee binaries linked against old versions of libevent continue working when we make changes to libevent that do not break backward compatibility. + o Fix evhttp.h compilation when TAILQ_ENTRY is not defined. + o Small code cleanups in epoll_dispatch(). + o Increase the maximum number of addresses read from a packet in evdns to 32. + o Remove support for the rtsig method: it hasn't compiled for a while, and nobody seems to miss it very much. Let us know if there's a good reason to put it back in. + o Rename the "class" field in evdns_server_request to dns_question_class, so that it won't break compilation under C++. Use a macro so that old code won't break. Mark the macro as deprecated. + o Fix DNS unit tests so that having a DNS server with broken IPv6 support is no longer cause for aborting the unit tests. + o Make event_base_free() succeed even if there are pending non-internal events on a base. This may still leak memory and fds, but at least it no longer crashes. + o Post-process the config.h file into a new, installed event-config.h file that we can install, and whose macros will be safe to include in header files. + o Remove the long-deprecated acconfig.h file. + o Do not require #include <sys/types.h> before #include <event.h>. + o Add new evutil_timer* functions to wrap (or replace) the regular timeval manipulation functions. + o Fix many build issues when using the Microsoft C compiler. + o Remove a bash-ism in autogen.sh + o When calling event_del on a signal, restore the signal handler's previous value rather than setting it to SIG_DFL. Patch from Christopher Layne. + o Make the logic for active events work better with internal events; patch from Christopher Layne. + o We do not need to specially remove a timeout before calling event_del; patch from Christopher Layne. diff --git a/contrib/libs/libevent/ChangeLog-2.0 b/contrib/libs/libevent/ChangeLog-2.0 index 16f36008cd..e67c66f929 100644 --- a/contrib/libs/libevent/ChangeLog-2.0 +++ b/contrib/libs/libevent/ChangeLog-2.0 @@ -1,1280 +1,1280 @@ -Changes in version 2.0.21-stable (18 Nov 2012) -BUGFIXES: - o ssl: Don't discard SSL read event when timeout and read come close together (576b29f) - o ssl: Stop looping in "consider_reading" if reading is suspended. (f719b8a Joachim Bauch) - o ssl: No need to reserve space if reading is suspended. (1acf2eb Joachim Bauch) - o dns: Avoid a memory-leak on OOM in evdns. (73e85dd, f2bff75 George Danchev) - o build: Use python2 rather than python (0eb0109 Ross Lagerwall) - o build: Compile without warnings on mingw64 (94866c2) - o build: Fix compilation on mingw64 with -DUSE_DEBUG (62bd2c4) - o build: Make rpcgen_wrapper.sh work on systems without a "python2" binary (f3009e4) - o iocp: Close IOCP listener socket on free when LEV_OPT_CLOSE_ON_FREE is set (cb853ea Juan Pablo Fernandez) - o core: Avoid crash when event_pending() called with no event_base set on event (e3cccf3) - o misc: remove stray 'x' so print_err will compile when uncommented (ac35650 Patrick Pelletier) - o tests: Fix renegotiation test to work around openssl 1.0.1 bug (c2f3086) - o tests: Warn when openssl version in unit test mismatches compiled version. (ac009f9) - - -Changes in version 2.0.20-stable (23 Aug 2012) -BUGFIXES: - o core: Make event_pending() threadsafe. (be7a95c Simon Liu) - o win32: avoid crash when waiting forever on zero fds. (160e58b) - o evhttp: Fix a memory leak on error in evhttp_uriencode (11c8b31) - o evbuffer: Avoid possible needless call to writev. Found by coverity. (6a4ec5c) - o evdns: memset sockaddr_in before using it. Found by coverity. (a1a0e67) - o evhttp: Check more setsockopt return values when binding sockets. Found by coverity (a0912e3) - o evdns: Avoid segfault on weird timeout during name lookup. (dc32077 Greg Hazel) - o bufferevent_ssl: Correctly invoke callbacks when a SSL bufferevent reads some and then blocks. (606ac43) - - -PORTABILITY FIXES: - o check for arc4random_buf at runtime, on OS X (bff5f94 Greg Hazel) - o Correctly check for arc4random_buf (fcec3e8 Sebastian Hahn) - o Add explicit AC_PROG_SED to configure.in so all autoconfs will expose $(SED) (ca80ea6) - -BUILD FIXES: - o Add GCC annotations so that the vsprintf functions get checked properly (117e327) - o Fix an unused variable warning on *BSD. (c0720c1) - -UNIT TEST FIXES: - o Fix a couple of memory leaks (found with Valgrind). (3b2529a Ross Lagerwall) - o Remove deadcode in http regression tests. Found by coverity. (5553346) - o Fix possible uninitialized read in dns regression tests. Found by coverity. (2259777) - o Set umask before calling mkstemp in unit tests. Found by coverity (f1ce15d) - o Fix various check-after-dereference issues in unit tests: found by coverity (4f3732d) - o Fix resource leaks in the unit tests; found by coverity (270f279) - o Add some missing null checks to unit tests; found by coverity (f021c3d) - o Avoid more crashes/bad calls in unit tests; found by coverity (3cde5bf) - o Remove unused variable; spotted by coverity (6355b2a) - o Add checks to various return values in unit tests. Found by coverity (b9e7329) - o Move assignment outside tt_assert in ssl unit tests. Appeases coverity. (a2006c0) - - - -Changes in version 2.0.19-stable (3 May 2012) -BUGFIXES (CORE): - o Refactor event_persist_closure: raise and extract some common logic (bec22b4) - o If time has jumped so we'd reschedule a periodic event in the past, schedule it for the future instead (dfd808c) - o If a higher-priority event becomes active, don't continue running events of the current priority. (2bfda40) - -BUGFIXES (SSL): - o Fixed potential double-readcb execution with openssl bufferevents. (4e62cd1 Mark Ellzey) - -BUGFIXES (DNS): - o Cancel a probe request when the server is freed, and ignore cancelled probe callbacks (94d2336 Greg Hazel) - o Remove redundant DNS_ERR_CANCEL check, move comment (46b8060 Greg Hazel) - o When retransmitting a timed-out DNS request, pick a fresh nameserver. (3d9e52a) - -DOCUMENTATION FIXES: - o Fix a typo in the bufferevent documentation (98e9119) - o Add missing ) to changelog; spotted by rransom (4c7ee6b) - o Fix the website URL in the readme (f775521) - -COMPILATION FIXES: - o Fix a compilation error with MSVC 2005 due to use of mode_t (336dcae) - o Configure with gcc older than 2.95 (4a6fd43 Sebastian Hahn) - o Generate event-config.h with a single sed script (30b6f88 Zack Weinberg) - -FORWARD-COMPATIBILITY: - o Backport: provide EVENT_LOG_* names, and deprecate _EVENT_LOG_* (d1a03b2) - -TESTING/DEBUGGING SUPPORT: - o dns-example.c can now take a resolv.conf file on the commandline (6610fa5) - o Make some evdns.c debug logs more verbose (d873d67) - o Work-around a stupid gcov-breaking bug in OSX 10.6 (b3887cd) - - - -Changes in version 2.0.18-stable (22 Mar 2012) -BUGFIXES (core): - o Make uses of open() close-on-exec safe by introducing an internal evutil_open_closeonexec. (d2b5f72 Ross Lagerwall, 03dce42) - -BUGFIXES (kqueue): - o Properly zero the kevent in kq_setup_kevent() (c2c7b39 Sebastian Hahn) - -BUILD FIXES: - o Added OPENSSL_LDFLAGS env variable which is appended to SSL checks. (9278196 Mark Ellzey) - o Changed OPENSSL_LDFLAGS to OPENSSL_LIBADD (2d67b63 Mark Ellzey) - o Don't do clang version detection when disabling some flags (083296b Sebastian Hahn) - -BUGFIXES (dns): - o Stop crashing in evdns when nameserver probes give a weird error (bec5068) - - -Changes in version 2.0.17-stable (10 Feb 2012) - -BUGFIXES (core): - o Be absolutely sure to clear pncalls before leaving event_signal_closure (11f36a5) - o check for sysctl before we use it (358c745 Mike Frysinger) - o Remove bogus casts of socket to int before calling ev_callback (f032516) - o Make evconnlistener work around bug in older Linux when getting nmapped (ecfc720) - o Fix a list corruption bug when using event_reinit() with signals present (6e41cdc) - o Fix a fd leak in event_reinit() (3f18ad1) - o Do a memberwise comparison of threading function tables (c94a5f2 Nate R) - o Use C-style comments in C source files (for compatibility with compilers such as xlc on AIX). (d84d917 Greg Hewgill) - o Avoid crash when freeing event_iocp and using event_set_mem_functions (19715a6) - o In the kqueue backend, do not report EBADF as an EV_READ (5d7bfa1 Nicholas Marriott) - -BUGFIXES (evbuffer and bufferevents): - o Fix behavior of evbuffer_peek(buf,-1,NULL,NULL,0) (c986f23 Zack Weinberg) - o Loop on filtering SSL reads until we are blocked or exhausted. (5b4b812) - -BUGFIXES (evhttp): - o Force strict validation of HTTP version in response. (790f6b3 Catalin Patulea) - -BUGFIXES (evdns): - o evdns: fix a bug in circular-queue implementation (d6094b1) - -BUILD FIXES: - o Fix a silly compilation error with the sun compiler (1927776 Colin Watt) - o Suppress a gcc warning from ignoring fwrite return in http-sample.c (7206e8c) - -DOCUMENTATION FIXES: - o Slightly clarify evbuffer_peek documentation (7bbf6ca) - o Update copyright notices to 2012 (e49e289) - -NEW APIS: - o Backport evhttp_connection_get_bufferevent to Libevent 2.0 (da70fa7 Arno Bakker) - -TESTS AND TEST FIXES: - o Fix a race condition in the dns/bufferevent_connect_hostname test. (cba48c7) - o Add function to check referential integrity of an event_base (27737d5) - o Check event_base correctness at end of each unit test (3312b02) - o Workaround in the unit tests for an apparent epoll bug in Linux 3.2 (dab9187) - o Better workaround for Linux 3.2 edge-triggered epoll bug (9f9e259) - -Changes in version 2.0.16-stable (18 Nov 2011) -BUGFIXES (core): - o More detailed message in case of libevent self-debugging failure. (9e6a4ef Leonid Evdokimov) - o epoll: close fd on alloc fail at initialization (1aee718 Jamie Iles) - o Fix compile warning from saying event2/*.h inside a comment (447b0ba) - o Warn when unable to construct base because of failing make_base_notifiable (4e797f3) - o Don't try to make notifiable event_base when no threading fns are configured (e787413) - -BUGFIXES (evbuffer): - o unit test for remove_buffer bug (90bd620 Greg Hazel) - o Fix an evbuffer crash in evbuffer_remove_buffer() (c37069c) - -BUGFIXES (bufferevent_openssl): - o Refactor amount-to-read calculations in buffervent_ssl consider_reading() (a186e73 Mark Ellzey) - o Move SSL rate-limit enforcement into bytes_to_read() (96c562f) - o Avoid spinning on OpenSSL reads (2aa036f Mark Ellzey) - -BUGFIXES (dns) - o Empty DNS reply with OK status is another way to say NODATA. (21a08d6 Leonid Evdokimov) - -TESTING: - o Tests for 94fba5b and f72e8f6 (d58c15e Leonid Evdokimov) - o Test for commit aff6ba1 (f7841bf Leonid Evdokimov) - o Style and comment tweaks for dns/leak* tests (5e42202) - o improve test to remove at least one buffer from src (7eb52eb Greg Hazel) - -DOCUMENTATION: - o Add note about evhttp_send_reply_end to its doxygen (724bfb5) - o Update copyright dates to 2011. (3c824bd) - o Fix typo in whatsnew-2.0.txt (674bc6a Mansour Moufid) - o Improve win32 behavior of dns-sample.c code (a3f320e Gisle Vanem) - - - -Changes in version 2.0.15-stable (12 Oct 2011) -BUGFIXES (DNS): - o DNS: add ttl for negative answers using RFC 2308 idea. (f72e8f6 Leonid Evdokimov) - o Add DNS_ERR_NODATA error code to handle empty replies. (94fba5b Leonid Evdokimov) - -BUFGIXES (bufferevents and evbuffers): - o Make evbuffer callbacks get the right n_added value after evbuffer_add (1ef1f68 Alex) - o Prefer mmap to sendfile unless a DRAINS_TO_FD flag is set. Allows add_file to work with SSL. (0ba0af9) - -BUGFIXES (event loop): - o When a signal callback is activated to run multiple times, allow event_base_loopbreak to work even before they all have run. (4e8eb6a) - -DOCUMENTATION FIXES: - o Fix docstring in dns.h (2b6eae5 Leonid Evdokimov) - o refer to non-deprecated evdns functions in comments (ba5c27d Greg Hazel) - -BUILD AND TESTING FIXES: - o le-proxy and regress depend on openssl directly (9ae061a Sergey Avseyev) - o Use _SOURCES, not _sources, in sample/Makefile.am (7f82382) - o Fixed compiler warnings for unchecked read/write calls. (c3b62fd Mark Ellzey) - o Make write-checking fixes use tt_fail_perror (2b76847) - o Fix some "value never used" warnings with gcc 4.6.1 (39c0cf7) - - - -Changes in version 2.0.14-stable (31 Aug 2011) -BUGFIXES (bufferevents and evbuffers): - o Propagate errors on the underlying bufferevent to the user. (4a34394 Joachim Bauch) - o Ignore OpenSSL deprecation warnings on OS X (5d1b255 Sebastian Hahn) - o Fix handling of group rate limits under 64 bytes of burst (6d5440e) - o Solaris sendfile: correctly detect amount of data sent (643922e Michael Herf) - o Make rate limiting work with common_timeout logic (5b18f13) - o clear read watermark on underlying bufferevent when creating filtering bev to fix potentially failing fragmented ssl handshakes (54f7e61 Joachim Bauch) - -BUGFIXES (IOCP): - o IOCP: don't launch reads or writes on an unconnected socket (495c227) - o Make IOCP rate-limiting group support stricter and less surprising. (a98da7b) - o Have test-ratelim.c support IOCP (0ff2c5a) - o Make overlapped reads result in evbuffer callbacks getting invoked (6acfbdd) - o Correctly terminate IO on an async bufferevent on bufferevent_free (e6af35d) - -BUGFIXES (other): - o Fix evsig_dealloc memory leak with debugging turned on. (9b724b2 Leonid Evdokimov) - o Fix request_finished memory leak with debugging turned on. (aff6ba1 Leonid Evdokimov) - -BUILD AND TESTING FIXES: - o Allow OS-neutral builds for platforms where some versions have arc4random_buf (b442302 Mitchell Livingston) - o Try to fix 'make distcheck' errors when building out-of-tree (04656ea Dave Hart) - o Clean up some problems identified by Coverity. (7c11e51 Harlan Stenn) - - -Changes in version 2.0.13-stable (18 Jul 2011) -BUGFIXES - o Avoid race-condition when initializing global locks (b683cae) - o Fix bug in SSL bufferevents backed by a bev with a write high-watermarks (e050703 Joachim Bauch) - o Speed up invoke_callbacks on evbuffers when there are no callbacks (f87f568 Mark Ellzey) - o Avoid a segfault when all methods are disabled or broken (27ce38b) - o Fix incorrect results from evbuffer_search_eol(EOL_LF) (4461f1a) - o Add some missing checks for mm_calloc failures (89d5e09) - o Replace an assertion for event_base_free(NULL) with a check-and-warn (09fe97d) - o Report kqueue ebadf, epipe, and eperm as EV_READ events (1fd34ab) - o Check if the `evhttp_new_object' function in `http.c' returns NULL. (446cc7a Mansour Moufid) - o Use the correct printf args when formatting size_t (3203f88) - o Complain if the caller tries to change threading cbs after setting them (cb6ecee) - -DOCUMENTATION FIXES AND IMPROVEMENTS - o Revise the event/evbuffer/bufferevent doxygen for clarity and accuracy (2888fac) - o Update Doxyfile to produce more useful output (aea0555) - -TEST FIXES - o Fix up test_evutil_snprintf (caf695a) - o Fix tinytest invocation from windows shell (57def34 Ed Day) - -BUILD FIXES - o Use AM_CPPFLAGS in sample/Makefile.am, not AM_CFLAGS (4a5c82d) - o Fix select.c compilation on systems with no NFDBITS (49d1136) - o Fix a few warnings on OpenBSD (8ee9f9c Nicholas Marriott) - o Don't break when building tests from git without python installed (b031adf) - o Don't install event_rpcgen.py when --disable-libevent-install is used (e23cda3 Harlan Stenn) - o Fix AIX build issue with TAILQ_FOREACH definition (e934096) - - -Changes in version 2.0.12-stable (4 Jun 2011) -BUGFIXES - o Fix a warn-and-fail bug in kqueue by providing kevent() room to report errors (28317a0) - o Fix an assert-inducing fencepost bug in the select backend (d90149d) - o Fix failing http assertion introducd in commit 0d6622e (0848814 Kevin Ko) - o Fix a bug that prevented us from configuring IPv6 nameservers. (74760f1) - o Prevent size_t overflow in evhttp_htmlescape. (06c51cd Mansour Moufid) - o Added several checks for under/overflow conditions in evhttp_handle_chunked_read (a279272 Mark Ellzey) - o Added overflow checks in evhttp_read_body and evhttp_get_body (84560fc Mark Ellzey) - -DOCUMENTATION: - o Add missing words to EVLOOP_NONBLOCK documentation (9556a7d) - -BUILD FIXES - o libssl depends on libcrypto, not the other way around. (274dd03 Peter Rosin) - o Libtool brings in the dependencies of libevent_openssl.la automatically (7b819f2 Peter Rosin) - o Use OPENSSL_LIBS in Makefile.am (292092e Sebastian Hahn) - o Move the win32 detection in configure.in (ceb03b9 Sebastian Hahn) - o Correctly detect openssl on windows (6619385 Sebastian Hahn) - o Fix a compile warning with zlib 1.2.4 and 1.2.5 (5786b91 Sebastian Hahn) - o Fix compilation with GCC 2, which had no __builtin_expect (09d39a1 Dave Hart) - o Fix new warnings from GCC 4.6 (06a714f) - o Link with -lshell32 and -ladvapi32 on Win32. (86090ee Peter Rosin) - o Make the tests build when OpenSSL is not available. (07c41be Peter Rosin) - o Bring in the compile script from automake, if needed. (f3c7a4c Peter Rosin) - o MSVC does not provide S_ISDIR, so provide it manually. (70be7d1 Peter Rosin) - o unistd.h and sys/time.h might not exist. (fe93022 Peter Rosin) - o Make sure TINYTEST_LOCAL is defined when building tinytest.c (8fa030c Peter Rosin) - o Fix winsock2.h #include issues with MSVC (3d768dc Peter Rosin) - o Use evutil_gettimeofday instead of relying on the system gettimeofday. (0de87fe Peter Rosin) - o Always use evutil_snprintf, even if OS provides it (d1b2d11 Sebastian Hahn) - o InitializeCriticalSectionAndSpinCount requires _WIN32_WINNT >= 0x0403. (816115a Peter Rosin) - o cygwin: make it possible to build DLLs (d54d3fc) - - - -Changes in version 2.0.11-stable (27 Apr 2011) - [Autogenerated from the Git log, sorted and cleaned by hand.] -BUGFIXES: - o Fix evport handling of POLLHUP and POLLERR (b42ce4b) - o Fix compilation on Windows with NDEBUG (cb8059d) - o Check for POLLERR, POLLHUP and POLLNVAL for Solaris event ports (0144886 Trond Norbye) - o Detect and handle more allocation failures. (666b096 Jardel Weyrich) - o Use event_err() only if the failure is truly unrecoverable. (3f8d22a Jardel Weyrich) - o Handle resize failures in the select backend better. (83e805a) - o Correctly free selectop fields when select_resize fails in select_init (0c0ec0b) - o Make --enable-gcc-warnings a no-op if not using gcc (3267703) - o Fix a type error in our (unused) arc4random_stir() (f736198) - o Correctly detect and stop non-chunked http requests when the body is too long (63a715e) - o Have event_base_gettimeofday_cached() always return wall-clock time (a459ef7) - o Workaround for http crash bug 3078187 (5dc5662 Tomash Brechko) - o Fix incorrect assertions and possible use-after-free in evrpc_free() (4b8f02f Christophe Fillot) - o Reset outgoing http connection when read data in idle state. (272823f Tomash Brechko) - o Fix subtle recursion in evhttp_connection_cb_cleanup(). (218cf19 Tomash Brechko) - o Fix the case when failed evhttp_make_request() leaved request in the queue. (0d6622e Tomash Brechko) - o Fix a crash bug in evdns server circular list code (00e91b3) - o Handle calloc failure in evdns. (Found by Dave Hart) (364291e) - o Fix a memory leak on win32 socket->event map. (b4f89f0) - o Add a forgotten NULL check to evhttp_parse_headers (12311ff Sebastian Hahn) - o Fix possible NULL-deref in evdns_cancel_request (5208544 Sebastian Hahn) - -PORTABILITY: - o Fall back to sscanf if we have no other way to implement strtoll (453317b) - o Build correctly on platforms without sockaddr_storage (9184563) - o Try to build correctly on platforms with no IPv6 support (713c254) - o Build on systems without AI_PASSIVE (cb92113) - o Fix http unit test on non-windows platforms without getaddrinfo (6092f12) - o Do not check for gethostbyname_r versions if we have getaddrinfo (c1260b0) - o Include arpa/inet.h as needed on HPUX (10c834c Harlan Stenn) - o Include util-internal.h as needed to build on platforms with no sockaddr_storage (bbf5515 Harlan Stenn) - o Check for getservbyname even if not on win32. (af08a94 Harlan Stenn) - o Add -D_OSF_SOURCE to fix hpux builds (0b33479 Harlan Stenn) - o Check for allocation failures in apply_socktype_protocol_hack (637d17a) - o Fix the check for multicast or broadcast addresses in evutil_check_interfaces (1a21d7b) - o Avoid a free(NULL) if out-of-memory in evdns_getaddrinfo. Found by Dave Hart (3417f68) - -DEFENSIVE PROGRAMMING: - o Add compile-time check for AF_UNSPEC==PF_UNSPEC (3c8f4e7) - -BUGS IN TESTS: - o Fix test.sh output on solaris (b4f89b6 Dave Hart) - o Make test-eof fail with a timeout if we never get an eof. (05a2c22 Harlan Stenn) - o Use %s with printf in test.sh (039b9bd) - o Add an assert to appease clang's static analyzer (b0ff7eb Sebastian Hahn) - o Add a forgotten return value check in the unit tests (3819b62 Sebastian Hahn) - o Actually send NULL request in http_bad_request_test (b693c32 Sebastian Hahn) - o add some (void) casts for unused variables (65707d7 Sebastian Hahn) - o Refactor test_getaddrinfo_async_cancel_stress() (48c44a6 Sebastian Hahn) - o Be nice and "handle" error return values in sample code (4bac793 Sebastian Hahn) - o Check return value of evbuffer_add_cb in tests (93a1abb Sebastian Hahn) - o Remote some dead code from dns-example.c (744c745 Sebastian Hahn) - o Zero a struct sockaddr_in before using it (646f9fe Sebastian Hahn) - -BUILD FIXES: - o Fix warnings about AC_LANG_PROGRAM usage (f663112 Sebastian Hahn) - o Skip check for zlib if we have no zlib.h (a317c06 Harlan Stenn) - o Fix autoconf bracket issues; make check for getaddrinfo include netdb.h (833e5e9 Harlan Stenn) - o Correct an AM_CFLAGS to an AM_CPPFLAGS in test/Makefile.am (9c469db Dave Hart) - o Fix make distcheck & installation of libevent 1 headers (b5a1f9f Dave Hart) - o Fix compilation under LLVM/clang with --enable-gcc-warnings (ad9ff58 Sebastian Hahn) - -FEATURES: - o Make URI parser able to tolerate nonconformant URIs. (95060b5) - -DOCUMENTATION: - o Clarify event_set_mem_functions doc (926f816) - o Correct evhttp_del_accept_socket documentation on whether socket is closed (f665924) - o fix spelling mistake in whatsnew-2.0.txt (deb2f73) - o Fix sample/http-server ipv6 fixes (eb692be) - o Comment internal headers used in sample code. (4eb281c) - o Be explicit about how long event loops run in event.h documentation (f95bafb) - o Add comment to configure.in to explain gc-sections test logic (c621359) - o Fix a couple of memory leaks in samples/http-server.c. Found by Dave Hart. (2e9f665) - -BUILD IMPROVEMENTS: - o Use the gcc -ffunction-segments feature to allow gc when linking with static libevent (0965c56 Dave Hart) - o Add configure options to disable installation, regression tests (49e9bb7 Dave Hart) - - - -Changes in version 2.0.10-stable (16 Dec 2010) - [Autogenerated from the Git log, sorted and cleaned by hand.] -BUGFIXES - o Minor fix for IOCP shutdown handling fix (2599b2d Kelly Brock) - o Correctly notify the main thread when activating an event from a subthread (5beeec9) - o Reject overlong http requests early when Expect:100-continue is set (d23839f Constantine Verutin) - o EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings with -DNDEBUG. (b63ab17 Evan Jones) - -CODE CLEANUPS - o bufferevent-internal.h: Use the new event2/util.h header, not evutil.h (ef5e65a Evan Jones) - o Use relative includes instead of system includes consistently. (fbe64f2 Evan Jones) - o Make whitespace more consistent - -TESTING - o tests: Use new event2 headers instead of old compatibility headers. (4f33209 Evan Jones) - -DOCUMENTATION - o Document that the cpu_hint is only used on Windows with IOCP for now (57689c4) - o Add stuff to "whats new in 2.0" based on reading include changes since August. (18adc3f) - - -Changes in 2.0.9-rc (30 Nov 2010): - [Autogenerated from the Git log, sorted and cleaned by hand.] -NEW AND MODIFIED APIs - o Add a function to change a listener's callback. (46ee061) - o Make evbuffer_add_file take ev_off_t, not off_t (ac7e52d) - o Make rate-limits go up to SIZE_MAX/EV_SSIZE_MAX, not just INT32_MAX (2cbb1a1) - o Add a bufferevent_get_base function (aab49b6) - -MAJOR BUGFIXES - o Disable changelist for epoll by default because of Linux dup() bug; add an option and/or an envvar to reenable it for speed. (9531763) - o Fix a 100%-CPU bug where an SSL connection would sometimes never stop trying to write (1213d3d) - o Fix a nasty bug related to use of dup() with epoll on Linux (c281aba) - o Fix bugs in posix thread-id calculation when sizeof(pthread_t) != sizeof(long) (fbaf077) - o Fix some ints to evutil_socket_t; make tests pass on win64. (f817bfa Dimitre Piskyulev) - o Set _EVENT_SIZEOF_VOID_P correctly on win32 and win64 (1ae82cd Dimitre Piskyulev) - o Avoid double-invocation of user callback with EVUTIL_EAI_CANCEL (abf01ed) - o Set SO_UPDATE_ACCEPT_CONTEXT on sockets from AcceptEx so that shutdown() can work (52aa419) - o When closing a filtering bufferevent, clear callbacks on the underlying bufferevent (fc7b1b0) - -NEW AND MODIFIED HTTP APIs - o Add evhttp_parse_query_str to be used with evhttp_uri_parse. (2075fbc) - o Add evhttp_response_code to remove one more reason to include http_struct.h (22e0a9b) - o Define enumerators for all HTTP methods, including PATCH from RFC5789 (75a7341 Felix Nawothnig) - o Functions to actually use evhttp_bound_socket with/as evconnlistener. (006efa7) - o Add evhttp_request_get_command so code can tell GET from POST without peeking at the struct. (49f4bf7) - o Introduce absolute URI parsing helpers. (86dd720 Pavel Plesov) - o Revise evhttp_uri_parse implementation to handle more of RFC3986 (eaa5f1d) - o Add evhttp_connection_get_base() to get the event_base from an http connection (cd00079) - o Let evhttp_parse_query return -1 on failure (b1756d0) - o New evhttp_uri(encode|decode) functions to handle + and NUL characters right (a8148ce) - o Add evhttp_response_code to remove one more reason to include http_struct.h (22e0a9b) - o Tweak interface for allowed methods (f5b391e) - o Add evhttp server alias interface, correct flagging of proxy requests. (aab8c38 Christopher Davis) - -HTTP BUGFIXES - o Add some comments to http.c and make a few functions static. (90b3ed5) - o Fix Content-Length when trying send more than 100GB of data (!) on an evhttp. (525da3e) - o Fix a bug where we would read too much data in HTTP bodies or requests. (58a1cc6) - o Correctly count req->body_size on http usage without Content-Length (8e342e5) - o Avoid missed-request bug when entire http request arrives before data is flushed (74c0e86) - o reset "chunked" flag when sending non-chunked reply (aa5f55f Joachim Bauch) - o evhttp_encode_uri encodes all reserved characters, including !$'()*+,/:=@ (2e63a60) - o Replace exact-version checks for HTTP/1.1 with >= or < checks (647e094) - o evhttp: Return 501 when we get an unrecognized method, not 400. (536311a) - o Don't disable reading from the HTTP connection after sending the request to be notified of connection-close in time (c76640b Felix Nawothnig) - o Never call evhttp_readcb while writing. (0512487) - o Try to fix an assertion failure related to close detection (0faaa39) - o Correctly detect timeouts during http connects (04861d5) - o Preliminary support for Continue expectation in evhttp. (fa9305f Christopher Davis) - -OTHER BUGFIXES - o Correct logic for realigning a chain in evbuffer_add (e4f34e8) - o Fix a minor syntax error that most compilers didn't care about (e56ff65) - o Fix some uses of int for socket in regress (5d389dc) - o Check return value for ioctlsocket on win32 (f5ad31c Trond Norbye) - o Fix som event_warns that should have been event_warnx (19c71e7) - o Fix signal handler types for win64. (b81217f) - o Try to clear up more size_t vs int/long issues. (598d133) - o Make sure IOCP evconnlistener uses virtual events. (7b40a00 Christopher Davis) - o Don't free evdns_request handles until after the callback is invoked (9ed30de) - o Fix some more cancel-related bugs in getaddrinfo_async (c7cfbcf) - o Make evdns_getaddrinfo_cancel threadsafe (d51b2fc) - o Only clear underlying callbacks when the user hasn't reset them. (1ac5b23) - o Fix bug in bufferevent_connect on an openssl bufferevent that already had an fd (4f228a1) - o Resolve an evport bug in the thread/forking test (3a67d0b) - o Make sure the CLOEXEC flag is set on fds we open for base notification (3ab578f) - o Fix IRIX build. sa_family collides with a #define in sys/socket.h on IRIX. (e874982 Kevin Bowling) - o If not WIN32, include <sys/socket.h> in event2/util.h. (1cd45e5 Kevin Bowling) - o Fix some C99-style comments to work with the xlC compiler. (c2e5e22 Kevin Bowling) - o Add some checks since lack of TAILQ_FOREACH doesn't imply lack of FIRST, END, NEXT, or INSERT_BEFORE. Quiet some warnings in XL C. (c4dc335 Kevin Bowling) - o Reworked AIX __ss_family workaround to use AC_STRUCT_MEMBER. (2e2a3d7 Kevin Bowling) - o Take select from <sys/select.h> when testing in autoconf. AIX build fix. (a3a9f6b Kevin Bowling) - o Fix snprintf related failures on IRIX. (3239073 Kevin Bowling) - o Remove _event_initialized(); make event_initialized() a function(); make it consistent on windows and non-windows (652024b) - o Do not let EVLOOP_ONCE exit the loop until all deferred callbacks have run (2d5e1bd) - o Make EVLOOP_ONCE ignore internal events (0617a81) - o Possible crash fix when freeing an underlying bufferevent of an openssl bufferevent (29f7623) - -HTTP CLEANUPS - o Stop using Libevent-1 headers in regress_http (1f507d7) - o Modernize header usage in bench_http.c (e587069) - o fix signed/unsigned warnings in http.c (74a91e5) - o Update the HTTP regression tests to use Libevent2 apis for non-http stuff (d9ffa89) - o Start porting http tests to not use legacy interfaces (8505a74) - o Convert the rest of the http tests to be non-legacy unit tests. (9bb8239) - o Rename the confusing "base" static variable in regress_http.c (353402a) - o Stop accessing http request struct directly from in the unit tests. (0b137f4) - o Refactor http version parsing into a single function (a38140b) - -TESTING - o Improvements to tinytest_macros.h (ad923a1) - o Add a huge pile of tests for the new URI functions, and make them pass. (a5a76e6) - o Unit tests for evhttp_uri_set* (bc98f5e) - o Increase the skew tolerance to 2 seconds in thread/deferred_cb_skew (f806476 Christopher Davis) - o Reorder backends in test.sh to match preference order in event.c (ece974f) - o Add a stress test for getaddrinfo_cancel (da1bf52) - o Units test for unexpected evhttp methods. (75e3320) - -DOCUMENTATION - o Document behavior of URI parsing more thoroughly. (3a33462) - o Document that two bufferevent functions only work on socket bufferevents (70e1b60) - o add a requested docstring for event_rpcgen.CommandLine.__init__ (f1250eb) - o Fix a mistake in http documentation found by Julien Blache (229714d) - o Add a basic example of how to write a static HTTP server. (4e794d5) - o Document event_get_assignment (88be27d) - o Note that reentrant calls to libevent from logging cbs may fail badly (e431bcd) - o Clarify EVLOOP_* documentation to be more precise. (057a514) - -CLEANUPS - o Simplify the logic for choosing EPOLL_CTL_ADD vs EPOLL_CTL_MOD (2c66983) - o Rename "size" variables in win32select that were really fd counts. (b6a158c) - o Fix even more win64 warnings (7484df6) - o Fix even more win64 warnings: buffer, event_tagging, http, evdns, evrpc (545a611) - o Fix more wn64 warnings. (34b84b9 Christopher Davis) - o Use the label_len local variable in evdns instead of recalculating it over and over (ba01456) - o Fix some irix compilation warnings spotted by Kevin Bowling (7bcace2) - - - -Changes in 2.0.8-rc (14 Oct 2010): - [Autogenerated from the Git log, sorted and cleaned by hand.] -NEW APIS - o Add error callback to evconnlistener (c4be8d8 Simon Perreault) - o Add a LEV_OPT_THREADSAFE option for threadsafe evconnlisteners (127d4f2) - -CHANGED BEHAVIOR - o Correct logic on disabling underlying bufferevents when disabling a filter (ac27eb8) - -BUGFIXES - o Obey enabled status when unsuspending (040a019 Simon Perreault) - o Warn when using the error-prone EV_SIGNAL interface in an error-prone way. Also, fix a couple of race conditions in signal.c (720bd93) - O Make default signal backend fully threadsafe (95a7d41) - o Put internal events at highest priority (90651b3) - o Fix warnings in the main codebase flagged by -Wsigned-compare (9c8db0, 5e4bafb, 5c214a, 6be589a, e06f514) - o Fix compile in kqueue.c (b395392 Sebastian Hahn) - o Do not search outside of the system directory for windows DLLs (d49b5e3) - o Fix a spurious-call bug on epoll.c (0faaee0) - o Send a shutdown(SHUT_WR) before closing an http connection (e0fd870 Christopher Davis) - o Fix warnings on mingw with gcc 4.5 (5b7a370) - o Fix an EINVAL on evbuffer_write_iovec on OpenSolaris. (fdc640b) - o Fix allocation error for IOCP listeners. Probably harmless, since struct event is big (481ef92) - o Make iocp/listener/error work; don't accept again if lev is disabled. (62b429a Christopher Davis) - o Handle rate-limiting for reading on OpenSSL bufferevents correctly. (819b171) - o Fix serious bugs in per-bufferevent rate-limiting code (34d64f8) - o Avoid spurious reads from just-created open openssl bufferevents (223ee40) - o Fix a case where an ssl bufferevent with CLOSE_ON_FREE didn't close its fd (93bb7d8) - o The corrected bufferevent filter semantics let us fix our openssl tests (34331e4) - -TESTING - o Make SSL tests cover enabling/disabling EV_READ. (a5ce9ad) - o Bump to the latest version of tinytest (f0bd83e) - o Unit tests for listener error callbacks (045eef4) - o New unit test for ssl bufferevents starting with connected SSLs. (02f6259) - -DEBUGGABILITY - o Make debugging output for epoll backend more comprehensive (ec2b05e) - o Make event.c debugging messages report fds (e119899) - o Make the --enable-gcc-warnings option include signed comparison warnings (d3b096c) - -DEADCODE REMOVAL - o Remove the now-useless evsig_caught and evsig_process (4858b79) - o Remove event_base.evsigbase; nothing used it. (38d0960) - - - -Changes in 2.0.7-rc (9 Sep 2010): - [Autogenerated from the Git log, sorted and cleaned by hand.] -NEW APIS - o Expose a evdns_base_nameserver_sockaddr_add() function to add a nameserver by sockaddr (1952143) - o Add event_config_set_num_cpus_hint() for tuning win32 IOCP thread pools, etc. (2447fe8 Christopher Davis) - -BUGFIXES - o Fix a nasty dangling-event bug when using rate-limiting groups (0bffe43) - o Clean up syntax on TAILQ_ENTRY() usage to build correctly with recent MSVC (60433a0 Gilad Benjamini) - o Make definition of WIN32_LEAN_AND_MEAN in event.h conditional (3920172 Gilad Benjamini) - o Correctly detect failure to delete bufferevent read-timeout event (da6e7cd) - o Set close-on-exec bit for filedescriptors created by dns subsystem (d0b8843) - o Fix kqueue correctness test on x84_64 (6123d12) - o Detect events with no ev_base; warn instead of crashing (f1074b7) - o Fix an issue with forking and signal socketpairs in select/poll backends (d61b2f3) - o Stop using global arrays to implement the EVUTIL_ctype functions (1fdec20) - o On windows, make lock/thread function tables static (5de2bcb) - o Close th_notify_fds and open a new pair on reinit (495ed66) - o Declare signal handler function as "__cdecl" on Windows (f0056d0) - o Use the _func() replacements for open, fstat, etc in evutil.c on win32 (e50c0fc) - o Only process up to MAX_DEFERRED deferred_cbs at a time (17a14f1 Christopher Davis) - -THREADING BUGFIXES - o Avoid deadlock when activating signals (970e6ad) - o Add a condition variable backend, with implementations for pthreads and win32 (d4977b5) - o Use conditions instead of current_event_lock to fix a deadlock (e0972c2) - o Fix logic error in win32 TRY_LOCK that caused problems with rate-limiting (4c32b9d) - o Avoid needlessly calling evthread_notify_base() when the loop is not running (c7a06bf) - o Minimize calls to base_notify implementation functions, thereby avoiding needless syscalls (4632b78) - -IOCP BUGFIXES - o IOCP-related evbuffer fixes (03afa20 Christopher Davis) - o Stop IOCP when freeing the event_base (d844242 Christopher Davis) - o Some IOCP bufferevent tweaks (76f7e7a Christopher Davis) - -TESTS - o Make the regress_pthread.c tests work on windows with current test APIs (d74ae38) - o Add a unit test for conditions (5fb1095) - o Allow more than one copy of regression tests to run at once (a97320a) - o Fix event_del(0) instance in bench.c (b0f284c Shuo Chen) - o Fix a few memory leaks in the tests (1115366) - o IOCP-related unit test tweaks (499452f Christopher Davis) - o Improve testing of when thread-notification occurs (ce85280) - -BUILD AND DISTRIBUTION - o Add pkgconfig files for libevent_{openssl,pthreads} (ebcb1f0) - o Change include order in Makefile.nmake (4022b28) - o Make include/event2/event-config.h not included in source dist (a4af9be) - o Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off in unit test code (743f866) - o Declare evkeyvalq and event_list even if event_struct.h comes before sys/queue.h (d3ceca8) - o Move evkeyvalq into a separate header for evhttp_parse_query users (ca9048f) - o Prefer autoreconf -ivf to manual autogen.sh (7ea8e89) - -CLEANUP - o Completely remove the (mostly-removed) obsolete thread functions (3808168) - o Rename regress_pthread.c to regress_thread.c (041989f) - o Make defer-internal.h use lock macros, not direct calls to lock fns (5218d2a) - -DOCUMENTATION - o Document that DNS_NO_SEARCH is an obsolete alias for DNS_QUERY_NO_SEARCH (33200e7) - o Update the whatsnew-2.0.txt document (4991669) - - - -Changes in 2.0.6-rc (6 Aug 2010): - [Autogenerated from the Git log, sorted by hand.] -DOCUMENTATION - o Document a change in the semantics of event_get_struct_event_size() (e21f5d1) - o Add a comment to describe our plan for library versioning (9659ece) - o Fix sentence fragment in docs for event_get_struct_event_size() (7b259b6) - -NEW FEATURES AND INTERFACE CHANGES - o Remove the obsolete evthread interfaces (c5bab56) - o Let evhttp_send_error infer the right error reasons (3990669) - o Add a function to retrieve the other side of a bufferevent pair (17a8e2d) - o Add bufferevent_lock()/bufferevent_unlock() (215e629) - o Stop asserting when asked for a (unsupported) TCP dns port. Just return NULL. (7e87a59) - o Replace (unused,always 0) is_tcp argument to evdns_add_server_port*() with flags (e1c1167) - o Constify a couple of arguments to evdns_server_request_add_*_reply (cc2379d) - o Add an interface to expose min_share in ratelimiting groups (6ae53d6) - -BUGFIXES - o Avoid event_del on uninitialized event in event_base_free (6d19510) - o Add some missing includes to fix Linux build again (75701e8) - o Avoid close of uninitialized socket in evbuffer unit test (bda21e7) - o Correctly recognize .255 addresses as link-local when looking for interfaces (8c3452b) - o If no evdns request can be launched, return NULL, not a handle (b14f151) - o Use generic win32 interfaces, not ASCII-only ones, where possible. (899b0a3) - o Fix the default HTTP error template (06bd056 Felix Nawothnig) - o Close the file in evutil_read_file whether there's an error or not. (0798dd1 Pierre Phaneuf) - o Fix possible nullptr dereference in evhttp_send_reply_end() (29b2e23 Felix Nawothnig) - o never let bufferevent_rlim functions return negative (0859870) - o Make sample/hello_world work on windows (d89fdba) - o Fix a deadlock related to event-base notification. Diagnosed by Zhou Li, Avi Bab, and Scott Lamb. (17522d2) - o Possible fix to 100% cpu usage with epoll and openssl (cf249e7 Mike Smellie) - o Don't race when calling event_active/event_add on a running signal event (fc5e0a2) - o Suppress a spurious EPERM warning in epoll.c (e73cbde) - o Fix wrong size calculation of iovec buffers when exact=1 (65abdc2 niks) - o Change bufferevent_openssl::do_write so it doesn't call SSL_write with a 0 length buffer (c991317 Mike Smellie) - o Fixed compilation of sample/le-proxy.c on win32 (13b912e Trond Norbye) - o Fix rate-limit calculation on openssl bufferevents. (009f300) - o Remember to initialize timeout events for bufferevent_async (de1f5d6 Christopher Davis) - -BUILD AND DISTRIBUTION CHANGES - o Test the unlocked-deferred callback case of bufferevents (dfb75ab) - o Remove the now-unusable EVTHREAD_LOCK/UNLOCK constants (fdfc3fc) - o Use -Wlogical-op on gcc 4.5 or higher (d14bb92) - o Add the libtool-generated /m4/* stuff to .gitignore (c21c663) - o Remove some automake-generated files from version control. (9b14911) - o Have autogen.sh pass --force-missing to automake (8a44062) - o Set library version for libevent_pthreads correctly (b2d7440) - o Really only add libevent_core.la to LIBADD on mingw (1425003 Sebastian Hahn) - o Build more cleanly with NetBSDs that dislike toupper(char) (42a8c71) - o Fix unit tests with -DUSE_DEBUG enabled (28f31a4) - o Fix evdns build with -DUNICODE (5fa30d2) - o Move event-config.h to include/event2 (ec347b9) - -TESTING - o Add options to test-ratelim.c to check its results (2b44dcc) - o Make test-ratelim clean up after itself better. (b5bfc44) - o Remove the now-obsolete setup_test() and cleanup_test() functions (e73f1d7) - o Remove all non-error prints from test/regress.c (8bc1e3d) - o Make test.sh exit with nonzero status if tests fail (faf2a04) - o Have the unit tests report errors from test.sh (3689bd2) - o Fix logic in correcting high values from FIONREAD (3467f2f) - o Add test for behavior on remote socket close (44d57ee) - o Unit test for event_get_struct_event_size() (7510aac) - o Make test/test.sh call test-changelist (7c92691) - o Fix badly-behaved subtest of dns/bufferevent_connect_hostname (840a72f Joachim Bauch) - o Add option to test-ratelim to test min_share (42f6b62) - o Fix an assertion bug in test-ratelim (b2c6202) - o Make tests quieter on local dns resolver failure (e996b3d) - o Increase the tolerance in our unit tests for sloppy clocks. (170ffd2) - o Use AF_INET socketpair to test sendfile on Solaris (9b60209) - o Make test-changelist count cpu usage right on win32 (ea1ea3d) - -INTERNALS, PERFORMANCE, AND CODE CLEANUPS - o Mark the event_err() functions as __attribute__((noreturn)) (33bbbed) - o Do not check that event_base is set in EVBASE_ACQUIRE_LOCK (218a3c3) - o Replace (safe) use of strcpy with memcpy to appease OpenBSD (caca2f4) - o Remove some dead assignments (47c5dfb) - o Fix a pedantic gcc 4.4 warning in event2/event.h (276e7ee) - o Drain th_notify_fd[0] more bytes at a time. (a5bc15b) - o Tidy up the code in evthread_make_base_notifiable a little (61e1eee) - o Pass flags to fcntl(F_SETFL) and fcntl(F_SETFD) as int, not long (7c2dea1) - o Remove unused variables in test/test-changelist.c (b00d4c0) - o Fix whitespace. (cb927a5) - o Improve error message for failed epoll to make debugging easier. (9e725f7) - o Turn our socketpair() replacement into its own function (57b30cd) - - - -Changes in 2.0.5-beta (10 May 2010): - [Autogenerated from the Git log, sorted by hand.] -DOCUMENTATION - o Update all our copyright notices to say "2010" (17efc1c) - o Add Christopher Clark and Maxim Yegorushkin to the LICENSE file (38b7b57) - o Clarify Christopher Clark's status as writer of original ht code. (78772c3) - o Try to comment some of the event code more (cdd4c49) - o Add a few more evmap/changelist comments (c247adc) - o Add a comment to explain why evdns_request is now separte from request (ceefbe8) - o Document evutil_secure_rng_init() and evutil_secure_rng_add_bytes() (a5bf43a) - o Stop distributing and installing manpages: they were too inaccurate (7731ec8) - -NEW FEATURES AND INTERFACE CHANGES - o Remove signal_assign() and signal_new() macros. (2fac0f7) - o Make evdns use the regular logging system by default (b2f2be6) - o Allow evbuffer_read() to split across more than 2 iovecs (e470ad3) - o Functions to manipulate existing rate limiting groups. (ee41aca) - o Functions to track the total bytes sent over a rate limit group. (fb366c1) - o Detect and refuse reentrant event_base_loop() calls (b557b17) - o Limit the maximum number of events on each socket to 65535 (819f949) - o Add evbuffer_copyout to copy data from an evbuffer without draining (eb86c8c) - o Expose the request and reply members of rpc_req_generic() (07edf78 Shuo Chen) - o Add void* arguments to request_new and reply_new evrpc hooks (755fbf1 Shuo Chen) - o Seed the RNG using sysctl() as well as /dev/urandom (71fc3eb) - o Make evutil_secure_rng_init() work even with builtin arc4random (f980716) - o Report DNS error when lookup fails during bufferevent_socket_connect_hostname. (0ef4070 Christopher Davis) - o Release locks on bufferevents while executing callbacks (a5208fe Joachim Bauch) o Make debug mode catch mixed ET and non-ET events on an fd (cb67074) - o Catch attempts to enable debug_mode too late (9ecf0d4) - o Refuse null keys in evhttp_parse_query() (953e229 Frank Denis) - -BUGFIXES - o Avoid a spurious close(-1) on Linux (70a44b6) - o Do not close(-1) when freeing an uninitialized socket bufferevent (b34abf3) - o Free evdns_base->req_heads on evdns_base_free (859af67) - o Avoid an (untriggerable so far) crash bug in bufferevent_free() (0cf1431) - o Set mem_offset for every bufferevent type (657d1b6) - o Fix infrequent memory leak in bufferevent_init_common(). (8398641 Jardel Weyrich) - o Make evutil_signal_active() match declaration. (e1e703d Patrick Galbraith) - o Fix minheap code to use replacement malloc functions (a527618) - o Fix a free(NULL) in minheap-internal.h (6f20492) - o Fix critical bug in evbuffer_write when writev is not available (cda56ab) - o Make the no_iovecs case of write_atmost compile (8e227b0) - o Fix a memory leak when appending/prepending to a buffer with unused space. (45068a3) - o Clean up a mistake in pointer manipulation in evbuffer_remove (28bfed4 Christopher Davis) - o Always round up when there's a fractional number of msecs. (8f9e60c Christopher Davis) - o Fix compiler warnings under WIN32 (d469c50 Giuseppe Scrivano) - o Clean up properly when adding a signal handler fails. (b84b598 Gilad Benjamini) o Ensure that evdns_request is a persistent handle. (15bb82d Christopher Davis) - o Free search state when finished searching to avoid an infinite loop. (a625840 Christopher Davis) - o Assert for valid requests as necessary. (67072f3 Christopher Davis) - o do not leak the request object on persistent connections (9d8edf2) - o Make evdns logging threadsafe (b1c7950) - o Fix a couple of bugs in the BSD sysctl arc4seed logic (a47a4b7) - o Remove one last bug in last_with_datap logic. Found with valgrind (d49b92a) - o fix a leak when unpausing evrpc requests (94ee125) - o Fix a memory leak when unmarshalling RPC object arrays (f6ab2a2) - o Fix compilation when openssl support is disabled (40c301b) - o Allow empty reason line in HTTP status (739e688 Pierre Phaneuf) - o Fix a compile warning introduced in 739e688 (bd1ed5f Sebastian Hahn) - o Fix nonstandard TAILQ_FOREACH_REVERSE() definition (71afc52 Frank Denis) - o Try /proc on Linux as entropy fallback; use sysctl as last resort (20fda29) - o Fix symbol conflict between mm_*() macros and libmm (99e50e9) - o Fix some crazy macro mistakes in arc4random.c (90d4225) - o Make evbuffer_add_file() work on windows (dcdae6b) - o Fix unused-variable warning when building with threads disabled (ad811cd) - o Numerous opensolaris compilation fixes (c44de06) - o Fix getaddrinfo with protocol unset on Solaris 9. Found by Dagobert Michelsen (2cf2a28) - o Fix another nasty solaris getaddrinfo() behavior (3557071) - o Define _REENTRANT as needed on Solaris, elsewhere (c1cd32a) - o Fix some autoconf issues on OpenBSD (7c519df) - -BUILD AND DISTRIBUTION CHANGES - o Distribute libevent.pc.in, not libevent.pc (22aff04) - o Avoid errors in evutil.c when building with _UNICODE defined (b677032 Brodie Thiesfield) - o Avoid errors in http.c when building with VC 2003 .NET (13e4f3b Brodie Thiesfield) - o Support the standard 'make check' target in place of 'make verify' (426c8fb) - o Remove redundant stuff from EXTRA_DIST (b660edf) - o Switch to using AM conditionals in place of AC_LIBOBJ (2e898f5) - o Remove an orphaned RELEASE flag in Makefile.am (0794b0d) - o Give a better warning for bad automake versions. (77c917d) - o Use dist_bin_SCRIPTS, not EXTRA_DIST, to distribute scripts (9eb2fd7) - o Never test for select() on windows (3eb044d Trond Norbye) - o Do not inhibit automake dependencies generation (10c4c90 Giuseppe Scrivano) - o Create shared libraries under Windows (3cbca86 Giuseppe Scrivano) - o Add ctags/etags files to .gitignore (0861d17) - o Only specify -no-undefined on mingw (25433b9) - o Only add libevent_core.la to LIBADD on mingw (fdc6297) - -TESTING - o Get bench_http to work on Windows; add a switch to enable IOCP. (4ac38a5 Christopher Davis) - o VC has no getopt(), so do without in bench_http. (1273d2f Christopher Davis) - o Fix an obnoxious typo in the bufferevent_timeout_filter test (0d047c3) - o Fix a write of uninitialized RAM in regression tests (68dc742) - o Fix some memory leaks in the unit tests (274a7bd) - o Make 'main/many_events' test 70 fds, not 64. (33874b0) - o Unit-test every evbuffer_add_file() implementation. (06a4443) - o Add more unit tests for evbuffer_expand (8c83e99) - o Test another case of evbuffer_prepend (1234b95) - o Fix a possible double-free bug in SSL bufferevents with CLOSE_ON_FREE (7501895) o Add dns/search_cancel unit test. (39b870b Christopher Davis) - o Make http_base_test stop leaking an event_base. (96730d3) - o Detect broken unsetenv at unit-test runtime (f37cd4c) - o Implement regress_make_tempfile on win32 to test evbuffer_add_file (b4f12a1) - o add more (currently skipped) add_file tests on win32 (05de45d) - o Fix bench_http build on win32. (384d124) - o Make unit test for add_file able to tell "error" from "done" (88a543f) - o Make test for bufferevent_connect_hostname system-neutral (f89168e) - o Make test.sh support mingw/msys on win32 (0ee6f6c) - o Fix test.sh on freebsd (3d9e05b) - -INTERNALS, PERFORMANCE, AND AND CODE CLEANUPS - o Improve the speed of evbuffer_readln() (cc1600a) - o more whitespace normalization (2c2618d) - o Revise evbuffer to add last_with_data (2a6d2a1) - o Use last_with_data in place of previous_to_last (c8ac57f) - o Remove previous_to_last from evbuffer (6f47bd1) - o Fix last_with_data compilation on windows (1e7b986) - o Add some glass-box tests for the last_with_data code. (17da042) - o Improve robustness for refcounting (f1bc125) - o Remove a needless min_heap_shift_up_() call (7204b91) - o Increase MIN_BUFFER_SIZE to 512 (1024 on 64-bit) (2014ae4) - o Do not use evbuffer_expand() to add the first chain to a buffer (5c0ebb3) - o Make evbuffer_prepend handle empty buffers better (c87272b) - o Replace last_with_data with a slightly smarter version (b7442f8) - o Turn the increasingly complex *_CHAIN() macros into functions (96865c4) - o Rewrite evbuffer_expand and its users (d5ebcf3) - o Add evutil_tv_to_msec for safe conversion of timevals to milliseconds. (850c3ff Christopher Davis) - o Initialize last_with_datap correctly in evbuffer_overlapped (a0983b6) - o Replace EVUTIL_CLOSESOCKET macro with a function (899c1dc Sebastian Sjöberg) - o Move domain search state to evdns_request. (beaa14a Christopher Davis) - o Remove redundant checks for lock!=NULL before calling EVLOCK_LOCK (50ec59f) - o Rename current_base symbol to event_global_current_base_ (c16e684) - o Fix whitespace in evutil.c (935e150) - o Replace users of "int fd" with "evutil_socket_t fd" in portable code (c7cf6f0) - - - -Changes in 2.0.4-alpha (28 Feb 2010): - [Autogenerated from the Git log, sorted by hand.] -DOCUMENTATION - o Add stub header for 2.0.4-alpha changelog. (94d0065) - o Improve the README with more information and links. (0b42726) - o Add more people who wrote patches to the acknowledgments (0af10d5) - o Add a warning about the use of event_initialized. (f32b575) - o Add a LICENSE file so people can find our license easily (7067006) - o Add a new "hello world" sample program (becb9f9) - o Clarify status of example programs (d60a1bd) - o Update time-test.c to use event2 (f4190bf) - o Add the arc4random.c license to the LICENSE file. (e15e1e9) - -NEW FEATURES AND INTERFACE CHANGES - o Improved optional lock debugging. (0cd3bb9) - o Rate-limiting for bufferevents; group and individual limits are supported. (737c9cd) - o Testing code for bufferevent rate-limiting. (f0c0124) - o Make the initial nameserver probe timeout configurable. (1e56a32) - o Revise the locking API: deprecate the old locking callbacks and add trylock. (347952f) - o Do not make bufferevent_setfd implicitly disable EV_READ and EV_WRITE. (8274379) - o Do not ignore bufferevent_enable(EV_READ) before bufferevent_connect(). (4a5b534) - o Introduced evutil_make_socket_closeonexec() to preserve fd flags for F_SETFD. (d0939d2 Jardel Weyrich) - o evdns_getaddrinfo() now supports the /etc/hosts file. (72dd666) - o Look at the proper /etc/hosts file on windows. (66c02c7) - o Allow http connections to use evdns for hostname looksups. (c698b77) - o Changelist code to defer event changes until just before dispatch (27308aa) - o do not use a function to assign the evdns base; instead assign it via evhttp_connection_base_new() which is a new function introduced in 2.0 (5032e52) - o Functions to access more fields of struct event. (0683950) - o Make kqueue use changelists. (45e5ae3) - o Remove kqueue->pend_changes. (3225dfb) - o Minimize epoll_ctl calls by using changelist (c8c6a89) - o Add support for a "debug mode" to try to catch common errors. (cd17c3a) - o Note a missing ratelim function (361da8f) - o Add ev_[u]intptr_t to include/event2/util.h (1fa4c81) - o const-ify a few more functions in event.h (d38a7a1) - o Deprecate EVENT_FD and EVENT_SIGNAL. (f6b2694) - o Remove EVUTIL_CHECK_FMT. (6c21c89) - o Add EV_*_MAX macros to event2/util.h to expose limits for ev_* types. (aba1fff) o Functions to view and manipulate rate-limiting buckets. (85047a6) - o Add the rest of the integer limits, and add a test for them. (60742d5) - o Remove the 'flags' argument from evdns_base_set_option() (1dd7e6d) - o Add an arc4random implementation for use by evdns (d4de062) - o Use off_t for the length parameter of evbuffer_add_file (3fe60fd) - o Construct Windows locks using InitializeCriticalSectionAndSpinCount (32c6f1b) - o Expose view of current rate limit as constrained by group limit (162ce8a) - o Provide consistent, tested semantics for bufferevent timeouts (d328829) - -BUGFIXES AND TESTS - o Tolerate code that returns from a fatal_cb. (91fe23f) - o Parenthesize macro arguments more aggressively (07e9e9b) - o Fix memory-leak of signal handler array with kqueue. (e1ffbb8) - o Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks. (76cd2b7) - o Fix two use-after-free bugs in unit tests spoted by lock debugging (d84d838) - o Fix a locking bug in event_base_loop() (da1718b) - o Fix an evdns lock violation. (2df1f82 Zhuang Yuyao) - o Valgrind fix: Clear struct kevent before checking for OSX bug. (56771a3 William Ahern) - o Fix up evthread compilation on windows (bd6f1ba Roman Puls) - o Fix regress_iocp.c usage of old lock allocation macros. (31687b4 unknown) - o Update nmake makefile to build evthread.c (b62d979 unknown) - o Fix a crash when reading badly formatted resolve.conf; from Yasuoka Masahiko (6c7c579 Yasuoka Masahiko) - o Fix a snow leopard compile warning in the unit tests. (7ae9445) - o Fix compile on Snow Leopard with gcc warnings enabled (70cdfe4 Sebastian Hahn) - o Only define _GNU_SOURCE if it is not already defined. (ea6b1df Joachim Bauch) - o Update sample/signal-test.c to use newer APIs and not leak. (f6430ac Evan Jones) - o Fix a segfault when writing a very fragmented evbuffer onto an SSL (a6adeca Joachim Bauch) - o Fix a segfault when freeing SSL bufferevents in an unusual order (a773df5 Joachim Bauch) - o Drop install-sh from our git repo: a mismatched version could break "make dist" (6799527) - o Set all instances of the version number correctly. (5a112d3) - o Fix a few locking issues on windows. (c51bb3c unknown) - o Use evutil_socket_t, not int, when logging socket errors. (292467c) - o Fix up behavior of never-defered callbacks a little (390e056) - o Replace some cases of uint32_t with ev_uint32_t. (a47d88d) - o Fix compilation of devpoll.c by adding missing thread includes. (fee2c77 Dagobert Michelsen) - o Make evutil_make_socket_nonblocking() leave any other flags alone. (4c8b7cd Jardel Weyrich) - o Fix an fd leak in evconnlistener_new_bind(). (24fb502 Jardel Weyrich) - o Fix a bogus free in evutil_new_addrinfo() (0d64051 Jardel Weyrich) - o Adjusted fcntl() retval comparison on evutil_make_socket_nonblocking(). (4df7dbc Jardel Weyrich) - o Fix the code that allowed DNS options to not end with : (ee4953f) - o Fix crash bugs when a bufferevent's eventcb is not set. (2e8eeea) - o Fix test-ratelim compilation on Linux. (885b427) - o Fix compilation of rate-limiting code on win32. (165d30e) - o Eradicated the last free() call. Let mm_free() take care of deallocation. (0546ce1 Jardel Weyrich) - o Fix byte counts when mixing deferred and non-deferred evbuffer callbacks. (29151e6) - o Fixed a memory leak on windows threads implementation. The CRITICAL_SECTION was not being free'd in evthread_win32_lock_free(). (2f33e00 Jardel Weyrich) - o Fixed a fd leak in start_accepting(), plus cosmetic changes (4367a33 Jardel Weyrich) - o Improved error handling in evconnlistener_new_async(). Also keeping the fd open because it is not opened by this function, so the caller is responsible for closing it. Additionally, since evconnlistener_new_bind() creates a socket and passes it to the function above, it required error checking to close the same socket. (fec66f9 Jardel Weyrich) - o Don't use a bind address for nameservers on loopback (8d4aaf9) - o Fix compilation of rate-limit code when threading support is disabled (97a8c79) - o Detect setenv/unsetenv; skip main/base_environ test if we can't fake them. (7296971) - o Check more internal event_add() calls for failure (ff3f6cd) - o Fix windows and msvc build (5c7a7bc) - o Call event_debug_unassign on internal events (a19b4a0) - o Try to fix a warning in hash_debug_entry (137f2c6) - o Fix a dumb typo in ev_intptr_t definitions. (27c9a40) - o do not fail while sending on http connections the client closed. (93d7369) - o make evhttp_send() safe against terminated connections, too (3978180) - o Make Libevent 1.4.12 build on win32 with Unicode enabled. (000a33e Brodie Thiesfield) - o Fix some additional -DUNICODE issues on win32. (a7a9431) - o Add a check to make soure our EVUTIL_AI flags do not conflict with the native ones (c18490e) - o Always use our own gai_strerror() replacement. (6810bdb) - o Make RNG work when we have arc4random() but not arc4random_buf() (4ec8fea) - o validate close cb on server when client connection closes (2f782af) - o Fix two unlocked reads in evbuffer. (7116bf2) - o When working without a current event base, don't try to use IOCP listeners (cb52838) - o Fix getpid() usage on Windows (ff2a134) - o Add a unit test for secure rng. (48a29b6) - o Add some headers to fix freebsd compilation (b72be50) - o When connect() succeeds immediately, don't invoke the callback immediately. (7515de9) - o Suspend read/write on bufferevents during hostname lookup (db08f64) - o Make bufferevent_free() clear all callbacks immediately. (b2fbeb3) - o Fix some race conditions in persistent events and event_reinit (e2642f0) - o Fix a bug in resetting timeouts on persistent events when IO triggers. (38ec0a7) - o Add a test for timeouts on filtering bufferevents. (c02bfe1) - o Add test for periodic timers that get activated for other reasons (8fcb7a1) - o Use new timeval diff comparison function in bufferevent test (f3dfe46) - o Delete stack-alloced event in new unit test before returning. (7ffd387) - o Fix mingw compilation (23170a6) - o Try to define a sane _EVENT_SIZEOF_SIZE_T for msvc compilation (1e14f82) - o Fix arc4random compilation on MSVC. (98edb89) - o deal with connect() failing immediately (7bc48bf) - o Small cleanups on freebsd-connect-refused patch. (57b7248) - -BUILD AND DISTRIBUTION CHANGES - o Remove the contents of WIN32-Prj as unmaintained. (c69d5a5) - o Allow the user to redirect the verbose output of test/test.sh to a file (c382de6) - o Allow test.sh to be run as ./test/test.sh (7dfbe94) - o Never believe that we have pthreads on win32, even if gcc thinks we do. (78ed097) - o Make it compile under gcc --std=c89. (e2ca403) - o Fix a number of warnings from gcc -pedantic (918e9c5) - o Add the msvc-generated .lib files to .gitignore. (e244a2e) - o Add the "compile" script to gitignore. (1ba6bed) - -INTERNALS AND CODE CLEANUPS - o Add a .gitignore file. (ba34071) - o New EVTHREAD_TRY_LOCK function to try to grab a lock. (689fc09) - o Add the abilitity to mark some buffer callbacks as never-deferred. (438f9ed) - o Refactor our 'suspend operation' logic on bufferevents. (0d744aa) - o Simplify the read high-watermark checking. (5846bf6) - o Improve readability of evutil_unparse_protoname() (5a43df8 Jardel Weyrich) - o Expose our cached gettimeofday value with a new interface (47854a8) - o Whitespace fixes in test.sh (0b151a9) - o Enable branch-prediction hints with EVUTIL_UNLIKELY. (eaaf27f) - o Refactor code from evdns into a new internal "read a file" function. (0f7144f) - o Comestic changes in evconnlistener_new(), new_accepting_socket(), accepted_socket_invoke_user_cb() and iocp_listener_enable(). (510ab6b Jardel Weyrich) - o Add unit-test for bad_request bug fixed in 1.4 recently. (6cc79c6 Pavel Plesov) o Add a comment on evthread_enable_lock_debuging. (b9f43b2) - o Fix test.sh on shells without echo -n (94131e9) - o More unit tests for getaddrinfo_async: v4timeout and cancel. (a334b31) - o Make http use evconnlistener. (ec34533) - o move dns utility functions into a separate file so that we can use them for http testing (b822639) - o add a test for evhttp_connection_base_new with a dns_base (26714ca) - o forgot to add void to test function (78a50fe) - o Add a forgotten header (changelist-internal.h) (4b9f307) - o Remove some commented-out code in evutil (26e1b6f) - o Remove a needless include of rpc_compat.h (70a4a3e) - o Use less memory for each entry in a hashtable (a66e947) - o Try to untangle the logic in server_port_flush(). (439aea0) - o Use ev_[u]intptr_t types in place of [u]intptr_t (cef61a2) - o Reduce windows header includes in our own headers. (da6135e) - o clean up terminate_chunked test (e8a9782) - o Increment the submicro version number. (63e868e) - o Update event-config.h version number to match configure.in (aae7db5) - o Clean up formatting: Disallow space-before-tab. (8fdf09c) - o Clean up formatting: use tabs, not 8-spaces, to indent. (e5bbd40) - o Clean up formatting: remove trailing spaces (e5cf987) - o Clean up formatting: function/keyword spacing consistency. (4faeaea) - - - -Changes in 2.0.3-alpha (20 Nov 2009): - o Add a new code to support SSL/TLS on bufferevents, using the OpenSSL library (where available). - o Fix a bug where we didn't allocate enough memory in event_get_supported_methods(). - o Avoid segfault during failed allocation of locked evdns_base. (Found by Rocco Carbone.) - o Export new evutil_ascii_* functions to perform locale-independent character type operations. - o Try to compile better with MSVC: patches from Brodie Thiesfield - o New evconnlistener_get_fd function to expose a listener's associated socket. - o Expose an ev_socklen_t type for consistent use across platforms. - o Make bufferevent_socket_connect() work when the original fd was -1. - o Fix a bug in bufferevent_socket_connect() when the connection succeeds too quickly. - o Export an evutil_sockaddr_cmp() to compare to sockaddr objects for equality. - o Add a bufferevent_get_enabled() to tell what a bufferevent has been configured to do. - o Add an evbuffer_search_eol() function to locate the end of a line nondestructively. - o Add an evbuffer_search_range() function to search a bounded range of a buffer. - o Fix a rare crash bug in evdns. - o Have bufferevent_socket_connect() with no arguments put a bufferevent into connecting mode. - o Support sendfile on Solaris: patch from Caitlin Mercer. - o New functions to explicitly reference a socket used by an evhttp object. Patches from David Reiss. - o When we send a BEV_EVENT_CONNECTED to indicate connected status, we no longer invoke the write callback as well unless we actually wrote data too. - o If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it. Fixes bug 2841177; found by Alexander Pronchenkov. - o Do not detect whether we have monotonic clock support every time a new event base is created: instead do it only once. Patch taken from Chromium. - o Do not allocate the maximum event queue for the epoll backend at startup. Instead, start out accepting 32 events at a time, and double the queue's size when it seems that the OS is generating events faster than we're requesting them. Saves up to 374K per epoll-based event_base. Resolves bug 2839240. - o Treat an event with a negative fd as valid but untriggerable by Libevent. This is useful for applications that want to manually activate events. - o Fix compilation on Android, which forgot to define fd_mask in its sys/select.h - o Do not drop data from evbuffer when out of memory; reported by Jacek Masiulaniec - o New event_base_got_exit() and event_base_got_break() functions to tell whether an event loop exited because of an event_base_loopexit() or an event_base_loopbreak(). Patch from Ka-Hing Cheung. - o When adding or deleting an event from a non-main thread, only wake up the main thread when its behavior actually needs to change. - o Fix some bugs when using the old evdns interfaces to initialize the evdns module. - o Detect errors during bufferevent_connect(). Patch from Christopher Davis. - o Fix compilation for listener.h for C++ - missing extern "C". Patch from Ferenc Szalai. - o Make the event_base_loop() family of functions respect thread-safety better. This should clear up a few hard-to-debug race conditions. - o Fix a bug when using a specialized memory allocator on win32. - o Have the win32 select() backend label TCP-socket-connected events as EV_WRITE, not EV_READ. This should bring it in line with the other backends, and improve portability. Patch from Christopher Davis. - o Stop using enums as arguments or return values when what we mean is a bitfield of enum values. C++ doesn't believe that you can OR two enum values together and get another enum, and C++ takes its typing seriously. Patch from Christopher Davis. - o Add an API to replace all fatal calls to exit() with a user-provided panic function. - o Replace all assert() calls with a variant that is aware of the user-provided logging and panic functions. - o Add a return value to event_assign so that it can fail rather than asserting when the user gives it bad input. event_set still dies on bad input. - o The event_base_new() and event_base_new_with_config() functions now never call exit() on failure. For backward "compatibility", event_init() still does, but more consistently. - o Remove compat/sys/_time.h. It interfered with system headers on HPUX, and its functionality has been subsumed by event2/util.h and util-internal.h. - o Add a new bufferevent_socket_connect_hostname() to encapsulate the resolve-then-connect operation. - o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian. - o Alternative queue-based timeout algorithm for programs that use a large number of timeouts with the same value. - o New event_base_config option to disable the timeval cache entirely. - o Make EV_PERSIST timeouts more accurate: schedule the next event based on the scheduled time of the previous event, not based on the current time. - o Allow http.c to handle cases where getaddrinfo returns an IPv6 address. Patch from Ryan Phillips. - o Fix a problem with excessive memory allocation when using multiple event priorities. - o Default to using arc4random for DNS transaction IDs on systems that have it; from OpenBSD. - o Never check the environment when we're running setuid or setgid; from OpenBSD. - o Options passed to evdns_set_option() no longer need to end with a colon. - o Add an evutil_getaddrinfo() function to clone getaddrinfo on platforms that don't have it. - o Add an evdns_getaddrinfo() function to provide a nonblocking getaddrinfo using evdns, so programs can perform useful hostname lookup. - o Finally expose the IOCP-based bufferevent backend. It passes its unit tests, but probably still has some bugs remaining. Code by Nick Mathewson and Christopher Davis. - o Numerous other bugfixes. - o On FreeBSD and other OSes, connect can return ECONREFUSED immediately; instead of failing the function call, pretend with faileld in the callback. - o Fix a race condition in the pthreads test case; found by Nick Mathewson - o Remove most calls to event_err() in http and deal with memory errors instead - - - -Changes in 2.0.2-alpha (25 Jul 2009): - o Add a new flag to bufferevents to make all callbacks automatically deferred. - o Make evdns functionality locked, and automatically defer dns callbacks. - o Fix a possible free(NULL) when freeing an event_base with no signals. - o Add a flag to disable checking environment varibles when making an event_base - o Disallow setting less than 1 priority. - o Fix a bug when removing a timeout from the heap. [Patch from Marko Kreen] - o Use signal.h, not sys/signal.h. [Patch from mmadia] - o Try harder to build with certain older c99 compilers. - o Make sure that an event_config's flags field is always initialized to 0. [Bug report from Victor Goya] - o Avoid data corruption when reading data entirely into the second-to-last chain of an evbuffer. [Bug report from Victor Goya] - o Make sendfile work on FreeBSD - o Do not use vararg macros for accessing evrpc structures; this is not backwards compatible, but we did not promise any backwards compatibility for the rpc code. - o Actually define the event_config_set_flag() function. - o Try harder to compile with Visual C++. - o Move event_set() and its allies to event2/event_compat.h where they belong. - o Remove the event_gotsig code, which has long been deprecated and unused. - o Add an event_get_base() function to return the base assigned to an event. - o New function to automate connecting on a socket-based bufferevent. - o New functions to automate listening for incoming TCP connections. - o Do case-insensitive checks with a locale-independent comparison function. - o Rename the evbuffercb and everrorcb callbacks to bufferevent_data_cb and bufferevent_event_cb respectively. The old names are available in bufferevent_compat.h. - o Rename the EVBUFFER_* codes used by bufferevent event callbacks to BEV_EVENT_*, to avoid namespace collision with evbuffer flags. The old names are available in bufferevent_compat.h. - o Move the EVBUFFER_INPUT and EVBUFFER_OUTPUT macros to bufferevent_compat.h - o Add a bufferevent_getfd() function to mirror bufferevent_setfd() - o Make bufferevent_setfd() return an error code if the operation is not successful. - o Shave 22 bytes off struct event on 32-bit platforms by shrinking and re-ordering fields. The savings on 64-bit platforms is likely higher. - o Cap the maximum number of priorities at 256. - o Change the semantics of evbuffer_cb_set_flags() to be set-flag only; add a new evbuffer_cb_clear_flags() to remove set flags. - o Change the interface of evbuffer_add_reference so that the cleanup callback gets more information - o Revise the new evbuffer_reserve_space/evbuffer_commit_space() interfaces so that you can use them without causing extraneous copies or leaving gaps in the evbuffer. - o Add a new evbuffer_peek() interface to inspect data in an evbuffer without removing it. - o Fix a deadlock when suspending reads in a bufferevent due to a full buffer. (Spotted by Joachim Bauch.) - o Fix a memory error when freeing a thread-enabled event base with registered events. (Spotted by Joachim Bauch.) - o Try to contain degree of failure when running on a win32 version so heavily firewalled that we can't fake a socketpair. - o Activate fd events in a pseudorandom order with O(N) backends, so that we don't systematically favor low fds (select) or earlier-added fds (poll, win32). - o Replace some read()/write() instances with send()/recv() to work properly on win32. - o Set truncated flag correctly in evdns server replies. - o Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg - o Fix preamble of rpcgen-generated files to rely on event2 includes; based on work by jmansion; patch from Zack Weinberg. - o Allow specifying the output filename for rpcgen; based on work by jmansion; patch from Zack Weinberg. - o Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg - o Mitigate a race condition when using socket bufferevents in multiple threads. - o Use AC_SEARCH_LIBS, not AC_CHECK_LIB to avoid needless library use. - o Do not allow event_del(ev) to return while that event's callback is executing in another thread. This fixes a nasty race condition. - o event_get_supported_methods() now lists methods that have been disabled with the EVENT_NO* environment options. - o Rename encode_int[64] to evtag_encode_int[64] to avoid polluting the global namespace. The old method names are still available as macros in event2/tag_compat.h. - - - -Changes in 2.0.1-alpha (17 Apr 2009): - o free minheap on event_base_free(); from Christopher Layne - o debug cleanups in signal.c; from Christopher Layne - o provide event_base_new() that does not set the current_base global - o bufferevent_write now uses a const source argument; report from Charles Kerr - o improve documentation on event_base_loopexit; patch from Scott Lamb - o New function, event_{base_}loopbreak. Like event_loopexit, it makes an event loop stop executing and return. Unlike event_loopexit, it keeps subsequent pending events from getting executed. Patch from Scott Lamb - o Check return value of event_add in signal.c - o provide event_reinit() to reintialize an event_base after fork - o New function event_set_mem_functinons. It allows the user to give libevent replacement functions to use for memory management in place of malloc(), free(), etc. This should be generally useful for memory instrumentation, specialized allocators, and so on. - o The kqueue implementation now catches signals that are raised after event_add() is called but before the event_loop() call. This makes it match the other implementations. - o The kqueue implementation now restores original signal handlers correctly when its signal events are removed. - o Check return value of event_add in signal.c - o Add a more powerful evbuffer_readln as a replacement for evbuffer_readline. The new function handles more newline styles, and is more useful with buffers that may contain a nul characters. - o Do not mangle socket handles on 64-bit windows. - o The configure script now takes an --enable-gcc-warnings option that turns on many optional gcc warnings. (Nick has been building with these for a while, but they might be useful to other developers.) - o move EV_PERSIST handling out of the event backends - o small improvements to evhttp documentation - o always generate Date and Content-Length headers for HTTP/1.1 replies - o set the correct event base for HTTP close events - o When building with GCC, use the "format" attribute to verify type correctness of calls to printf-like functions. - o Rewrite win32.c backend to be O(n lg n) rather than O(n^2). - o Removed obsoleted recalc code - o support for 32-bit tag numbers in rpc structures; this is wire compatible, but changes the API slightly. - o pull setters/getters out of RPC structures into a base class to which we just need to store a pointer; this reduces the memory footprint of these structures. - o prefix {encode,decode}_tag functions with evtag to avoid collisions - o fix a bug with event_rpcgen for integers - o Correctly handle DNS replies with no answers set (Fixes bug 1846282) - o add -Wstrict-aliasing to warnings and more cleanup - o removed linger from http server socket; reported by Ilya Martynov - o event_rpcgen now allows creating integer arrays - o support string arrays in event_rpcgen - o change evrpc hooking to allow pausing of RPCs; this will make it possible for the hook to do some meaning ful work; this is not backwards compatible. - o allow an http request callback to take ownership of a request structure - o allow association of meta data with RPC requests for hook processing - o associate more context for hooks to query such as the connection object - o remove pending timeouts on event_base_free() - o also check EAGAIN for Solaris' event ports; from W.C.A. Wijngaards - o devpoll and evport need reinit; tested by W.C.A Wijngaards - o event_base_get_method; from Springande Ulv - o Send CRLF after each chunk in HTTP output, for compliance with RFC2626. Patch from "propanbutan". Fixes bug 1894184. - o Add a int64_t parsing function, with unit tests, so we can apply Scott Lamb's fix to allow large HTTP values. - o Use a 64-bit field to hold HTTP content-lengths. Patch from Scott Lamb. - o Allow regression code to build even without Python installed - o remove NDEBUG ifdefs from evdns.c - o detect integer types properly on platforms without stdint.h - o udpate documentation of event_loop and event_base_loop; from Tani Hosokawa. - o simplify evbuffer by removing orig_buffer - o do not insert event into list when evsel->add fails - o add support for PUT/DELETE requests; from Josh Rotenberg - o introduce evhttp_accept_socket() to accept from an already created socket - o include Content-Length in reply for HTTP/1.0 requests with keep-alive - o increase listen queue for http sockets to 128; if that is not enough the evhttp_accpet_socket() api can be used with a prepared socket. - o Patch from Tani Hosokawa: make some functions in http.c threadsafe. - o test support for PUT/DELETE requests; from Josh Rotenberg - o rewrite of the evbuffer code to reduce memory copies - o Some older Solaris versions demand that _REENTRANT be defined to get strtok_r(); do so. - o Do not free the kqop file descriptor in other processes, also allow it to be 0; from Andrei Nigmatulin - o Provide OpenSSL style support for multiple threads accessing the same event_base - o make event_rpcgen.py generate code include event-config.h; reported by Sam Banks. - o switch thread support so that locks get allocated as they are needed. - o make event methods static so that they are not exported; from Andrei Nigmatulin - o make RPC replies use application/octet-stream as mime type - o do not delete uninitialized timeout event in evdns - o Correct the documentation on buffer printf functions. - o Don't warn on unimplemented epoll_create(): this isn't a problem, just a reason to fall back to poll or select. - o Correctly handle timeouts larger than 35 minutes on Linux with epoll.c. This is probably a kernel defect, but we'll have to support old kernels anyway even if it gets fixed. - o Make name_from_addr() threadsafe in http.c - o Add new thread-safe interfaces to evdns functions. - o Make all event_tagging interfaces threadsafe. - o Rename internal memory management functions. - o New functions (event_assign, event_new, event_free) for use by apps that want to be safely threadsafe, or want to remain ignorant of the contents of struct event. - o introduce bufferevent_read_buffer; allows reading without memory copy. - o expose bufferevent_setwatermark via header files and fix high watermark on read - o fix a bug in buffrevent read water marks and add a test for them - o fix a bug in which bufferevent_write_buffer would not schedule a write event - o provide bufferevent_input and bufferevent_output without requiring knowledge of the structure - o introduce bufferevent_setcb and bufferevent_setfd to allow better manipulation of bufferevents - o convert evhttp_connection to use bufferevents. - o use libevent's internal timercmp on all platforms, to avoid bugs on old platforms where timercmp(a,b,<=) is buggy. - o Remove the never-exported, never-used evhttp_hostportfile function. - o Support input/output filters for bufferevents; somewhat similar to libio's model. This will allow us to implement SSL, compression, etc, transparently to users of bufferevents such as the http layer. - o allow connections to be removed from an rpc pool - o add new evtimer_assign, signal_assign, evtimer_new, and signal_new functions to manipulate timer and signal events, analagous to the now-recommended event_assign and event_new - o switch internal uses of event_set over to use event_assign. - o introduce evbuffer_contiguous_space() api that tells a user how much data is available in the first buffer chain - o introduce evbuffer_reserve_space() and evbuffer_commit_space() to make processing in filters more efficient. - o reduce system calls for getting current time by caching it. - o separate signal events from io events; making the code less complex. - o support for periodic timeouts - o support for virtual HTTP hosts. - o turn event_initialized() into a function, and add function equivalents to EVENT_SIGNAL and EVENT_FD so that people don't need to include event_struct.h - o Build test directory correctly with CPPFLAGS set. - o Provide an API for retrieving the supported event mechanisms. - o event_base_new_with_config() and corresponding config APIs. - o migrate the evhttp header to event2/ but accessors are still missing. - o deprecate timeout_* event functions by moving them to event_compat.h - o Move windows gettimeofday replacement into a new evutil_gettimeofday(). - o Make configure script work on IRIX. - o provide a method for canceling ongoing http requests. - o Make vsnprintf() returns consistent on win32. - o Fix connection keep-alive behavior for HTTP/1.0 - o Fix use of freed memory in event_reinit; pointed out by Peter Postma - o constify struct timeval * where possible - o make event_get_supported_methods obey environment variables - o support for edge-triggered events on epoll and kqueue backends: patch from Valery Kholodkov - o support for selecting event backends by their features, and for querying the features of a backend. - o change failing behavior of event_base_new_with_config: if a config is provided and no backend is selected, return NULL instead of aborting. - o deliver partial data to request callbacks when chunked callback is set even if there is no chunking on the http level; allows cancelation of requests from within the chunked callback; from Scott Lamb. - o allow min_heap_erase to be called on removed members; from liusifan. - o Rename INPUT and OUTPUT to EVRPC_INPUT and EVRPC_OUTPUT. Retain INPUT/OUTPUT aliases on on-win32 platforms for backwards compatibility. - o Do not use SO_REUSEADDR when connecting - o Support 64-bit integers in RPC structs - o Correct handling of trailing headers in chunked replies; from Scott Lamb. - o Support multi-line HTTP headers; based on a patch from Moshe Litvin - o Reject negative Content-Length headers; anonymous bug report - o Detect CLOCK_MONOTONIC at runtime for evdns; anonymous bug report - o Various HTTP correctness fixes from Scott Lamb - o Fix a bug where deleting signals with the kqueue backend would cause subsequent adds to fail - o Support multiple events listening on the same signal; make signals regular events that go on the same event queue; problem report by Alexander Drozdov. - o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov. - o Fix off-by-one errors in devpoll; from Ian Bell - o Make event_add not change any state if it fails; reported by Ian Bell. - o Fix a bug where headers arriving in multiple packets were not parsed; fix from Jiang Hong; test by me. - o Match the query in DNS replies to the query in the request; from Vsevolod Stakhov. - o Add new utility functions to correctly observe and log winsock errors. - o Do not remove Accept-Encoding header - o Clear the timer cache on entering the event loop; reported by Victor Chang - o Only bind the socket on connect when a local address has been provided; reported by Alejo Sanchez - o Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones. - o Clear the timer cache when leaving the event loop; reported by Robin Haberkorn - o Fix a typo in setting the global event base; reported by lance. - o Set the 0x20 bit on outgoing alphabetic characters in DNS requests randomly, and insist on a match in replies. This helps resist DNS poisoning attacks. - o Make the http connection close detection work properly with bufferevents and fix a potential memory leak associated with it. - o Restructure the event backends so that they do not need to keep track of events themselves, as a side effect multiple events can use the same fd or signal. - o Add generic implementations for parsing and emiting IPv6 addresses on platforms that do not have inet_ntop and/or inet_pton. - o Allow DNS servers that have IPv6 addresses. - o Add an evbuffer_write_atmost() function to write a limited number of bytes to an fd. - o Refactor internal notify-main-thread logic to prefer eventfd to pipe, then pipe to socketpair, and only use socketpairs as a last resort. - o Try harder to pack all evbuffer reads into as few chains as possible, using readv/WSARecv as appropriate. - o New evthread_use_windows_threads() and evthread_use_pthreads() functions to set up the evthread callbacks with reasonable defaults. - o Change the semantics of timeouts in conjunction with EV_PERSIST; timeouts in that case will now repeat until deleted. - o sendfile, mmap and memory reference support for evbuffers. - o New evutil_make_listen_socket_reuseable() to abstract SO_REUSEADDR. - o New bind-to option to allow DNS clients to bind to an arbitrary port for outgoing requests. - o evbuffers can now be "frozen" to prevent operations at one or both ends. - o Bufferevents now notice external attempts to add data to an inbuf or remove it from an outbuf, and stop them. - o Fix parsing of queries where the encoded queries contained \r, \n or + - o Do not allow internal events to starve lower-priority events. - +Changes in version 2.0.21-stable (18 Nov 2012) +BUGFIXES: + o ssl: Don't discard SSL read event when timeout and read come close together (576b29f) + o ssl: Stop looping in "consider_reading" if reading is suspended. (f719b8a Joachim Bauch) + o ssl: No need to reserve space if reading is suspended. (1acf2eb Joachim Bauch) + o dns: Avoid a memory-leak on OOM in evdns. (73e85dd, f2bff75 George Danchev) + o build: Use python2 rather than python (0eb0109 Ross Lagerwall) + o build: Compile without warnings on mingw64 (94866c2) + o build: Fix compilation on mingw64 with -DUSE_DEBUG (62bd2c4) + o build: Make rpcgen_wrapper.sh work on systems without a "python2" binary (f3009e4) + o iocp: Close IOCP listener socket on free when LEV_OPT_CLOSE_ON_FREE is set (cb853ea Juan Pablo Fernandez) + o core: Avoid crash when event_pending() called with no event_base set on event (e3cccf3) + o misc: remove stray 'x' so print_err will compile when uncommented (ac35650 Patrick Pelletier) + o tests: Fix renegotiation test to work around openssl 1.0.1 bug (c2f3086) + o tests: Warn when openssl version in unit test mismatches compiled version. (ac009f9) + + +Changes in version 2.0.20-stable (23 Aug 2012) +BUGFIXES: + o core: Make event_pending() threadsafe. (be7a95c Simon Liu) + o win32: avoid crash when waiting forever on zero fds. (160e58b) + o evhttp: Fix a memory leak on error in evhttp_uriencode (11c8b31) + o evbuffer: Avoid possible needless call to writev. Found by coverity. (6a4ec5c) + o evdns: memset sockaddr_in before using it. Found by coverity. (a1a0e67) + o evhttp: Check more setsockopt return values when binding sockets. Found by coverity (a0912e3) + o evdns: Avoid segfault on weird timeout during name lookup. (dc32077 Greg Hazel) + o bufferevent_ssl: Correctly invoke callbacks when a SSL bufferevent reads some and then blocks. (606ac43) + + +PORTABILITY FIXES: + o check for arc4random_buf at runtime, on OS X (bff5f94 Greg Hazel) + o Correctly check for arc4random_buf (fcec3e8 Sebastian Hahn) + o Add explicit AC_PROG_SED to configure.in so all autoconfs will expose $(SED) (ca80ea6) + +BUILD FIXES: + o Add GCC annotations so that the vsprintf functions get checked properly (117e327) + o Fix an unused variable warning on *BSD. (c0720c1) + +UNIT TEST FIXES: + o Fix a couple of memory leaks (found with Valgrind). (3b2529a Ross Lagerwall) + o Remove deadcode in http regression tests. Found by coverity. (5553346) + o Fix possible uninitialized read in dns regression tests. Found by coverity. (2259777) + o Set umask before calling mkstemp in unit tests. Found by coverity (f1ce15d) + o Fix various check-after-dereference issues in unit tests: found by coverity (4f3732d) + o Fix resource leaks in the unit tests; found by coverity (270f279) + o Add some missing null checks to unit tests; found by coverity (f021c3d) + o Avoid more crashes/bad calls in unit tests; found by coverity (3cde5bf) + o Remove unused variable; spotted by coverity (6355b2a) + o Add checks to various return values in unit tests. Found by coverity (b9e7329) + o Move assignment outside tt_assert in ssl unit tests. Appeases coverity. (a2006c0) + + + +Changes in version 2.0.19-stable (3 May 2012) +BUGFIXES (CORE): + o Refactor event_persist_closure: raise and extract some common logic (bec22b4) + o If time has jumped so we'd reschedule a periodic event in the past, schedule it for the future instead (dfd808c) + o If a higher-priority event becomes active, don't continue running events of the current priority. (2bfda40) + +BUGFIXES (SSL): + o Fixed potential double-readcb execution with openssl bufferevents. (4e62cd1 Mark Ellzey) + +BUGFIXES (DNS): + o Cancel a probe request when the server is freed, and ignore cancelled probe callbacks (94d2336 Greg Hazel) + o Remove redundant DNS_ERR_CANCEL check, move comment (46b8060 Greg Hazel) + o When retransmitting a timed-out DNS request, pick a fresh nameserver. (3d9e52a) + +DOCUMENTATION FIXES: + o Fix a typo in the bufferevent documentation (98e9119) + o Add missing ) to changelog; spotted by rransom (4c7ee6b) + o Fix the website URL in the readme (f775521) + +COMPILATION FIXES: + o Fix a compilation error with MSVC 2005 due to use of mode_t (336dcae) + o Configure with gcc older than 2.95 (4a6fd43 Sebastian Hahn) + o Generate event-config.h with a single sed script (30b6f88 Zack Weinberg) + +FORWARD-COMPATIBILITY: + o Backport: provide EVENT_LOG_* names, and deprecate _EVENT_LOG_* (d1a03b2) + +TESTING/DEBUGGING SUPPORT: + o dns-example.c can now take a resolv.conf file on the commandline (6610fa5) + o Make some evdns.c debug logs more verbose (d873d67) + o Work-around a stupid gcov-breaking bug in OSX 10.6 (b3887cd) + + + +Changes in version 2.0.18-stable (22 Mar 2012) +BUGFIXES (core): + o Make uses of open() close-on-exec safe by introducing an internal evutil_open_closeonexec. (d2b5f72 Ross Lagerwall, 03dce42) + +BUGFIXES (kqueue): + o Properly zero the kevent in kq_setup_kevent() (c2c7b39 Sebastian Hahn) + +BUILD FIXES: + o Added OPENSSL_LDFLAGS env variable which is appended to SSL checks. (9278196 Mark Ellzey) + o Changed OPENSSL_LDFLAGS to OPENSSL_LIBADD (2d67b63 Mark Ellzey) + o Don't do clang version detection when disabling some flags (083296b Sebastian Hahn) + +BUGFIXES (dns): + o Stop crashing in evdns when nameserver probes give a weird error (bec5068) + + +Changes in version 2.0.17-stable (10 Feb 2012) + +BUGFIXES (core): + o Be absolutely sure to clear pncalls before leaving event_signal_closure (11f36a5) + o check for sysctl before we use it (358c745 Mike Frysinger) + o Remove bogus casts of socket to int before calling ev_callback (f032516) + o Make evconnlistener work around bug in older Linux when getting nmapped (ecfc720) + o Fix a list corruption bug when using event_reinit() with signals present (6e41cdc) + o Fix a fd leak in event_reinit() (3f18ad1) + o Do a memberwise comparison of threading function tables (c94a5f2 Nate R) + o Use C-style comments in C source files (for compatibility with compilers such as xlc on AIX). (d84d917 Greg Hewgill) + o Avoid crash when freeing event_iocp and using event_set_mem_functions (19715a6) + o In the kqueue backend, do not report EBADF as an EV_READ (5d7bfa1 Nicholas Marriott) + +BUGFIXES (evbuffer and bufferevents): + o Fix behavior of evbuffer_peek(buf,-1,NULL,NULL,0) (c986f23 Zack Weinberg) + o Loop on filtering SSL reads until we are blocked or exhausted. (5b4b812) + +BUGFIXES (evhttp): + o Force strict validation of HTTP version in response. (790f6b3 Catalin Patulea) + +BUGFIXES (evdns): + o evdns: fix a bug in circular-queue implementation (d6094b1) + +BUILD FIXES: + o Fix a silly compilation error with the sun compiler (1927776 Colin Watt) + o Suppress a gcc warning from ignoring fwrite return in http-sample.c (7206e8c) + +DOCUMENTATION FIXES: + o Slightly clarify evbuffer_peek documentation (7bbf6ca) + o Update copyright notices to 2012 (e49e289) + +NEW APIS: + o Backport evhttp_connection_get_bufferevent to Libevent 2.0 (da70fa7 Arno Bakker) + +TESTS AND TEST FIXES: + o Fix a race condition in the dns/bufferevent_connect_hostname test. (cba48c7) + o Add function to check referential integrity of an event_base (27737d5) + o Check event_base correctness at end of each unit test (3312b02) + o Workaround in the unit tests for an apparent epoll bug in Linux 3.2 (dab9187) + o Better workaround for Linux 3.2 edge-triggered epoll bug (9f9e259) + +Changes in version 2.0.16-stable (18 Nov 2011) +BUGFIXES (core): + o More detailed message in case of libevent self-debugging failure. (9e6a4ef Leonid Evdokimov) + o epoll: close fd on alloc fail at initialization (1aee718 Jamie Iles) + o Fix compile warning from saying event2/*.h inside a comment (447b0ba) + o Warn when unable to construct base because of failing make_base_notifiable (4e797f3) + o Don't try to make notifiable event_base when no threading fns are configured (e787413) + +BUGFIXES (evbuffer): + o unit test for remove_buffer bug (90bd620 Greg Hazel) + o Fix an evbuffer crash in evbuffer_remove_buffer() (c37069c) + +BUGFIXES (bufferevent_openssl): + o Refactor amount-to-read calculations in buffervent_ssl consider_reading() (a186e73 Mark Ellzey) + o Move SSL rate-limit enforcement into bytes_to_read() (96c562f) + o Avoid spinning on OpenSSL reads (2aa036f Mark Ellzey) + +BUGFIXES (dns) + o Empty DNS reply with OK status is another way to say NODATA. (21a08d6 Leonid Evdokimov) + +TESTING: + o Tests for 94fba5b and f72e8f6 (d58c15e Leonid Evdokimov) + o Test for commit aff6ba1 (f7841bf Leonid Evdokimov) + o Style and comment tweaks for dns/leak* tests (5e42202) + o improve test to remove at least one buffer from src (7eb52eb Greg Hazel) + +DOCUMENTATION: + o Add note about evhttp_send_reply_end to its doxygen (724bfb5) + o Update copyright dates to 2011. (3c824bd) + o Fix typo in whatsnew-2.0.txt (674bc6a Mansour Moufid) + o Improve win32 behavior of dns-sample.c code (a3f320e Gisle Vanem) + + + +Changes in version 2.0.15-stable (12 Oct 2011) +BUGFIXES (DNS): + o DNS: add ttl for negative answers using RFC 2308 idea. (f72e8f6 Leonid Evdokimov) + o Add DNS_ERR_NODATA error code to handle empty replies. (94fba5b Leonid Evdokimov) + +BUFGIXES (bufferevents and evbuffers): + o Make evbuffer callbacks get the right n_added value after evbuffer_add (1ef1f68 Alex) + o Prefer mmap to sendfile unless a DRAINS_TO_FD flag is set. Allows add_file to work with SSL. (0ba0af9) + +BUGFIXES (event loop): + o When a signal callback is activated to run multiple times, allow event_base_loopbreak to work even before they all have run. (4e8eb6a) + +DOCUMENTATION FIXES: + o Fix docstring in dns.h (2b6eae5 Leonid Evdokimov) + o refer to non-deprecated evdns functions in comments (ba5c27d Greg Hazel) + +BUILD AND TESTING FIXES: + o le-proxy and regress depend on openssl directly (9ae061a Sergey Avseyev) + o Use _SOURCES, not _sources, in sample/Makefile.am (7f82382) + o Fixed compiler warnings for unchecked read/write calls. (c3b62fd Mark Ellzey) + o Make write-checking fixes use tt_fail_perror (2b76847) + o Fix some "value never used" warnings with gcc 4.6.1 (39c0cf7) + + + +Changes in version 2.0.14-stable (31 Aug 2011) +BUGFIXES (bufferevents and evbuffers): + o Propagate errors on the underlying bufferevent to the user. (4a34394 Joachim Bauch) + o Ignore OpenSSL deprecation warnings on OS X (5d1b255 Sebastian Hahn) + o Fix handling of group rate limits under 64 bytes of burst (6d5440e) + o Solaris sendfile: correctly detect amount of data sent (643922e Michael Herf) + o Make rate limiting work with common_timeout logic (5b18f13) + o clear read watermark on underlying bufferevent when creating filtering bev to fix potentially failing fragmented ssl handshakes (54f7e61 Joachim Bauch) + +BUGFIXES (IOCP): + o IOCP: don't launch reads or writes on an unconnected socket (495c227) + o Make IOCP rate-limiting group support stricter and less surprising. (a98da7b) + o Have test-ratelim.c support IOCP (0ff2c5a) + o Make overlapped reads result in evbuffer callbacks getting invoked (6acfbdd) + o Correctly terminate IO on an async bufferevent on bufferevent_free (e6af35d) + +BUGFIXES (other): + o Fix evsig_dealloc memory leak with debugging turned on. (9b724b2 Leonid Evdokimov) + o Fix request_finished memory leak with debugging turned on. (aff6ba1 Leonid Evdokimov) + +BUILD AND TESTING FIXES: + o Allow OS-neutral builds for platforms where some versions have arc4random_buf (b442302 Mitchell Livingston) + o Try to fix 'make distcheck' errors when building out-of-tree (04656ea Dave Hart) + o Clean up some problems identified by Coverity. (7c11e51 Harlan Stenn) + + +Changes in version 2.0.13-stable (18 Jul 2011) +BUGFIXES + o Avoid race-condition when initializing global locks (b683cae) + o Fix bug in SSL bufferevents backed by a bev with a write high-watermarks (e050703 Joachim Bauch) + o Speed up invoke_callbacks on evbuffers when there are no callbacks (f87f568 Mark Ellzey) + o Avoid a segfault when all methods are disabled or broken (27ce38b) + o Fix incorrect results from evbuffer_search_eol(EOL_LF) (4461f1a) + o Add some missing checks for mm_calloc failures (89d5e09) + o Replace an assertion for event_base_free(NULL) with a check-and-warn (09fe97d) + o Report kqueue ebadf, epipe, and eperm as EV_READ events (1fd34ab) + o Check if the `evhttp_new_object' function in `http.c' returns NULL. (446cc7a Mansour Moufid) + o Use the correct printf args when formatting size_t (3203f88) + o Complain if the caller tries to change threading cbs after setting them (cb6ecee) + +DOCUMENTATION FIXES AND IMPROVEMENTS + o Revise the event/evbuffer/bufferevent doxygen for clarity and accuracy (2888fac) + o Update Doxyfile to produce more useful output (aea0555) + +TEST FIXES + o Fix up test_evutil_snprintf (caf695a) + o Fix tinytest invocation from windows shell (57def34 Ed Day) + +BUILD FIXES + o Use AM_CPPFLAGS in sample/Makefile.am, not AM_CFLAGS (4a5c82d) + o Fix select.c compilation on systems with no NFDBITS (49d1136) + o Fix a few warnings on OpenBSD (8ee9f9c Nicholas Marriott) + o Don't break when building tests from git without python installed (b031adf) + o Don't install event_rpcgen.py when --disable-libevent-install is used (e23cda3 Harlan Stenn) + o Fix AIX build issue with TAILQ_FOREACH definition (e934096) + + +Changes in version 2.0.12-stable (4 Jun 2011) +BUGFIXES + o Fix a warn-and-fail bug in kqueue by providing kevent() room to report errors (28317a0) + o Fix an assert-inducing fencepost bug in the select backend (d90149d) + o Fix failing http assertion introducd in commit 0d6622e (0848814 Kevin Ko) + o Fix a bug that prevented us from configuring IPv6 nameservers. (74760f1) + o Prevent size_t overflow in evhttp_htmlescape. (06c51cd Mansour Moufid) + o Added several checks for under/overflow conditions in evhttp_handle_chunked_read (a279272 Mark Ellzey) + o Added overflow checks in evhttp_read_body and evhttp_get_body (84560fc Mark Ellzey) + +DOCUMENTATION: + o Add missing words to EVLOOP_NONBLOCK documentation (9556a7d) + +BUILD FIXES + o libssl depends on libcrypto, not the other way around. (274dd03 Peter Rosin) + o Libtool brings in the dependencies of libevent_openssl.la automatically (7b819f2 Peter Rosin) + o Use OPENSSL_LIBS in Makefile.am (292092e Sebastian Hahn) + o Move the win32 detection in configure.in (ceb03b9 Sebastian Hahn) + o Correctly detect openssl on windows (6619385 Sebastian Hahn) + o Fix a compile warning with zlib 1.2.4 and 1.2.5 (5786b91 Sebastian Hahn) + o Fix compilation with GCC 2, which had no __builtin_expect (09d39a1 Dave Hart) + o Fix new warnings from GCC 4.6 (06a714f) + o Link with -lshell32 and -ladvapi32 on Win32. (86090ee Peter Rosin) + o Make the tests build when OpenSSL is not available. (07c41be Peter Rosin) + o Bring in the compile script from automake, if needed. (f3c7a4c Peter Rosin) + o MSVC does not provide S_ISDIR, so provide it manually. (70be7d1 Peter Rosin) + o unistd.h and sys/time.h might not exist. (fe93022 Peter Rosin) + o Make sure TINYTEST_LOCAL is defined when building tinytest.c (8fa030c Peter Rosin) + o Fix winsock2.h #include issues with MSVC (3d768dc Peter Rosin) + o Use evutil_gettimeofday instead of relying on the system gettimeofday. (0de87fe Peter Rosin) + o Always use evutil_snprintf, even if OS provides it (d1b2d11 Sebastian Hahn) + o InitializeCriticalSectionAndSpinCount requires _WIN32_WINNT >= 0x0403. (816115a Peter Rosin) + o cygwin: make it possible to build DLLs (d54d3fc) + + + +Changes in version 2.0.11-stable (27 Apr 2011) + [Autogenerated from the Git log, sorted and cleaned by hand.] +BUGFIXES: + o Fix evport handling of POLLHUP and POLLERR (b42ce4b) + o Fix compilation on Windows with NDEBUG (cb8059d) + o Check for POLLERR, POLLHUP and POLLNVAL for Solaris event ports (0144886 Trond Norbye) + o Detect and handle more allocation failures. (666b096 Jardel Weyrich) + o Use event_err() only if the failure is truly unrecoverable. (3f8d22a Jardel Weyrich) + o Handle resize failures in the select backend better. (83e805a) + o Correctly free selectop fields when select_resize fails in select_init (0c0ec0b) + o Make --enable-gcc-warnings a no-op if not using gcc (3267703) + o Fix a type error in our (unused) arc4random_stir() (f736198) + o Correctly detect and stop non-chunked http requests when the body is too long (63a715e) + o Have event_base_gettimeofday_cached() always return wall-clock time (a459ef7) + o Workaround for http crash bug 3078187 (5dc5662 Tomash Brechko) + o Fix incorrect assertions and possible use-after-free in evrpc_free() (4b8f02f Christophe Fillot) + o Reset outgoing http connection when read data in idle state. (272823f Tomash Brechko) + o Fix subtle recursion in evhttp_connection_cb_cleanup(). (218cf19 Tomash Brechko) + o Fix the case when failed evhttp_make_request() leaved request in the queue. (0d6622e Tomash Brechko) + o Fix a crash bug in evdns server circular list code (00e91b3) + o Handle calloc failure in evdns. (Found by Dave Hart) (364291e) + o Fix a memory leak on win32 socket->event map. (b4f89f0) + o Add a forgotten NULL check to evhttp_parse_headers (12311ff Sebastian Hahn) + o Fix possible NULL-deref in evdns_cancel_request (5208544 Sebastian Hahn) + +PORTABILITY: + o Fall back to sscanf if we have no other way to implement strtoll (453317b) + o Build correctly on platforms without sockaddr_storage (9184563) + o Try to build correctly on platforms with no IPv6 support (713c254) + o Build on systems without AI_PASSIVE (cb92113) + o Fix http unit test on non-windows platforms without getaddrinfo (6092f12) + o Do not check for gethostbyname_r versions if we have getaddrinfo (c1260b0) + o Include arpa/inet.h as needed on HPUX (10c834c Harlan Stenn) + o Include util-internal.h as needed to build on platforms with no sockaddr_storage (bbf5515 Harlan Stenn) + o Check for getservbyname even if not on win32. (af08a94 Harlan Stenn) + o Add -D_OSF_SOURCE to fix hpux builds (0b33479 Harlan Stenn) + o Check for allocation failures in apply_socktype_protocol_hack (637d17a) + o Fix the check for multicast or broadcast addresses in evutil_check_interfaces (1a21d7b) + o Avoid a free(NULL) if out-of-memory in evdns_getaddrinfo. Found by Dave Hart (3417f68) + +DEFENSIVE PROGRAMMING: + o Add compile-time check for AF_UNSPEC==PF_UNSPEC (3c8f4e7) + +BUGS IN TESTS: + o Fix test.sh output on solaris (b4f89b6 Dave Hart) + o Make test-eof fail with a timeout if we never get an eof. (05a2c22 Harlan Stenn) + o Use %s with printf in test.sh (039b9bd) + o Add an assert to appease clang's static analyzer (b0ff7eb Sebastian Hahn) + o Add a forgotten return value check in the unit tests (3819b62 Sebastian Hahn) + o Actually send NULL request in http_bad_request_test (b693c32 Sebastian Hahn) + o add some (void) casts for unused variables (65707d7 Sebastian Hahn) + o Refactor test_getaddrinfo_async_cancel_stress() (48c44a6 Sebastian Hahn) + o Be nice and "handle" error return values in sample code (4bac793 Sebastian Hahn) + o Check return value of evbuffer_add_cb in tests (93a1abb Sebastian Hahn) + o Remote some dead code from dns-example.c (744c745 Sebastian Hahn) + o Zero a struct sockaddr_in before using it (646f9fe Sebastian Hahn) + +BUILD FIXES: + o Fix warnings about AC_LANG_PROGRAM usage (f663112 Sebastian Hahn) + o Skip check for zlib if we have no zlib.h (a317c06 Harlan Stenn) + o Fix autoconf bracket issues; make check for getaddrinfo include netdb.h (833e5e9 Harlan Stenn) + o Correct an AM_CFLAGS to an AM_CPPFLAGS in test/Makefile.am (9c469db Dave Hart) + o Fix make distcheck & installation of libevent 1 headers (b5a1f9f Dave Hart) + o Fix compilation under LLVM/clang with --enable-gcc-warnings (ad9ff58 Sebastian Hahn) + +FEATURES: + o Make URI parser able to tolerate nonconformant URIs. (95060b5) + +DOCUMENTATION: + o Clarify event_set_mem_functions doc (926f816) + o Correct evhttp_del_accept_socket documentation on whether socket is closed (f665924) + o fix spelling mistake in whatsnew-2.0.txt (deb2f73) + o Fix sample/http-server ipv6 fixes (eb692be) + o Comment internal headers used in sample code. (4eb281c) + o Be explicit about how long event loops run in event.h documentation (f95bafb) + o Add comment to configure.in to explain gc-sections test logic (c621359) + o Fix a couple of memory leaks in samples/http-server.c. Found by Dave Hart. (2e9f665) + +BUILD IMPROVEMENTS: + o Use the gcc -ffunction-segments feature to allow gc when linking with static libevent (0965c56 Dave Hart) + o Add configure options to disable installation, regression tests (49e9bb7 Dave Hart) + + + +Changes in version 2.0.10-stable (16 Dec 2010) + [Autogenerated from the Git log, sorted and cleaned by hand.] +BUGFIXES + o Minor fix for IOCP shutdown handling fix (2599b2d Kelly Brock) + o Correctly notify the main thread when activating an event from a subthread (5beeec9) + o Reject overlong http requests early when Expect:100-continue is set (d23839f Constantine Verutin) + o EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings with -DNDEBUG. (b63ab17 Evan Jones) + +CODE CLEANUPS + o bufferevent-internal.h: Use the new event2/util.h header, not evutil.h (ef5e65a Evan Jones) + o Use relative includes instead of system includes consistently. (fbe64f2 Evan Jones) + o Make whitespace more consistent + +TESTING + o tests: Use new event2 headers instead of old compatibility headers. (4f33209 Evan Jones) + +DOCUMENTATION + o Document that the cpu_hint is only used on Windows with IOCP for now (57689c4) + o Add stuff to "whats new in 2.0" based on reading include changes since August. (18adc3f) + + +Changes in 2.0.9-rc (30 Nov 2010): + [Autogenerated from the Git log, sorted and cleaned by hand.] +NEW AND MODIFIED APIs + o Add a function to change a listener's callback. (46ee061) + o Make evbuffer_add_file take ev_off_t, not off_t (ac7e52d) + o Make rate-limits go up to SIZE_MAX/EV_SSIZE_MAX, not just INT32_MAX (2cbb1a1) + o Add a bufferevent_get_base function (aab49b6) + +MAJOR BUGFIXES + o Disable changelist for epoll by default because of Linux dup() bug; add an option and/or an envvar to reenable it for speed. (9531763) + o Fix a 100%-CPU bug where an SSL connection would sometimes never stop trying to write (1213d3d) + o Fix a nasty bug related to use of dup() with epoll on Linux (c281aba) + o Fix bugs in posix thread-id calculation when sizeof(pthread_t) != sizeof(long) (fbaf077) + o Fix some ints to evutil_socket_t; make tests pass on win64. (f817bfa Dimitre Piskyulev) + o Set _EVENT_SIZEOF_VOID_P correctly on win32 and win64 (1ae82cd Dimitre Piskyulev) + o Avoid double-invocation of user callback with EVUTIL_EAI_CANCEL (abf01ed) + o Set SO_UPDATE_ACCEPT_CONTEXT on sockets from AcceptEx so that shutdown() can work (52aa419) + o When closing a filtering bufferevent, clear callbacks on the underlying bufferevent (fc7b1b0) + +NEW AND MODIFIED HTTP APIs + o Add evhttp_parse_query_str to be used with evhttp_uri_parse. (2075fbc) + o Add evhttp_response_code to remove one more reason to include http_struct.h (22e0a9b) + o Define enumerators for all HTTP methods, including PATCH from RFC5789 (75a7341 Felix Nawothnig) + o Functions to actually use evhttp_bound_socket with/as evconnlistener. (006efa7) + o Add evhttp_request_get_command so code can tell GET from POST without peeking at the struct. (49f4bf7) + o Introduce absolute URI parsing helpers. (86dd720 Pavel Plesov) + o Revise evhttp_uri_parse implementation to handle more of RFC3986 (eaa5f1d) + o Add evhttp_connection_get_base() to get the event_base from an http connection (cd00079) + o Let evhttp_parse_query return -1 on failure (b1756d0) + o New evhttp_uri(encode|decode) functions to handle + and NUL characters right (a8148ce) + o Add evhttp_response_code to remove one more reason to include http_struct.h (22e0a9b) + o Tweak interface for allowed methods (f5b391e) + o Add evhttp server alias interface, correct flagging of proxy requests. (aab8c38 Christopher Davis) + +HTTP BUGFIXES + o Add some comments to http.c and make a few functions static. (90b3ed5) + o Fix Content-Length when trying send more than 100GB of data (!) on an evhttp. (525da3e) + o Fix a bug where we would read too much data in HTTP bodies or requests. (58a1cc6) + o Correctly count req->body_size on http usage without Content-Length (8e342e5) + o Avoid missed-request bug when entire http request arrives before data is flushed (74c0e86) + o reset "chunked" flag when sending non-chunked reply (aa5f55f Joachim Bauch) + o evhttp_encode_uri encodes all reserved characters, including !$'()*+,/:=@ (2e63a60) + o Replace exact-version checks for HTTP/1.1 with >= or < checks (647e094) + o evhttp: Return 501 when we get an unrecognized method, not 400. (536311a) + o Don't disable reading from the HTTP connection after sending the request to be notified of connection-close in time (c76640b Felix Nawothnig) + o Never call evhttp_readcb while writing. (0512487) + o Try to fix an assertion failure related to close detection (0faaa39) + o Correctly detect timeouts during http connects (04861d5) + o Preliminary support for Continue expectation in evhttp. (fa9305f Christopher Davis) + +OTHER BUGFIXES + o Correct logic for realigning a chain in evbuffer_add (e4f34e8) + o Fix a minor syntax error that most compilers didn't care about (e56ff65) + o Fix some uses of int for socket in regress (5d389dc) + o Check return value for ioctlsocket on win32 (f5ad31c Trond Norbye) + o Fix som event_warns that should have been event_warnx (19c71e7) + o Fix signal handler types for win64. (b81217f) + o Try to clear up more size_t vs int/long issues. (598d133) + o Make sure IOCP evconnlistener uses virtual events. (7b40a00 Christopher Davis) + o Don't free evdns_request handles until after the callback is invoked (9ed30de) + o Fix some more cancel-related bugs in getaddrinfo_async (c7cfbcf) + o Make evdns_getaddrinfo_cancel threadsafe (d51b2fc) + o Only clear underlying callbacks when the user hasn't reset them. (1ac5b23) + o Fix bug in bufferevent_connect on an openssl bufferevent that already had an fd (4f228a1) + o Resolve an evport bug in the thread/forking test (3a67d0b) + o Make sure the CLOEXEC flag is set on fds we open for base notification (3ab578f) + o Fix IRIX build. sa_family collides with a #define in sys/socket.h on IRIX. (e874982 Kevin Bowling) + o If not WIN32, include <sys/socket.h> in event2/util.h. (1cd45e5 Kevin Bowling) + o Fix some C99-style comments to work with the xlC compiler. (c2e5e22 Kevin Bowling) + o Add some checks since lack of TAILQ_FOREACH doesn't imply lack of FIRST, END, NEXT, or INSERT_BEFORE. Quiet some warnings in XL C. (c4dc335 Kevin Bowling) + o Reworked AIX __ss_family workaround to use AC_STRUCT_MEMBER. (2e2a3d7 Kevin Bowling) + o Take select from <sys/select.h> when testing in autoconf. AIX build fix. (a3a9f6b Kevin Bowling) + o Fix snprintf related failures on IRIX. (3239073 Kevin Bowling) + o Remove _event_initialized(); make event_initialized() a function(); make it consistent on windows and non-windows (652024b) + o Do not let EVLOOP_ONCE exit the loop until all deferred callbacks have run (2d5e1bd) + o Make EVLOOP_ONCE ignore internal events (0617a81) + o Possible crash fix when freeing an underlying bufferevent of an openssl bufferevent (29f7623) + +HTTP CLEANUPS + o Stop using Libevent-1 headers in regress_http (1f507d7) + o Modernize header usage in bench_http.c (e587069) + o fix signed/unsigned warnings in http.c (74a91e5) + o Update the HTTP regression tests to use Libevent2 apis for non-http stuff (d9ffa89) + o Start porting http tests to not use legacy interfaces (8505a74) + o Convert the rest of the http tests to be non-legacy unit tests. (9bb8239) + o Rename the confusing "base" static variable in regress_http.c (353402a) + o Stop accessing http request struct directly from in the unit tests. (0b137f4) + o Refactor http version parsing into a single function (a38140b) + +TESTING + o Improvements to tinytest_macros.h (ad923a1) + o Add a huge pile of tests for the new URI functions, and make them pass. (a5a76e6) + o Unit tests for evhttp_uri_set* (bc98f5e) + o Increase the skew tolerance to 2 seconds in thread/deferred_cb_skew (f806476 Christopher Davis) + o Reorder backends in test.sh to match preference order in event.c (ece974f) + o Add a stress test for getaddrinfo_cancel (da1bf52) + o Units test for unexpected evhttp methods. (75e3320) + +DOCUMENTATION + o Document behavior of URI parsing more thoroughly. (3a33462) + o Document that two bufferevent functions only work on socket bufferevents (70e1b60) + o add a requested docstring for event_rpcgen.CommandLine.__init__ (f1250eb) + o Fix a mistake in http documentation found by Julien Blache (229714d) + o Add a basic example of how to write a static HTTP server. (4e794d5) + o Document event_get_assignment (88be27d) + o Note that reentrant calls to libevent from logging cbs may fail badly (e431bcd) + o Clarify EVLOOP_* documentation to be more precise. (057a514) + +CLEANUPS + o Simplify the logic for choosing EPOLL_CTL_ADD vs EPOLL_CTL_MOD (2c66983) + o Rename "size" variables in win32select that were really fd counts. (b6a158c) + o Fix even more win64 warnings (7484df6) + o Fix even more win64 warnings: buffer, event_tagging, http, evdns, evrpc (545a611) + o Fix more wn64 warnings. (34b84b9 Christopher Davis) + o Use the label_len local variable in evdns instead of recalculating it over and over (ba01456) + o Fix some irix compilation warnings spotted by Kevin Bowling (7bcace2) + + + +Changes in 2.0.8-rc (14 Oct 2010): + [Autogenerated from the Git log, sorted and cleaned by hand.] +NEW APIS + o Add error callback to evconnlistener (c4be8d8 Simon Perreault) + o Add a LEV_OPT_THREADSAFE option for threadsafe evconnlisteners (127d4f2) + +CHANGED BEHAVIOR + o Correct logic on disabling underlying bufferevents when disabling a filter (ac27eb8) + +BUGFIXES + o Obey enabled status when unsuspending (040a019 Simon Perreault) + o Warn when using the error-prone EV_SIGNAL interface in an error-prone way. Also, fix a couple of race conditions in signal.c (720bd93) + O Make default signal backend fully threadsafe (95a7d41) + o Put internal events at highest priority (90651b3) + o Fix warnings in the main codebase flagged by -Wsigned-compare (9c8db0, 5e4bafb, 5c214a, 6be589a, e06f514) + o Fix compile in kqueue.c (b395392 Sebastian Hahn) + o Do not search outside of the system directory for windows DLLs (d49b5e3) + o Fix a spurious-call bug on epoll.c (0faaee0) + o Send a shutdown(SHUT_WR) before closing an http connection (e0fd870 Christopher Davis) + o Fix warnings on mingw with gcc 4.5 (5b7a370) + o Fix an EINVAL on evbuffer_write_iovec on OpenSolaris. (fdc640b) + o Fix allocation error for IOCP listeners. Probably harmless, since struct event is big (481ef92) + o Make iocp/listener/error work; don't accept again if lev is disabled. (62b429a Christopher Davis) + o Handle rate-limiting for reading on OpenSSL bufferevents correctly. (819b171) + o Fix serious bugs in per-bufferevent rate-limiting code (34d64f8) + o Avoid spurious reads from just-created open openssl bufferevents (223ee40) + o Fix a case where an ssl bufferevent with CLOSE_ON_FREE didn't close its fd (93bb7d8) + o The corrected bufferevent filter semantics let us fix our openssl tests (34331e4) + +TESTING + o Make SSL tests cover enabling/disabling EV_READ. (a5ce9ad) + o Bump to the latest version of tinytest (f0bd83e) + o Unit tests for listener error callbacks (045eef4) + o New unit test for ssl bufferevents starting with connected SSLs. (02f6259) + +DEBUGGABILITY + o Make debugging output for epoll backend more comprehensive (ec2b05e) + o Make event.c debugging messages report fds (e119899) + o Make the --enable-gcc-warnings option include signed comparison warnings (d3b096c) + +DEADCODE REMOVAL + o Remove the now-useless evsig_caught and evsig_process (4858b79) + o Remove event_base.evsigbase; nothing used it. (38d0960) + + + +Changes in 2.0.7-rc (9 Sep 2010): + [Autogenerated from the Git log, sorted and cleaned by hand.] +NEW APIS + o Expose a evdns_base_nameserver_sockaddr_add() function to add a nameserver by sockaddr (1952143) + o Add event_config_set_num_cpus_hint() for tuning win32 IOCP thread pools, etc. (2447fe8 Christopher Davis) + +BUGFIXES + o Fix a nasty dangling-event bug when using rate-limiting groups (0bffe43) + o Clean up syntax on TAILQ_ENTRY() usage to build correctly with recent MSVC (60433a0 Gilad Benjamini) + o Make definition of WIN32_LEAN_AND_MEAN in event.h conditional (3920172 Gilad Benjamini) + o Correctly detect failure to delete bufferevent read-timeout event (da6e7cd) + o Set close-on-exec bit for filedescriptors created by dns subsystem (d0b8843) + o Fix kqueue correctness test on x84_64 (6123d12) + o Detect events with no ev_base; warn instead of crashing (f1074b7) + o Fix an issue with forking and signal socketpairs in select/poll backends (d61b2f3) + o Stop using global arrays to implement the EVUTIL_ctype functions (1fdec20) + o On windows, make lock/thread function tables static (5de2bcb) + o Close th_notify_fds and open a new pair on reinit (495ed66) + o Declare signal handler function as "__cdecl" on Windows (f0056d0) + o Use the _func() replacements for open, fstat, etc in evutil.c on win32 (e50c0fc) + o Only process up to MAX_DEFERRED deferred_cbs at a time (17a14f1 Christopher Davis) + +THREADING BUGFIXES + o Avoid deadlock when activating signals (970e6ad) + o Add a condition variable backend, with implementations for pthreads and win32 (d4977b5) + o Use conditions instead of current_event_lock to fix a deadlock (e0972c2) + o Fix logic error in win32 TRY_LOCK that caused problems with rate-limiting (4c32b9d) + o Avoid needlessly calling evthread_notify_base() when the loop is not running (c7a06bf) + o Minimize calls to base_notify implementation functions, thereby avoiding needless syscalls (4632b78) + +IOCP BUGFIXES + o IOCP-related evbuffer fixes (03afa20 Christopher Davis) + o Stop IOCP when freeing the event_base (d844242 Christopher Davis) + o Some IOCP bufferevent tweaks (76f7e7a Christopher Davis) + +TESTS + o Make the regress_pthread.c tests work on windows with current test APIs (d74ae38) + o Add a unit test for conditions (5fb1095) + o Allow more than one copy of regression tests to run at once (a97320a) + o Fix event_del(0) instance in bench.c (b0f284c Shuo Chen) + o Fix a few memory leaks in the tests (1115366) + o IOCP-related unit test tweaks (499452f Christopher Davis) + o Improve testing of when thread-notification occurs (ce85280) + +BUILD AND DISTRIBUTION + o Add pkgconfig files for libevent_{openssl,pthreads} (ebcb1f0) + o Change include order in Makefile.nmake (4022b28) + o Make include/event2/event-config.h not included in source dist (a4af9be) + o Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off in unit test code (743f866) + o Declare evkeyvalq and event_list even if event_struct.h comes before sys/queue.h (d3ceca8) + o Move evkeyvalq into a separate header for evhttp_parse_query users (ca9048f) + o Prefer autoreconf -ivf to manual autogen.sh (7ea8e89) + +CLEANUP + o Completely remove the (mostly-removed) obsolete thread functions (3808168) + o Rename regress_pthread.c to regress_thread.c (041989f) + o Make defer-internal.h use lock macros, not direct calls to lock fns (5218d2a) + +DOCUMENTATION + o Document that DNS_NO_SEARCH is an obsolete alias for DNS_QUERY_NO_SEARCH (33200e7) + o Update the whatsnew-2.0.txt document (4991669) + + + +Changes in 2.0.6-rc (6 Aug 2010): + [Autogenerated from the Git log, sorted by hand.] +DOCUMENTATION + o Document a change in the semantics of event_get_struct_event_size() (e21f5d1) + o Add a comment to describe our plan for library versioning (9659ece) + o Fix sentence fragment in docs for event_get_struct_event_size() (7b259b6) + +NEW FEATURES AND INTERFACE CHANGES + o Remove the obsolete evthread interfaces (c5bab56) + o Let evhttp_send_error infer the right error reasons (3990669) + o Add a function to retrieve the other side of a bufferevent pair (17a8e2d) + o Add bufferevent_lock()/bufferevent_unlock() (215e629) + o Stop asserting when asked for a (unsupported) TCP dns port. Just return NULL. (7e87a59) + o Replace (unused,always 0) is_tcp argument to evdns_add_server_port*() with flags (e1c1167) + o Constify a couple of arguments to evdns_server_request_add_*_reply (cc2379d) + o Add an interface to expose min_share in ratelimiting groups (6ae53d6) + +BUGFIXES + o Avoid event_del on uninitialized event in event_base_free (6d19510) + o Add some missing includes to fix Linux build again (75701e8) + o Avoid close of uninitialized socket in evbuffer unit test (bda21e7) + o Correctly recognize .255 addresses as link-local when looking for interfaces (8c3452b) + o If no evdns request can be launched, return NULL, not a handle (b14f151) + o Use generic win32 interfaces, not ASCII-only ones, where possible. (899b0a3) + o Fix the default HTTP error template (06bd056 Felix Nawothnig) + o Close the file in evutil_read_file whether there's an error or not. (0798dd1 Pierre Phaneuf) + o Fix possible nullptr dereference in evhttp_send_reply_end() (29b2e23 Felix Nawothnig) + o never let bufferevent_rlim functions return negative (0859870) + o Make sample/hello_world work on windows (d89fdba) + o Fix a deadlock related to event-base notification. Diagnosed by Zhou Li, Avi Bab, and Scott Lamb. (17522d2) + o Possible fix to 100% cpu usage with epoll and openssl (cf249e7 Mike Smellie) + o Don't race when calling event_active/event_add on a running signal event (fc5e0a2) + o Suppress a spurious EPERM warning in epoll.c (e73cbde) + o Fix wrong size calculation of iovec buffers when exact=1 (65abdc2 niks) + o Change bufferevent_openssl::do_write so it doesn't call SSL_write with a 0 length buffer (c991317 Mike Smellie) + o Fixed compilation of sample/le-proxy.c on win32 (13b912e Trond Norbye) + o Fix rate-limit calculation on openssl bufferevents. (009f300) + o Remember to initialize timeout events for bufferevent_async (de1f5d6 Christopher Davis) + +BUILD AND DISTRIBUTION CHANGES + o Test the unlocked-deferred callback case of bufferevents (dfb75ab) + o Remove the now-unusable EVTHREAD_LOCK/UNLOCK constants (fdfc3fc) + o Use -Wlogical-op on gcc 4.5 or higher (d14bb92) + o Add the libtool-generated /m4/* stuff to .gitignore (c21c663) + o Remove some automake-generated files from version control. (9b14911) + o Have autogen.sh pass --force-missing to automake (8a44062) + o Set library version for libevent_pthreads correctly (b2d7440) + o Really only add libevent_core.la to LIBADD on mingw (1425003 Sebastian Hahn) + o Build more cleanly with NetBSDs that dislike toupper(char) (42a8c71) + o Fix unit tests with -DUSE_DEBUG enabled (28f31a4) + o Fix evdns build with -DUNICODE (5fa30d2) + o Move event-config.h to include/event2 (ec347b9) + +TESTING + o Add options to test-ratelim.c to check its results (2b44dcc) + o Make test-ratelim clean up after itself better. (b5bfc44) + o Remove the now-obsolete setup_test() and cleanup_test() functions (e73f1d7) + o Remove all non-error prints from test/regress.c (8bc1e3d) + o Make test.sh exit with nonzero status if tests fail (faf2a04) + o Have the unit tests report errors from test.sh (3689bd2) + o Fix logic in correcting high values from FIONREAD (3467f2f) + o Add test for behavior on remote socket close (44d57ee) + o Unit test for event_get_struct_event_size() (7510aac) + o Make test/test.sh call test-changelist (7c92691) + o Fix badly-behaved subtest of dns/bufferevent_connect_hostname (840a72f Joachim Bauch) + o Add option to test-ratelim to test min_share (42f6b62) + o Fix an assertion bug in test-ratelim (b2c6202) + o Make tests quieter on local dns resolver failure (e996b3d) + o Increase the tolerance in our unit tests for sloppy clocks. (170ffd2) + o Use AF_INET socketpair to test sendfile on Solaris (9b60209) + o Make test-changelist count cpu usage right on win32 (ea1ea3d) + +INTERNALS, PERFORMANCE, AND CODE CLEANUPS + o Mark the event_err() functions as __attribute__((noreturn)) (33bbbed) + o Do not check that event_base is set in EVBASE_ACQUIRE_LOCK (218a3c3) + o Replace (safe) use of strcpy with memcpy to appease OpenBSD (caca2f4) + o Remove some dead assignments (47c5dfb) + o Fix a pedantic gcc 4.4 warning in event2/event.h (276e7ee) + o Drain th_notify_fd[0] more bytes at a time. (a5bc15b) + o Tidy up the code in evthread_make_base_notifiable a little (61e1eee) + o Pass flags to fcntl(F_SETFL) and fcntl(F_SETFD) as int, not long (7c2dea1) + o Remove unused variables in test/test-changelist.c (b00d4c0) + o Fix whitespace. (cb927a5) + o Improve error message for failed epoll to make debugging easier. (9e725f7) + o Turn our socketpair() replacement into its own function (57b30cd) + + + +Changes in 2.0.5-beta (10 May 2010): + [Autogenerated from the Git log, sorted by hand.] +DOCUMENTATION + o Update all our copyright notices to say "2010" (17efc1c) + o Add Christopher Clark and Maxim Yegorushkin to the LICENSE file (38b7b57) + o Clarify Christopher Clark's status as writer of original ht code. (78772c3) + o Try to comment some of the event code more (cdd4c49) + o Add a few more evmap/changelist comments (c247adc) + o Add a comment to explain why evdns_request is now separte from request (ceefbe8) + o Document evutil_secure_rng_init() and evutil_secure_rng_add_bytes() (a5bf43a) + o Stop distributing and installing manpages: they were too inaccurate (7731ec8) + +NEW FEATURES AND INTERFACE CHANGES + o Remove signal_assign() and signal_new() macros. (2fac0f7) + o Make evdns use the regular logging system by default (b2f2be6) + o Allow evbuffer_read() to split across more than 2 iovecs (e470ad3) + o Functions to manipulate existing rate limiting groups. (ee41aca) + o Functions to track the total bytes sent over a rate limit group. (fb366c1) + o Detect and refuse reentrant event_base_loop() calls (b557b17) + o Limit the maximum number of events on each socket to 65535 (819f949) + o Add evbuffer_copyout to copy data from an evbuffer without draining (eb86c8c) + o Expose the request and reply members of rpc_req_generic() (07edf78 Shuo Chen) + o Add void* arguments to request_new and reply_new evrpc hooks (755fbf1 Shuo Chen) + o Seed the RNG using sysctl() as well as /dev/urandom (71fc3eb) + o Make evutil_secure_rng_init() work even with builtin arc4random (f980716) + o Report DNS error when lookup fails during bufferevent_socket_connect_hostname. (0ef4070 Christopher Davis) + o Release locks on bufferevents while executing callbacks (a5208fe Joachim Bauch) o Make debug mode catch mixed ET and non-ET events on an fd (cb67074) + o Catch attempts to enable debug_mode too late (9ecf0d4) + o Refuse null keys in evhttp_parse_query() (953e229 Frank Denis) + +BUGFIXES + o Avoid a spurious close(-1) on Linux (70a44b6) + o Do not close(-1) when freeing an uninitialized socket bufferevent (b34abf3) + o Free evdns_base->req_heads on evdns_base_free (859af67) + o Avoid an (untriggerable so far) crash bug in bufferevent_free() (0cf1431) + o Set mem_offset for every bufferevent type (657d1b6) + o Fix infrequent memory leak in bufferevent_init_common(). (8398641 Jardel Weyrich) + o Make evutil_signal_active() match declaration. (e1e703d Patrick Galbraith) + o Fix minheap code to use replacement malloc functions (a527618) + o Fix a free(NULL) in minheap-internal.h (6f20492) + o Fix critical bug in evbuffer_write when writev is not available (cda56ab) + o Make the no_iovecs case of write_atmost compile (8e227b0) + o Fix a memory leak when appending/prepending to a buffer with unused space. (45068a3) + o Clean up a mistake in pointer manipulation in evbuffer_remove (28bfed4 Christopher Davis) + o Always round up when there's a fractional number of msecs. (8f9e60c Christopher Davis) + o Fix compiler warnings under WIN32 (d469c50 Giuseppe Scrivano) + o Clean up properly when adding a signal handler fails. (b84b598 Gilad Benjamini) o Ensure that evdns_request is a persistent handle. (15bb82d Christopher Davis) + o Free search state when finished searching to avoid an infinite loop. (a625840 Christopher Davis) + o Assert for valid requests as necessary. (67072f3 Christopher Davis) + o do not leak the request object on persistent connections (9d8edf2) + o Make evdns logging threadsafe (b1c7950) + o Fix a couple of bugs in the BSD sysctl arc4seed logic (a47a4b7) + o Remove one last bug in last_with_datap logic. Found with valgrind (d49b92a) + o fix a leak when unpausing evrpc requests (94ee125) + o Fix a memory leak when unmarshalling RPC object arrays (f6ab2a2) + o Fix compilation when openssl support is disabled (40c301b) + o Allow empty reason line in HTTP status (739e688 Pierre Phaneuf) + o Fix a compile warning introduced in 739e688 (bd1ed5f Sebastian Hahn) + o Fix nonstandard TAILQ_FOREACH_REVERSE() definition (71afc52 Frank Denis) + o Try /proc on Linux as entropy fallback; use sysctl as last resort (20fda29) + o Fix symbol conflict between mm_*() macros and libmm (99e50e9) + o Fix some crazy macro mistakes in arc4random.c (90d4225) + o Make evbuffer_add_file() work on windows (dcdae6b) + o Fix unused-variable warning when building with threads disabled (ad811cd) + o Numerous opensolaris compilation fixes (c44de06) + o Fix getaddrinfo with protocol unset on Solaris 9. Found by Dagobert Michelsen (2cf2a28) + o Fix another nasty solaris getaddrinfo() behavior (3557071) + o Define _REENTRANT as needed on Solaris, elsewhere (c1cd32a) + o Fix some autoconf issues on OpenBSD (7c519df) + +BUILD AND DISTRIBUTION CHANGES + o Distribute libevent.pc.in, not libevent.pc (22aff04) + o Avoid errors in evutil.c when building with _UNICODE defined (b677032 Brodie Thiesfield) + o Avoid errors in http.c when building with VC 2003 .NET (13e4f3b Brodie Thiesfield) + o Support the standard 'make check' target in place of 'make verify' (426c8fb) + o Remove redundant stuff from EXTRA_DIST (b660edf) + o Switch to using AM conditionals in place of AC_LIBOBJ (2e898f5) + o Remove an orphaned RELEASE flag in Makefile.am (0794b0d) + o Give a better warning for bad automake versions. (77c917d) + o Use dist_bin_SCRIPTS, not EXTRA_DIST, to distribute scripts (9eb2fd7) + o Never test for select() on windows (3eb044d Trond Norbye) + o Do not inhibit automake dependencies generation (10c4c90 Giuseppe Scrivano) + o Create shared libraries under Windows (3cbca86 Giuseppe Scrivano) + o Add ctags/etags files to .gitignore (0861d17) + o Only specify -no-undefined on mingw (25433b9) + o Only add libevent_core.la to LIBADD on mingw (fdc6297) + +TESTING + o Get bench_http to work on Windows; add a switch to enable IOCP. (4ac38a5 Christopher Davis) + o VC has no getopt(), so do without in bench_http. (1273d2f Christopher Davis) + o Fix an obnoxious typo in the bufferevent_timeout_filter test (0d047c3) + o Fix a write of uninitialized RAM in regression tests (68dc742) + o Fix some memory leaks in the unit tests (274a7bd) + o Make 'main/many_events' test 70 fds, not 64. (33874b0) + o Unit-test every evbuffer_add_file() implementation. (06a4443) + o Add more unit tests for evbuffer_expand (8c83e99) + o Test another case of evbuffer_prepend (1234b95) + o Fix a possible double-free bug in SSL bufferevents with CLOSE_ON_FREE (7501895) o Add dns/search_cancel unit test. (39b870b Christopher Davis) + o Make http_base_test stop leaking an event_base. (96730d3) + o Detect broken unsetenv at unit-test runtime (f37cd4c) + o Implement regress_make_tempfile on win32 to test evbuffer_add_file (b4f12a1) + o add more (currently skipped) add_file tests on win32 (05de45d) + o Fix bench_http build on win32. (384d124) + o Make unit test for add_file able to tell "error" from "done" (88a543f) + o Make test for bufferevent_connect_hostname system-neutral (f89168e) + o Make test.sh support mingw/msys on win32 (0ee6f6c) + o Fix test.sh on freebsd (3d9e05b) + +INTERNALS, PERFORMANCE, AND AND CODE CLEANUPS + o Improve the speed of evbuffer_readln() (cc1600a) + o more whitespace normalization (2c2618d) + o Revise evbuffer to add last_with_data (2a6d2a1) + o Use last_with_data in place of previous_to_last (c8ac57f) + o Remove previous_to_last from evbuffer (6f47bd1) + o Fix last_with_data compilation on windows (1e7b986) + o Add some glass-box tests for the last_with_data code. (17da042) + o Improve robustness for refcounting (f1bc125) + o Remove a needless min_heap_shift_up_() call (7204b91) + o Increase MIN_BUFFER_SIZE to 512 (1024 on 64-bit) (2014ae4) + o Do not use evbuffer_expand() to add the first chain to a buffer (5c0ebb3) + o Make evbuffer_prepend handle empty buffers better (c87272b) + o Replace last_with_data with a slightly smarter version (b7442f8) + o Turn the increasingly complex *_CHAIN() macros into functions (96865c4) + o Rewrite evbuffer_expand and its users (d5ebcf3) + o Add evutil_tv_to_msec for safe conversion of timevals to milliseconds. (850c3ff Christopher Davis) + o Initialize last_with_datap correctly in evbuffer_overlapped (a0983b6) + o Replace EVUTIL_CLOSESOCKET macro with a function (899c1dc Sebastian Sjöberg) + o Move domain search state to evdns_request. (beaa14a Christopher Davis) + o Remove redundant checks for lock!=NULL before calling EVLOCK_LOCK (50ec59f) + o Rename current_base symbol to event_global_current_base_ (c16e684) + o Fix whitespace in evutil.c (935e150) + o Replace users of "int fd" with "evutil_socket_t fd" in portable code (c7cf6f0) + + + +Changes in 2.0.4-alpha (28 Feb 2010): + [Autogenerated from the Git log, sorted by hand.] +DOCUMENTATION + o Add stub header for 2.0.4-alpha changelog. (94d0065) + o Improve the README with more information and links. (0b42726) + o Add more people who wrote patches to the acknowledgments (0af10d5) + o Add a warning about the use of event_initialized. (f32b575) + o Add a LICENSE file so people can find our license easily (7067006) + o Add a new "hello world" sample program (becb9f9) + o Clarify status of example programs (d60a1bd) + o Update time-test.c to use event2 (f4190bf) + o Add the arc4random.c license to the LICENSE file. (e15e1e9) + +NEW FEATURES AND INTERFACE CHANGES + o Improved optional lock debugging. (0cd3bb9) + o Rate-limiting for bufferevents; group and individual limits are supported. (737c9cd) + o Testing code for bufferevent rate-limiting. (f0c0124) + o Make the initial nameserver probe timeout configurable. (1e56a32) + o Revise the locking API: deprecate the old locking callbacks and add trylock. (347952f) + o Do not make bufferevent_setfd implicitly disable EV_READ and EV_WRITE. (8274379) + o Do not ignore bufferevent_enable(EV_READ) before bufferevent_connect(). (4a5b534) + o Introduced evutil_make_socket_closeonexec() to preserve fd flags for F_SETFD. (d0939d2 Jardel Weyrich) + o evdns_getaddrinfo() now supports the /etc/hosts file. (72dd666) + o Look at the proper /etc/hosts file on windows. (66c02c7) + o Allow http connections to use evdns for hostname looksups. (c698b77) + o Changelist code to defer event changes until just before dispatch (27308aa) + o do not use a function to assign the evdns base; instead assign it via evhttp_connection_base_new() which is a new function introduced in 2.0 (5032e52) + o Functions to access more fields of struct event. (0683950) + o Make kqueue use changelists. (45e5ae3) + o Remove kqueue->pend_changes. (3225dfb) + o Minimize epoll_ctl calls by using changelist (c8c6a89) + o Add support for a "debug mode" to try to catch common errors. (cd17c3a) + o Note a missing ratelim function (361da8f) + o Add ev_[u]intptr_t to include/event2/util.h (1fa4c81) + o const-ify a few more functions in event.h (d38a7a1) + o Deprecate EVENT_FD and EVENT_SIGNAL. (f6b2694) + o Remove EVUTIL_CHECK_FMT. (6c21c89) + o Add EV_*_MAX macros to event2/util.h to expose limits for ev_* types. (aba1fff) o Functions to view and manipulate rate-limiting buckets. (85047a6) + o Add the rest of the integer limits, and add a test for them. (60742d5) + o Remove the 'flags' argument from evdns_base_set_option() (1dd7e6d) + o Add an arc4random implementation for use by evdns (d4de062) + o Use off_t for the length parameter of evbuffer_add_file (3fe60fd) + o Construct Windows locks using InitializeCriticalSectionAndSpinCount (32c6f1b) + o Expose view of current rate limit as constrained by group limit (162ce8a) + o Provide consistent, tested semantics for bufferevent timeouts (d328829) + +BUGFIXES AND TESTS + o Tolerate code that returns from a fatal_cb. (91fe23f) + o Parenthesize macro arguments more aggressively (07e9e9b) + o Fix memory-leak of signal handler array with kqueue. (e1ffbb8) + o Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks. (76cd2b7) + o Fix two use-after-free bugs in unit tests spoted by lock debugging (d84d838) + o Fix a locking bug in event_base_loop() (da1718b) + o Fix an evdns lock violation. (2df1f82 Zhuang Yuyao) + o Valgrind fix: Clear struct kevent before checking for OSX bug. (56771a3 William Ahern) + o Fix up evthread compilation on windows (bd6f1ba Roman Puls) + o Fix regress_iocp.c usage of old lock allocation macros. (31687b4 unknown) + o Update nmake makefile to build evthread.c (b62d979 unknown) + o Fix a crash when reading badly formatted resolve.conf; from Yasuoka Masahiko (6c7c579 Yasuoka Masahiko) + o Fix a snow leopard compile warning in the unit tests. (7ae9445) + o Fix compile on Snow Leopard with gcc warnings enabled (70cdfe4 Sebastian Hahn) + o Only define _GNU_SOURCE if it is not already defined. (ea6b1df Joachim Bauch) + o Update sample/signal-test.c to use newer APIs and not leak. (f6430ac Evan Jones) + o Fix a segfault when writing a very fragmented evbuffer onto an SSL (a6adeca Joachim Bauch) + o Fix a segfault when freeing SSL bufferevents in an unusual order (a773df5 Joachim Bauch) + o Drop install-sh from our git repo: a mismatched version could break "make dist" (6799527) + o Set all instances of the version number correctly. (5a112d3) + o Fix a few locking issues on windows. (c51bb3c unknown) + o Use evutil_socket_t, not int, when logging socket errors. (292467c) + o Fix up behavior of never-defered callbacks a little (390e056) + o Replace some cases of uint32_t with ev_uint32_t. (a47d88d) + o Fix compilation of devpoll.c by adding missing thread includes. (fee2c77 Dagobert Michelsen) + o Make evutil_make_socket_nonblocking() leave any other flags alone. (4c8b7cd Jardel Weyrich) + o Fix an fd leak in evconnlistener_new_bind(). (24fb502 Jardel Weyrich) + o Fix a bogus free in evutil_new_addrinfo() (0d64051 Jardel Weyrich) + o Adjusted fcntl() retval comparison on evutil_make_socket_nonblocking(). (4df7dbc Jardel Weyrich) + o Fix the code that allowed DNS options to not end with : (ee4953f) + o Fix crash bugs when a bufferevent's eventcb is not set. (2e8eeea) + o Fix test-ratelim compilation on Linux. (885b427) + o Fix compilation of rate-limiting code on win32. (165d30e) + o Eradicated the last free() call. Let mm_free() take care of deallocation. (0546ce1 Jardel Weyrich) + o Fix byte counts when mixing deferred and non-deferred evbuffer callbacks. (29151e6) + o Fixed a memory leak on windows threads implementation. The CRITICAL_SECTION was not being free'd in evthread_win32_lock_free(). (2f33e00 Jardel Weyrich) + o Fixed a fd leak in start_accepting(), plus cosmetic changes (4367a33 Jardel Weyrich) + o Improved error handling in evconnlistener_new_async(). Also keeping the fd open because it is not opened by this function, so the caller is responsible for closing it. Additionally, since evconnlistener_new_bind() creates a socket and passes it to the function above, it required error checking to close the same socket. (fec66f9 Jardel Weyrich) + o Don't use a bind address for nameservers on loopback (8d4aaf9) + o Fix compilation of rate-limit code when threading support is disabled (97a8c79) + o Detect setenv/unsetenv; skip main/base_environ test if we can't fake them. (7296971) + o Check more internal event_add() calls for failure (ff3f6cd) + o Fix windows and msvc build (5c7a7bc) + o Call event_debug_unassign on internal events (a19b4a0) + o Try to fix a warning in hash_debug_entry (137f2c6) + o Fix a dumb typo in ev_intptr_t definitions. (27c9a40) + o do not fail while sending on http connections the client closed. (93d7369) + o make evhttp_send() safe against terminated connections, too (3978180) + o Make Libevent 1.4.12 build on win32 with Unicode enabled. (000a33e Brodie Thiesfield) + o Fix some additional -DUNICODE issues on win32. (a7a9431) + o Add a check to make soure our EVUTIL_AI flags do not conflict with the native ones (c18490e) + o Always use our own gai_strerror() replacement. (6810bdb) + o Make RNG work when we have arc4random() but not arc4random_buf() (4ec8fea) + o validate close cb on server when client connection closes (2f782af) + o Fix two unlocked reads in evbuffer. (7116bf2) + o When working without a current event base, don't try to use IOCP listeners (cb52838) + o Fix getpid() usage on Windows (ff2a134) + o Add a unit test for secure rng. (48a29b6) + o Add some headers to fix freebsd compilation (b72be50) + o When connect() succeeds immediately, don't invoke the callback immediately. (7515de9) + o Suspend read/write on bufferevents during hostname lookup (db08f64) + o Make bufferevent_free() clear all callbacks immediately. (b2fbeb3) + o Fix some race conditions in persistent events and event_reinit (e2642f0) + o Fix a bug in resetting timeouts on persistent events when IO triggers. (38ec0a7) + o Add a test for timeouts on filtering bufferevents. (c02bfe1) + o Add test for periodic timers that get activated for other reasons (8fcb7a1) + o Use new timeval diff comparison function in bufferevent test (f3dfe46) + o Delete stack-alloced event in new unit test before returning. (7ffd387) + o Fix mingw compilation (23170a6) + o Try to define a sane _EVENT_SIZEOF_SIZE_T for msvc compilation (1e14f82) + o Fix arc4random compilation on MSVC. (98edb89) + o deal with connect() failing immediately (7bc48bf) + o Small cleanups on freebsd-connect-refused patch. (57b7248) + +BUILD AND DISTRIBUTION CHANGES + o Remove the contents of WIN32-Prj as unmaintained. (c69d5a5) + o Allow the user to redirect the verbose output of test/test.sh to a file (c382de6) + o Allow test.sh to be run as ./test/test.sh (7dfbe94) + o Never believe that we have pthreads on win32, even if gcc thinks we do. (78ed097) + o Make it compile under gcc --std=c89. (e2ca403) + o Fix a number of warnings from gcc -pedantic (918e9c5) + o Add the msvc-generated .lib files to .gitignore. (e244a2e) + o Add the "compile" script to gitignore. (1ba6bed) + +INTERNALS AND CODE CLEANUPS + o Add a .gitignore file. (ba34071) + o New EVTHREAD_TRY_LOCK function to try to grab a lock. (689fc09) + o Add the abilitity to mark some buffer callbacks as never-deferred. (438f9ed) + o Refactor our 'suspend operation' logic on bufferevents. (0d744aa) + o Simplify the read high-watermark checking. (5846bf6) + o Improve readability of evutil_unparse_protoname() (5a43df8 Jardel Weyrich) + o Expose our cached gettimeofday value with a new interface (47854a8) + o Whitespace fixes in test.sh (0b151a9) + o Enable branch-prediction hints with EVUTIL_UNLIKELY. (eaaf27f) + o Refactor code from evdns into a new internal "read a file" function. (0f7144f) + o Comestic changes in evconnlistener_new(), new_accepting_socket(), accepted_socket_invoke_user_cb() and iocp_listener_enable(). (510ab6b Jardel Weyrich) + o Add unit-test for bad_request bug fixed in 1.4 recently. (6cc79c6 Pavel Plesov) o Add a comment on evthread_enable_lock_debuging. (b9f43b2) + o Fix test.sh on shells without echo -n (94131e9) + o More unit tests for getaddrinfo_async: v4timeout and cancel. (a334b31) + o Make http use evconnlistener. (ec34533) + o move dns utility functions into a separate file so that we can use them for http testing (b822639) + o add a test for evhttp_connection_base_new with a dns_base (26714ca) + o forgot to add void to test function (78a50fe) + o Add a forgotten header (changelist-internal.h) (4b9f307) + o Remove some commented-out code in evutil (26e1b6f) + o Remove a needless include of rpc_compat.h (70a4a3e) + o Use less memory for each entry in a hashtable (a66e947) + o Try to untangle the logic in server_port_flush(). (439aea0) + o Use ev_[u]intptr_t types in place of [u]intptr_t (cef61a2) + o Reduce windows header includes in our own headers. (da6135e) + o clean up terminate_chunked test (e8a9782) + o Increment the submicro version number. (63e868e) + o Update event-config.h version number to match configure.in (aae7db5) + o Clean up formatting: Disallow space-before-tab. (8fdf09c) + o Clean up formatting: use tabs, not 8-spaces, to indent. (e5bbd40) + o Clean up formatting: remove trailing spaces (e5cf987) + o Clean up formatting: function/keyword spacing consistency. (4faeaea) + + + +Changes in 2.0.3-alpha (20 Nov 2009): + o Add a new code to support SSL/TLS on bufferevents, using the OpenSSL library (where available). + o Fix a bug where we didn't allocate enough memory in event_get_supported_methods(). + o Avoid segfault during failed allocation of locked evdns_base. (Found by Rocco Carbone.) + o Export new evutil_ascii_* functions to perform locale-independent character type operations. + o Try to compile better with MSVC: patches from Brodie Thiesfield + o New evconnlistener_get_fd function to expose a listener's associated socket. + o Expose an ev_socklen_t type for consistent use across platforms. + o Make bufferevent_socket_connect() work when the original fd was -1. + o Fix a bug in bufferevent_socket_connect() when the connection succeeds too quickly. + o Export an evutil_sockaddr_cmp() to compare to sockaddr objects for equality. + o Add a bufferevent_get_enabled() to tell what a bufferevent has been configured to do. + o Add an evbuffer_search_eol() function to locate the end of a line nondestructively. + o Add an evbuffer_search_range() function to search a bounded range of a buffer. + o Fix a rare crash bug in evdns. + o Have bufferevent_socket_connect() with no arguments put a bufferevent into connecting mode. + o Support sendfile on Solaris: patch from Caitlin Mercer. + o New functions to explicitly reference a socket used by an evhttp object. Patches from David Reiss. + o When we send a BEV_EVENT_CONNECTED to indicate connected status, we no longer invoke the write callback as well unless we actually wrote data too. + o If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it. Fixes bug 2841177; found by Alexander Pronchenkov. + o Do not detect whether we have monotonic clock support every time a new event base is created: instead do it only once. Patch taken from Chromium. + o Do not allocate the maximum event queue for the epoll backend at startup. Instead, start out accepting 32 events at a time, and double the queue's size when it seems that the OS is generating events faster than we're requesting them. Saves up to 374K per epoll-based event_base. Resolves bug 2839240. + o Treat an event with a negative fd as valid but untriggerable by Libevent. This is useful for applications that want to manually activate events. + o Fix compilation on Android, which forgot to define fd_mask in its sys/select.h + o Do not drop data from evbuffer when out of memory; reported by Jacek Masiulaniec + o New event_base_got_exit() and event_base_got_break() functions to tell whether an event loop exited because of an event_base_loopexit() or an event_base_loopbreak(). Patch from Ka-Hing Cheung. + o When adding or deleting an event from a non-main thread, only wake up the main thread when its behavior actually needs to change. + o Fix some bugs when using the old evdns interfaces to initialize the evdns module. + o Detect errors during bufferevent_connect(). Patch from Christopher Davis. + o Fix compilation for listener.h for C++ - missing extern "C". Patch from Ferenc Szalai. + o Make the event_base_loop() family of functions respect thread-safety better. This should clear up a few hard-to-debug race conditions. + o Fix a bug when using a specialized memory allocator on win32. + o Have the win32 select() backend label TCP-socket-connected events as EV_WRITE, not EV_READ. This should bring it in line with the other backends, and improve portability. Patch from Christopher Davis. + o Stop using enums as arguments or return values when what we mean is a bitfield of enum values. C++ doesn't believe that you can OR two enum values together and get another enum, and C++ takes its typing seriously. Patch from Christopher Davis. + o Add an API to replace all fatal calls to exit() with a user-provided panic function. + o Replace all assert() calls with a variant that is aware of the user-provided logging and panic functions. + o Add a return value to event_assign so that it can fail rather than asserting when the user gives it bad input. event_set still dies on bad input. + o The event_base_new() and event_base_new_with_config() functions now never call exit() on failure. For backward "compatibility", event_init() still does, but more consistently. + o Remove compat/sys/_time.h. It interfered with system headers on HPUX, and its functionality has been subsumed by event2/util.h and util-internal.h. + o Add a new bufferevent_socket_connect_hostname() to encapsulate the resolve-then-connect operation. + o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian. + o Alternative queue-based timeout algorithm for programs that use a large number of timeouts with the same value. + o New event_base_config option to disable the timeval cache entirely. + o Make EV_PERSIST timeouts more accurate: schedule the next event based on the scheduled time of the previous event, not based on the current time. + o Allow http.c to handle cases where getaddrinfo returns an IPv6 address. Patch from Ryan Phillips. + o Fix a problem with excessive memory allocation when using multiple event priorities. + o Default to using arc4random for DNS transaction IDs on systems that have it; from OpenBSD. + o Never check the environment when we're running setuid or setgid; from OpenBSD. + o Options passed to evdns_set_option() no longer need to end with a colon. + o Add an evutil_getaddrinfo() function to clone getaddrinfo on platforms that don't have it. + o Add an evdns_getaddrinfo() function to provide a nonblocking getaddrinfo using evdns, so programs can perform useful hostname lookup. + o Finally expose the IOCP-based bufferevent backend. It passes its unit tests, but probably still has some bugs remaining. Code by Nick Mathewson and Christopher Davis. + o Numerous other bugfixes. + o On FreeBSD and other OSes, connect can return ECONREFUSED immediately; instead of failing the function call, pretend with faileld in the callback. + o Fix a race condition in the pthreads test case; found by Nick Mathewson + o Remove most calls to event_err() in http and deal with memory errors instead + + + +Changes in 2.0.2-alpha (25 Jul 2009): + o Add a new flag to bufferevents to make all callbacks automatically deferred. + o Make evdns functionality locked, and automatically defer dns callbacks. + o Fix a possible free(NULL) when freeing an event_base with no signals. + o Add a flag to disable checking environment varibles when making an event_base + o Disallow setting less than 1 priority. + o Fix a bug when removing a timeout from the heap. [Patch from Marko Kreen] + o Use signal.h, not sys/signal.h. [Patch from mmadia] + o Try harder to build with certain older c99 compilers. + o Make sure that an event_config's flags field is always initialized to 0. [Bug report from Victor Goya] + o Avoid data corruption when reading data entirely into the second-to-last chain of an evbuffer. [Bug report from Victor Goya] + o Make sendfile work on FreeBSD + o Do not use vararg macros for accessing evrpc structures; this is not backwards compatible, but we did not promise any backwards compatibility for the rpc code. + o Actually define the event_config_set_flag() function. + o Try harder to compile with Visual C++. + o Move event_set() and its allies to event2/event_compat.h where they belong. + o Remove the event_gotsig code, which has long been deprecated and unused. + o Add an event_get_base() function to return the base assigned to an event. + o New function to automate connecting on a socket-based bufferevent. + o New functions to automate listening for incoming TCP connections. + o Do case-insensitive checks with a locale-independent comparison function. + o Rename the evbuffercb and everrorcb callbacks to bufferevent_data_cb and bufferevent_event_cb respectively. The old names are available in bufferevent_compat.h. + o Rename the EVBUFFER_* codes used by bufferevent event callbacks to BEV_EVENT_*, to avoid namespace collision with evbuffer flags. The old names are available in bufferevent_compat.h. + o Move the EVBUFFER_INPUT and EVBUFFER_OUTPUT macros to bufferevent_compat.h + o Add a bufferevent_getfd() function to mirror bufferevent_setfd() + o Make bufferevent_setfd() return an error code if the operation is not successful. + o Shave 22 bytes off struct event on 32-bit platforms by shrinking and re-ordering fields. The savings on 64-bit platforms is likely higher. + o Cap the maximum number of priorities at 256. + o Change the semantics of evbuffer_cb_set_flags() to be set-flag only; add a new evbuffer_cb_clear_flags() to remove set flags. + o Change the interface of evbuffer_add_reference so that the cleanup callback gets more information + o Revise the new evbuffer_reserve_space/evbuffer_commit_space() interfaces so that you can use them without causing extraneous copies or leaving gaps in the evbuffer. + o Add a new evbuffer_peek() interface to inspect data in an evbuffer without removing it. + o Fix a deadlock when suspending reads in a bufferevent due to a full buffer. (Spotted by Joachim Bauch.) + o Fix a memory error when freeing a thread-enabled event base with registered events. (Spotted by Joachim Bauch.) + o Try to contain degree of failure when running on a win32 version so heavily firewalled that we can't fake a socketpair. + o Activate fd events in a pseudorandom order with O(N) backends, so that we don't systematically favor low fds (select) or earlier-added fds (poll, win32). + o Replace some read()/write() instances with send()/recv() to work properly on win32. + o Set truncated flag correctly in evdns server replies. + o Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg + o Fix preamble of rpcgen-generated files to rely on event2 includes; based on work by jmansion; patch from Zack Weinberg. + o Allow specifying the output filename for rpcgen; based on work by jmansion; patch from Zack Weinberg. + o Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg + o Mitigate a race condition when using socket bufferevents in multiple threads. + o Use AC_SEARCH_LIBS, not AC_CHECK_LIB to avoid needless library use. + o Do not allow event_del(ev) to return while that event's callback is executing in another thread. This fixes a nasty race condition. + o event_get_supported_methods() now lists methods that have been disabled with the EVENT_NO* environment options. + o Rename encode_int[64] to evtag_encode_int[64] to avoid polluting the global namespace. The old method names are still available as macros in event2/tag_compat.h. + + + +Changes in 2.0.1-alpha (17 Apr 2009): + o free minheap on event_base_free(); from Christopher Layne + o debug cleanups in signal.c; from Christopher Layne + o provide event_base_new() that does not set the current_base global + o bufferevent_write now uses a const source argument; report from Charles Kerr + o improve documentation on event_base_loopexit; patch from Scott Lamb + o New function, event_{base_}loopbreak. Like event_loopexit, it makes an event loop stop executing and return. Unlike event_loopexit, it keeps subsequent pending events from getting executed. Patch from Scott Lamb + o Check return value of event_add in signal.c + o provide event_reinit() to reintialize an event_base after fork + o New function event_set_mem_functinons. It allows the user to give libevent replacement functions to use for memory management in place of malloc(), free(), etc. This should be generally useful for memory instrumentation, specialized allocators, and so on. + o The kqueue implementation now catches signals that are raised after event_add() is called but before the event_loop() call. This makes it match the other implementations. + o The kqueue implementation now restores original signal handlers correctly when its signal events are removed. + o Check return value of event_add in signal.c + o Add a more powerful evbuffer_readln as a replacement for evbuffer_readline. The new function handles more newline styles, and is more useful with buffers that may contain a nul characters. + o Do not mangle socket handles on 64-bit windows. + o The configure script now takes an --enable-gcc-warnings option that turns on many optional gcc warnings. (Nick has been building with these for a while, but they might be useful to other developers.) + o move EV_PERSIST handling out of the event backends + o small improvements to evhttp documentation + o always generate Date and Content-Length headers for HTTP/1.1 replies + o set the correct event base for HTTP close events + o When building with GCC, use the "format" attribute to verify type correctness of calls to printf-like functions. + o Rewrite win32.c backend to be O(n lg n) rather than O(n^2). + o Removed obsoleted recalc code + o support for 32-bit tag numbers in rpc structures; this is wire compatible, but changes the API slightly. + o pull setters/getters out of RPC structures into a base class to which we just need to store a pointer; this reduces the memory footprint of these structures. + o prefix {encode,decode}_tag functions with evtag to avoid collisions + o fix a bug with event_rpcgen for integers + o Correctly handle DNS replies with no answers set (Fixes bug 1846282) + o add -Wstrict-aliasing to warnings and more cleanup + o removed linger from http server socket; reported by Ilya Martynov + o event_rpcgen now allows creating integer arrays + o support string arrays in event_rpcgen + o change evrpc hooking to allow pausing of RPCs; this will make it possible for the hook to do some meaning ful work; this is not backwards compatible. + o allow an http request callback to take ownership of a request structure + o allow association of meta data with RPC requests for hook processing + o associate more context for hooks to query such as the connection object + o remove pending timeouts on event_base_free() + o also check EAGAIN for Solaris' event ports; from W.C.A. Wijngaards + o devpoll and evport need reinit; tested by W.C.A Wijngaards + o event_base_get_method; from Springande Ulv + o Send CRLF after each chunk in HTTP output, for compliance with RFC2626. Patch from "propanbutan". Fixes bug 1894184. + o Add a int64_t parsing function, with unit tests, so we can apply Scott Lamb's fix to allow large HTTP values. + o Use a 64-bit field to hold HTTP content-lengths. Patch from Scott Lamb. + o Allow regression code to build even without Python installed + o remove NDEBUG ifdefs from evdns.c + o detect integer types properly on platforms without stdint.h + o udpate documentation of event_loop and event_base_loop; from Tani Hosokawa. + o simplify evbuffer by removing orig_buffer + o do not insert event into list when evsel->add fails + o add support for PUT/DELETE requests; from Josh Rotenberg + o introduce evhttp_accept_socket() to accept from an already created socket + o include Content-Length in reply for HTTP/1.0 requests with keep-alive + o increase listen queue for http sockets to 128; if that is not enough the evhttp_accpet_socket() api can be used with a prepared socket. + o Patch from Tani Hosokawa: make some functions in http.c threadsafe. + o test support for PUT/DELETE requests; from Josh Rotenberg + o rewrite of the evbuffer code to reduce memory copies + o Some older Solaris versions demand that _REENTRANT be defined to get strtok_r(); do so. + o Do not free the kqop file descriptor in other processes, also allow it to be 0; from Andrei Nigmatulin + o Provide OpenSSL style support for multiple threads accessing the same event_base + o make event_rpcgen.py generate code include event-config.h; reported by Sam Banks. + o switch thread support so that locks get allocated as they are needed. + o make event methods static so that they are not exported; from Andrei Nigmatulin + o make RPC replies use application/octet-stream as mime type + o do not delete uninitialized timeout event in evdns + o Correct the documentation on buffer printf functions. + o Don't warn on unimplemented epoll_create(): this isn't a problem, just a reason to fall back to poll or select. + o Correctly handle timeouts larger than 35 minutes on Linux with epoll.c. This is probably a kernel defect, but we'll have to support old kernels anyway even if it gets fixed. + o Make name_from_addr() threadsafe in http.c + o Add new thread-safe interfaces to evdns functions. + o Make all event_tagging interfaces threadsafe. + o Rename internal memory management functions. + o New functions (event_assign, event_new, event_free) for use by apps that want to be safely threadsafe, or want to remain ignorant of the contents of struct event. + o introduce bufferevent_read_buffer; allows reading without memory copy. + o expose bufferevent_setwatermark via header files and fix high watermark on read + o fix a bug in buffrevent read water marks and add a test for them + o fix a bug in which bufferevent_write_buffer would not schedule a write event + o provide bufferevent_input and bufferevent_output without requiring knowledge of the structure + o introduce bufferevent_setcb and bufferevent_setfd to allow better manipulation of bufferevents + o convert evhttp_connection to use bufferevents. + o use libevent's internal timercmp on all platforms, to avoid bugs on old platforms where timercmp(a,b,<=) is buggy. + o Remove the never-exported, never-used evhttp_hostportfile function. + o Support input/output filters for bufferevents; somewhat similar to libio's model. This will allow us to implement SSL, compression, etc, transparently to users of bufferevents such as the http layer. + o allow connections to be removed from an rpc pool + o add new evtimer_assign, signal_assign, evtimer_new, and signal_new functions to manipulate timer and signal events, analagous to the now-recommended event_assign and event_new + o switch internal uses of event_set over to use event_assign. + o introduce evbuffer_contiguous_space() api that tells a user how much data is available in the first buffer chain + o introduce evbuffer_reserve_space() and evbuffer_commit_space() to make processing in filters more efficient. + o reduce system calls for getting current time by caching it. + o separate signal events from io events; making the code less complex. + o support for periodic timeouts + o support for virtual HTTP hosts. + o turn event_initialized() into a function, and add function equivalents to EVENT_SIGNAL and EVENT_FD so that people don't need to include event_struct.h + o Build test directory correctly with CPPFLAGS set. + o Provide an API for retrieving the supported event mechanisms. + o event_base_new_with_config() and corresponding config APIs. + o migrate the evhttp header to event2/ but accessors are still missing. + o deprecate timeout_* event functions by moving them to event_compat.h + o Move windows gettimeofday replacement into a new evutil_gettimeofday(). + o Make configure script work on IRIX. + o provide a method for canceling ongoing http requests. + o Make vsnprintf() returns consistent on win32. + o Fix connection keep-alive behavior for HTTP/1.0 + o Fix use of freed memory in event_reinit; pointed out by Peter Postma + o constify struct timeval * where possible + o make event_get_supported_methods obey environment variables + o support for edge-triggered events on epoll and kqueue backends: patch from Valery Kholodkov + o support for selecting event backends by their features, and for querying the features of a backend. + o change failing behavior of event_base_new_with_config: if a config is provided and no backend is selected, return NULL instead of aborting. + o deliver partial data to request callbacks when chunked callback is set even if there is no chunking on the http level; allows cancelation of requests from within the chunked callback; from Scott Lamb. + o allow min_heap_erase to be called on removed members; from liusifan. + o Rename INPUT and OUTPUT to EVRPC_INPUT and EVRPC_OUTPUT. Retain INPUT/OUTPUT aliases on on-win32 platforms for backwards compatibility. + o Do not use SO_REUSEADDR when connecting + o Support 64-bit integers in RPC structs + o Correct handling of trailing headers in chunked replies; from Scott Lamb. + o Support multi-line HTTP headers; based on a patch from Moshe Litvin + o Reject negative Content-Length headers; anonymous bug report + o Detect CLOCK_MONOTONIC at runtime for evdns; anonymous bug report + o Various HTTP correctness fixes from Scott Lamb + o Fix a bug where deleting signals with the kqueue backend would cause subsequent adds to fail + o Support multiple events listening on the same signal; make signals regular events that go on the same event queue; problem report by Alexander Drozdov. + o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov. + o Fix off-by-one errors in devpoll; from Ian Bell + o Make event_add not change any state if it fails; reported by Ian Bell. + o Fix a bug where headers arriving in multiple packets were not parsed; fix from Jiang Hong; test by me. + o Match the query in DNS replies to the query in the request; from Vsevolod Stakhov. + o Add new utility functions to correctly observe and log winsock errors. + o Do not remove Accept-Encoding header + o Clear the timer cache on entering the event loop; reported by Victor Chang + o Only bind the socket on connect when a local address has been provided; reported by Alejo Sanchez + o Allow setting of local port for evhttp connections to support millions of connections from a single system; from Richard Jones. + o Clear the timer cache when leaving the event loop; reported by Robin Haberkorn + o Fix a typo in setting the global event base; reported by lance. + o Set the 0x20 bit on outgoing alphabetic characters in DNS requests randomly, and insist on a match in replies. This helps resist DNS poisoning attacks. + o Make the http connection close detection work properly with bufferevents and fix a potential memory leak associated with it. + o Restructure the event backends so that they do not need to keep track of events themselves, as a side effect multiple events can use the same fd or signal. + o Add generic implementations for parsing and emiting IPv6 addresses on platforms that do not have inet_ntop and/or inet_pton. + o Allow DNS servers that have IPv6 addresses. + o Add an evbuffer_write_atmost() function to write a limited number of bytes to an fd. + o Refactor internal notify-main-thread logic to prefer eventfd to pipe, then pipe to socketpair, and only use socketpairs as a last resort. + o Try harder to pack all evbuffer reads into as few chains as possible, using readv/WSARecv as appropriate. + o New evthread_use_windows_threads() and evthread_use_pthreads() functions to set up the evthread callbacks with reasonable defaults. + o Change the semantics of timeouts in conjunction with EV_PERSIST; timeouts in that case will now repeat until deleted. + o sendfile, mmap and memory reference support for evbuffers. + o New evutil_make_listen_socket_reuseable() to abstract SO_REUSEADDR. + o New bind-to option to allow DNS clients to bind to an arbitrary port for outgoing requests. + o evbuffers can now be "frozen" to prevent operations at one or both ends. + o Bufferevents now notice external attempts to add data to an inbuf or remove it from an outbuf, and stop them. + o Fix parsing of queries where the encoded queries contained \r, \n or + + o Do not allow internal events to starve lower-priority events. + diff --git a/contrib/libs/libevent/LICENSE b/contrib/libs/libevent/LICENSE index 402ca50896..280d3d18ba 100644 --- a/contrib/libs/libevent/LICENSE +++ b/contrib/libs/libevent/LICENSE @@ -72,28 +72,28 @@ The arc4module is available under the following, sometimes called the ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -============================== - -The Windows timer code is based on code from libutp, which is -distributed under this license, sometimes called the "MIT" license. - - -Copyright (c) 2010 BitTorrent, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +============================== + +The Windows timer code is based on code from libutp, which is +distributed under this license, sometimes called the "MIT" license. + + +Copyright (c) 2010 BitTorrent, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/contrib/libs/libevent/README.md b/contrib/libs/libevent/README.md index 1247e220f5..3482f71ce0 100644 --- a/contrib/libs/libevent/README.md +++ b/contrib/libs/libevent/README.md @@ -1,469 +1,469 @@ -<p align="center"> - <img src="https://strcpy.net/libevent3.png" alt="libevent logo"/> -</p> - - - -[![Appveyor Win32 Build Status](https://ci.appveyor.com/api/projects/status/ng3jg0uhy44mp7ik?svg=true)](https://ci.appveyor.com/project/libevent/libevent) -[![Travis Build Status](https://travis-ci.org/libevent/libevent.svg?branch=master)](https://travis-ci.org/libevent/libevent) -[![Coverage Status](https://coveralls.io/repos/github/libevent/libevent/badge.svg)](https://coveralls.io/github/libevent/libevent) -[![Join the chat at https://gitter.im/libevent/libevent](https://badges.gitter.im/libevent/libevent.svg)](https://gitter.im/libevent/libevent?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - - - -# 0. BUILDING AND INSTALLATION (Briefly) - -## Autoconf - - $ ./configure - $ make - $ make verify # (optional) - $ sudo make install - -## CMake (General) - - -The following Libevent specific CMake variables are as follows (the values being -the default). - -``` -# Type of the library to build (SHARED or STATIC) -# Default is: SHARED for MSVC, otherwise BOTH -EVENT__LIBRARY_TYPE:STRING=DEFAULT - -# Installation directory for CMake files -EVENT_INSTALL_CMAKE_DIR:PATH=lib/cmake/libevent - -# Enable running gcov to get a test coverage report (only works with -# GCC/CLang). Make sure to enable -DCMAKE_BUILD_TYPE=Debug as well. -EVENT__COVERAGE:BOOL=OFF - -# Defines if Libevent should build without the benchmark executables -EVENT__DISABLE_BENCHMARK:BOOL=OFF - -# Define if Libevent should build without support for a debug mode -EVENT__DISABLE_DEBUG_MODE:BOOL=OFF - -# Define if Libevent should not allow replacing the mm functions -EVENT__DISABLE_MM_REPLACEMENT:BOOL=OFF - -# Define if Libevent should build without support for OpenSSL encryption -EVENT__DISABLE_OPENSSL:BOOL=OFF - -# Disable the regress tests -EVENT__DISABLE_REGRESS:BOOL=OFF - -# Disable sample files -EVENT__DISABLE_SAMPLES:BOOL=OFF - -# If tests should be compiled or not -EVENT__DISABLE_TESTS:BOOL=OFF - -# Define if Libevent should not be compiled with thread support -EVENT__DISABLE_THREAD_SUPPORT:BOOL=OFF - -# Enables verbose debugging -EVENT__ENABLE_VERBOSE_DEBUG:BOOL=OFF - -# When cross compiling, forces running a test program that verifies that Kqueue -# works with pipes. Note that this requires you to manually run the test program -# on the the cross compilation target to verify that it works. See CMake -# documentation for try_run for more details -EVENT__FORCE_KQUEUE_CHECK:BOOL=OFF -``` - -__More variables can be found by running `cmake -LAH <sourcedir_path>`__ - - -## CMake (Windows) - -Install CMake: <https://www.cmake.org> - - - $ md build && cd build - $ cmake -G "Visual Studio 10" .. # Or whatever generator you want to use cmake --help for a list. - $ start libevent.sln - -## CMake (Unix) - - $ mkdir build && cd build - $ cmake .. # Default to Unix Makefiles. - $ make - $ make verify # (optional) - - -# 1. BUILDING AND INSTALLATION (In Depth) - -## Autoconf - -To build Libevent, type - - $ ./configure && make - - - (If you got Libevent from the git repository, you will - first need to run the included "autogen.sh" script in order to - generate the configure script.) - -You can run the regression tests by running - - $ make verify - -Install as root via - - $ make install - -Before reporting any problems, please run the regression tests. - -To enable low-level tracing, build the library as: - - $ CFLAGS=-DUSE_DEBUG ./configure [...] - -Standard configure flags should work. In particular, see: - - --disable-shared Only build static libraries. - --prefix Install all files relative to this directory. - - -The configure script also supports the following flags: - - --enable-gcc-warnings Enable extra compiler checking with GCC. - --disable-malloc-replacement - Don't let applications replace our memory - management functions. - --disable-openssl Disable support for OpenSSL encryption. - --disable-thread-support Don't support multithreaded environments. - -## CMake (Windows) - -(Note that autoconf is currently the most mature and supported build -environment for Libevent; the CMake instructions here are new and -experimental, though they _should_ be solid. We hope that CMake will -still be supported in future versions of Libevent, and will try to -make sure that happens.) - -First of all install <https://www.cmake.org>. - -To build Libevent using Microsoft Visual studio open the "Visual Studio Command prompt" and type: - -``` -$ cd <libevent source dir> -$ mkdir build && cd build -$ cmake -G "Visual Studio 10" .. # Or whatever generator you want to use cmake --help for a list. -$ start libevent.sln -``` - -In the above, the ".." refers to the dir containing the Libevent source code. -You can build multiple versions (with different compile time settings) from the same source tree -by creating other build directories. - -It is highly recommended to build "out of source" when using -CMake instead of "in source" like the normal behaviour of autoconf for this reason. - -The "NMake Makefiles" CMake generator can be used to build entirely via the command line. - -To get a list of settings available for the project you can type: - -``` -$ cmake -LH .. -``` - -### GUI - -CMake also provides a GUI that lets you specify the source directory and output (binary) directory -that the build should be placed in. - -# 2. USEFUL LINKS: - -For the latest released version of Libevent, see the official website at -<http://libevent.org/> . - -There's a pretty good work-in-progress manual up at - <http://www.wangafu.net/~nickm/libevent-book/> . - -For the latest development versions of Libevent, access our Git repository -via - -``` -$ git clone https://github.com/libevent/libevent.git -``` - -You can browse the git repository online at: - -<https://github.com/libevent/libevent> - -To report bugs, issues, or ask for new features: - -__Patches__: https://github.com/libevent/libevent/pulls -> OK, those are not really _patches_. You fork, modify, and hit the "Create Pull Request" button. -> You can still submit normal git patches via the mailing list. - -__Bugs, Features [RFC], and Issues__: https://github.com/libevent/libevent/issues -> Or you can do it via the mailing list. - -There's also a libevent-users mailing list for talking about Libevent -use and development: - -<http://archives.seul.org/libevent/users/> - -# 3. ACKNOWLEDGMENTS - -The following people have helped with suggestions, ideas, code or -fixing bugs: - - * Samy Al Bahra - * Antony Antony - * Jacob Appelbaum - * Arno Bakker - * Weston Andros Adamson - * William Ahern - * Ivan Andropov - * Sergey Avseyev - * Avi Bab - * Joachim Bauch - * Andrey Belobrov - * Gilad Benjamini - * Stas Bekman - * Denis Bilenko - * Julien Blache - * Kevin Bowling - * Tomash Brechko - * Kelly Brock - * Ralph Castain - * Adrian Chadd - * Lawnstein Chan - * Shuo Chen - * Ka-Hing Cheung - * Andrew Cox - * Paul Croome - * George Danchev - * Andrew Danforth - * Ed Day - * Christopher Davis - * Mike Davis - * Frank Denis - * Antony Dovgal - * Mihai Draghicioiu - * Alexander Drozdov - * Mark Ellzey - * Shie Erlich - * Leonid Evdokimov - * Juan Pablo Fernandez - * Christophe Fillot - * Mike Frysinger - * Remi Gacogne - * Artem Germanov - * Alexander von Gernler - * Diego Giagio - * Artur Grabowski - * Diwaker Gupta - * Kuldeep Gupta - * Sebastian Hahn - * Dave Hart - * Greg Hazel - * Nicholas Heath - * Michael Herf - * Savg He - * Mark Heily - * Maxime Henrion - * Michael Herf - * Greg Hewgill - * Andrew Hochhaus - * Aaron Hopkins - * Tani Hosokawa - * Jamie Iles - * Xiuqiang Jiang - * Claudio Jeker - * Evan Jones - * Marcin Juszkiewicz - * George Kadianakis - * Makoto Kato - * Phua Keat - * Azat Khuzhin - * Alexander Klauer - * Kevin Ko - * Brian Koehmstedt - * Marko Kreen - * OndÅ™ej KuznÃk - * Valery Kyholodov - * Ross Lagerwall - * Scott Lamb - * Christopher Layne - * Adam Langley - * Graham Leggett - * Volker Lendecke - * Philip Lewis - * Zhou Li - * David Libenzi - * Yan Lin - * Moshe Litvin - * Simon Liu - * Mitchell Livingston - * Hagne Mahre - * Lubomir Marinov - * Abilio Marques - * Nicolas Martyanoff - * Abel Mathew - * Nick Mathewson - * James Mansion - * Nicholas Marriott - * Andrey Matveev - * Caitlin Mercer - * Dagobert Michelsen - * Andrea Montefusco - * Mansour Moufid - * Mina Naguib - * Felix Nawothnig - * Trond Norbye - * Linus Nordberg - * Richard Nyberg - * Jon Oberheide - * John Ohl - * Phil Oleson - * Alexey Ozeritsky - * Dave Pacheco - * Derrick Pallas - * Tassilo von Parseval - * Catalin Patulea - * Patrick Pelletier - * Simon Perreault - * Dan Petro - * Pierre Phaneuf - * Amarin Phaosawasdi - * Ryan Phillips - * Dimitre Piskyulev - * Pavel Plesov - * Jon Poland - * Roman Puls - * Nate R - * Robert Ransom - * Balint Reczey - * Bert JW Regeer - * Nate Rosenblum - * Peter Rosin - * Maseeb Abdul Qadir - * Wang Qin - * Alex S - * Gyepi Sam - * Hanna Schroeter - * Ralf Schmitt - * Mike Smellie - * Steve Snyder - * Nir Soffer - * Dug Song - * Dongsheng Song - * Hannes Sowa - * Joakim Soderberg - * Joseph Spadavecchia - * Kevin Springborn - * Harlan Stenn - * Andrew Sweeney - * Ferenc Szalai - * Brodie Thiesfield - * Jason Toffaletti - * Brian Utterback - * Gisle Vanem - * Bas Verhoeven - * Constantine Verutin - * Colin Watt - * Zack Weinberg - * Jardel Weyrich - * Jay R. Wren - * Zack Weinberg - * Mobai Zhang - * Alejo - * Alex - * Taral - * propanbutan - * masksqwe - * mmadia - * yangacer - * Andrey Skriabin - * basavesh.as - * billsegall - * Bill Vaughan - * Christopher Wiley - * David Paschich - * Ed Schouten - * Eduardo Panisset - * Jan Heylen - * jer-gentoo - * Joakim Söderberg - * kirillDanshin - * lzmths - * Marcus Sundberg - * Mark Mentovai - * Mattes D - * Matyas Dolak - * Neeraj Badlani - * Nick Mathewson - * Rainer Keller - * Seungmo Koo - * Thomas Bernard - * Xiao Bao Clark - * zeliard - * Zonr Chang - * Kurt Roeckx - * Seven - * Simone Basso - * Vlad Shcherban - * Tim Hentenaar - * Breaker - * johnsonlee - * Philip Prindeville - * Vis Virial - * Andreas Gustafsson - * Andrey Okoshkin - * an-tao - * baixiangcpp - * Bernard Spil - * Bogdan Harjoc - * Carlo Marcelo Arenas Belón - * David Benjamin - * David Disseldorp - * Dmitry Alimov - * Dominic Chen - * dpayne - * ejurgensen - * Fredrik Strupe - * Gonçalo Ribeiro - * James Synge - * Jan Beich - * Jesse Fang - * Jiri Luznicky - * José Luis Millán - * Kiyoshi Aman - * Leo Zhang - * lightningkay - * Luke Dashjr - * Marcin Szewczyk - * Maximilian Brunner - * Maya Rashish - * Murat Demirten - * Nathan French - * Nikolay Edigaryev - * Philip Herron - * Redfoxmoon - * stenn - * SuckShit - * The Gitter Badger - * tim-le - * Vincent JARDIN - * Xiang Zhang - * Xiaozhou Liu - * yongqing.jiao - * Enji Cooper - * linxiaohui - * Seong-Joong Kim - * Tobias Stoeckmann - * Yury Korzhetsky - * zhuizhuhaomeng - * Pierce Lopez - * yuangongji - * Keith Smiley - * jeremyerb - * Fabrice Fontaine - * wenyg +<p align="center"> + <img src="https://strcpy.net/libevent3.png" alt="libevent logo"/> +</p> + + + +[![Appveyor Win32 Build Status](https://ci.appveyor.com/api/projects/status/ng3jg0uhy44mp7ik?svg=true)](https://ci.appveyor.com/project/libevent/libevent) +[![Travis Build Status](https://travis-ci.org/libevent/libevent.svg?branch=master)](https://travis-ci.org/libevent/libevent) +[![Coverage Status](https://coveralls.io/repos/github/libevent/libevent/badge.svg)](https://coveralls.io/github/libevent/libevent) +[![Join the chat at https://gitter.im/libevent/libevent](https://badges.gitter.im/libevent/libevent.svg)](https://gitter.im/libevent/libevent?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + + + +# 0. BUILDING AND INSTALLATION (Briefly) + +## Autoconf + + $ ./configure + $ make + $ make verify # (optional) + $ sudo make install + +## CMake (General) + + +The following Libevent specific CMake variables are as follows (the values being +the default). + +``` +# Type of the library to build (SHARED or STATIC) +# Default is: SHARED for MSVC, otherwise BOTH +EVENT__LIBRARY_TYPE:STRING=DEFAULT + +# Installation directory for CMake files +EVENT_INSTALL_CMAKE_DIR:PATH=lib/cmake/libevent + +# Enable running gcov to get a test coverage report (only works with +# GCC/CLang). Make sure to enable -DCMAKE_BUILD_TYPE=Debug as well. +EVENT__COVERAGE:BOOL=OFF + +# Defines if Libevent should build without the benchmark executables +EVENT__DISABLE_BENCHMARK:BOOL=OFF + +# Define if Libevent should build without support for a debug mode +EVENT__DISABLE_DEBUG_MODE:BOOL=OFF + +# Define if Libevent should not allow replacing the mm functions +EVENT__DISABLE_MM_REPLACEMENT:BOOL=OFF + +# Define if Libevent should build without support for OpenSSL encryption +EVENT__DISABLE_OPENSSL:BOOL=OFF + +# Disable the regress tests +EVENT__DISABLE_REGRESS:BOOL=OFF + +# Disable sample files +EVENT__DISABLE_SAMPLES:BOOL=OFF + +# If tests should be compiled or not +EVENT__DISABLE_TESTS:BOOL=OFF + +# Define if Libevent should not be compiled with thread support +EVENT__DISABLE_THREAD_SUPPORT:BOOL=OFF + +# Enables verbose debugging +EVENT__ENABLE_VERBOSE_DEBUG:BOOL=OFF + +# When cross compiling, forces running a test program that verifies that Kqueue +# works with pipes. Note that this requires you to manually run the test program +# on the the cross compilation target to verify that it works. See CMake +# documentation for try_run for more details +EVENT__FORCE_KQUEUE_CHECK:BOOL=OFF +``` + +__More variables can be found by running `cmake -LAH <sourcedir_path>`__ + + +## CMake (Windows) + +Install CMake: <https://www.cmake.org> + + + $ md build && cd build + $ cmake -G "Visual Studio 10" .. # Or whatever generator you want to use cmake --help for a list. + $ start libevent.sln + +## CMake (Unix) + + $ mkdir build && cd build + $ cmake .. # Default to Unix Makefiles. + $ make + $ make verify # (optional) + + +# 1. BUILDING AND INSTALLATION (In Depth) + +## Autoconf + +To build Libevent, type + + $ ./configure && make + + + (If you got Libevent from the git repository, you will + first need to run the included "autogen.sh" script in order to + generate the configure script.) + +You can run the regression tests by running + + $ make verify + +Install as root via + + $ make install + +Before reporting any problems, please run the regression tests. + +To enable low-level tracing, build the library as: + + $ CFLAGS=-DUSE_DEBUG ./configure [...] + +Standard configure flags should work. In particular, see: + + --disable-shared Only build static libraries. + --prefix Install all files relative to this directory. + + +The configure script also supports the following flags: + + --enable-gcc-warnings Enable extra compiler checking with GCC. + --disable-malloc-replacement + Don't let applications replace our memory + management functions. + --disable-openssl Disable support for OpenSSL encryption. + --disable-thread-support Don't support multithreaded environments. + +## CMake (Windows) + +(Note that autoconf is currently the most mature and supported build +environment for Libevent; the CMake instructions here are new and +experimental, though they _should_ be solid. We hope that CMake will +still be supported in future versions of Libevent, and will try to +make sure that happens.) + +First of all install <https://www.cmake.org>. + +To build Libevent using Microsoft Visual studio open the "Visual Studio Command prompt" and type: + +``` +$ cd <libevent source dir> +$ mkdir build && cd build +$ cmake -G "Visual Studio 10" .. # Or whatever generator you want to use cmake --help for a list. +$ start libevent.sln +``` + +In the above, the ".." refers to the dir containing the Libevent source code. +You can build multiple versions (with different compile time settings) from the same source tree +by creating other build directories. + +It is highly recommended to build "out of source" when using +CMake instead of "in source" like the normal behaviour of autoconf for this reason. + +The "NMake Makefiles" CMake generator can be used to build entirely via the command line. + +To get a list of settings available for the project you can type: + +``` +$ cmake -LH .. +``` + +### GUI + +CMake also provides a GUI that lets you specify the source directory and output (binary) directory +that the build should be placed in. + +# 2. USEFUL LINKS: + +For the latest released version of Libevent, see the official website at +<http://libevent.org/> . + +There's a pretty good work-in-progress manual up at + <http://www.wangafu.net/~nickm/libevent-book/> . + +For the latest development versions of Libevent, access our Git repository +via + +``` +$ git clone https://github.com/libevent/libevent.git +``` + +You can browse the git repository online at: + +<https://github.com/libevent/libevent> + +To report bugs, issues, or ask for new features: + +__Patches__: https://github.com/libevent/libevent/pulls +> OK, those are not really _patches_. You fork, modify, and hit the "Create Pull Request" button. +> You can still submit normal git patches via the mailing list. + +__Bugs, Features [RFC], and Issues__: https://github.com/libevent/libevent/issues +> Or you can do it via the mailing list. + +There's also a libevent-users mailing list for talking about Libevent +use and development: + +<http://archives.seul.org/libevent/users/> + +# 3. ACKNOWLEDGMENTS + +The following people have helped with suggestions, ideas, code or +fixing bugs: + + * Samy Al Bahra + * Antony Antony + * Jacob Appelbaum + * Arno Bakker + * Weston Andros Adamson + * William Ahern + * Ivan Andropov + * Sergey Avseyev + * Avi Bab + * Joachim Bauch + * Andrey Belobrov + * Gilad Benjamini + * Stas Bekman + * Denis Bilenko + * Julien Blache + * Kevin Bowling + * Tomash Brechko + * Kelly Brock + * Ralph Castain + * Adrian Chadd + * Lawnstein Chan + * Shuo Chen + * Ka-Hing Cheung + * Andrew Cox + * Paul Croome + * George Danchev + * Andrew Danforth + * Ed Day + * Christopher Davis + * Mike Davis + * Frank Denis + * Antony Dovgal + * Mihai Draghicioiu + * Alexander Drozdov + * Mark Ellzey + * Shie Erlich + * Leonid Evdokimov + * Juan Pablo Fernandez + * Christophe Fillot + * Mike Frysinger + * Remi Gacogne + * Artem Germanov + * Alexander von Gernler + * Diego Giagio + * Artur Grabowski + * Diwaker Gupta + * Kuldeep Gupta + * Sebastian Hahn + * Dave Hart + * Greg Hazel + * Nicholas Heath + * Michael Herf + * Savg He + * Mark Heily + * Maxime Henrion + * Michael Herf + * Greg Hewgill + * Andrew Hochhaus + * Aaron Hopkins + * Tani Hosokawa + * Jamie Iles + * Xiuqiang Jiang + * Claudio Jeker + * Evan Jones + * Marcin Juszkiewicz + * George Kadianakis + * Makoto Kato + * Phua Keat + * Azat Khuzhin + * Alexander Klauer + * Kevin Ko + * Brian Koehmstedt + * Marko Kreen + * OndÅ™ej KuznÃk + * Valery Kyholodov + * Ross Lagerwall + * Scott Lamb + * Christopher Layne + * Adam Langley + * Graham Leggett + * Volker Lendecke + * Philip Lewis + * Zhou Li + * David Libenzi + * Yan Lin + * Moshe Litvin + * Simon Liu + * Mitchell Livingston + * Hagne Mahre + * Lubomir Marinov + * Abilio Marques + * Nicolas Martyanoff + * Abel Mathew + * Nick Mathewson + * James Mansion + * Nicholas Marriott + * Andrey Matveev + * Caitlin Mercer + * Dagobert Michelsen + * Andrea Montefusco + * Mansour Moufid + * Mina Naguib + * Felix Nawothnig + * Trond Norbye + * Linus Nordberg + * Richard Nyberg + * Jon Oberheide + * John Ohl + * Phil Oleson + * Alexey Ozeritsky + * Dave Pacheco + * Derrick Pallas + * Tassilo von Parseval + * Catalin Patulea + * Patrick Pelletier + * Simon Perreault + * Dan Petro + * Pierre Phaneuf + * Amarin Phaosawasdi + * Ryan Phillips + * Dimitre Piskyulev + * Pavel Plesov + * Jon Poland + * Roman Puls + * Nate R + * Robert Ransom + * Balint Reczey + * Bert JW Regeer + * Nate Rosenblum + * Peter Rosin + * Maseeb Abdul Qadir + * Wang Qin + * Alex S + * Gyepi Sam + * Hanna Schroeter + * Ralf Schmitt + * Mike Smellie + * Steve Snyder + * Nir Soffer + * Dug Song + * Dongsheng Song + * Hannes Sowa + * Joakim Soderberg + * Joseph Spadavecchia + * Kevin Springborn + * Harlan Stenn + * Andrew Sweeney + * Ferenc Szalai + * Brodie Thiesfield + * Jason Toffaletti + * Brian Utterback + * Gisle Vanem + * Bas Verhoeven + * Constantine Verutin + * Colin Watt + * Zack Weinberg + * Jardel Weyrich + * Jay R. Wren + * Zack Weinberg + * Mobai Zhang + * Alejo + * Alex + * Taral + * propanbutan + * masksqwe + * mmadia + * yangacer + * Andrey Skriabin + * basavesh.as + * billsegall + * Bill Vaughan + * Christopher Wiley + * David Paschich + * Ed Schouten + * Eduardo Panisset + * Jan Heylen + * jer-gentoo + * Joakim Söderberg + * kirillDanshin + * lzmths + * Marcus Sundberg + * Mark Mentovai + * Mattes D + * Matyas Dolak + * Neeraj Badlani + * Nick Mathewson + * Rainer Keller + * Seungmo Koo + * Thomas Bernard + * Xiao Bao Clark + * zeliard + * Zonr Chang + * Kurt Roeckx + * Seven + * Simone Basso + * Vlad Shcherban + * Tim Hentenaar + * Breaker + * johnsonlee + * Philip Prindeville + * Vis Virial + * Andreas Gustafsson + * Andrey Okoshkin + * an-tao + * baixiangcpp + * Bernard Spil + * Bogdan Harjoc + * Carlo Marcelo Arenas Belón + * David Benjamin + * David Disseldorp + * Dmitry Alimov + * Dominic Chen + * dpayne + * ejurgensen + * Fredrik Strupe + * Gonçalo Ribeiro + * James Synge + * Jan Beich + * Jesse Fang + * Jiri Luznicky + * José Luis Millán + * Kiyoshi Aman + * Leo Zhang + * lightningkay + * Luke Dashjr + * Marcin Szewczyk + * Maximilian Brunner + * Maya Rashish + * Murat Demirten + * Nathan French + * Nikolay Edigaryev + * Philip Herron + * Redfoxmoon + * stenn + * SuckShit + * The Gitter Badger + * tim-le + * Vincent JARDIN + * Xiang Zhang + * Xiaozhou Liu + * yongqing.jiao + * Enji Cooper + * linxiaohui + * Seong-Joong Kim + * Tobias Stoeckmann + * Yury Korzhetsky + * zhuizhuhaomeng + * Pierce Lopez + * yuangongji + * Keith Smiley + * jeremyerb + * Fabrice Fontaine + * wenyg * Aleksandr-Melnikov * ayuseleznev * chenguolong @@ -482,6 +482,6 @@ fixing bugs: * Wataru Ashihara * William A Rowe Jr * yangyongsheng - - -If we have forgotten your name, please contact us. + + +If we have forgotten your name, please contact us. diff --git a/contrib/libs/libevent/arc4random.c b/contrib/libs/libevent/arc4random.c index 8729f6b92f..e8fbd1661f 100644 --- a/contrib/libs/libevent/arc4random.c +++ b/contrib/libs/libevent/arc4random.c @@ -50,17 +50,17 @@ #endif #ifndef ARC4RANDOM_NO_INCLUDES -#include "evconfig-private.h" -#ifdef _WIN32 +#include "evconfig-private.h" +#ifdef _WIN32 #include <wincrypt.h> #include <process.h> -#include <winerror.h> +#include <winerror.h> #else #include <fcntl.h> #include <unistd.h> #include <sys/param.h> #include <sys/time.h> -#ifdef EVENT__HAVE_SYS_SYSCTL_H +#ifdef EVENT__HAVE_SYS_SYSCTL_H #include <sys/sysctl.h> #endif #ifdef EVENT__HAVE_SYS_RANDOM_H @@ -84,7 +84,7 @@ struct arc4_stream { unsigned char s[256]; }; -#ifdef _WIN32 +#ifdef _WIN32 #define getpid _getpid #define pid_t int #endif @@ -124,7 +124,7 @@ arc4_addrandom(const unsigned char *dat, int datlen) rs.j = rs.i; } -#ifndef _WIN32 +#ifndef _WIN32 static ssize_t read_all(int fd, unsigned char *buf, size_t count) { @@ -144,7 +144,7 @@ read_all(int fd, unsigned char *buf, size_t count) } #endif -#ifdef _WIN32 +#ifdef _WIN32 #define TRY_SEED_WIN32 static int arc4_seed_win32(void) @@ -202,7 +202,7 @@ arc4_seed_getrandom(void) #endif /* EVENT__HAVE_GETRANDOM */ #if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL) -#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_ARND +#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_ARND #define TRY_SEED_SYSCTL_BSD static int arc4_seed_sysctl_bsd(void) @@ -240,7 +240,7 @@ arc4_seed_sysctl_bsd(void) return 0; } #endif -#endif /* defined(EVENT__HAVE_SYS_SYSCTL_H) */ +#endif /* defined(EVENT__HAVE_SYS_SYSCTL_H) */ #ifdef __linux__ #define TRY_SEED_PROC_SYS_KERNEL_RANDOM_UUID @@ -256,7 +256,7 @@ arc4_seed_proc_sys_kernel_random_uuid(void) unsigned char entropy[64]; int bytes, n, i, nybbles; for (bytes = 0; bytes<ADD_ENTROPY; ) { - fd = evutil_open_closeonexec_("/proc/sys/kernel/random/uuid", O_RDONLY, 0); + fd = evutil_open_closeonexec_("/proc/sys/kernel/random/uuid", O_RDONLY, 0); if (fd < 0) return -1; n = read(fd, buf, sizeof(buf)); @@ -265,8 +265,8 @@ arc4_seed_proc_sys_kernel_random_uuid(void) return -1; memset(entropy, 0, sizeof(entropy)); for (i=nybbles=0; i<n; ++i) { - if (EVUTIL_ISXDIGIT_(buf[i])) { - int nyb = evutil_hex_char_to_int_(buf[i]); + if (EVUTIL_ISXDIGIT_(buf[i])) { + int nyb = evutil_hex_char_to_int_(buf[i]); if (nybbles & 1) { entropy[nybbles/2] |= nyb; } else { @@ -286,7 +286,7 @@ arc4_seed_proc_sys_kernel_random_uuid(void) } #endif -#ifndef _WIN32 +#ifndef _WIN32 #define TRY_SEED_URANDOM static char *arc4random_urandom_filename = NULL; @@ -296,7 +296,7 @@ static int arc4_seed_urandom_helper_(const char *fname) int fd; size_t n; - fd = evutil_open_closeonexec_(fname, O_RDONLY, 0); + fd = evutil_open_closeonexec_(fname, O_RDONLY, 0); if (fd<0) return -1; n = read_all(fd, buf, sizeof(buf)); @@ -370,7 +370,7 @@ arc4_stir(void) rs_initialized = 1; } - if (0 != arc4_seed()) + if (0 != arc4_seed()) return -1; /* @@ -444,9 +444,9 @@ ARC4RANDOM_EXPORT int arc4random_stir(void) { int val; - ARC4_LOCK_(); + ARC4_LOCK_(); val = arc4_stir(); - ARC4_UNLOCK_(); + ARC4_UNLOCK_(); return val; } #endif @@ -456,7 +456,7 @@ ARC4RANDOM_EXPORT void arc4random_addrandom(const unsigned char *dat, int datlen) { int j; - ARC4_LOCK_(); + ARC4_LOCK_(); if (!rs_initialized) arc4_stir(); for (j = 0; j < datlen; j += 256) { @@ -466,7 +466,7 @@ arc4random_addrandom(const unsigned char *dat, int datlen) * crazy like passing us all the files in /var/log. */ arc4_addrandom(dat + j, datlen - j); } - ARC4_UNLOCK_(); + ARC4_UNLOCK_(); } #endif @@ -475,27 +475,27 @@ ARC4RANDOM_EXPORT ARC4RANDOM_UINT32 arc4random(void) { ARC4RANDOM_UINT32 val; - ARC4_LOCK_(); + ARC4_LOCK_(); arc4_count -= 4; arc4_stir_if_needed(); val = arc4_getword(); - ARC4_UNLOCK_(); + ARC4_UNLOCK_(); return val; } #endif ARC4RANDOM_EXPORT void -arc4random_buf(void *buf_, size_t n) +arc4random_buf(void *buf_, size_t n) { - unsigned char *buf = buf_; - ARC4_LOCK_(); + unsigned char *buf = buf_; + ARC4_LOCK_(); arc4_stir_if_needed(); while (n--) { if (--arc4_count <= 0) arc4_stir(); buf[n] = arc4_getbyte(); } - ARC4_UNLOCK_(); + ARC4_UNLOCK_(); } #ifndef ARC4RANDOM_NOUNIFORM diff --git a/contrib/libs/libevent/buffer.c b/contrib/libs/libevent/buffer.c index 3524b3504d..9714b59ae9 100644 --- a/contrib/libs/libevent/buffer.c +++ b/contrib/libs/libevent/buffer.c @@ -26,58 +26,58 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #include <windows.h> #include <io.h> #endif -#ifdef EVENT__HAVE_VASPRINTF -/* If we have vasprintf, we need to define _GNU_SOURCE before we include - * stdio.h. This comes from evconfig-private.h. - */ -#endif - +#ifdef EVENT__HAVE_VASPRINTF +/* If we have vasprintf, we need to define _GNU_SOURCE before we include + * stdio.h. This comes from evconfig-private.h. + */ +#endif + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif -#ifdef EVENT__HAVE_SYS_UIO_H +#ifdef EVENT__HAVE_SYS_UIO_H #include <sys/uio.h> #endif -#ifdef EVENT__HAVE_SYS_IOCTL_H +#ifdef EVENT__HAVE_SYS_IOCTL_H #include <sys/ioctl.h> #endif -#ifdef EVENT__HAVE_SYS_MMAN_H +#ifdef EVENT__HAVE_SYS_MMAN_H #include <sys/mman.h> #endif -#ifdef EVENT__HAVE_SYS_SENDFILE_H +#ifdef EVENT__HAVE_SYS_SENDFILE_H #include <sys/sendfile.h> #endif -#ifdef EVENT__HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif - +#ifdef EVENT__HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_STDARG_H +#ifdef EVENT__HAVE_STDARG_H #include <stdarg.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif #include <limits.h> @@ -95,7 +95,7 @@ #include "evthread-internal.h" #include "evbuffer-internal.h" #include "bufferevent-internal.h" -#include "event-internal.h" +#include "event-internal.h" /* some systems do not have MAP_FAILED */ #ifndef MAP_FAILED @@ -103,16 +103,16 @@ #endif /* send file support */ -#if defined(EVENT__HAVE_SYS_SENDFILE_H) && defined(EVENT__HAVE_SENDFILE) && defined(__linux__) +#if defined(EVENT__HAVE_SYS_SENDFILE_H) && defined(EVENT__HAVE_SENDFILE) && defined(__linux__) #define USE_SENDFILE 1 #define SENDFILE_IS_LINUX 1 -#elif defined(EVENT__HAVE_SENDFILE) && defined(__FreeBSD__) +#elif defined(EVENT__HAVE_SENDFILE) && defined(__FreeBSD__) #define USE_SENDFILE 1 #define SENDFILE_IS_FREEBSD 1 -#elif defined(EVENT__HAVE_SENDFILE) && defined(__APPLE__) +#elif defined(EVENT__HAVE_SENDFILE) && defined(__APPLE__) #define USE_SENDFILE 1 #define SENDFILE_IS_MACOSX 1 -#elif defined(EVENT__HAVE_SENDFILE) && defined(__sun__) && defined(__svr4__) +#elif defined(EVENT__HAVE_SENDFILE) && defined(__sun__) && defined(__svr4__) #define USE_SENDFILE 1 #define SENDFILE_IS_SOLARIS 1 #endif @@ -133,25 +133,25 @@ #define CHAIN_PINNED(ch) (((ch)->flags & EVBUFFER_MEM_PINNED_ANY) != 0) #define CHAIN_PINNED_R(ch) (((ch)->flags & EVBUFFER_MEM_PINNED_R) != 0) -/* evbuffer_ptr support */ -#define PTR_NOT_FOUND(ptr) do { \ - (ptr)->pos = -1; \ - (ptr)->internal_.chain = NULL; \ - (ptr)->internal_.pos_in_chain = 0; \ -} while (0) - +/* evbuffer_ptr support */ +#define PTR_NOT_FOUND(ptr) do { \ + (ptr)->pos = -1; \ + (ptr)->internal_.chain = NULL; \ + (ptr)->internal_.pos_in_chain = 0; \ +} while (0) + static void evbuffer_chain_align(struct evbuffer_chain *chain); static int evbuffer_chain_should_realign(struct evbuffer_chain *chain, size_t datalen); -static void evbuffer_deferred_callback(struct event_callback *cb, void *arg); +static void evbuffer_deferred_callback(struct event_callback *cb, void *arg); static int evbuffer_ptr_memcmp(const struct evbuffer *buf, const struct evbuffer_ptr *pos, const char *mem, size_t len); static struct evbuffer_chain *evbuffer_expand_singlechain(struct evbuffer *buf, size_t datlen); -static int evbuffer_ptr_subtract(struct evbuffer *buf, struct evbuffer_ptr *pos, - size_t howfar); -static int evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg); -static inline void evbuffer_chain_incref(struct evbuffer_chain *chain); +static int evbuffer_ptr_subtract(struct evbuffer *buf, struct evbuffer_ptr *pos, + size_t howfar); +static int evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg); +static inline void evbuffer_chain_incref(struct evbuffer_chain *chain); static struct evbuffer_chain * evbuffer_chain_new(size_t size) @@ -185,69 +185,69 @@ evbuffer_chain_new(size_t size) /* this way we can manipulate the buffer to different addresses, * which is required for mmap for example. */ - chain->buffer = EVBUFFER_CHAIN_EXTRA(unsigned char, chain); - - chain->refcnt = 1; + chain->buffer = EVBUFFER_CHAIN_EXTRA(unsigned char, chain); + chain->refcnt = 1; + return (chain); } static inline void evbuffer_chain_free(struct evbuffer_chain *chain) { - EVUTIL_ASSERT(chain->refcnt > 0); - if (--chain->refcnt > 0) { - /* chain is still referenced by other chains */ - return; - } - + EVUTIL_ASSERT(chain->refcnt > 0); + if (--chain->refcnt > 0) { + /* chain is still referenced by other chains */ + return; + } + if (CHAIN_PINNED(chain)) { - /* will get freed once no longer dangling */ - chain->refcnt++; + /* will get freed once no longer dangling */ + chain->refcnt++; chain->flags |= EVBUFFER_DANGLING; return; } - - /* safe to release chain, it's either a referencing - * chain or all references to it have been freed */ - if (chain->flags & EVBUFFER_REFERENCE) { - struct evbuffer_chain_reference *info = - EVBUFFER_CHAIN_EXTRA( - struct evbuffer_chain_reference, - chain); - if (info->cleanupfn) - (*info->cleanupfn)(chain->buffer, - chain->buffer_len, - info->extra); - } - if (chain->flags & EVBUFFER_FILESEGMENT) { - struct evbuffer_chain_file_segment *info = - EVBUFFER_CHAIN_EXTRA( - struct evbuffer_chain_file_segment, - chain); - if (info->segment) { -#ifdef _WIN32 - if (info->segment->is_mapping) - UnmapViewOfFile(chain->buffer); + + /* safe to release chain, it's either a referencing + * chain or all references to it have been freed */ + if (chain->flags & EVBUFFER_REFERENCE) { + struct evbuffer_chain_reference *info = + EVBUFFER_CHAIN_EXTRA( + struct evbuffer_chain_reference, + chain); + if (info->cleanupfn) + (*info->cleanupfn)(chain->buffer, + chain->buffer_len, + info->extra); + } + if (chain->flags & EVBUFFER_FILESEGMENT) { + struct evbuffer_chain_file_segment *info = + EVBUFFER_CHAIN_EXTRA( + struct evbuffer_chain_file_segment, + chain); + if (info->segment) { +#ifdef _WIN32 + if (info->segment->is_mapping) + UnmapViewOfFile(chain->buffer); #endif - evbuffer_file_segment_free(info->segment); + evbuffer_file_segment_free(info->segment); } } - if (chain->flags & EVBUFFER_MULTICAST) { - struct evbuffer_multicast_parent *info = - EVBUFFER_CHAIN_EXTRA( - struct evbuffer_multicast_parent, - chain); - /* referencing chain is being freed, decrease - * refcounts of source chain and associated - * evbuffer (which get freed once both reach - * zero) */ - EVUTIL_ASSERT(info->source != NULL); - EVUTIL_ASSERT(info->parent != NULL); - EVBUFFER_LOCK(info->source); - evbuffer_chain_free(info->parent); - evbuffer_decref_and_unlock_(info->source); - } + if (chain->flags & EVBUFFER_MULTICAST) { + struct evbuffer_multicast_parent *info = + EVBUFFER_CHAIN_EXTRA( + struct evbuffer_multicast_parent, + chain); + /* referencing chain is being freed, decrease + * refcounts of source chain and associated + * evbuffer (which get freed once both reach + * zero) */ + EVUTIL_ASSERT(info->source != NULL); + EVUTIL_ASSERT(info->parent != NULL); + EVBUFFER_LOCK(info->source); + evbuffer_chain_free(info->parent); + evbuffer_decref_and_unlock_(info->source); + } mm_free(chain); } @@ -316,11 +316,11 @@ evbuffer_chain_insert(struct evbuffer *buf, EVUTIL_ASSERT(buf->first == NULL); buf->first = buf->last = chain; } else { - struct evbuffer_chain **chp; - chp = evbuffer_free_trailing_empty_chains(buf); - *chp = chain; - if (chain->off) - buf->last_with_datap = chp; + struct evbuffer_chain **chp; + chp = evbuffer_free_trailing_empty_chains(buf); + *chp = chain; + if (chain->off) + buf->last_with_datap = chp; buf->last = chain; } buf->total_len += chain->off; @@ -337,14 +337,14 @@ evbuffer_chain_insert_new(struct evbuffer *buf, size_t datlen) } void -evbuffer_chain_pin_(struct evbuffer_chain *chain, unsigned flag) +evbuffer_chain_pin_(struct evbuffer_chain *chain, unsigned flag) { EVUTIL_ASSERT((chain->flags & flag) == 0); chain->flags |= flag; } void -evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag) +evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag) { EVUTIL_ASSERT((chain->flags & flag) != 0); chain->flags &= ~flag; @@ -352,12 +352,12 @@ evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag) evbuffer_chain_free(chain); } -static inline void -evbuffer_chain_incref(struct evbuffer_chain *chain) -{ - ++chain->refcnt; -} - +static inline void +evbuffer_chain_incref(struct evbuffer_chain *chain) +{ + ++chain->refcnt; +} + struct evbuffer * evbuffer_new(void) { @@ -367,7 +367,7 @@ evbuffer_new(void) if (buffer == NULL) return (NULL); - LIST_INIT(&buffer->callbacks); + LIST_INIT(&buffer->callbacks); buffer->refcnt = 1; buffer->last_with_datap = &buffer->first; @@ -393,7 +393,7 @@ evbuffer_clear_flags(struct evbuffer *buf, ev_uint64_t flags) } void -evbuffer_incref_(struct evbuffer *buf) +evbuffer_incref_(struct evbuffer *buf) { EVBUFFER_LOCK(buf); ++buf->refcnt; @@ -401,7 +401,7 @@ evbuffer_incref_(struct evbuffer *buf) } void -evbuffer_incref_and_lock_(struct evbuffer *buf) +evbuffer_incref_and_lock_(struct evbuffer *buf) { EVBUFFER_LOCK(buf); ++buf->refcnt; @@ -411,10 +411,10 @@ int evbuffer_defer_callbacks(struct evbuffer *buffer, struct event_base *base) { EVBUFFER_LOCK(buffer); - buffer->cb_queue = base; + buffer->cb_queue = base; buffer->deferred_cbs = 1; - event_deferred_cb_init_(&buffer->deferred, - event_base_get_npriorities(base) / 2, + event_deferred_cb_init_(&buffer->deferred, + event_base_get_npriorities(base) / 2, evbuffer_deferred_callback, buffer); EVBUFFER_UNLOCK(buffer); return 0; @@ -423,7 +423,7 @@ evbuffer_defer_callbacks(struct evbuffer *buffer, struct event_base *base) int evbuffer_enable_locking(struct evbuffer *buf, void *lock) { -#ifdef EVENT__DISABLE_THREAD_SUPPORT +#ifdef EVENT__DISABLE_THREAD_SUPPORT return -1; #else if (buf->lock) @@ -445,7 +445,7 @@ evbuffer_enable_locking(struct evbuffer *buf, void *lock) } void -evbuffer_set_parent_(struct evbuffer *buf, struct bufferevent *bev) +evbuffer_set_parent_(struct evbuffer *buf, struct bufferevent *bev) { EVBUFFER_LOCK(buf); buf->parent = bev; @@ -477,7 +477,7 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred) ASSERT_EVBUFFER_LOCKED(buffer); - if (LIST_EMPTY(&buffer->callbacks)) { + if (LIST_EMPTY(&buffer->callbacks)) { buffer->n_add_for_cb = buffer->n_del_for_cb = 0; return; } @@ -492,12 +492,12 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred) buffer->n_add_for_cb = 0; buffer->n_del_for_cb = 0; } - for (cbent = LIST_FIRST(&buffer->callbacks); - cbent != LIST_END(&buffer->callbacks); + for (cbent = LIST_FIRST(&buffer->callbacks); + cbent != LIST_END(&buffer->callbacks); cbent = next) { /* Get the 'next' pointer now in case this callback decides * to remove itself or something. */ - next = LIST_NEXT(cbent, next); + next = LIST_NEXT(cbent, next); if ((cbent->flags & mask) != masked_val) continue; @@ -511,27 +511,27 @@ evbuffer_run_callbacks(struct evbuffer *buffer, int running_deferred) } void -evbuffer_invoke_callbacks_(struct evbuffer *buffer) +evbuffer_invoke_callbacks_(struct evbuffer *buffer) { - if (LIST_EMPTY(&buffer->callbacks)) { + if (LIST_EMPTY(&buffer->callbacks)) { buffer->n_add_for_cb = buffer->n_del_for_cb = 0; return; } if (buffer->deferred_cbs) { - if (event_deferred_cb_schedule_(buffer->cb_queue, &buffer->deferred)) { - evbuffer_incref_and_lock_(buffer); - if (buffer->parent) - bufferevent_incref_(buffer->parent); - EVBUFFER_UNLOCK(buffer); - } + if (event_deferred_cb_schedule_(buffer->cb_queue, &buffer->deferred)) { + evbuffer_incref_and_lock_(buffer); + if (buffer->parent) + bufferevent_incref_(buffer->parent); + EVBUFFER_UNLOCK(buffer); + } } evbuffer_run_callbacks(buffer, 0); } static void -evbuffer_deferred_callback(struct event_callback *cb, void *arg) +evbuffer_deferred_callback(struct event_callback *cb, void *arg) { struct bufferevent *parent = NULL; struct evbuffer *buffer = arg; @@ -541,9 +541,9 @@ evbuffer_deferred_callback(struct event_callback *cb, void *arg) EVBUFFER_LOCK(buffer); parent = buffer->parent; evbuffer_run_callbacks(buffer, 1); - evbuffer_decref_and_unlock_(buffer); + evbuffer_decref_and_unlock_(buffer); if (parent) - bufferevent_decref_(parent); + bufferevent_decref_(parent); } static void @@ -551,14 +551,14 @@ evbuffer_remove_all_callbacks(struct evbuffer *buffer) { struct evbuffer_cb_entry *cbent; - while ((cbent = LIST_FIRST(&buffer->callbacks))) { - LIST_REMOVE(cbent, next); - mm_free(cbent); + while ((cbent = LIST_FIRST(&buffer->callbacks))) { + LIST_REMOVE(cbent, next); + mm_free(cbent); } } void -evbuffer_decref_and_unlock_(struct evbuffer *buffer) +evbuffer_decref_and_unlock_(struct evbuffer *buffer) { struct evbuffer_chain *chain, *next; ASSERT_EVBUFFER_LOCKED(buffer); @@ -576,7 +576,7 @@ evbuffer_decref_and_unlock_(struct evbuffer *buffer) } evbuffer_remove_all_callbacks(buffer); if (buffer->deferred_cbs) - event_deferred_cb_cancel_(buffer->cb_queue, &buffer->deferred); + event_deferred_cb_cancel_(buffer->cb_queue, &buffer->deferred); EVBUFFER_UNLOCK(buffer); if (buffer->own_lock) @@ -588,7 +588,7 @@ void evbuffer_free(struct evbuffer *buffer) { EVBUFFER_LOCK(buffer); - evbuffer_decref_and_unlock_(buffer); + evbuffer_decref_and_unlock_(buffer); } void @@ -631,42 +631,42 @@ evbuffer_get_contiguous_space(const struct evbuffer *buf) return result; } -size_t -evbuffer_add_iovec(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec) { - int n; - size_t res; - size_t to_alloc; - - EVBUFFER_LOCK(buf); - - res = to_alloc = 0; - - for (n = 0; n < n_vec; n++) { - to_alloc += vec[n].iov_len; - } - - if (evbuffer_expand_fast_(buf, to_alloc, 2) < 0) { - goto done; - } - - for (n = 0; n < n_vec; n++) { - /* XXX each 'add' call here does a bunch of setup that's - * obviated by evbuffer_expand_fast_, and some cleanup that we - * would like to do only once. Instead we should just extract - * the part of the code that's needed. */ - - if (evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len) < 0) { - goto done; - } - - res += vec[n].iov_len; - } - -done: - EVBUFFER_UNLOCK(buf); - return res; -} - +size_t +evbuffer_add_iovec(struct evbuffer * buf, struct evbuffer_iovec * vec, int n_vec) { + int n; + size_t res; + size_t to_alloc; + + EVBUFFER_LOCK(buf); + + res = to_alloc = 0; + + for (n = 0; n < n_vec; n++) { + to_alloc += vec[n].iov_len; + } + + if (evbuffer_expand_fast_(buf, to_alloc, 2) < 0) { + goto done; + } + + for (n = 0; n < n_vec; n++) { + /* XXX each 'add' call here does a bunch of setup that's + * obviated by evbuffer_expand_fast_, and some cleanup that we + * would like to do only once. Instead we should just extract + * the part of the code that's needed. */ + + if (evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len) < 0) { + goto done; + } + + res += vec[n].iov_len; + } + +done: + EVBUFFER_UNLOCK(buf); + return res; +} + int evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size, struct evbuffer_iovec *vec, int n_vecs) @@ -683,14 +683,14 @@ evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size, if ((chain = evbuffer_expand_singlechain(buf, size)) == NULL) goto done; - vec[0].iov_base = (void *)CHAIN_SPACE_PTR(chain); - vec[0].iov_len = (size_t)CHAIN_SPACE_LEN(chain); + vec[0].iov_base = (void *)CHAIN_SPACE_PTR(chain); + vec[0].iov_len = (size_t)CHAIN_SPACE_LEN(chain); EVUTIL_ASSERT(size<0 || (size_t)vec[0].iov_len >= (size_t)size); n = 1; } else { - if (evbuffer_expand_fast_(buf, size, n_vecs)<0) + if (evbuffer_expand_fast_(buf, size, n_vecs)<0) goto done; - n = evbuffer_read_setup_vecs_(buf, size, vec, n_vecs, + n = evbuffer_read_setup_vecs_(buf, size, vec, n_vecs, &chainp, 0); } @@ -704,17 +704,17 @@ static int advance_last_with_data(struct evbuffer *buf) { int n = 0; - struct evbuffer_chain **chainp = buf->last_with_datap; - + struct evbuffer_chain **chainp = buf->last_with_datap; + ASSERT_EVBUFFER_LOCKED(buf); - if (!*chainp) + if (!*chainp) return 0; - while ((*chainp)->next) { - chainp = &(*chainp)->next; - if ((*chainp)->off) - buf->last_with_datap = chainp; + while ((*chainp)->next) { + chainp = &(*chainp)->next; + if ((*chainp)->off) + buf->last_with_datap = chainp; ++n; } return n; @@ -737,7 +737,7 @@ evbuffer_commit_space(struct evbuffer *buf, result = 0; goto done; } else if (n_vecs == 1 && - (buf->last && vec[0].iov_base == (void *)CHAIN_SPACE_PTR(buf->last))) { + (buf->last && vec[0].iov_base == (void *)CHAIN_SPACE_PTR(buf->last))) { /* The user only got or used one chain; it might not * be the first one with space in it. */ if ((size_t)vec[0].iov_len > (size_t)CHAIN_SPACE_LEN(buf->last)) @@ -763,7 +763,7 @@ evbuffer_commit_space(struct evbuffer *buf, for (i=0; i<n_vecs; ++i) { if (!chain) goto done; - if (vec[i].iov_base != (void *)CHAIN_SPACE_PTR(chain) || + if (vec[i].iov_base != (void *)CHAIN_SPACE_PTR(chain) || (size_t)vec[i].iov_len > CHAIN_SPACE_LEN(chain)) goto done; chain = chain->next; @@ -783,7 +783,7 @@ okay: buf->total_len += added; buf->n_add_for_cb += added; result = 0; - evbuffer_invoke_callbacks_(buf); + evbuffer_invoke_callbacks_(buf); done: EVBUFFER_UNLOCK(buf); @@ -888,62 +888,62 @@ COPY_CHAIN(struct evbuffer *dst, struct evbuffer *src) static void APPEND_CHAIN(struct evbuffer *dst, struct evbuffer *src) { - struct evbuffer_chain **chp; - + struct evbuffer_chain **chp; + ASSERT_EVBUFFER_LOCKED(dst); ASSERT_EVBUFFER_LOCKED(src); - - chp = evbuffer_free_trailing_empty_chains(dst); - *chp = src->first; - + + chp = evbuffer_free_trailing_empty_chains(dst); + *chp = src->first; + if (src->last_with_datap == &src->first) - dst->last_with_datap = chp; + dst->last_with_datap = chp; else dst->last_with_datap = src->last_with_datap; dst->last = src->last; dst->total_len += src->total_len; } -static inline void -APPEND_CHAIN_MULTICAST(struct evbuffer *dst, struct evbuffer *src) -{ - struct evbuffer_chain *tmp; - struct evbuffer_chain *chain = src->first; - struct evbuffer_multicast_parent *extra; - - ASSERT_EVBUFFER_LOCKED(dst); - ASSERT_EVBUFFER_LOCKED(src); - - for (; chain; chain = chain->next) { - if (!chain->off || chain->flags & EVBUFFER_DANGLING) { - /* skip empty chains */ - continue; - } - - tmp = evbuffer_chain_new(sizeof(struct evbuffer_multicast_parent)); - if (!tmp) { - event_warn("%s: out of memory", __func__); - return; - } - extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_multicast_parent, tmp); - /* reference evbuffer containing source chain so it - * doesn't get released while the chain is still - * being referenced to */ - evbuffer_incref_(src); - extra->source = src; - /* reference source chain which now becomes immutable */ - evbuffer_chain_incref(chain); - extra->parent = chain; - chain->flags |= EVBUFFER_IMMUTABLE; - tmp->buffer_len = chain->buffer_len; - tmp->misalign = chain->misalign; - tmp->off = chain->off; - tmp->flags |= EVBUFFER_MULTICAST|EVBUFFER_IMMUTABLE; - tmp->buffer = chain->buffer; - evbuffer_chain_insert(dst, tmp); - } -} - +static inline void +APPEND_CHAIN_MULTICAST(struct evbuffer *dst, struct evbuffer *src) +{ + struct evbuffer_chain *tmp; + struct evbuffer_chain *chain = src->first; + struct evbuffer_multicast_parent *extra; + + ASSERT_EVBUFFER_LOCKED(dst); + ASSERT_EVBUFFER_LOCKED(src); + + for (; chain; chain = chain->next) { + if (!chain->off || chain->flags & EVBUFFER_DANGLING) { + /* skip empty chains */ + continue; + } + + tmp = evbuffer_chain_new(sizeof(struct evbuffer_multicast_parent)); + if (!tmp) { + event_warn("%s: out of memory", __func__); + return; + } + extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_multicast_parent, tmp); + /* reference evbuffer containing source chain so it + * doesn't get released while the chain is still + * being referenced to */ + evbuffer_incref_(src); + extra->source = src; + /* reference source chain which now becomes immutable */ + evbuffer_chain_incref(chain); + extra->parent = chain; + chain->flags |= EVBUFFER_IMMUTABLE; + tmp->buffer_len = chain->buffer_len; + tmp->misalign = chain->misalign; + tmp->off = chain->off; + tmp->flags |= EVBUFFER_MULTICAST|EVBUFFER_IMMUTABLE; + tmp->buffer = chain->buffer; + evbuffer_chain_insert(dst, tmp); + } +} + static void PREPEND_CHAIN(struct evbuffer *dst, struct evbuffer *src) { @@ -1000,51 +1000,8 @@ evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf) inbuf->n_del_for_cb += in_total_len; outbuf->n_add_for_cb += in_total_len; - evbuffer_invoke_callbacks_(inbuf); - evbuffer_invoke_callbacks_(outbuf); - -done: - EVBUFFER_UNLOCK2(inbuf, outbuf); - return result; -} - -int -evbuffer_add_buffer_reference(struct evbuffer *outbuf, struct evbuffer *inbuf) -{ - size_t in_total_len, out_total_len; - struct evbuffer_chain *chain; - int result = 0; - - EVBUFFER_LOCK2(inbuf, outbuf); - in_total_len = inbuf->total_len; - out_total_len = outbuf->total_len; - chain = inbuf->first; - - if (in_total_len == 0) - goto done; - - if (outbuf->freeze_end || outbuf == inbuf) { - result = -1; - goto done; - } - - for (; chain; chain = chain->next) { - if ((chain->flags & (EVBUFFER_FILESEGMENT|EVBUFFER_SENDFILE|EVBUFFER_MULTICAST)) != 0) { - /* chain type can not be referenced */ - result = -1; - goto done; - } - } - - if (out_total_len == 0) { - /* There might be an empty chain at the start of outbuf; free - * it. */ - evbuffer_free_all_chains(outbuf->first); - } - APPEND_CHAIN_MULTICAST(outbuf, inbuf); - - outbuf->n_add_for_cb += in_total_len; - evbuffer_invoke_callbacks_(outbuf); + evbuffer_invoke_callbacks_(inbuf); + evbuffer_invoke_callbacks_(outbuf); done: EVBUFFER_UNLOCK2(inbuf, outbuf); @@ -1052,6 +1009,49 @@ done: } int +evbuffer_add_buffer_reference(struct evbuffer *outbuf, struct evbuffer *inbuf) +{ + size_t in_total_len, out_total_len; + struct evbuffer_chain *chain; + int result = 0; + + EVBUFFER_LOCK2(inbuf, outbuf); + in_total_len = inbuf->total_len; + out_total_len = outbuf->total_len; + chain = inbuf->first; + + if (in_total_len == 0) + goto done; + + if (outbuf->freeze_end || outbuf == inbuf) { + result = -1; + goto done; + } + + for (; chain; chain = chain->next) { + if ((chain->flags & (EVBUFFER_FILESEGMENT|EVBUFFER_SENDFILE|EVBUFFER_MULTICAST)) != 0) { + /* chain type can not be referenced */ + result = -1; + goto done; + } + } + + if (out_total_len == 0) { + /* There might be an empty chain at the start of outbuf; free + * it. */ + evbuffer_free_all_chains(outbuf->first); + } + APPEND_CHAIN_MULTICAST(outbuf, inbuf); + + outbuf->n_add_for_cb += in_total_len; + evbuffer_invoke_callbacks_(outbuf); + +done: + EVBUFFER_UNLOCK2(inbuf, outbuf); + return result; +} + +int evbuffer_prepend_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf) { struct evbuffer_chain *pinned, *last; @@ -1090,8 +1090,8 @@ evbuffer_prepend_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf) inbuf->n_del_for_cb += in_total_len; outbuf->n_add_for_cb += in_total_len; - evbuffer_invoke_callbacks_(inbuf); - evbuffer_invoke_callbacks_(outbuf); + evbuffer_invoke_callbacks_(inbuf); + evbuffer_invoke_callbacks_(outbuf); done: EVBUFFER_UNLOCK2(inbuf, outbuf); return result; @@ -1151,14 +1151,14 @@ evbuffer_drain(struct evbuffer *buf, size_t len) } buf->first = chain; - EVUTIL_ASSERT(remaining <= chain->off); - chain->misalign += remaining; - chain->off -= remaining; + EVUTIL_ASSERT(remaining <= chain->off); + chain->misalign += remaining; + chain->off -= remaining; } buf->n_del_for_cb += len; /* Tell someone about changes in this buffer */ - evbuffer_invoke_callbacks_(buf); + evbuffer_invoke_callbacks_(buf); done: EVBUFFER_UNLOCK(buf); @@ -1171,7 +1171,7 @@ evbuffer_remove(struct evbuffer *buf, void *data_out, size_t datlen) { ev_ssize_t n; EVBUFFER_LOCK(buf); - n = evbuffer_copyout_from(buf, NULL, data_out, datlen); + n = evbuffer_copyout_from(buf, NULL, data_out, datlen); if (n > 0) { if (evbuffer_drain(buf, n)<0) n = -1; @@ -1183,37 +1183,37 @@ evbuffer_remove(struct evbuffer *buf, void *data_out, size_t datlen) ev_ssize_t evbuffer_copyout(struct evbuffer *buf, void *data_out, size_t datlen) { - return evbuffer_copyout_from(buf, NULL, data_out, datlen); -} - -ev_ssize_t -evbuffer_copyout_from(struct evbuffer *buf, const struct evbuffer_ptr *pos, - void *data_out, size_t datlen) -{ + return evbuffer_copyout_from(buf, NULL, data_out, datlen); +} + +ev_ssize_t +evbuffer_copyout_from(struct evbuffer *buf, const struct evbuffer_ptr *pos, + void *data_out, size_t datlen) +{ /*XXX fails badly on sendfile case. */ struct evbuffer_chain *chain; char *data = data_out; size_t nread; ev_ssize_t result = 0; - size_t pos_in_chain; + size_t pos_in_chain; EVBUFFER_LOCK(buf); - if (pos) { - if (datlen > (size_t)(EV_SSIZE_MAX - pos->pos)) { - result = -1; - goto done; - } - chain = pos->internal_.chain; - pos_in_chain = pos->internal_.pos_in_chain; - if (datlen + pos->pos > buf->total_len) - datlen = buf->total_len - pos->pos; - } else { - chain = buf->first; - pos_in_chain = 0; - if (datlen > buf->total_len) - datlen = buf->total_len; - } + if (pos) { + if (datlen > (size_t)(EV_SSIZE_MAX - pos->pos)) { + result = -1; + goto done; + } + chain = pos->internal_.chain; + pos_in_chain = pos->internal_.pos_in_chain; + if (datlen + pos->pos > buf->total_len) + datlen = buf->total_len - pos->pos; + } else { + chain = buf->first; + pos_in_chain = 0; + if (datlen > buf->total_len) + datlen = buf->total_len; + } if (datlen == 0) @@ -1226,25 +1226,25 @@ evbuffer_copyout_from(struct evbuffer *buf, const struct evbuffer_ptr *pos, nread = datlen; - while (datlen && datlen >= chain->off - pos_in_chain) { - size_t copylen = chain->off - pos_in_chain; - memcpy(data, - chain->buffer + chain->misalign + pos_in_chain, - copylen); - data += copylen; - datlen -= copylen; + while (datlen && datlen >= chain->off - pos_in_chain) { + size_t copylen = chain->off - pos_in_chain; + memcpy(data, + chain->buffer + chain->misalign + pos_in_chain, + copylen); + data += copylen; + datlen -= copylen; chain = chain->next; - pos_in_chain = 0; + pos_in_chain = 0; EVUTIL_ASSERT(chain || datlen==0); } if (datlen) { EVUTIL_ASSERT(chain); - EVUTIL_ASSERT(datlen+pos_in_chain <= chain->off); - - memcpy(data, chain->buffer + chain->misalign + pos_in_chain, - datlen); + EVUTIL_ASSERT(datlen+pos_in_chain <= chain->off); + + memcpy(data, chain->buffer + chain->misalign + pos_in_chain, + datlen); } result = nread; @@ -1303,7 +1303,7 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst, chain = chain->next; } - if (chain != src->first) { + if (chain != src->first) { /* we can remove the chain */ struct evbuffer_chain **chp; chp = evbuffer_free_trailing_empty_chains(dst); @@ -1336,8 +1336,8 @@ evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst, src->n_del_for_cb += nread; if (nread) { - evbuffer_invoke_callbacks_(dst); - evbuffer_invoke_callbacks_(src); + evbuffer_invoke_callbacks_(dst); + evbuffer_invoke_callbacks_(src); } result = (int)nread;/*XXXX should change return type */ @@ -1473,14 +1473,14 @@ evbuffer_readline(struct evbuffer *buffer) static inline ev_ssize_t evbuffer_strchr(struct evbuffer_ptr *it, const char chr) { - struct evbuffer_chain *chain = it->internal_.chain; - size_t i = it->internal_.pos_in_chain; + struct evbuffer_chain *chain = it->internal_.chain; + size_t i = it->internal_.pos_in_chain; while (chain != NULL) { char *buffer = (char *)chain->buffer + chain->misalign; char *cp = memchr(buffer+i, chr, chain->off-i); if (cp) { - it->internal_.chain = chain; - it->internal_.pos_in_chain = cp - buffer; + it->internal_.chain = chain; + it->internal_.pos_in_chain = cp - buffer; it->pos += (cp - buffer - i); return it->pos; } @@ -1522,14 +1522,14 @@ find_eol_char(char *s, size_t len) static ev_ssize_t evbuffer_find_eol_char(struct evbuffer_ptr *it) { - struct evbuffer_chain *chain = it->internal_.chain; - size_t i = it->internal_.pos_in_chain; + struct evbuffer_chain *chain = it->internal_.chain; + size_t i = it->internal_.pos_in_chain; while (chain != NULL) { char *buffer = (char *)chain->buffer + chain->misalign; char *cp = find_eol_char(buffer+i, chain->off-i); if (cp) { - it->internal_.chain = chain; - it->internal_.pos_in_chain = cp - buffer; + it->internal_.chain = chain; + it->internal_.pos_in_chain = cp - buffer; it->pos += (cp - buffer) - i; return it->pos; } @@ -1541,16 +1541,16 @@ evbuffer_find_eol_char(struct evbuffer_ptr *it) return (-1); } -static inline size_t +static inline size_t evbuffer_strspn( struct evbuffer_ptr *ptr, const char *chrset) { - size_t count = 0; - struct evbuffer_chain *chain = ptr->internal_.chain; - size_t i = ptr->internal_.pos_in_chain; + size_t count = 0; + struct evbuffer_chain *chain = ptr->internal_.chain; + size_t i = ptr->internal_.pos_in_chain; if (!chain) - return 0; + return 0; while (1) { char *buffer = (char *)chain->buffer + chain->misalign; @@ -1560,8 +1560,8 @@ evbuffer_strspn( if (buffer[i] == *p++) goto next; } - ptr->internal_.chain = chain; - ptr->internal_.pos_in_chain = i; + ptr->internal_.chain = chain; + ptr->internal_.pos_in_chain = i; ptr->pos += count; return count; next: @@ -1570,8 +1570,8 @@ evbuffer_strspn( i = 0; if (! chain->next) { - ptr->internal_.chain = chain; - ptr->internal_.pos_in_chain = i; + ptr->internal_.chain = chain; + ptr->internal_.pos_in_chain = i; ptr->pos += count; return count; } @@ -1581,16 +1581,16 @@ evbuffer_strspn( } -static inline int +static inline int evbuffer_getchr(struct evbuffer_ptr *it) { - struct evbuffer_chain *chain = it->internal_.chain; - size_t off = it->internal_.pos_in_chain; + struct evbuffer_chain *chain = it->internal_.chain; + size_t off = it->internal_.pos_in_chain; - if (chain == NULL) - return -1; - - return (unsigned char)chain->buffer[chain->misalign + off]; + if (chain == NULL) + return -1; + + return (unsigned char)chain->buffer[chain->misalign + off]; } struct evbuffer_ptr @@ -1602,22 +1602,22 @@ evbuffer_search_eol(struct evbuffer *buffer, size_t extra_drain = 0; int ok = 0; - /* Avoid locking in trivial edge cases */ - if (start && start->internal_.chain == NULL) { - PTR_NOT_FOUND(&it); - if (eol_len_out) - *eol_len_out = extra_drain; - return it; - } - + /* Avoid locking in trivial edge cases */ + if (start && start->internal_.chain == NULL) { + PTR_NOT_FOUND(&it); + if (eol_len_out) + *eol_len_out = extra_drain; + return it; + } + EVBUFFER_LOCK(buffer); if (start) { memcpy(&it, start, sizeof(it)); } else { it.pos = 0; - it.internal_.chain = buffer->first; - it.internal_.pos_in_chain = 0; + it.internal_.chain = buffer->first; + it.internal_.pos_in_chain = 0; } /* the eol_style determines our first stop character and how many @@ -1636,37 +1636,37 @@ evbuffer_search_eol(struct evbuffer *buffer, extra_drain = 2; break; } - case EVBUFFER_EOL_CRLF: { - ev_ssize_t start_pos = it.pos; - /* Look for a LF ... */ - if (evbuffer_strchr(&it, '\n') < 0) - goto done; - extra_drain = 1; - /* ... optionally preceeded by a CR. */ - if (it.pos == start_pos) - break; /* If the first character is \n, don't back up */ - /* This potentially does an extra linear walk over the first - * few chains. Probably, that's not too expensive unless you - * have a really pathological setup. */ - memcpy(&it2, &it, sizeof(it)); - if (evbuffer_ptr_subtract(buffer, &it2, 1)<0) - break; - if (evbuffer_getchr(&it2) == '\r') { - memcpy(&it, &it2, sizeof(it)); - extra_drain = 2; + case EVBUFFER_EOL_CRLF: { + ev_ssize_t start_pos = it.pos; + /* Look for a LF ... */ + if (evbuffer_strchr(&it, '\n') < 0) + goto done; + extra_drain = 1; + /* ... optionally preceeded by a CR. */ + if (it.pos == start_pos) + break; /* If the first character is \n, don't back up */ + /* This potentially does an extra linear walk over the first + * few chains. Probably, that's not too expensive unless you + * have a really pathological setup. */ + memcpy(&it2, &it, sizeof(it)); + if (evbuffer_ptr_subtract(buffer, &it2, 1)<0) + break; + if (evbuffer_getchr(&it2) == '\r') { + memcpy(&it, &it2, sizeof(it)); + extra_drain = 2; } break; - } + } case EVBUFFER_EOL_LF: if (evbuffer_strchr(&it, '\n') < 0) goto done; extra_drain = 1; break; - case EVBUFFER_EOL_NUL: - if (evbuffer_strchr(&it, '\0') < 0) - goto done; - extra_drain = 1; - break; + case EVBUFFER_EOL_NUL: + if (evbuffer_strchr(&it, '\0') < 0) + goto done; + extra_drain = 1; + break; default: goto done; } @@ -1675,8 +1675,8 @@ evbuffer_search_eol(struct evbuffer *buffer, done: EVBUFFER_UNLOCK(buffer); - if (!ok) - PTR_NOT_FOUND(&it); + if (!ok) + PTR_NOT_FOUND(&it); if (eol_len_out) *eol_len_out = extra_drain; @@ -1744,11 +1744,11 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen) goto done; } - if (*buf->last_with_datap == NULL) { - chain = buf->last; - } else { - chain = *buf->last_with_datap; - } + if (*buf->last_with_datap == NULL) { + chain = buf->last; + } else { + chain = *buf->last_with_datap; + } /* If there are no chains allocated for this buffer, allocate one * big enough to hold all the data. */ @@ -1816,7 +1816,7 @@ evbuffer_add(struct evbuffer *buf, const void *data_in, size_t datlen) buf->n_add_for_cb += datlen; out: - evbuffer_invoke_callbacks_(buf); + evbuffer_invoke_callbacks_(buf); result = 0; done: EVBUFFER_UNLOCK(buf); @@ -1831,10 +1831,10 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen) EVBUFFER_LOCK(buf); - if (datlen == 0) { - result = 0; - goto done; - } + if (datlen == 0) { + result = 0; + goto done; + } if (buf->freeze_start) { goto done; } @@ -1888,7 +1888,7 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen) if ((tmp = evbuffer_chain_new(datlen)) == NULL) goto done; buf->first = tmp; - if (buf->last_with_datap == &buf->first && chain->off) + if (buf->last_with_datap == &buf->first && chain->off) buf->last_with_datap = &tmp->next; tmp->next = chain; @@ -1899,10 +1899,10 @@ evbuffer_prepend(struct evbuffer *buf, const void *data, size_t datlen) memcpy(tmp->buffer + tmp->misalign, data, datlen); buf->total_len += datlen; - buf->n_add_for_cb += datlen; + buf->n_add_for_cb += datlen; out: - evbuffer_invoke_callbacks_(buf); + evbuffer_invoke_callbacks_(buf); result = 0; done: EVBUFFER_UNLOCK(buf); @@ -1994,7 +1994,7 @@ evbuffer_expand_singlechain(struct evbuffer *buf, size_t datlen) /* Would expanding this chunk be affordable and worthwhile? */ if (CHAIN_SPACE_LEN(chain) < chain->buffer_len / 8 || chain->off > MAX_TO_COPY_IN_EXPAND || - datlen >= (EVBUFFER_CHAIN_MAX - chain->off)) { + datlen >= (EVBUFFER_CHAIN_MAX - chain->off)) { /* It's not worth resizing this chain. Can the next one be * used? */ if (chain->next && CHAIN_SPACE_LEN(chain->next) >= datlen) { @@ -2048,7 +2048,7 @@ err: /* Make sure that datlen bytes are available for writing in the last n * chains. Never copies or moves data. */ int -evbuffer_expand_fast_(struct evbuffer *buf, size_t datlen, int n) +evbuffer_expand_fast_(struct evbuffer *buf, size_t datlen, int n) { struct evbuffer_chain *chain = buf->last, *tmp, *next; size_t avail; @@ -2172,13 +2172,13 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen) * Reads data from a file descriptor into a buffer. */ -#if defined(EVENT__HAVE_SYS_UIO_H) || defined(_WIN32) +#if defined(EVENT__HAVE_SYS_UIO_H) || defined(_WIN32) #define USE_IOVEC_IMPL #endif #ifdef USE_IOVEC_IMPL -#ifdef EVENT__HAVE_SYS_UIO_H +#ifdef EVENT__HAVE_SYS_UIO_H /* number of iovec we use for writev, fragmentation is going to determine * how much we end up writing */ @@ -2222,7 +2222,7 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen) @return The number of buffers we're using. */ int -evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, +evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, struct evbuffer_iovec *vecs, int n_vecs_avail, struct evbuffer_chain ***chainp, int exact) { @@ -2238,18 +2238,18 @@ evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, so_far = 0; /* Let firstchain be the first chain with any space on it */ firstchainp = buf->last_with_datap; - EVUTIL_ASSERT(*firstchainp); + EVUTIL_ASSERT(*firstchainp); if (CHAIN_SPACE_LEN(*firstchainp) == 0) { firstchainp = &(*firstchainp)->next; } chain = *firstchainp; - EVUTIL_ASSERT(chain); + EVUTIL_ASSERT(chain); for (i = 0; i < n_vecs_avail && so_far < (size_t)howmuch; ++i) { size_t avail = (size_t) CHAIN_SPACE_LEN(chain); if (avail > (howmuch - so_far) && exact) avail = howmuch - so_far; - vecs[i].iov_base = (void *)CHAIN_SPACE_PTR(chain); + vecs[i].iov_base = (void *)CHAIN_SPACE_PTR(chain); vecs[i].iov_len = avail; so_far += avail; chain = chain->next; @@ -2262,7 +2262,7 @@ evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, static int get_n_bytes_readable_on_socket(evutil_socket_t fd) { -#if defined(FIONREAD) && defined(_WIN32) +#if defined(FIONREAD) && defined(_WIN32) unsigned long lng = EVBUFFER_MAX_READ; if (ioctlsocket(fd, FIONREAD, &lng) < 0) return -1; @@ -2310,26 +2310,26 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch) #ifdef USE_IOVEC_IMPL /* Since we can use iovecs, we're willing to use the last * NUM_READ_IOVEC chains. */ - if (evbuffer_expand_fast_(buf, howmuch, NUM_READ_IOVEC) == -1) { + if (evbuffer_expand_fast_(buf, howmuch, NUM_READ_IOVEC) == -1) { result = -1; goto done; } else { IOV_TYPE vecs[NUM_READ_IOVEC]; -#ifdef EVBUFFER_IOVEC_IS_NATIVE_ - nvecs = evbuffer_read_setup_vecs_(buf, howmuch, vecs, +#ifdef EVBUFFER_IOVEC_IS_NATIVE_ + nvecs = evbuffer_read_setup_vecs_(buf, howmuch, vecs, NUM_READ_IOVEC, &chainp, 1); #else /* We aren't using the native struct iovec. Therefore, we are on win32. */ struct evbuffer_iovec ev_vecs[NUM_READ_IOVEC]; - nvecs = evbuffer_read_setup_vecs_(buf, howmuch, ev_vecs, 2, + nvecs = evbuffer_read_setup_vecs_(buf, howmuch, ev_vecs, 2, &chainp, 1); for (i=0; i < nvecs; ++i) WSABUF_FROM_EVBUFFER_IOV(&vecs[i], &ev_vecs[i]); #endif -#ifdef _WIN32 +#ifdef _WIN32 { DWORD bytesRead; DWORD flags=0; @@ -2360,7 +2360,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch) /* We can append new data at this point */ p = chain->buffer + chain->misalign + chain->off; -#ifndef _WIN32 +#ifndef _WIN32 n = read(fd, p, howmuch); #else n = recv(fd, p, howmuch, 0); @@ -2404,7 +2404,7 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch) buf->n_add_for_cb += n; /* Tell someone about changes in this buffer */ - evbuffer_invoke_callbacks_(buf); + evbuffer_invoke_callbacks_(buf); result = n; done: EVBUFFER_UNLOCK(buf); @@ -2447,8 +2447,8 @@ evbuffer_write_iovec(struct evbuffer *buffer, evutil_socket_t fd, } if (! i) return 0; - -#ifdef _WIN32 + +#ifdef _WIN32 { DWORD bytesSent; if (WSASend(fd, iov, i, &bytesSent, 0, NULL, NULL)) @@ -2465,17 +2465,17 @@ evbuffer_write_iovec(struct evbuffer *buffer, evutil_socket_t fd, #ifdef USE_SENDFILE static inline int -evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t dest_fd, +evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t dest_fd, ev_ssize_t howmuch) { struct evbuffer_chain *chain = buffer->first; - struct evbuffer_chain_file_segment *info = - EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, - chain); - const int source_fd = info->segment->fd; + struct evbuffer_chain_file_segment *info = + EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, + chain); + const int source_fd = info->segment->fd; #if defined(SENDFILE_IS_MACOSX) || defined(SENDFILE_IS_FREEBSD) int res; - ev_off_t len = chain->off; + ev_off_t len = chain->off; #elif defined(SENDFILE_IS_LINUX) || defined(SENDFILE_IS_SOLARIS) ev_ssize_t res; off_t offset = chain->misalign; @@ -2484,20 +2484,20 @@ evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t dest_fd, ASSERT_EVBUFFER_LOCKED(buffer); #if defined(SENDFILE_IS_MACOSX) - res = sendfile(source_fd, dest_fd, chain->misalign, &len, NULL, 0); + res = sendfile(source_fd, dest_fd, chain->misalign, &len, NULL, 0); if (res == -1 && !EVUTIL_ERR_RW_RETRIABLE(errno)) return (-1); return (len); #elif defined(SENDFILE_IS_FREEBSD) - res = sendfile(source_fd, dest_fd, chain->misalign, chain->off, NULL, &len, 0); + res = sendfile(source_fd, dest_fd, chain->misalign, chain->off, NULL, &len, 0); if (res == -1 && !EVUTIL_ERR_RW_RETRIABLE(errno)) return (-1); return (len); #elif defined(SENDFILE_IS_LINUX) /* TODO(niels): implement splice */ - res = sendfile(dest_fd, source_fd, &offset, chain->off); + res = sendfile(dest_fd, source_fd, &offset, chain->off); if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) { /* if this is EAGAIN or EINTR return 0; otherwise, -1 */ return (0); @@ -2506,7 +2506,7 @@ evbuffer_write_sendfile(struct evbuffer *buffer, evutil_socket_t dest_fd, #elif defined(SENDFILE_IS_SOLARIS) { const off_t offset_orig = offset; - res = sendfile(dest_fd, source_fd, &offset, chain->off); + res = sendfile(dest_fd, source_fd, &offset, chain->off); if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) { if (offset - offset_orig) return offset - offset_orig; @@ -2544,7 +2544,7 @@ evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd, #endif #ifdef USE_IOVEC_IMPL n = evbuffer_write_iovec(buffer, fd, howmuch); -#elif defined(_WIN32) +#elif defined(_WIN32) /* XXX(nickm) Don't disable this code until we know if * the WSARecv code above works. */ void *p = evbuffer_pullup(buffer, howmuch); @@ -2594,38 +2594,38 @@ evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len) return search; } -/* Subract <b>howfar</b> from the position of <b>pos</b> within - * <b>buf</b>. Returns 0 on success, -1 on failure. - * - * This isn't exposed yet, because of potential inefficiency issues. - * Maybe it should be. */ -static int -evbuffer_ptr_subtract(struct evbuffer *buf, struct evbuffer_ptr *pos, - size_t howfar) -{ - if (pos->pos < 0) - return -1; - if (howfar > (size_t)pos->pos) - return -1; - if (pos->internal_.chain && howfar <= pos->internal_.pos_in_chain) { - pos->internal_.pos_in_chain -= howfar; - pos->pos -= howfar; - return 0; - } else { - const size_t newpos = pos->pos - howfar; - /* Here's the inefficient part: it walks over the - * chains until we hit newpos. */ - return evbuffer_ptr_set(buf, pos, newpos, EVBUFFER_PTR_SET); - } -} - +/* Subract <b>howfar</b> from the position of <b>pos</b> within + * <b>buf</b>. Returns 0 on success, -1 on failure. + * + * This isn't exposed yet, because of potential inefficiency issues. + * Maybe it should be. */ +static int +evbuffer_ptr_subtract(struct evbuffer *buf, struct evbuffer_ptr *pos, + size_t howfar) +{ + if (pos->pos < 0) + return -1; + if (howfar > (size_t)pos->pos) + return -1; + if (pos->internal_.chain && howfar <= pos->internal_.pos_in_chain) { + pos->internal_.pos_in_chain -= howfar; + pos->pos -= howfar; + return 0; + } else { + const size_t newpos = pos->pos - howfar; + /* Here's the inefficient part: it walks over the + * chains until we hit newpos. */ + return evbuffer_ptr_set(buf, pos, newpos, EVBUFFER_PTR_SET); + } +} + int evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos, size_t position, enum evbuffer_ptr_how how) { size_t left = position; struct evbuffer_chain *chain = NULL; - int result = 0; + int result = 0; EVBUFFER_LOCK(buf); @@ -2642,9 +2642,9 @@ evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos, EVBUFFER_UNLOCK(buf); return -1; } - chain = pos->internal_.chain; + chain = pos->internal_.chain; pos->pos += position; - position = pos->internal_.pos_in_chain; + position = pos->internal_.pos_in_chain; break; } @@ -2655,20 +2655,20 @@ evbuffer_ptr_set(struct evbuffer *buf, struct evbuffer_ptr *pos, position = 0; } if (chain) { - pos->internal_.chain = chain; - pos->internal_.pos_in_chain = position + left; - } else if (left == 0) { - /* The first byte in the (nonexistent) chain after the last chain */ - pos->internal_.chain = NULL; - pos->internal_.pos_in_chain = 0; + pos->internal_.chain = chain; + pos->internal_.pos_in_chain = position + left; + } else if (left == 0) { + /* The first byte in the (nonexistent) chain after the last chain */ + pos->internal_.chain = NULL; + pos->internal_.pos_in_chain = 0; } else { - PTR_NOT_FOUND(pos); - result = -1; + PTR_NOT_FOUND(pos); + result = -1; } EVBUFFER_UNLOCK(buf); - return result; + return result; } /** @@ -2690,8 +2690,8 @@ evbuffer_ptr_memcmp(const struct evbuffer *buf, const struct evbuffer_ptr *pos, pos->pos + len > buf->total_len) return -1; - chain = pos->internal_.chain; - position = pos->internal_.pos_in_chain; + chain = pos->internal_.chain; + position = pos->internal_.pos_in_chain; while (len && chain) { size_t n_comparable; if (len + position > chain->off) @@ -2729,15 +2729,15 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con if (start) { memcpy(&pos, start, sizeof(pos)); - chain = pos.internal_.chain; + chain = pos.internal_.chain; } else { pos.pos = 0; - chain = pos.internal_.chain = buffer->first; - pos.internal_.pos_in_chain = 0; + chain = pos.internal_.chain = buffer->first; + pos.internal_.pos_in_chain = 0; } if (end) - last_chain = end->internal_.chain; + last_chain = end->internal_.chain; if (!len || len > EV_SSIZE_MAX) goto done; @@ -2747,12 +2747,12 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con while (chain) { const unsigned char *start_at = chain->buffer + chain->misalign + - pos.internal_.pos_in_chain; + pos.internal_.pos_in_chain; p = memchr(start_at, first, - chain->off - pos.internal_.pos_in_chain); + chain->off - pos.internal_.pos_in_chain); if (p) { pos.pos += p - start_at; - pos.internal_.pos_in_chain += p - start_at; + pos.internal_.pos_in_chain += p - start_at; if (!evbuffer_ptr_memcmp(buffer, &pos, what, len)) { if (end && pos.pos + (ev_ssize_t)len > end->pos) goto not_found; @@ -2760,22 +2760,22 @@ evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, con goto done; } ++pos.pos; - ++pos.internal_.pos_in_chain; - if (pos.internal_.pos_in_chain == chain->off) { - chain = pos.internal_.chain = chain->next; - pos.internal_.pos_in_chain = 0; + ++pos.internal_.pos_in_chain; + if (pos.internal_.pos_in_chain == chain->off) { + chain = pos.internal_.chain = chain->next; + pos.internal_.pos_in_chain = 0; } } else { if (chain == last_chain) goto not_found; - pos.pos += chain->off - pos.internal_.pos_in_chain; - chain = pos.internal_.chain = chain->next; - pos.internal_.pos_in_chain = 0; + pos.pos += chain->off - pos.internal_.pos_in_chain; + chain = pos.internal_.chain = chain->next; + pos.internal_.pos_in_chain = 0; } } not_found: - PTR_NOT_FOUND(&pos); + PTR_NOT_FOUND(&pos); done: EVBUFFER_UNLOCK(buffer); return pos; @@ -2790,20 +2790,20 @@ evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len, int idx = 0; ev_ssize_t len_so_far = 0; - /* Avoid locking in trivial edge cases */ - if (start_at && start_at->internal_.chain == NULL) - return 0; - + /* Avoid locking in trivial edge cases */ + if (start_at && start_at->internal_.chain == NULL) + return 0; + EVBUFFER_LOCK(buffer); if (start_at) { - chain = start_at->internal_.chain; + chain = start_at->internal_.chain; len_so_far = chain->off - - start_at->internal_.pos_in_chain; + - start_at->internal_.pos_in_chain; idx = 1; if (n_vec > 0) { - vec[0].iov_base = (void *)(chain->buffer + chain->misalign - + start_at->internal_.pos_in_chain); + vec[0].iov_base = (void *)(chain->buffer + chain->misalign + + start_at->internal_.pos_in_chain); vec[0].iov_len = len_so_far; } chain = chain->next; @@ -2824,7 +2824,7 @@ evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len, if (len >= 0 && len_so_far >= len) break; if (idx<n_vec) { - vec[idx].iov_base = (void *)(chain->buffer + chain->misalign); + vec[idx].iov_base = (void *)(chain->buffer + chain->misalign); vec[idx].iov_len = chain->off; } else if (len<0) { break; @@ -2890,7 +2890,7 @@ evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap) buf->n_add_for_cb += sz; advance_last_with_data(buf); - evbuffer_invoke_callbacks_(buf); + evbuffer_invoke_callbacks_(buf); result = sz; goto done; } @@ -2930,7 +2930,7 @@ evbuffer_add_reference(struct evbuffer *outbuf, if (!chain) return (-1); chain->flags |= EVBUFFER_REFERENCE | EVBUFFER_IMMUTABLE; - chain->buffer = (unsigned char *)data; + chain->buffer = (unsigned char *)data; chain->buffer_len = datlen; chain->off = datlen; @@ -2948,7 +2948,7 @@ evbuffer_add_reference(struct evbuffer *outbuf, evbuffer_chain_insert(outbuf, chain); outbuf->n_add_for_cb += datlen; - evbuffer_invoke_callbacks_(outbuf); + evbuffer_invoke_callbacks_(outbuf); result = 0; done: @@ -2960,374 +2960,374 @@ done: /* TODO(niels): we may want to add to automagically convert to mmap, in * case evbuffer_remove() or evbuffer_pullup() are being used. */ -struct evbuffer_file_segment * -evbuffer_file_segment_new( - int fd, ev_off_t offset, ev_off_t length, unsigned flags) -{ - struct evbuffer_file_segment *seg = - mm_calloc(sizeof(struct evbuffer_file_segment), 1); - if (!seg) - return NULL; - seg->refcnt = 1; - seg->fd = fd; - seg->flags = flags; - seg->file_offset = offset; - seg->cleanup_cb = NULL; - seg->cleanup_cb_arg = NULL; -#ifdef _WIN32 -#ifndef lseek -#define lseek _lseeki64 -#endif -#ifndef fstat -#define fstat _fstat +struct evbuffer_file_segment * +evbuffer_file_segment_new( + int fd, ev_off_t offset, ev_off_t length, unsigned flags) +{ + struct evbuffer_file_segment *seg = + mm_calloc(sizeof(struct evbuffer_file_segment), 1); + if (!seg) + return NULL; + seg->refcnt = 1; + seg->fd = fd; + seg->flags = flags; + seg->file_offset = offset; + seg->cleanup_cb = NULL; + seg->cleanup_cb_arg = NULL; +#ifdef _WIN32 +#ifndef lseek +#define lseek _lseeki64 #endif -#ifndef stat -#define stat _stat +#ifndef fstat +#define fstat _fstat #endif -#endif - if (length == -1) { - struct stat st; - if (fstat(fd, &st) < 0) - goto err; - length = st.st_size; - } - seg->length = length; +#ifndef stat +#define stat _stat +#endif +#endif + if (length == -1) { + struct stat st; + if (fstat(fd, &st) < 0) + goto err; + length = st.st_size; + } + seg->length = length; if (offset < 0 || length < 0 || ((ev_uint64_t)length > EVBUFFER_CHAIN_MAX) || (ev_uint64_t)offset > (ev_uint64_t)(EVBUFFER_CHAIN_MAX - length)) - goto err; - -#if defined(USE_SENDFILE) - if (!(flags & EVBUF_FS_DISABLE_SENDFILE)) { - seg->can_sendfile = 1; - goto done; - } -#endif - - if (evbuffer_file_segment_materialize(seg)<0) - goto err; + goto err; #if defined(USE_SENDFILE) -done: -#endif - if (!(flags & EVBUF_FS_DISABLE_LOCKING)) { - EVTHREAD_ALLOC_LOCK(seg->lock, 0); - } - return seg; -err: - mm_free(seg); - return NULL; -} - -#ifdef EVENT__HAVE_MMAP -static long -get_page_size(void) -{ -#ifdef SC_PAGE_SIZE - return sysconf(SC_PAGE_SIZE); -#elif defined(_SC_PAGE_SIZE) - return sysconf(_SC_PAGE_SIZE); -#else - return 1; -#endif -} -#endif - -/* DOCDOC */ -/* Requires lock */ -static int -evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg) -{ - const unsigned flags = seg->flags; - const int fd = seg->fd; - const ev_off_t length = seg->length; - const ev_off_t offset = seg->file_offset; - - if (seg->contents) - return 0; /* already materialized */ - -#if defined(EVENT__HAVE_MMAP) - if (!(flags & EVBUF_FS_DISABLE_MMAP)) { - off_t offset_rounded = 0, offset_leftover = 0; - void *mapped; - if (offset) { - /* mmap implementations don't generally like us - * to have an offset that isn't a round */ - long page_size = get_page_size(); - if (page_size == -1) - goto err; - offset_leftover = offset % page_size; - offset_rounded = offset - offset_leftover; + if (!(flags & EVBUF_FS_DISABLE_SENDFILE)) { + seg->can_sendfile = 1; + goto done; + } +#endif + + if (evbuffer_file_segment_materialize(seg)<0) + goto err; + +#if defined(USE_SENDFILE) +done: +#endif + if (!(flags & EVBUF_FS_DISABLE_LOCKING)) { + EVTHREAD_ALLOC_LOCK(seg->lock, 0); + } + return seg; +err: + mm_free(seg); + return NULL; +} + +#ifdef EVENT__HAVE_MMAP +static long +get_page_size(void) +{ +#ifdef SC_PAGE_SIZE + return sysconf(SC_PAGE_SIZE); +#elif defined(_SC_PAGE_SIZE) + return sysconf(_SC_PAGE_SIZE); +#else + return 1; +#endif +} +#endif + +/* DOCDOC */ +/* Requires lock */ +static int +evbuffer_file_segment_materialize(struct evbuffer_file_segment *seg) +{ + const unsigned flags = seg->flags; + const int fd = seg->fd; + const ev_off_t length = seg->length; + const ev_off_t offset = seg->file_offset; + + if (seg->contents) + return 0; /* already materialized */ + +#if defined(EVENT__HAVE_MMAP) + if (!(flags & EVBUF_FS_DISABLE_MMAP)) { + off_t offset_rounded = 0, offset_leftover = 0; + void *mapped; + if (offset) { + /* mmap implementations don't generally like us + * to have an offset that isn't a round */ + long page_size = get_page_size(); + if (page_size == -1) + goto err; + offset_leftover = offset % page_size; + offset_rounded = offset - offset_leftover; } - mapped = mmap(NULL, length + offset_leftover, - PROT_READ, + mapped = mmap(NULL, length + offset_leftover, + PROT_READ, #ifdef MAP_NOCACHE - MAP_NOCACHE | /* ??? */ + MAP_NOCACHE | /* ??? */ #endif #ifdef MAP_FILE MAP_FILE | #endif MAP_PRIVATE, - fd, offset_rounded); + fd, offset_rounded); if (mapped == MAP_FAILED) { event_warn("%s: mmap(%d, %d, %zu) failed", __func__, fd, 0, (size_t)(offset + length)); - } else { - seg->mapping = mapped; - seg->contents = (char*)mapped+offset_leftover; - seg->mmap_offset = 0; - seg->is_mapping = 1; - goto done; - } - } -#endif -#ifdef _WIN32 - if (!(flags & EVBUF_FS_DISABLE_MMAP)) { - intptr_t h = _get_osfhandle(fd); - HANDLE m; - ev_uint64_t total_size = length+offset; - if ((HANDLE)h == INVALID_HANDLE_VALUE) - goto err; - m = CreateFileMapping((HANDLE)h, NULL, PAGE_READONLY, - (total_size >> 32), total_size & 0xfffffffful, - NULL); - if (m != INVALID_HANDLE_VALUE) { /* Does h leak? */ - seg->mapping_handle = m; - seg->mmap_offset = offset; - seg->is_mapping = 1; - goto done; - } - } -#endif - { - ev_off_t start_pos = lseek(fd, 0, SEEK_CUR), pos; - ev_off_t read_so_far = 0; - char *mem; - int e; - ev_ssize_t n = 0; - if (!(mem = mm_malloc(length))) - goto err; - if (start_pos < 0) { - mm_free(mem); - goto err; - } - if (lseek(fd, offset, SEEK_SET) < 0) { - mm_free(mem); - goto err; + } else { + seg->mapping = mapped; + seg->contents = (char*)mapped+offset_leftover; + seg->mmap_offset = 0; + seg->is_mapping = 1; + goto done; } - while (read_so_far < length) { - n = read(fd, mem+read_so_far, length-read_so_far); - if (n <= 0) - break; - read_so_far += n; + } +#endif +#ifdef _WIN32 + if (!(flags & EVBUF_FS_DISABLE_MMAP)) { + intptr_t h = _get_osfhandle(fd); + HANDLE m; + ev_uint64_t total_size = length+offset; + if ((HANDLE)h == INVALID_HANDLE_VALUE) + goto err; + m = CreateFileMapping((HANDLE)h, NULL, PAGE_READONLY, + (total_size >> 32), total_size & 0xfffffffful, + NULL); + if (m != INVALID_HANDLE_VALUE) { /* Does h leak? */ + seg->mapping_handle = m; + seg->mmap_offset = offset; + seg->is_mapping = 1; + goto done; } - - e = errno; - pos = lseek(fd, start_pos, SEEK_SET); - if (n < 0 || (n == 0 && length > read_so_far)) { - mm_free(mem); - errno = e; - goto err; - } else if (pos < 0) { - mm_free(mem); - goto err; - } - - seg->contents = mem; - } - -done: - return 0; -err: - return -1; -} - -void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment *seg, - evbuffer_file_segment_cleanup_cb cb, void* arg) -{ - EVUTIL_ASSERT(seg->refcnt > 0); - seg->cleanup_cb = cb; - seg->cleanup_cb_arg = arg; -} - -void -evbuffer_file_segment_free(struct evbuffer_file_segment *seg) -{ - int refcnt; - EVLOCK_LOCK(seg->lock, 0); - refcnt = --seg->refcnt; - EVLOCK_UNLOCK(seg->lock, 0); - if (refcnt > 0) - return; - EVUTIL_ASSERT(refcnt == 0); - - if (seg->is_mapping) { -#ifdef _WIN32 - CloseHandle(seg->mapping_handle); -#elif defined (EVENT__HAVE_MMAP) - off_t offset_leftover; - offset_leftover = seg->file_offset % get_page_size(); - if (munmap(seg->mapping, seg->length + offset_leftover) == -1) - event_warn("%s: munmap failed", __func__); + } +#endif + { + ev_off_t start_pos = lseek(fd, 0, SEEK_CUR), pos; + ev_off_t read_so_far = 0; + char *mem; + int e; + ev_ssize_t n = 0; + if (!(mem = mm_malloc(length))) + goto err; + if (start_pos < 0) { + mm_free(mem); + goto err; + } + if (lseek(fd, offset, SEEK_SET) < 0) { + mm_free(mem); + goto err; + } + while (read_so_far < length) { + n = read(fd, mem+read_so_far, length-read_so_far); + if (n <= 0) + break; + read_so_far += n; + } + + e = errno; + pos = lseek(fd, start_pos, SEEK_SET); + if (n < 0 || (n == 0 && length > read_so_far)) { + mm_free(mem); + errno = e; + goto err; + } else if (pos < 0) { + mm_free(mem); + goto err; + } + + seg->contents = mem; + } + +done: + return 0; +err: + return -1; +} + +void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment *seg, + evbuffer_file_segment_cleanup_cb cb, void* arg) +{ + EVUTIL_ASSERT(seg->refcnt > 0); + seg->cleanup_cb = cb; + seg->cleanup_cb_arg = arg; +} + +void +evbuffer_file_segment_free(struct evbuffer_file_segment *seg) +{ + int refcnt; + EVLOCK_LOCK(seg->lock, 0); + refcnt = --seg->refcnt; + EVLOCK_UNLOCK(seg->lock, 0); + if (refcnt > 0) + return; + EVUTIL_ASSERT(refcnt == 0); + + if (seg->is_mapping) { +#ifdef _WIN32 + CloseHandle(seg->mapping_handle); +#elif defined (EVENT__HAVE_MMAP) + off_t offset_leftover; + offset_leftover = seg->file_offset % get_page_size(); + if (munmap(seg->mapping, seg->length + offset_leftover) == -1) + event_warn("%s: munmap failed", __func__); #endif - } else if (seg->contents) { - mm_free(seg->contents); - } - - if ((seg->flags & EVBUF_FS_CLOSE_ON_FREE) && seg->fd >= 0) { - close(seg->fd); - } - - if (seg->cleanup_cb) { - (*seg->cleanup_cb)((struct evbuffer_file_segment const*)seg, - seg->flags, seg->cleanup_cb_arg); - seg->cleanup_cb = NULL; - seg->cleanup_cb_arg = NULL; - } - - EVTHREAD_FREE_LOCK(seg->lock, 0); - mm_free(seg); -} - -int -evbuffer_add_file_segment(struct evbuffer *buf, - struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length) -{ - struct evbuffer_chain *chain; - struct evbuffer_chain_file_segment *extra; - int can_use_sendfile = 0; - - EVBUFFER_LOCK(buf); - EVLOCK_LOCK(seg->lock, 0); - if (buf->flags & EVBUFFER_FLAG_DRAINS_TO_FD) { - can_use_sendfile = 1; - } else { - if (!seg->contents) { - if (evbuffer_file_segment_materialize(seg)<0) { - EVLOCK_UNLOCK(seg->lock, 0); - EVBUFFER_UNLOCK(buf); - return -1; + } else if (seg->contents) { + mm_free(seg->contents); + } + + if ((seg->flags & EVBUF_FS_CLOSE_ON_FREE) && seg->fd >= 0) { + close(seg->fd); + } + + if (seg->cleanup_cb) { + (*seg->cleanup_cb)((struct evbuffer_file_segment const*)seg, + seg->flags, seg->cleanup_cb_arg); + seg->cleanup_cb = NULL; + seg->cleanup_cb_arg = NULL; + } + + EVTHREAD_FREE_LOCK(seg->lock, 0); + mm_free(seg); +} + +int +evbuffer_add_file_segment(struct evbuffer *buf, + struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length) +{ + struct evbuffer_chain *chain; + struct evbuffer_chain_file_segment *extra; + int can_use_sendfile = 0; + + EVBUFFER_LOCK(buf); + EVLOCK_LOCK(seg->lock, 0); + if (buf->flags & EVBUFFER_FLAG_DRAINS_TO_FD) { + can_use_sendfile = 1; + } else { + if (!seg->contents) { + if (evbuffer_file_segment_materialize(seg)<0) { + EVLOCK_UNLOCK(seg->lock, 0); + EVBUFFER_UNLOCK(buf); + return -1; } } - } - EVLOCK_UNLOCK(seg->lock, 0); - - if (buf->freeze_end) - goto err; - - if (length < 0) { - if (offset > seg->length) - goto err; - length = seg->length - offset; - } - - /* Can we actually add this? */ - if (offset+length > seg->length) - goto err; - - chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_file_segment)); - if (!chain) - goto err; - extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, chain); - - chain->flags |= EVBUFFER_IMMUTABLE|EVBUFFER_FILESEGMENT; - if (can_use_sendfile && seg->can_sendfile) { - chain->flags |= EVBUFFER_SENDFILE; - chain->misalign = seg->file_offset + offset; - chain->off = length; - chain->buffer_len = chain->misalign + length; - } else if (seg->is_mapping) { -#ifdef _WIN32 - ev_uint64_t total_offset = seg->mmap_offset+offset; - ev_uint64_t offset_rounded=0, offset_remaining=0; - LPVOID data; - if (total_offset) { - SYSTEM_INFO si; - memset(&si, 0, sizeof(si)); /* cargo cult */ - GetSystemInfo(&si); - offset_remaining = total_offset % si.dwAllocationGranularity; - offset_rounded = total_offset - offset_remaining; - } - data = MapViewOfFile( - seg->mapping_handle, - FILE_MAP_READ, - offset_rounded >> 32, - offset_rounded & 0xfffffffful, - length + offset_remaining); - if (data == NULL) { - mm_free(chain); - goto err; - } - chain->buffer = (unsigned char*) data; - chain->buffer_len = length+offset_remaining; - chain->misalign = offset_remaining; - chain->off = length; -#else - chain->buffer = (unsigned char*)(seg->contents + offset); - chain->buffer_len = length; - chain->off = length; + } + EVLOCK_UNLOCK(seg->lock, 0); + + if (buf->freeze_end) + goto err; + + if (length < 0) { + if (offset > seg->length) + goto err; + length = seg->length - offset; + } + + /* Can we actually add this? */ + if (offset+length > seg->length) + goto err; + + chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_file_segment)); + if (!chain) + goto err; + extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, chain); + + chain->flags |= EVBUFFER_IMMUTABLE|EVBUFFER_FILESEGMENT; + if (can_use_sendfile && seg->can_sendfile) { + chain->flags |= EVBUFFER_SENDFILE; + chain->misalign = seg->file_offset + offset; + chain->off = length; + chain->buffer_len = chain->misalign + length; + } else if (seg->is_mapping) { +#ifdef _WIN32 + ev_uint64_t total_offset = seg->mmap_offset+offset; + ev_uint64_t offset_rounded=0, offset_remaining=0; + LPVOID data; + if (total_offset) { + SYSTEM_INFO si; + memset(&si, 0, sizeof(si)); /* cargo cult */ + GetSystemInfo(&si); + offset_remaining = total_offset % si.dwAllocationGranularity; + offset_rounded = total_offset - offset_remaining; + } + data = MapViewOfFile( + seg->mapping_handle, + FILE_MAP_READ, + offset_rounded >> 32, + offset_rounded & 0xfffffffful, + length + offset_remaining); + if (data == NULL) { + mm_free(chain); + goto err; + } + chain->buffer = (unsigned char*) data; + chain->buffer_len = length+offset_remaining; + chain->misalign = offset_remaining; + chain->off = length; +#else + chain->buffer = (unsigned char*)(seg->contents + offset); + chain->buffer_len = length; + chain->off = length; #endif - } else { - chain->buffer = (unsigned char*)(seg->contents + offset); - chain->buffer_len = length; - chain->off = length; + } else { + chain->buffer = (unsigned char*)(seg->contents + offset); + chain->buffer_len = length; + chain->off = length; } EVLOCK_LOCK(seg->lock, 0); ++seg->refcnt; EVLOCK_UNLOCK(seg->lock, 0); - extra->segment = seg; - buf->n_add_for_cb += length; - evbuffer_chain_insert(buf, chain); - - evbuffer_invoke_callbacks_(buf); - - EVBUFFER_UNLOCK(buf); - - return 0; -err: - EVBUFFER_UNLOCK(buf); - evbuffer_file_segment_free(seg); /* Lowers the refcount */ - return -1; -} - -int -evbuffer_add_file(struct evbuffer *buf, int fd, ev_off_t offset, ev_off_t length) -{ - struct evbuffer_file_segment *seg; - unsigned flags = EVBUF_FS_CLOSE_ON_FREE; - int r; - - seg = evbuffer_file_segment_new(fd, offset, length, flags); - if (!seg) - return -1; - r = evbuffer_add_file_segment(buf, seg, 0, length); - if (r == 0) - evbuffer_file_segment_free(seg); - return r; -} - -int + extra->segment = seg; + buf->n_add_for_cb += length; + evbuffer_chain_insert(buf, chain); + + evbuffer_invoke_callbacks_(buf); + + EVBUFFER_UNLOCK(buf); + + return 0; +err: + EVBUFFER_UNLOCK(buf); + evbuffer_file_segment_free(seg); /* Lowers the refcount */ + return -1; +} + +int +evbuffer_add_file(struct evbuffer *buf, int fd, ev_off_t offset, ev_off_t length) +{ + struct evbuffer_file_segment *seg; + unsigned flags = EVBUF_FS_CLOSE_ON_FREE; + int r; + + seg = evbuffer_file_segment_new(fd, offset, length, flags); + if (!seg) + return -1; + r = evbuffer_add_file_segment(buf, seg, 0, length); + if (r == 0) + evbuffer_file_segment_free(seg); + return r; +} + +int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg) { EVBUFFER_LOCK(buffer); - if (!LIST_EMPTY(&buffer->callbacks)) + if (!LIST_EMPTY(&buffer->callbacks)) evbuffer_remove_all_callbacks(buffer); if (cb) { struct evbuffer_cb_entry *ent = evbuffer_add_cb(buffer, NULL, cbarg); - if (!ent) { - EVBUFFER_UNLOCK(buffer); - return -1; - } + if (!ent) { + EVBUFFER_UNLOCK(buffer); + return -1; + } ent->cb.cb_obsolete = cb; ent->flags |= EVBUFFER_CB_OBSOLETE; } EVBUFFER_UNLOCK(buffer); - return 0; + return 0; } struct evbuffer_cb_entry * @@ -3340,7 +3340,7 @@ evbuffer_add_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg) e->cb.cb_func = cb; e->cbarg = cbarg; e->flags = EVBUFFER_CB_ENABLED; - LIST_INSERT_HEAD(&buffer->callbacks, e, next); + LIST_INSERT_HEAD(&buffer->callbacks, e, next); EVBUFFER_UNLOCK(buffer); return e; } @@ -3350,7 +3350,7 @@ evbuffer_remove_cb_entry(struct evbuffer *buffer, struct evbuffer_cb_entry *ent) { EVBUFFER_LOCK(buffer); - LIST_REMOVE(ent, next); + LIST_REMOVE(ent, next); EVBUFFER_UNLOCK(buffer); mm_free(ent); return 0; @@ -3362,7 +3362,7 @@ evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg) struct evbuffer_cb_entry *cbent; int result = -1; EVBUFFER_LOCK(buffer); - LIST_FOREACH(cbent, &buffer->callbacks, next) { + LIST_FOREACH(cbent, &buffer->callbacks, next) { if (cb == cbent->cb.cb_func && cbarg == cbent->cbarg) { result = evbuffer_remove_cb_entry(buffer, cbent); goto done; @@ -3448,20 +3448,20 @@ evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb) #endif int -evbuffer_get_callbacks_(struct evbuffer *buffer, struct event_callback **cbs, - int max_cbs) -{ - int r = 0; - EVBUFFER_LOCK(buffer); - if (buffer->deferred_cbs) { - if (max_cbs < 1) { - r = -1; - goto done; - } - cbs[0] = &buffer->deferred; - r = 1; - } -done: - EVBUFFER_UNLOCK(buffer); - return r; +evbuffer_get_callbacks_(struct evbuffer *buffer, struct event_callback **cbs, + int max_cbs) +{ + int r = 0; + EVBUFFER_LOCK(buffer); + if (buffer->deferred_cbs) { + if (max_cbs < 1) { + r = -1; + goto done; + } + cbs[0] = &buffer->deferred; + r = 1; + } +done: + EVBUFFER_UNLOCK(buffer); + return r; } diff --git a/contrib/libs/libevent/buffer_iocp.c b/contrib/libs/libevent/buffer_iocp.c index 2af0c49cc6..e5a4b76292 100644 --- a/contrib/libs/libevent/buffer_iocp.c +++ b/contrib/libs/libevent/buffer_iocp.c @@ -30,8 +30,8 @@ This module implements overlapped read and write functions for evbuffer objects on Windows. */ -#include "event2/event-config.h" -#include "evconfig-private.h" +#include "event2/event-config.h" +#include "evconfig-private.h" #include "event2/buffer.h" #include "event2/buffer_compat.h" @@ -44,7 +44,7 @@ #include "mm-internal.h" #include <winsock2.h> -#include <winerror.h> +#include <winerror.h> #include <windows.h> #include <stdio.h> @@ -89,13 +89,13 @@ pin_release(struct evbuffer_overlapped *eo, unsigned flag) for (i = 0; i < eo->n_buffers; ++i) { EVUTIL_ASSERT(chain); next = chain->next; - evbuffer_chain_unpin_(chain, flag); + evbuffer_chain_unpin_(chain, flag); chain = next; } } void -evbuffer_commit_read_(struct evbuffer *evbuf, ev_ssize_t nBytes) +evbuffer_commit_read_(struct evbuffer *evbuf, ev_ssize_t nBytes) { struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf); struct evbuffer_chain **chainp; @@ -130,13 +130,13 @@ evbuffer_commit_read_(struct evbuffer *evbuf, ev_ssize_t nBytes) evbuf->total_len += nBytes; evbuf->n_add_for_cb += nBytes; - evbuffer_invoke_callbacks_(evbuf); + evbuffer_invoke_callbacks_(evbuf); - evbuffer_decref_and_unlock_(evbuf); + evbuffer_decref_and_unlock_(evbuf); } void -evbuffer_commit_write_(struct evbuffer *evbuf, ev_ssize_t nBytes) +evbuffer_commit_write_(struct evbuffer *evbuf, ev_ssize_t nBytes) { struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf); @@ -146,11 +146,11 @@ evbuffer_commit_write_(struct evbuffer *evbuf, ev_ssize_t nBytes) evbuffer_drain(evbuf, nBytes); pin_release(buf,EVBUFFER_MEM_PINNED_W); buf->write_in_progress = 0; - evbuffer_decref_and_unlock_(evbuf); + evbuffer_decref_and_unlock_(evbuf); } struct evbuffer * -evbuffer_overlapped_new_(evutil_socket_t fd) +evbuffer_overlapped_new_(evutil_socket_t fd) { struct evbuffer_overlapped *evo; @@ -158,7 +158,7 @@ evbuffer_overlapped_new_(evutil_socket_t fd) if (!evo) return NULL; - LIST_INIT(&evo->buffer.callbacks); + LIST_INIT(&evo->buffer.callbacks); evo->buffer.refcnt = 1; evo->buffer.last_with_datap = &evo->buffer.first; @@ -169,7 +169,7 @@ evbuffer_overlapped_new_(evutil_socket_t fd) } int -evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t at_most, +evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t at_most, struct event_overlapped *ol) { struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); @@ -205,7 +205,7 @@ evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t at_most, for (i=0; i < MAX_WSABUFS && chain; ++i, chain=chain->next) { WSABUF *b = &buf_o->buffers[i]; b->buf = (char*)( chain->buffer + chain->misalign ); - evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_W); + evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_W); if ((size_t)at_most > chain->off) { /* XXXX Cast is safe for now, since win32 has no @@ -222,7 +222,7 @@ evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t at_most, } buf_o->n_buffers = i; - evbuffer_incref_(buf); + evbuffer_incref_(buf); if (WSASend(buf_o->fd, buf_o->buffers, i, &bytesSent, 0, &ol->overlapped, NULL)) { int error = WSAGetLastError(); @@ -243,7 +243,7 @@ done: } int -evbuffer_launch_read_(struct evbuffer *buf, size_t at_most, +evbuffer_launch_read_(struct evbuffer *buf, size_t at_most, struct event_overlapped *ol) { struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); @@ -266,11 +266,11 @@ evbuffer_launch_read_(struct evbuffer *buf, size_t at_most, buf_o->n_buffers = 0; memset(buf_o->buffers, 0, sizeof(buf_o->buffers)); - if (evbuffer_expand_fast_(buf, at_most, MAX_WSABUFS) == -1) + if (evbuffer_expand_fast_(buf, at_most, MAX_WSABUFS) == -1) goto done; evbuffer_freeze(buf, 0); - nvecs = evbuffer_read_setup_vecs_(buf, at_most, + nvecs = evbuffer_read_setup_vecs_(buf, at_most, vecs, MAX_WSABUFS, &chainp, 1); for (i=0;i<nvecs;++i) { WSABUF_FROM_EVBUFFER_IOV( @@ -283,12 +283,12 @@ evbuffer_launch_read_(struct evbuffer *buf, size_t at_most, npin=0; for ( ; chain; chain = chain->next) { - evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_R); + evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_R); ++npin; } EVUTIL_ASSERT(npin == nvecs); - evbuffer_incref_(buf); + evbuffer_incref_(buf); if (WSARecv(buf_o->fd, buf_o->buffers, nvecs, &bytesRead, &flags, &ol->overlapped, NULL)) { int error = WSAGetLastError(); @@ -309,14 +309,14 @@ done: } evutil_socket_t -evbuffer_overlapped_get_fd_(struct evbuffer *buf) +evbuffer_overlapped_get_fd_(struct evbuffer *buf) { struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); return buf_o ? buf_o->fd : -1; } void -evbuffer_overlapped_set_fd_(struct evbuffer *buf, evutil_socket_t fd) +evbuffer_overlapped_set_fd_(struct evbuffer *buf, evutil_socket_t fd) { struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); EVBUFFER_LOCK(buf); diff --git a/contrib/libs/libevent/bufferevent-internal.h b/contrib/libs/libevent/bufferevent-internal.h index c89fa0d6b7..be3950fe0a 100644 --- a/contrib/libs/libevent/bufferevent-internal.h +++ b/contrib/libs/libevent/bufferevent-internal.h @@ -23,16 +23,16 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef BUFFEREVENT_INTERNAL_H_INCLUDED_ -#define BUFFEREVENT_INTERNAL_H_INCLUDED_ +#ifndef BUFFEREVENT_INTERNAL_H_INCLUDED_ +#define BUFFEREVENT_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { #endif #include "event2/event-config.h" -#include "event2/event_struct.h" -#include "evconfig-private.h" +#include "event2/event_struct.h" +#include "evconfig-private.h" #include "event2/util.h" #include "defer-internal.h" #include "evthread-internal.h" @@ -40,17 +40,17 @@ extern "C" { #include "ratelim-internal.h" #include "event2/bufferevent_struct.h" -#include "ipv6-internal.h" -#ifdef _WIN32 -#include <ws2tcpip.h> -#endif -#ifdef EVENT__HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif -#ifdef EVENT__HAVE_NETINET_IN6_H -#error #include <netinet/in6.h> -#endif - +#include "ipv6-internal.h" +#ifdef _WIN32 +#include <ws2tcpip.h> +#endif +#ifdef EVENT__HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#ifdef EVENT__HAVE_NETINET_IN6_H +#error #include <netinet/in6.h> +#endif + /* These flags are reasons that we might be declining to actually enable reading or writing on a bufferevent. */ @@ -78,7 +78,7 @@ typedef ev_uint16_t bufferevent_suspend_flags; struct bufferevent_rate_limit_group { /** List of all members in the group */ - LIST_HEAD(rlim_group_member_list, bufferevent_private) members; + LIST_HEAD(rlim_group_member_list, bufferevent_private) members; /** Current limits for the group. */ struct ev_token_bucket rate_limit; struct ev_token_bucket_cfg rate_limit_cfg; @@ -116,10 +116,10 @@ struct bufferevent_rate_limit_group { /** Timeout event that goes off once a tick, when the bucket is ready * to refill. */ struct event master_refill_event; - - /** Seed for weak random number generator. Protected by 'lock' */ - struct evutil_weakrand_state weakrand_seed; - + + /** Seed for weak random number generator. Protected by 'lock' */ + struct evutil_weakrand_state weakrand_seed; + /** Lock to protect the members of this group. This lock should nest * within every bufferevent lock: if you are holding this lock, do * not assume you can lock another bufferevent. */ @@ -133,7 +133,7 @@ struct bufferevent_rate_limit { * * Note that this field is supposed to be protected by the group * lock */ - LIST_ENTRY(bufferevent_private) next_in_group; + LIST_ENTRY(bufferevent_private) next_in_group; /** The rate-limiting group for this bufferevent, or NULL if it is * only rate-limited on its own. */ struct bufferevent_rate_limit_group *group; @@ -194,7 +194,7 @@ struct bufferevent_private { int dns_error; /** Used to implement deferred callbacks */ - struct event_callback deferred; + struct event_callback deferred; /** The options this bufferevent was constructed with */ enum bufferevent_options options; @@ -206,30 +206,30 @@ struct bufferevent_private { * If NULL, locking is disabled. */ void *lock; - /** No matter how big our bucket gets, don't try to read more than this - * much in a single read operation. */ - ev_ssize_t max_single_read; - - /** No matter how big our bucket gets, don't try to write more than this - * much in a single write operation. */ - ev_ssize_t max_single_write; - + /** No matter how big our bucket gets, don't try to read more than this + * much in a single read operation. */ + ev_ssize_t max_single_read; + + /** No matter how big our bucket gets, don't try to write more than this + * much in a single write operation. */ + ev_ssize_t max_single_write; + /** Rate-limiting information for this bufferevent */ struct bufferevent_rate_limit *rate_limiting; - - /* Saved conn_addr, to extract IP address from it. - * - * Because some servers may reset/close connection without waiting clients, - * in that case we can't extract IP address even in close_cb. - * So we need to save it, just after we connected to remote server, or - * after resolving (to avoid extra dns requests during retrying, since UDP - * is slow) */ - union { - struct sockaddr_in6 in6; - struct sockaddr_in in; - } conn_address; - - struct evdns_getaddrinfo_request *dns_request; + + /* Saved conn_addr, to extract IP address from it. + * + * Because some servers may reset/close connection without waiting clients, + * in that case we can't extract IP address even in close_cb. + * So we need to save it, just after we connected to remote server, or + * after resolving (to avoid extra dns requests during retrying, since UDP + * is slow) */ + union { + struct sockaddr_in6 in6; + struct sockaddr_in in; + } conn_address; + + struct evdns_getaddrinfo_request *dns_request; }; /** Possible operations for a control callback. */ @@ -277,13 +277,13 @@ struct bufferevent_ops { */ int (*disable)(struct bufferevent *, short); - /** Detatches the bufferevent from related data structures. Called as - * soon as its reference count reaches 0. */ - void (*unlink)(struct bufferevent *); - + /** Detatches the bufferevent from related data structures. Called as + * soon as its reference count reaches 0. */ + void (*unlink)(struct bufferevent *); + /** Free any storage and deallocate any extra data or structures used - in this implementation. Called when the bufferevent is - finalized. + in this implementation. Called when the bufferevent is + finalized. */ void (*destruct)(struct bufferevent *); @@ -306,14 +306,14 @@ extern const struct bufferevent_ops bufferevent_ops_pair; #define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter) #define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair) -#if defined(EVENT__HAVE_OPENSSL) -extern const struct bufferevent_ops bufferevent_ops_openssl; -#define BEV_IS_OPENSSL(bevp) ((bevp)->be_ops == &bufferevent_ops_openssl) -#else -#define BEV_IS_OPENSSL(bevp) 0 -#endif - -#ifdef _WIN32 +#if defined(EVENT__HAVE_OPENSSL) +extern const struct bufferevent_ops bufferevent_ops_openssl; +#define BEV_IS_OPENSSL(bevp) ((bevp)->be_ops == &bufferevent_ops_openssl) +#else +#define BEV_IS_OPENSSL(bevp) 0 +#endif + +#ifdef _WIN32 extern const struct bufferevent_ops bufferevent_ops_async; #define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async) #else @@ -321,103 +321,103 @@ extern const struct bufferevent_ops bufferevent_ops_async; #endif /** Initialize the shared parts of a bufferevent. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_init_common_(struct bufferevent_private *, struct event_base *, const struct bufferevent_ops *, enum bufferevent_options options); +EVENT2_EXPORT_SYMBOL +int bufferevent_init_common_(struct bufferevent_private *, struct event_base *, const struct bufferevent_ops *, enum bufferevent_options options); /** For internal use: temporarily stop all reads on bufev, until the conditions * in 'what' are over. */ -EVENT2_EXPORT_SYMBOL -void bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what); +EVENT2_EXPORT_SYMBOL +void bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what); /** For internal use: clear the conditions 'what' on bufev, and re-enable * reading if there are no conditions left. */ -EVENT2_EXPORT_SYMBOL -void bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what); +EVENT2_EXPORT_SYMBOL +void bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what); /** For internal use: temporarily stop all writes on bufev, until the conditions * in 'what' are over. */ -void bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what); +void bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what); /** For internal use: clear the conditions 'what' on bufev, and re-enable * writing if there are no conditions left. */ -void bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what); +void bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what); #define bufferevent_wm_suspend_read(b) \ - bufferevent_suspend_read_((b), BEV_SUSPEND_WM) + bufferevent_suspend_read_((b), BEV_SUSPEND_WM) #define bufferevent_wm_unsuspend_read(b) \ - bufferevent_unsuspend_read_((b), BEV_SUSPEND_WM) + bufferevent_unsuspend_read_((b), BEV_SUSPEND_WM) /* Disable a bufferevent. Equivalent to bufferevent_disable(), but first resets 'connecting' flag to force EV_WRITE down for sure. XXXX this method will go away in the future; try not to add new users. - See comment in evhttp_connection_reset_() for discussion. + See comment in evhttp_connection_reset_() for discussion. @param bufev the bufferevent to be disabled @param event any combination of EV_READ | EV_WRITE. @return 0 if successful, or -1 if an error occurred @see bufferevent_disable() */ -EVENT2_EXPORT_SYMBOL -int bufferevent_disable_hard_(struct bufferevent *bufev, short event); +EVENT2_EXPORT_SYMBOL +int bufferevent_disable_hard_(struct bufferevent *bufev, short event); /** Internal: Set up locking on a bufferevent. If lock is set, use it. * Otherwise, use a new lock. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_enable_locking_(struct bufferevent *bufev, void *lock); -/** Internal: backwards compat macro for the now public function - * Increment the reference count on bufev. */ -#define bufferevent_incref_(bufev) bufferevent_incref(bufev) +EVENT2_EXPORT_SYMBOL +int bufferevent_enable_locking_(struct bufferevent *bufev, void *lock); +/** Internal: backwards compat macro for the now public function + * Increment the reference count on bufev. */ +#define bufferevent_incref_(bufev) bufferevent_incref(bufev) /** Internal: Lock bufev and increase its reference count. * unlocking it otherwise. */ -EVENT2_EXPORT_SYMBOL -void bufferevent_incref_and_lock_(struct bufferevent *bufev); -/** Internal: backwards compat macro for the now public function - * Decrement the reference count on bufev. Returns 1 if it freed +EVENT2_EXPORT_SYMBOL +void bufferevent_incref_and_lock_(struct bufferevent *bufev); +/** Internal: backwards compat macro for the now public function + * Decrement the reference count on bufev. Returns 1 if it freed * the bufferevent.*/ -#define bufferevent_decref_(bufev) bufferevent_decref(bufev) - +#define bufferevent_decref_(bufev) bufferevent_decref(bufev) + /** Internal: Drop the reference count on bufev, freeing as necessary, and * unlocking it otherwise. Returns 1 if it freed the bufferevent. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_decref_and_unlock_(struct bufferevent *bufev); +EVENT2_EXPORT_SYMBOL +int bufferevent_decref_and_unlock_(struct bufferevent *bufev); /** Internal: If callbacks are deferred and we have a read callback, schedule - * a readcb. Otherwise just run the readcb. Ignores watermarks. */ -EVENT2_EXPORT_SYMBOL -void bufferevent_run_readcb_(struct bufferevent *bufev, int options); + * a readcb. Otherwise just run the readcb. Ignores watermarks. */ +EVENT2_EXPORT_SYMBOL +void bufferevent_run_readcb_(struct bufferevent *bufev, int options); /** Internal: If callbacks are deferred and we have a write callback, schedule - * a writecb. Otherwise just run the writecb. Ignores watermarks. */ -EVENT2_EXPORT_SYMBOL -void bufferevent_run_writecb_(struct bufferevent *bufev, int options); + * a writecb. Otherwise just run the writecb. Ignores watermarks. */ +EVENT2_EXPORT_SYMBOL +void bufferevent_run_writecb_(struct bufferevent *bufev, int options); /** Internal: If callbacks are deferred and we have an eventcb, schedule - * it to run with events "what". Otherwise just run the eventcb. - * See bufferevent_trigger_event for meaning of "options". */ -EVENT2_EXPORT_SYMBOL -void bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options); - -/** Internal: Run or schedule (if deferred or options contain - * BEV_TRIG_DEFER_CALLBACKS) I/O callbacks specified in iotype. - * Must already hold the bufev lock. Honors watermarks unless - * BEV_TRIG_IGNORE_WATERMARKS is in options. */ -static inline void bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options); - -/* Making this inline since all of the common-case calls to this function in - * libevent use constant arguments. */ -static inline void -bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options) -{ - if ((iotype & EV_READ) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || - evbuffer_get_length(bufev->input) >= bufev->wm_read.low)) - bufferevent_run_readcb_(bufev, options); - if ((iotype & EV_WRITE) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || - evbuffer_get_length(bufev->output) <= bufev->wm_write.low)) - bufferevent_run_writecb_(bufev, options); -} - + * it to run with events "what". Otherwise just run the eventcb. + * See bufferevent_trigger_event for meaning of "options". */ +EVENT2_EXPORT_SYMBOL +void bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options); + +/** Internal: Run or schedule (if deferred or options contain + * BEV_TRIG_DEFER_CALLBACKS) I/O callbacks specified in iotype. + * Must already hold the bufev lock. Honors watermarks unless + * BEV_TRIG_IGNORE_WATERMARKS is in options. */ +static inline void bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options); + +/* Making this inline since all of the common-case calls to this function in + * libevent use constant arguments. */ +static inline void +bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options) +{ + if ((iotype & EV_READ) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || + evbuffer_get_length(bufev->input) >= bufev->wm_read.low)) + bufferevent_run_readcb_(bufev, options); + if ((iotype & EV_WRITE) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || + evbuffer_get_length(bufev->output) <= bufev->wm_write.low)) + bufferevent_run_writecb_(bufev, options); +} + /** Internal: Add the event 'ev' with timeout tv, unless tv is set to 0, in * which case add ev with no timeout. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_add_event_(struct event *ev, const struct timeval *tv); +EVENT2_EXPORT_SYMBOL +int bufferevent_add_event_(struct event *ev, const struct timeval *tv); /* ========= * These next functions implement timeouts for bufferevents that aren't doing @@ -426,33 +426,33 @@ int bufferevent_add_event_(struct event *ev, const struct timeval *tv); /** Internal use: Set up the ev_read and ev_write callbacks so that * the other "generic_timeout" functions will work on it. Call this from * the constructor function. */ -EVENT2_EXPORT_SYMBOL -void bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev); +EVENT2_EXPORT_SYMBOL +void bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev); /** Internal use: Add or delete the generic timeout events as appropriate. * (If an event is enabled and a timeout is set, we add the event. Otherwise * we delete it.) Call this from anything that changes the timeout values, * that enabled EV_READ or EV_WRITE, or that disables EV_READ or EV_WRITE. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_generic_adj_timeouts_(struct bufferevent *bev); -EVENT2_EXPORT_SYMBOL -int bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev); - -EVENT2_EXPORT_SYMBOL -enum bufferevent_options bufferevent_get_options_(struct bufferevent *bev); - -EVENT2_EXPORT_SYMBOL -const struct sockaddr* -bufferevent_socket_get_conn_address_(struct bufferevent *bev); - -EVENT2_EXPORT_SYMBOL -void -bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, evutil_socket_t fd); - -EVENT2_EXPORT_SYMBOL -void -bufferevent_socket_set_conn_address_(struct bufferevent *bev, struct sockaddr *addr, size_t addrlen); - - +EVENT2_EXPORT_SYMBOL +int bufferevent_generic_adj_timeouts_(struct bufferevent *bev); +EVENT2_EXPORT_SYMBOL +int bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev); + +EVENT2_EXPORT_SYMBOL +enum bufferevent_options bufferevent_get_options_(struct bufferevent *bev); + +EVENT2_EXPORT_SYMBOL +const struct sockaddr* +bufferevent_socket_get_conn_address_(struct bufferevent *bev); + +EVENT2_EXPORT_SYMBOL +void +bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, evutil_socket_t fd); + +EVENT2_EXPORT_SYMBOL +void +bufferevent_socket_set_conn_address_(struct bufferevent *bev, struct sockaddr *addr, size_t addrlen); + + /** Internal use: We have just successfully read data into an inbuf, so * reset the read timeout (if any). */ #define BEV_RESET_GENERIC_READ_TIMEOUT(bev) \ @@ -477,9 +477,9 @@ bufferevent_socket_set_conn_address_(struct bufferevent *bev, struct sockaddr *a * bufferevent_private. */ #define BEV_UPCAST(b) EVUTIL_UPCAST((b), struct bufferevent_private, bev) -#ifdef EVENT__DISABLE_THREAD_SUPPORT -#define BEV_LOCK(b) EVUTIL_NIL_STMT_ -#define BEV_UNLOCK(b) EVUTIL_NIL_STMT_ +#ifdef EVENT__DISABLE_THREAD_SUPPORT +#define BEV_LOCK(b) EVUTIL_NIL_STMT_ +#define BEV_UNLOCK(b) EVUTIL_NIL_STMT_ #else /** Internal: Grab the lock (if any) on a bufferevent */ #define BEV_LOCK(b) do { \ @@ -497,22 +497,22 @@ bufferevent_socket_set_conn_address_(struct bufferevent *bev, struct sockaddr *a /* ==== For rate-limiting. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, +EVENT2_EXPORT_SYMBOL +int bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes); -EVENT2_EXPORT_SYMBOL -int bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, +EVENT2_EXPORT_SYMBOL +int bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes); -EVENT2_EXPORT_SYMBOL -ev_ssize_t bufferevent_get_read_max_(struct bufferevent_private *bev); -EVENT2_EXPORT_SYMBOL -ev_ssize_t bufferevent_get_write_max_(struct bufferevent_private *bev); - -int bufferevent_ratelim_init_(struct bufferevent_private *bev); +EVENT2_EXPORT_SYMBOL +ev_ssize_t bufferevent_get_read_max_(struct bufferevent_private *bev); +EVENT2_EXPORT_SYMBOL +ev_ssize_t bufferevent_get_write_max_(struct bufferevent_private *bev); +int bufferevent_ratelim_init_(struct bufferevent_private *bev); + #ifdef __cplusplus } #endif -#endif /* BUFFEREVENT_INTERNAL_H_INCLUDED_ */ +#endif /* BUFFEREVENT_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/bufferevent.c b/contrib/libs/libevent/bufferevent.c index 08c0486c08..ed09604241 100644 --- a/contrib/libs/libevent/bufferevent.c +++ b/contrib/libs/libevent/bufferevent.c @@ -25,12 +25,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "event2/event-config.h" -#include "evconfig-private.h" - +#include "event2/event-config.h" +#include "evconfig-private.h" + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -38,11 +38,11 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_STDARG_H +#ifdef EVENT__HAVE_STDARG_H #include <stdarg.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #endif @@ -53,20 +53,20 @@ #include "event2/bufferevent_struct.h" #include "event2/bufferevent_compat.h" #include "event2/event.h" -#include "event-internal.h" +#include "event-internal.h" #include "log-internal.h" #include "mm-internal.h" #include "bufferevent-internal.h" #include "evbuffer-internal.h" #include "util-internal.h" -static void bufferevent_cancel_all_(struct bufferevent *bev); -static void bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_); +static void bufferevent_cancel_all_(struct bufferevent *bev); +static void bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_); void -bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what) +bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); if (!bufev_private->read_suspended) bufev->be_ops->disable(bufev, EV_READ); @@ -75,9 +75,9 @@ bufferevent_suspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags w } void -bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what) +bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags what) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); bufev_private->read_suspended &= ~what; if (!bufev_private->read_suspended && (bufev->enabled & EV_READ)) @@ -86,9 +86,9 @@ bufferevent_unsuspend_read_(struct bufferevent *bufev, bufferevent_suspend_flags } void -bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what) +bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); if (!bufev_private->write_suspended) bufev->be_ops->disable(bufev, EV_WRITE); @@ -97,9 +97,9 @@ bufferevent_suspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags } void -bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what) +bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flags what) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); bufev_private->write_suspended &= ~what; if (!bufev_private->write_suspended && (bufev->enabled & EV_WRITE)) @@ -107,29 +107,29 @@ bufferevent_unsuspend_write_(struct bufferevent *bufev, bufferevent_suspend_flag BEV_UNLOCK(bufev); } -/** - * Sometimes bufferevent's implementation can overrun high watermarks - * (one of examples is openssl) and in this case if the read callback - * will not handle enough data do over condition above the read - * callback will never be called again (due to suspend above). - * - * To avoid this we are scheduling read callback again here, but only - * from the user callback to avoid multiple scheduling: - * - when the data had been added to it - * - when the data had been drained from it (user specified read callback) - */ -static void bufferevent_inbuf_wm_check(struct bufferevent *bev) -{ - if (!bev->wm_read.high) - return; - if (!(bev->enabled & EV_READ)) - return; - if (evbuffer_get_length(bev->input) < bev->wm_read.high) - return; - - bufferevent_trigger(bev, EV_READ, BEV_OPT_DEFER_CALLBACKS); -} - +/** + * Sometimes bufferevent's implementation can overrun high watermarks + * (one of examples is openssl) and in this case if the read callback + * will not handle enough data do over condition above the read + * callback will never be called again (due to suspend above). + * + * To avoid this we are scheduling read callback again here, but only + * from the user callback to avoid multiple scheduling: + * - when the data had been added to it + * - when the data had been drained from it (user specified read callback) + */ +static void bufferevent_inbuf_wm_check(struct bufferevent *bev) +{ + if (!bev->wm_read.high) + return; + if (!(bev->enabled & EV_READ)) + return; + if (evbuffer_get_length(bev->input) < bev->wm_read.high) + return; + + bufferevent_trigger(bev, EV_READ, BEV_OPT_DEFER_CALLBACKS); +} + /* Callback to implement watermarks on the input buffer. Only enabled * if the watermark is set. */ static void @@ -149,7 +149,7 @@ bufferevent_inbuf_wm_cb(struct evbuffer *buf, } static void -bufferevent_run_deferred_callbacks_locked(struct event_callback *cb, void *arg) +bufferevent_run_deferred_callbacks_locked(struct event_callback *cb, void *arg) { struct bufferevent_private *bufev_private = arg; struct bufferevent *bufev = &bufev_private->bev; @@ -165,7 +165,7 @@ bufferevent_run_deferred_callbacks_locked(struct event_callback *cb, void *arg) if (bufev_private->readcb_pending && bufev->readcb) { bufev_private->readcb_pending = 0; bufev->readcb(bufev, bufev->cbarg); - bufferevent_inbuf_wm_check(bufev); + bufferevent_inbuf_wm_check(bufev); } if (bufev_private->writecb_pending && bufev->writecb) { bufev_private->writecb_pending = 0; @@ -179,11 +179,11 @@ bufferevent_run_deferred_callbacks_locked(struct event_callback *cb, void *arg) EVUTIL_SET_SOCKET_ERROR(err); bufev->errorcb(bufev, what, bufev->cbarg); } - bufferevent_decref_and_unlock_(bufev); + bufferevent_decref_and_unlock_(bufev); } static void -bufferevent_run_deferred_callbacks_unlocked(struct event_callback *cb, void *arg) +bufferevent_run_deferred_callbacks_unlocked(struct event_callback *cb, void *arg) { struct bufferevent_private *bufev_private = arg; struct bufferevent *bufev = &bufev_private->bev; @@ -206,7 +206,7 @@ bufferevent_run_deferred_callbacks_unlocked(struct event_callback *cb, void *arg void *cbarg = bufev->cbarg; bufev_private->readcb_pending = 0; UNLOCKED(readcb(bufev, cbarg)); - bufferevent_inbuf_wm_check(bufev); + bufferevent_inbuf_wm_check(bufev); } if (bufev_private->writecb_pending && bufev->writecb) { bufferevent_data_cb writecb = bufev->writecb; @@ -224,89 +224,89 @@ bufferevent_run_deferred_callbacks_unlocked(struct event_callback *cb, void *arg EVUTIL_SET_SOCKET_ERROR(err); UNLOCKED(errorcb(bufev,what,cbarg)); } - bufferevent_decref_and_unlock_(bufev); + bufferevent_decref_and_unlock_(bufev); #undef UNLOCKED } #define SCHEDULE_DEFERRED(bevp) \ do { \ - if (event_deferred_cb_schedule_( \ - (bevp)->bev.ev_base, \ - &(bevp)->deferred)) \ - bufferevent_incref_(&(bevp)->bev); \ + if (event_deferred_cb_schedule_( \ + (bevp)->bev.ev_base, \ + &(bevp)->deferred)) \ + bufferevent_incref_(&(bevp)->bev); \ } while (0) void -bufferevent_run_readcb_(struct bufferevent *bufev, int options) +bufferevent_run_readcb_(struct bufferevent *bufev, int options) { /* Requires that we hold the lock and a reference */ - struct bufferevent_private *p = BEV_UPCAST(bufev); + struct bufferevent_private *p = BEV_UPCAST(bufev); if (bufev->readcb == NULL) return; - if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) { + if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) { p->readcb_pending = 1; - SCHEDULE_DEFERRED(p); + SCHEDULE_DEFERRED(p); } else { bufev->readcb(bufev, bufev->cbarg); - bufferevent_inbuf_wm_check(bufev); + bufferevent_inbuf_wm_check(bufev); } } void -bufferevent_run_writecb_(struct bufferevent *bufev, int options) +bufferevent_run_writecb_(struct bufferevent *bufev, int options) { /* Requires that we hold the lock and a reference */ - struct bufferevent_private *p = BEV_UPCAST(bufev); + struct bufferevent_private *p = BEV_UPCAST(bufev); if (bufev->writecb == NULL) return; - if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) { + if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) { p->writecb_pending = 1; - SCHEDULE_DEFERRED(p); + SCHEDULE_DEFERRED(p); } else { bufev->writecb(bufev, bufev->cbarg); } } -#define BEV_TRIG_ALL_OPTS ( \ - BEV_TRIG_IGNORE_WATERMARKS| \ - BEV_TRIG_DEFER_CALLBACKS \ - ) - -void -bufferevent_trigger(struct bufferevent *bufev, short iotype, int options) -{ - bufferevent_incref_and_lock_(bufev); - bufferevent_trigger_nolock_(bufev, iotype, options&BEV_TRIG_ALL_OPTS); - bufferevent_decref_and_unlock_(bufev); -} - +#define BEV_TRIG_ALL_OPTS ( \ + BEV_TRIG_IGNORE_WATERMARKS| \ + BEV_TRIG_DEFER_CALLBACKS \ + ) + void -bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options) +bufferevent_trigger(struct bufferevent *bufev, short iotype, int options) { + bufferevent_incref_and_lock_(bufev); + bufferevent_trigger_nolock_(bufev, iotype, options&BEV_TRIG_ALL_OPTS); + bufferevent_decref_and_unlock_(bufev); +} + +void +bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options) +{ /* Requires that we hold the lock and a reference */ - struct bufferevent_private *p = BEV_UPCAST(bufev); + struct bufferevent_private *p = BEV_UPCAST(bufev); if (bufev->errorcb == NULL) return; - if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) { + if ((p->options|options) & BEV_OPT_DEFER_CALLBACKS) { p->eventcb_pending |= what; p->errno_pending = EVUTIL_SOCKET_ERROR(); - SCHEDULE_DEFERRED(p); + SCHEDULE_DEFERRED(p); } else { bufev->errorcb(bufev, what, bufev->cbarg); } } -void -bufferevent_trigger_event(struct bufferevent *bufev, short what, int options) -{ - bufferevent_incref_and_lock_(bufev); - bufferevent_run_eventcb_(bufev, what, options&BEV_TRIG_ALL_OPTS); - bufferevent_decref_and_unlock_(bufev); -} - +void +bufferevent_trigger_event(struct bufferevent *bufev, short what, int options) +{ + bufferevent_incref_and_lock_(bufev); + bufferevent_run_eventcb_(bufev, what, options&BEV_TRIG_ALL_OPTS); + bufferevent_decref_and_unlock_(bufev); +} + int -bufferevent_init_common_(struct bufferevent_private *bufev_private, +bufferevent_init_common_(struct bufferevent_private *bufev_private, struct event_base *base, const struct bufferevent_ops *ops, enum bufferevent_options options) @@ -315,12 +315,12 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private, if (!bufev->input) { if ((bufev->input = evbuffer_new()) == NULL) - goto err; + goto err; } if (!bufev->output) { - if ((bufev->output = evbuffer_new()) == NULL) - goto err; + if ((bufev->output = evbuffer_new()) == NULL) + goto err; } bufev_private->refcnt = 1; @@ -332,9 +332,9 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private, bufev->be_ops = ops; - if (bufferevent_ratelim_init_(bufev_private)) - goto err; - + if (bufferevent_ratelim_init_(bufev_private)) + goto err; + /* * Set to EV_WRITE so that using bufferevent_write is going to * trigger a callback. Reading needs to be explicitly enabled @@ -342,47 +342,47 @@ bufferevent_init_common_(struct bufferevent_private *bufev_private, */ bufev->enabled = EV_WRITE; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT if (options & BEV_OPT_THREADSAFE) { - if (bufferevent_enable_locking_(bufev, NULL) < 0) - goto err; + if (bufferevent_enable_locking_(bufev, NULL) < 0) + goto err; } #endif if ((options & (BEV_OPT_DEFER_CALLBACKS|BEV_OPT_UNLOCK_CALLBACKS)) == BEV_OPT_UNLOCK_CALLBACKS) { event_warnx("UNLOCK_CALLBACKS requires DEFER_CALLBACKS"); - goto err; + goto err; } - if (options & BEV_OPT_UNLOCK_CALLBACKS) - event_deferred_cb_init_( - &bufev_private->deferred, - event_base_get_npriorities(base) / 2, - bufferevent_run_deferred_callbacks_unlocked, - bufev_private); - else - event_deferred_cb_init_( - &bufev_private->deferred, - event_base_get_npriorities(base) / 2, - bufferevent_run_deferred_callbacks_locked, - bufev_private); + if (options & BEV_OPT_UNLOCK_CALLBACKS) + event_deferred_cb_init_( + &bufev_private->deferred, + event_base_get_npriorities(base) / 2, + bufferevent_run_deferred_callbacks_unlocked, + bufev_private); + else + event_deferred_cb_init_( + &bufev_private->deferred, + event_base_get_npriorities(base) / 2, + bufferevent_run_deferred_callbacks_locked, + bufev_private); bufev_private->options = options; - evbuffer_set_parent_(bufev->input, bufev); - evbuffer_set_parent_(bufev->output, bufev); + evbuffer_set_parent_(bufev->input, bufev); + evbuffer_set_parent_(bufev->output, bufev); return 0; - -err: - if (bufev->input) { - evbuffer_free(bufev->input); - bufev->input = NULL; - } - if (bufev->output) { - evbuffer_free(bufev->output); - bufev->output = NULL; - } - return -1; + +err: + if (bufev->input) { + evbuffer_free(bufev->input); + bufev->input = NULL; + } + if (bufev->output) { + evbuffer_free(bufev->output); + bufev->output = NULL; + } + return -1; } void @@ -400,26 +400,26 @@ bufferevent_setcb(struct bufferevent *bufev, BEV_UNLOCK(bufev); } -void -bufferevent_getcb(struct bufferevent *bufev, - bufferevent_data_cb *readcb_ptr, - bufferevent_data_cb *writecb_ptr, - bufferevent_event_cb *eventcb_ptr, - void **cbarg_ptr) -{ - BEV_LOCK(bufev); - if (readcb_ptr) - *readcb_ptr = bufev->readcb; - if (writecb_ptr) - *writecb_ptr = bufev->writecb; - if (eventcb_ptr) - *eventcb_ptr = bufev->errorcb; - if (cbarg_ptr) - *cbarg_ptr = bufev->cbarg; - - BEV_UNLOCK(bufev); -} - +void +bufferevent_getcb(struct bufferevent *bufev, + bufferevent_data_cb *readcb_ptr, + bufferevent_data_cb *writecb_ptr, + bufferevent_event_cb *eventcb_ptr, + void **cbarg_ptr) +{ + BEV_LOCK(bufev); + if (readcb_ptr) + *readcb_ptr = bufev->readcb; + if (writecb_ptr) + *writecb_ptr = bufev->writecb; + if (eventcb_ptr) + *eventcb_ptr = bufev->errorcb; + if (cbarg_ptr) + *cbarg_ptr = bufev->cbarg; + + BEV_UNLOCK(bufev); +} + struct evbuffer * bufferevent_get_input(struct bufferevent *bufev) { @@ -439,16 +439,16 @@ bufferevent_get_base(struct bufferevent *bufev) } int -bufferevent_get_priority(const struct bufferevent *bufev) -{ - if (event_initialized(&bufev->ev_read)) { - return event_get_priority(&bufev->ev_read); - } else { - return event_base_get_npriorities(bufev->ev_base) / 2; - } -} - -int +bufferevent_get_priority(const struct bufferevent *bufev) +{ + if (event_initialized(&bufev->ev_read)) { + return event_get_priority(&bufev->ev_read); + } else { + return event_base_get_npriorities(bufev->ev_base) / 2; + } +} + +int bufferevent_write(struct bufferevent *bufev, const void *data, size_t size) { if (evbuffer_add(bufev->output, data, size) == -1) @@ -481,11 +481,11 @@ bufferevent_read_buffer(struct bufferevent *bufev, struct evbuffer *buf) int bufferevent_enable(struct bufferevent *bufev, short event) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); short impl_events = event; int r = 0; - bufferevent_incref_and_lock_(bufev); + bufferevent_incref_and_lock_(bufev); if (bufev_private->read_suspended) impl_events &= ~EV_READ; if (bufev_private->write_suspended) @@ -495,10 +495,10 @@ bufferevent_enable(struct bufferevent *bufev, short event) if (impl_events && bufev->be_ops->enable(bufev, impl_events) < 0) r = -1; - if (r) - event_debug(("%s: cannot enable 0x%hx on %p", __func__, event, bufev)); + if (r) + event_debug(("%s: cannot enable 0x%hx on %p", __func__, event, bufev)); - bufferevent_decref_and_unlock_(bufev); + bufferevent_decref_and_unlock_(bufev); return r; } @@ -553,10 +553,10 @@ bufferevent_settimeout(struct bufferevent *bufev, int -bufferevent_disable_hard_(struct bufferevent *bufev, short event) +bufferevent_disable_hard_(struct bufferevent *bufev, short event) { int r = 0; - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); bufev->enabled &= ~event; @@ -579,8 +579,8 @@ bufferevent_disable(struct bufferevent *bufev, short event) if (bufev->be_ops->disable(bufev, event) < 0) r = -1; - if (r) - event_debug(("%s: cannot disable 0x%hx on %p", __func__, event, bufev)); + if (r) + event_debug(("%s: cannot disable 0x%hx on %p", __func__, event, bufev)); BEV_UNLOCK(bufev); return r; @@ -594,7 +594,7 @@ void bufferevent_setwatermark(struct bufferevent *bufev, short events, size_t lowmark, size_t highmark) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); if (events & EV_WRITE) { @@ -638,32 +638,32 @@ bufferevent_setwatermark(struct bufferevent *bufev, short events, } int -bufferevent_getwatermark(struct bufferevent *bufev, short events, - size_t *lowmark, size_t *highmark) -{ - if (events == EV_WRITE) { - BEV_LOCK(bufev); - if (lowmark) - *lowmark = bufev->wm_write.low; - if (highmark) - *highmark = bufev->wm_write.high; - BEV_UNLOCK(bufev); - return 0; - } - - if (events == EV_READ) { - BEV_LOCK(bufev); - if (lowmark) - *lowmark = bufev->wm_read.low; - if (highmark) - *highmark = bufev->wm_read.high; - BEV_UNLOCK(bufev); - return 0; - } - return -1; -} - -int +bufferevent_getwatermark(struct bufferevent *bufev, short events, + size_t *lowmark, size_t *highmark) +{ + if (events == EV_WRITE) { + BEV_LOCK(bufev); + if (lowmark) + *lowmark = bufev->wm_write.low; + if (highmark) + *highmark = bufev->wm_write.high; + BEV_UNLOCK(bufev); + return 0; + } + + if (events == EV_READ) { + BEV_LOCK(bufev); + if (lowmark) + *lowmark = bufev->wm_read.low; + if (highmark) + *highmark = bufev->wm_read.high; + BEV_UNLOCK(bufev); + return 0; + } + return -1; +} + +int bufferevent_flush(struct bufferevent *bufev, short iotype, enum bufferevent_flush_mode mode) @@ -677,16 +677,16 @@ bufferevent_flush(struct bufferevent *bufev, } void -bufferevent_incref_and_lock_(struct bufferevent *bufev) +bufferevent_incref_and_lock_(struct bufferevent *bufev) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); BEV_LOCK(bufev); ++bufev_private->refcnt; } #if 0 static void -bufferevent_transfer_lock_ownership_(struct bufferevent *donor, +bufferevent_transfer_lock_ownership_(struct bufferevent *donor, struct bufferevent *recipient) { struct bufferevent_private *d = BEV_UPCAST(donor); @@ -703,12 +703,12 @@ bufferevent_transfer_lock_ownership_(struct bufferevent *donor, #endif int -bufferevent_decref_and_unlock_(struct bufferevent *bufev) +bufferevent_decref_and_unlock_(struct bufferevent *bufev) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); - int n_cbs = 0; -#define MAX_CBS 16 - struct event_callback *cbs[MAX_CBS]; + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + int n_cbs = 0; +#define MAX_CBS 16 + struct event_callback *cbs[MAX_CBS]; EVUTIL_ASSERT(bufev_private->refcnt > 0); @@ -717,40 +717,40 @@ bufferevent_decref_and_unlock_(struct bufferevent *bufev) return 0; } - if (bufev->be_ops->unlink) - bufev->be_ops->unlink(bufev); - - /* Okay, we're out of references. Let's finalize this once all the - * callbacks are done running. */ - cbs[0] = &bufev->ev_read.ev_evcallback; - cbs[1] = &bufev->ev_write.ev_evcallback; - cbs[2] = &bufev_private->deferred; - n_cbs = 3; - if (bufev_private->rate_limiting) { - struct event *e = &bufev_private->rate_limiting->refill_bucket_event; - if (event_initialized(e)) - cbs[n_cbs++] = &e->ev_evcallback; - } - n_cbs += evbuffer_get_callbacks_(bufev->input, cbs+n_cbs, MAX_CBS-n_cbs); - n_cbs += evbuffer_get_callbacks_(bufev->output, cbs+n_cbs, MAX_CBS-n_cbs); - - event_callback_finalize_many_(bufev->ev_base, n_cbs, cbs, - bufferevent_finalize_cb_); - -#undef MAX_CBS - BEV_UNLOCK(bufev); - - return 1; -} - -static void -bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_) -{ - struct bufferevent *bufev = arg_; - struct bufferevent *underlying; - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); - - BEV_LOCK(bufev); + if (bufev->be_ops->unlink) + bufev->be_ops->unlink(bufev); + + /* Okay, we're out of references. Let's finalize this once all the + * callbacks are done running. */ + cbs[0] = &bufev->ev_read.ev_evcallback; + cbs[1] = &bufev->ev_write.ev_evcallback; + cbs[2] = &bufev_private->deferred; + n_cbs = 3; + if (bufev_private->rate_limiting) { + struct event *e = &bufev_private->rate_limiting->refill_bucket_event; + if (event_initialized(e)) + cbs[n_cbs++] = &e->ev_evcallback; + } + n_cbs += evbuffer_get_callbacks_(bufev->input, cbs+n_cbs, MAX_CBS-n_cbs); + n_cbs += evbuffer_get_callbacks_(bufev->output, cbs+n_cbs, MAX_CBS-n_cbs); + + event_callback_finalize_many_(bufev->ev_base, n_cbs, cbs, + bufferevent_finalize_cb_); + +#undef MAX_CBS + BEV_UNLOCK(bufev); + + return 1; +} + +static void +bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_) +{ + struct bufferevent *bufev = arg_; + struct bufferevent *underlying; + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + + BEV_LOCK(bufev); underlying = bufferevent_get_underlying(bufev); /* Clean up the shared info */ @@ -766,14 +766,14 @@ bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_) if (bufev_private->rate_limiting) { if (bufev_private->rate_limiting->group) - bufferevent_remove_from_rate_limit_group_internal_(bufev,0); + bufferevent_remove_from_rate_limit_group_internal_(bufev,0); mm_free(bufev_private->rate_limiting); bufev_private->rate_limiting = NULL; } BEV_UNLOCK(bufev); - + if (bufev_private->own_lock) EVTHREAD_FREE_LOCK(bufev_private->lock, EVTHREAD_LOCKTYPE_RECURSIVE); @@ -792,14 +792,14 @@ bufferevent_finalize_cb_(struct event_callback *evcb, void *arg_) * It would probably save us some headaches. */ if (underlying) - bufferevent_decref_(underlying); + bufferevent_decref_(underlying); } int bufferevent_decref(struct bufferevent *bufev) { BEV_LOCK(bufev); - return bufferevent_decref_and_unlock_(bufev); + return bufferevent_decref_and_unlock_(bufev); } void @@ -807,28 +807,28 @@ bufferevent_free(struct bufferevent *bufev) { BEV_LOCK(bufev); bufferevent_setcb(bufev, NULL, NULL, NULL, NULL); - bufferevent_cancel_all_(bufev); - bufferevent_decref_and_unlock_(bufev); + bufferevent_cancel_all_(bufev); + bufferevent_decref_and_unlock_(bufev); } void bufferevent_incref(struct bufferevent *bufev) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); - /* XXX: now that this function is public, we might want to - * - return the count from this function - * - create a new function to atomically grab the current refcount - */ + /* XXX: now that this function is public, we might want to + * - return the count from this function + * - create a new function to atomically grab the current refcount + */ BEV_LOCK(bufev); ++bufev_private->refcnt; BEV_UNLOCK(bufev); } int -bufferevent_enable_locking_(struct bufferevent *bufev, void *lock) +bufferevent_enable_locking_(struct bufferevent *bufev, void *lock) { -#ifdef EVENT__DISABLE_THREAD_SUPPORT +#ifdef EVENT__DISABLE_THREAD_SUPPORT return -1; #else struct bufferevent *underlying; @@ -855,7 +855,7 @@ bufferevent_enable_locking_(struct bufferevent *bufev, void *lock) evbuffer_enable_locking(bufev->output, lock); if (underlying && !BEV_UPCAST(underlying)->lock) - bufferevent_enable_locking_(underlying, lock); + bufferevent_enable_locking_(underlying, lock); return 0; #endif @@ -870,8 +870,8 @@ bufferevent_setfd(struct bufferevent *bev, evutil_socket_t fd) BEV_LOCK(bev); if (bev->be_ops->ctrl) res = bev->be_ops->ctrl(bev, BEV_CTRL_SET_FD, &d); - if (res) - event_debug(("%s: cannot set fd for %p to "EV_SOCK_FMT, __func__, bev, fd)); + if (res) + event_debug(("%s: cannot set fd for %p to "EV_SOCK_FMT, __func__, bev, fd)); BEV_UNLOCK(bev); return res; } @@ -885,27 +885,27 @@ bufferevent_getfd(struct bufferevent *bev) BEV_LOCK(bev); if (bev->be_ops->ctrl) res = bev->be_ops->ctrl(bev, BEV_CTRL_GET_FD, &d); - if (res) - event_debug(("%s: cannot get fd for %p", __func__, bev)); + if (res) + event_debug(("%s: cannot get fd for %p", __func__, bev)); BEV_UNLOCK(bev); return (res<0) ? -1 : d.fd; } -enum bufferevent_options -bufferevent_get_options_(struct bufferevent *bev) -{ - struct bufferevent_private *bev_p = BEV_UPCAST(bev); - enum bufferevent_options options; - - BEV_LOCK(bev); - options = bev_p->options; - BEV_UNLOCK(bev); - return options; -} - - +enum bufferevent_options +bufferevent_get_options_(struct bufferevent *bev) +{ + struct bufferevent_private *bev_p = BEV_UPCAST(bev); + enum bufferevent_options options; + + BEV_LOCK(bev); + options = bev_p->options; + BEV_UNLOCK(bev); + return options; +} + + static void -bufferevent_cancel_all_(struct bufferevent *bev) +bufferevent_cancel_all_(struct bufferevent *bev) { union bufferevent_ctrl_data d; memset(&d, 0, sizeof(d)); @@ -942,35 +942,35 @@ static void bufferevent_generic_read_timeout_cb(evutil_socket_t fd, short event, void *ctx) { struct bufferevent *bev = ctx; - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); bufferevent_disable(bev, EV_READ); - bufferevent_run_eventcb_(bev, BEV_EVENT_TIMEOUT|BEV_EVENT_READING, 0); - bufferevent_decref_and_unlock_(bev); + bufferevent_run_eventcb_(bev, BEV_EVENT_TIMEOUT|BEV_EVENT_READING, 0); + bufferevent_decref_and_unlock_(bev); } static void bufferevent_generic_write_timeout_cb(evutil_socket_t fd, short event, void *ctx) { struct bufferevent *bev = ctx; - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); bufferevent_disable(bev, EV_WRITE); - bufferevent_run_eventcb_(bev, BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING, 0); - bufferevent_decref_and_unlock_(bev); + bufferevent_run_eventcb_(bev, BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING, 0); + bufferevent_decref_and_unlock_(bev); } void -bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev) +bufferevent_init_generic_timeout_cbs_(struct bufferevent *bev) { - event_assign(&bev->ev_read, bev->ev_base, -1, EV_FINALIZE, + event_assign(&bev->ev_read, bev->ev_base, -1, EV_FINALIZE, bufferevent_generic_read_timeout_cb, bev); - event_assign(&bev->ev_write, bev->ev_base, -1, EV_FINALIZE, + event_assign(&bev->ev_write, bev->ev_base, -1, EV_FINALIZE, bufferevent_generic_write_timeout_cb, bev); } int -bufferevent_generic_adj_timeouts_(struct bufferevent *bev) +bufferevent_generic_adj_timeouts_(struct bufferevent *bev) { const short enabled = bev->enabled; - struct bufferevent_private *bev_p = BEV_UPCAST(bev); + struct bufferevent_private *bev_p = BEV_UPCAST(bev); int r1=0, r2=0; if ((enabled & EV_READ) && !bev_p->read_suspended && evutil_timerisset(&bev->timeout_read)) @@ -990,47 +990,47 @@ bufferevent_generic_adj_timeouts_(struct bufferevent *bev) } int -bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev) -{ - int r = 0; - if (event_pending(&bev->ev_read, EV_READ, NULL)) { - if (evutil_timerisset(&bev->timeout_read)) { - if (bufferevent_add_event_(&bev->ev_read, &bev->timeout_read) < 0) - r = -1; - } else { - event_remove_timer(&bev->ev_read); - } - } - if (event_pending(&bev->ev_write, EV_WRITE, NULL)) { - if (evutil_timerisset(&bev->timeout_write)) { - if (bufferevent_add_event_(&bev->ev_write, &bev->timeout_write) < 0) - r = -1; - } else { - event_remove_timer(&bev->ev_write); - } - } - return r; -} - -int -bufferevent_add_event_(struct event *ev, const struct timeval *tv) +bufferevent_generic_adj_existing_timeouts_(struct bufferevent *bev) { - if (!evutil_timerisset(tv)) + int r = 0; + if (event_pending(&bev->ev_read, EV_READ, NULL)) { + if (evutil_timerisset(&bev->timeout_read)) { + if (bufferevent_add_event_(&bev->ev_read, &bev->timeout_read) < 0) + r = -1; + } else { + event_remove_timer(&bev->ev_read); + } + } + if (event_pending(&bev->ev_write, EV_WRITE, NULL)) { + if (evutil_timerisset(&bev->timeout_write)) { + if (bufferevent_add_event_(&bev->ev_write, &bev->timeout_write) < 0) + r = -1; + } else { + event_remove_timer(&bev->ev_write); + } + } + return r; +} + +int +bufferevent_add_event_(struct event *ev, const struct timeval *tv) +{ + if (!evutil_timerisset(tv)) return event_add(ev, NULL); else return event_add(ev, tv); } /* For use by user programs only; internally, we should be calling - either bufferevent_incref_and_lock_(), or BEV_LOCK. */ + either bufferevent_incref_and_lock_(), or BEV_LOCK. */ void bufferevent_lock(struct bufferevent *bev) { - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); } void bufferevent_unlock(struct bufferevent *bev) { - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } diff --git a/contrib/libs/libevent/bufferevent_async.c b/contrib/libs/libevent/bufferevent_async.c index 40c7c5e8d0..5548721234 100644 --- a/contrib/libs/libevent/bufferevent_async.c +++ b/contrib/libs/libevent/bufferevent_async.c @@ -27,9 +27,9 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -37,16 +37,16 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_STDARG_H +#ifdef EVENT__HAVE_STDARG_H #include <stdarg.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> -#include <winerror.h> +#include <winerror.h> #include <ws2tcpip.h> #endif @@ -94,39 +94,39 @@ const struct bufferevent_ops bufferevent_ops_async = { evutil_offsetof(struct bufferevent_async, bev.bev), be_async_enable, be_async_disable, - NULL, /* Unlink */ + NULL, /* Unlink */ be_async_destruct, - bufferevent_generic_adj_timeouts_, + bufferevent_generic_adj_timeouts_, be_async_flush, be_async_ctrl, }; -static inline void -be_async_run_eventcb(struct bufferevent *bev, short what, int options) -{ bufferevent_run_eventcb_(bev, what, options|BEV_TRIG_DEFER_CALLBACKS); } - -static inline void -be_async_trigger_nolock(struct bufferevent *bev, short what, int options) -{ bufferevent_trigger_nolock_(bev, what, options|BEV_TRIG_DEFER_CALLBACKS); } - -static inline int -fatal_error(int err) -{ - switch (err) { - /* We may have already associated this fd with a port. - * Let's hope it's this port, and that the error code - * for doing this neer changes. */ - case ERROR_INVALID_PARAMETER: - return 0; - } - return 1; -} - +static inline void +be_async_run_eventcb(struct bufferevent *bev, short what, int options) +{ bufferevent_run_eventcb_(bev, what, options|BEV_TRIG_DEFER_CALLBACKS); } + +static inline void +be_async_trigger_nolock(struct bufferevent *bev, short what, int options) +{ bufferevent_trigger_nolock_(bev, what, options|BEV_TRIG_DEFER_CALLBACKS); } + +static inline int +fatal_error(int err) +{ + switch (err) { + /* We may have already associated this fd with a port. + * Let's hope it's this port, and that the error code + * for doing this neer changes. */ + case ERROR_INVALID_PARAMETER: + return 0; + } + return 1; +} + static inline struct bufferevent_async * upcast(struct bufferevent *bev) { struct bufferevent_async *bev_a; - if (!BEV_IS_ASYNC(bev)) + if (!BEV_IS_ASYNC(bev)) return NULL; bev_a = EVUTIL_UPCAST(bev, struct bufferevent_async, bev.bev); return bev_a; @@ -166,7 +166,7 @@ bev_async_del_write(struct bufferevent_async *beva) if (beva->write_added) { beva->write_added = 0; - event_base_del_virtual_(bev->ev_base); + event_base_del_virtual_(bev->ev_base); } } @@ -177,7 +177,7 @@ bev_async_del_read(struct bufferevent_async *beva) if (beva->read_added) { beva->read_added = 0; - event_base_del_virtual_(bev->ev_base); + event_base_del_virtual_(bev->ev_base); } } @@ -188,7 +188,7 @@ bev_async_add_write(struct bufferevent_async *beva) if (!beva->write_added) { beva->write_added = 1; - event_base_add_virtual_(bev->ev_base); + event_base_add_virtual_(bev->ev_base); } } @@ -199,7 +199,7 @@ bev_async_add_read(struct bufferevent_async *beva) if (!beva->read_added) { beva->read_added = 1; - event_base_add_virtual_(bev->ev_base); + event_base_add_virtual_(bev->ev_base); } } @@ -224,7 +224,7 @@ bev_async_consider_writing(struct bufferevent_async *beva) /* This is safe so long as bufferevent_get_write_max never returns * more than INT_MAX. That's true for now. XXXX */ - limit = (int)bufferevent_get_write_max_(&beva->bev); + limit = (int)bufferevent_get_write_max_(&beva->bev); if (at_most >= (size_t)limit && limit >= 0) at_most = limit; @@ -234,15 +234,15 @@ bev_async_consider_writing(struct bufferevent_async *beva) } /* XXXX doesn't respect low-water mark very well. */ - bufferevent_incref_(bev); - if (evbuffer_launch_write_(bev->output, at_most, + bufferevent_incref_(bev); + if (evbuffer_launch_write_(bev->output, at_most, &beva->write_overlapped)) { - bufferevent_decref_(bev); + bufferevent_decref_(bev); beva->ok = 0; - be_async_run_eventcb(bev, BEV_EVENT_ERROR, 0); + be_async_run_eventcb(bev, BEV_EVENT_ERROR, 0); } else { beva->write_in_progress = at_most; - bufferevent_decrement_write_buckets_(&beva->bev, at_most); + bufferevent_decrement_write_buckets_(&beva->bev, at_most); bev_async_add_write(beva); } } @@ -279,8 +279,8 @@ bev_async_consider_reading(struct bufferevent_async *beva) } /* XXXX This over-commits. */ - /* XXXX see also not above on cast on bufferevent_get_write_max_() */ - limit = (int)bufferevent_get_read_max_(&beva->bev); + /* XXXX see also not above on cast on bufferevent_get_write_max_() */ + limit = (int)bufferevent_get_read_max_(&beva->bev); if (at_most >= (size_t)limit && limit >= 0) at_most = limit; @@ -289,14 +289,14 @@ bev_async_consider_reading(struct bufferevent_async *beva) return; } - bufferevent_incref_(bev); - if (evbuffer_launch_read_(bev->input, at_most, &beva->read_overlapped)) { + bufferevent_incref_(bev); + if (evbuffer_launch_read_(bev->input, at_most, &beva->read_overlapped)) { beva->ok = 0; - be_async_run_eventcb(bev, BEV_EVENT_ERROR, 0); - bufferevent_decref_(bev); + be_async_run_eventcb(bev, BEV_EVENT_ERROR, 0); + bufferevent_decref_(bev); } else { beva->read_in_progress = at_most; - bufferevent_decrement_read_buckets_(&beva->bev, at_most); + bufferevent_decrement_read_buckets_(&beva->bev, at_most); bev_async_add_read(beva); } @@ -314,12 +314,12 @@ be_async_outbuf_callback(struct evbuffer *buf, /* If we added data to the outbuf and were not writing before, * we may want to write now. */ - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); if (cbinfo->n_added) bev_async_consider_writing(bev_async); - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } static void @@ -333,12 +333,12 @@ be_async_inbuf_callback(struct evbuffer *buf, /* If we drained data from the inbuf and were not reading before, * we may want to read now */ - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); if (cbinfo->n_deleted) bev_async_consider_reading(bev_async); - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } static int @@ -402,11 +402,11 @@ be_async_destruct(struct bufferevent *bev) bev_async_del_read(bev_async); bev_async_del_write(bev_async); - fd = evbuffer_overlapped_get_fd_(bev->input); - if (fd != (evutil_socket_t)EVUTIL_INVALID_SOCKET && - (bev_p->options & BEV_OPT_CLOSE_ON_FREE)) { + fd = evbuffer_overlapped_get_fd_(bev->input); + if (fd != (evutil_socket_t)EVUTIL_INVALID_SOCKET && + (bev_p->options & BEV_OPT_CLOSE_ON_FREE)) { evutil_closesocket(fd); - evbuffer_overlapped_set_fd_(bev->input, EVUTIL_INVALID_SOCKET); + evbuffer_overlapped_set_fd_(bev->input, EVUTIL_INVALID_SOCKET); } } @@ -418,7 +418,7 @@ bev_async_set_wsa_error(struct bufferevent *bev, struct event_overlapped *eo) DWORD bytes, flags; evutil_socket_t fd; - fd = evbuffer_overlapped_get_fd_(bev->input); + fd = evbuffer_overlapped_get_fd_(bev->input); WSAGetOverlappedResult(fd, &eo->overlapped, &bytes, FALSE, &flags); } @@ -441,20 +441,20 @@ connect_complete(struct event_overlapped *eo, ev_uintptr_t key, EVUTIL_ASSERT(bev_a->bev.connecting); bev_a->bev.connecting = 0; - sock = evbuffer_overlapped_get_fd_(bev_a->bev.bev.input); + sock = evbuffer_overlapped_get_fd_(bev_a->bev.bev.input); /* XXXX Handle error? */ setsockopt(sock, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); if (ok) - bufferevent_async_set_connected_(bev); + bufferevent_async_set_connected_(bev); else bev_async_set_wsa_error(bev, eo); - be_async_run_eventcb(bev, ok ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR, 0); + be_async_run_eventcb(bev, ok ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR, 0); - event_base_del_virtual_(bev->ev_base); + event_base_del_virtual_(bev->ev_base); - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } static void @@ -469,10 +469,10 @@ read_complete(struct event_overlapped *eo, ev_uintptr_t key, EVUTIL_ASSERT(bev_a->read_in_progress); amount_unread = bev_a->read_in_progress - nbytes; - evbuffer_commit_read_(bev->input, nbytes); + evbuffer_commit_read_(bev->input, nbytes); bev_a->read_in_progress = 0; if (amount_unread) - bufferevent_decrement_read_buckets_(&bev_a->bev, -amount_unread); + bufferevent_decrement_read_buckets_(&bev_a->bev, -amount_unread); if (!ok) bev_async_set_wsa_error(bev, eo); @@ -480,20 +480,20 @@ read_complete(struct event_overlapped *eo, ev_uintptr_t key, if (bev_a->ok) { if (ok && nbytes) { BEV_RESET_GENERIC_READ_TIMEOUT(bev); - be_async_trigger_nolock(bev, EV_READ, 0); + be_async_trigger_nolock(bev, EV_READ, 0); bev_async_consider_reading(bev_a); } else if (!ok) { what |= BEV_EVENT_ERROR; bev_a->ok = 0; - be_async_run_eventcb(bev, what, 0); + be_async_run_eventcb(bev, what, 0); } else if (!nbytes) { what |= BEV_EVENT_EOF; bev_a->ok = 0; - be_async_run_eventcb(bev, what, 0); + be_async_run_eventcb(bev, what, 0); } } - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } static void @@ -509,11 +509,11 @@ write_complete(struct event_overlapped *eo, ev_uintptr_t key, EVUTIL_ASSERT(bev_a->write_in_progress); amount_unwritten = bev_a->write_in_progress - nbytes; - evbuffer_commit_write_(bev->output, nbytes); + evbuffer_commit_write_(bev->output, nbytes); bev_a->write_in_progress = 0; if (amount_unwritten) - bufferevent_decrement_write_buckets_(&bev_a->bev, + bufferevent_decrement_write_buckets_(&bev_a->bev, -amount_unwritten); @@ -523,24 +523,24 @@ write_complete(struct event_overlapped *eo, ev_uintptr_t key, if (bev_a->ok) { if (ok && nbytes) { BEV_RESET_GENERIC_WRITE_TIMEOUT(bev); - be_async_trigger_nolock(bev, EV_WRITE, 0); + be_async_trigger_nolock(bev, EV_WRITE, 0); bev_async_consider_writing(bev_a); } else if (!ok) { what |= BEV_EVENT_ERROR; bev_a->ok = 0; - be_async_run_eventcb(bev, what, 0); + be_async_run_eventcb(bev, what, 0); } else if (!nbytes) { what |= BEV_EVENT_EOF; bev_a->ok = 0; - be_async_run_eventcb(bev, what, 0); + be_async_run_eventcb(bev, what, 0); } } - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } struct bufferevent * -bufferevent_async_new_(struct event_base *base, +bufferevent_async_new_(struct event_base *base, evutil_socket_t fd, int options) { struct bufferevent_async *bev_a; @@ -549,11 +549,11 @@ bufferevent_async_new_(struct event_base *base, options |= BEV_OPT_THREADSAFE; - if (!(iocp = event_base_get_iocp_(base))) + if (!(iocp = event_base_get_iocp_(base))) return NULL; - if (fd >= 0 && event_iocp_port_associate_(iocp, fd, 1)<0) { - if (fatal_error(GetLastError())) + if (fd >= 0 && event_iocp_port_associate_(iocp, fd, 1)<0) { + if (fatal_error(GetLastError())) return NULL; } @@ -561,29 +561,29 @@ bufferevent_async_new_(struct event_base *base, return NULL; bev = &bev_a->bev.bev; - if (!(bev->input = evbuffer_overlapped_new_(fd))) { + if (!(bev->input = evbuffer_overlapped_new_(fd))) { mm_free(bev_a); return NULL; } - if (!(bev->output = evbuffer_overlapped_new_(fd))) { + if (!(bev->output = evbuffer_overlapped_new_(fd))) { evbuffer_free(bev->input); mm_free(bev_a); return NULL; } - if (bufferevent_init_common_(&bev_a->bev, base, &bufferevent_ops_async, + if (bufferevent_init_common_(&bev_a->bev, base, &bufferevent_ops_async, options)<0) goto err; evbuffer_add_cb(bev->input, be_async_inbuf_callback, bev); evbuffer_add_cb(bev->output, be_async_outbuf_callback, bev); - event_overlapped_init_(&bev_a->connect_overlapped, connect_complete); - event_overlapped_init_(&bev_a->read_overlapped, read_complete); - event_overlapped_init_(&bev_a->write_overlapped, write_complete); - - bufferevent_init_generic_timeout_cbs_(bev); + event_overlapped_init_(&bev_a->connect_overlapped, connect_complete); + event_overlapped_init_(&bev_a->read_overlapped, read_complete); + event_overlapped_init_(&bev_a->write_overlapped, write_complete); + bufferevent_init_generic_timeout_cbs_(bev); + bev_a->ok = fd >= 0; return bev; @@ -593,7 +593,7 @@ err: } void -bufferevent_async_set_connected_(struct bufferevent *bev) +bufferevent_async_set_connected_(struct bufferevent *bev) { struct bufferevent_async *bev_async = upcast(bev); bev_async->ok = 1; @@ -602,13 +602,13 @@ bufferevent_async_set_connected_(struct bufferevent *bev) } int -bufferevent_async_can_connect_(struct bufferevent *bev) +bufferevent_async_can_connect_(struct bufferevent *bev) { const struct win32_extension_fns *ext = - event_get_win32_extension_fns_(); + event_get_win32_extension_fns_(); if (BEV_IS_ASYNC(bev) && - event_base_get_iocp_(bev->ev_base) && + event_base_get_iocp_(bev->ev_base) && ext && ext->ConnectEx) return 1; @@ -616,14 +616,14 @@ bufferevent_async_can_connect_(struct bufferevent *bev) } int -bufferevent_async_connect_(struct bufferevent *bev, evutil_socket_t fd, +bufferevent_async_connect_(struct bufferevent *bev, evutil_socket_t fd, const struct sockaddr *sa, int socklen) { BOOL rc; struct bufferevent_async *bev_async = upcast(bev); struct sockaddr_storage ss; const struct win32_extension_fns *ext = - event_get_win32_extension_fns_(); + event_get_win32_extension_fns_(); EVUTIL_ASSERT(ext && ext->ConnectEx && fd >= 0 && sa != NULL); @@ -648,15 +648,15 @@ bufferevent_async_connect_(struct bufferevent *bev, evutil_socket_t fd, WSAGetLastError() != WSAEINVAL) return -1; - event_base_add_virtual_(bev->ev_base); - bufferevent_incref_(bev); + event_base_add_virtual_(bev->ev_base); + bufferevent_incref_(bev); rc = ext->ConnectEx(fd, sa, socklen, NULL, 0, NULL, &bev_async->connect_overlapped.overlapped); if (rc || WSAGetLastError() == ERROR_IO_PENDING) return 0; - event_base_del_virtual_(bev->ev_base); - bufferevent_decref_(bev); + event_base_del_virtual_(bev->ev_base); + bufferevent_decref_(bev); return -1; } @@ -667,32 +667,32 @@ be_async_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, { switch (op) { case BEV_CTRL_GET_FD: - data->fd = evbuffer_overlapped_get_fd_(bev->input); + data->fd = evbuffer_overlapped_get_fd_(bev->input); return 0; case BEV_CTRL_SET_FD: { - struct bufferevent_async *bev_a = upcast(bev); + struct bufferevent_async *bev_a = upcast(bev); struct event_iocp_port *iocp; - if (data->fd == evbuffer_overlapped_get_fd_(bev->input)) + if (data->fd == evbuffer_overlapped_get_fd_(bev->input)) return 0; - if (!(iocp = event_base_get_iocp_(bev->ev_base))) + if (!(iocp = event_base_get_iocp_(bev->ev_base))) return -1; - if (event_iocp_port_associate_(iocp, data->fd, 1) < 0) { - if (fatal_error(GetLastError())) - return -1; - } - evbuffer_overlapped_set_fd_(bev->input, data->fd); - evbuffer_overlapped_set_fd_(bev->output, data->fd); - bev_a->ok = data->fd >= 0; + if (event_iocp_port_associate_(iocp, data->fd, 1) < 0) { + if (fatal_error(GetLastError())) + return -1; + } + evbuffer_overlapped_set_fd_(bev->input, data->fd); + evbuffer_overlapped_set_fd_(bev->output, data->fd); + bev_a->ok = data->fd >= 0; return 0; } case BEV_CTRL_CANCEL_ALL: { struct bufferevent_async *bev_a = upcast(bev); - evutil_socket_t fd = evbuffer_overlapped_get_fd_(bev->input); - if (fd != (evutil_socket_t)EVUTIL_INVALID_SOCKET && + evutil_socket_t fd = evbuffer_overlapped_get_fd_(bev->input); + if (fd != (evutil_socket_t)EVUTIL_INVALID_SOCKET && (bev_a->bev.options & BEV_OPT_CLOSE_ON_FREE)) { closesocket(fd); - evbuffer_overlapped_set_fd_(bev->input, EVUTIL_INVALID_SOCKET); + evbuffer_overlapped_set_fd_(bev->input, EVUTIL_INVALID_SOCKET); } bev_a->ok = 0; return 0; diff --git a/contrib/libs/libevent/bufferevent_filter.c b/contrib/libs/libevent/bufferevent_filter.c index a7bdedddfe..ad21a391fa 100644 --- a/contrib/libs/libevent/bufferevent_filter.c +++ b/contrib/libs/libevent/bufferevent_filter.c @@ -26,13 +26,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "evconfig-private.h" - +#include "evconfig-private.h" + #include <sys/types.h> #include "event2/event-config.h" -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -40,11 +40,11 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_STDARG_H +#ifdef EVENT__HAVE_STDARG_H #include <stdarg.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #endif @@ -61,7 +61,7 @@ /* prototypes */ static int be_filter_enable(struct bufferevent *, short); static int be_filter_disable(struct bufferevent *, short); -static void be_filter_unlink(struct bufferevent *); +static void be_filter_unlink(struct bufferevent *); static void be_filter_destruct(struct bufferevent *); static void be_filter_readcb(struct bufferevent *, void *); @@ -71,9 +71,9 @@ static int be_filter_flush(struct bufferevent *bufev, short iotype, enum bufferevent_flush_mode mode); static int be_filter_ctrl(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *); -static void bufferevent_filtered_inbuf_cb(struct evbuffer *buf, - const struct evbuffer_cb_info *cbinfo, void *arg); - +static void bufferevent_filtered_inbuf_cb(struct evbuffer *buf, + const struct evbuffer_cb_info *cbinfo, void *arg); + static void bufferevent_filtered_outbuf_cb(struct evbuffer *buf, const struct evbuffer_cb_info *info, void *arg); @@ -82,8 +82,8 @@ struct bufferevent_filtered { /** The bufferevent that we read/write filtered data from/to. */ struct bufferevent *underlying; - /** A callback on our inbuf to notice somebory removes data */ - struct evbuffer_cb_entry *inbuf_cb; + /** A callback on our inbuf to notice somebory removes data */ + struct evbuffer_cb_entry *inbuf_cb; /** A callback on our outbuf to notice when somebody adds data */ struct evbuffer_cb_entry *outbuf_cb; /** True iff we have received an EOF callback from the underlying @@ -105,9 +105,9 @@ const struct bufferevent_ops bufferevent_ops_filter = { evutil_offsetof(struct bufferevent_filtered, bev.bev), be_filter_enable, be_filter_disable, - be_filter_unlink, + be_filter_unlink, be_filter_destruct, - bufferevent_generic_adj_timeouts_, + bufferevent_generic_adj_timeouts_, be_filter_flush, be_filter_ctrl, }; @@ -118,11 +118,11 @@ static inline struct bufferevent_filtered * upcast(struct bufferevent *bev) { struct bufferevent_filtered *bev_f; - if (!BEV_IS_FILTER(bev)) + if (!BEV_IS_FILTER(bev)) return NULL; bev_f = (void*)( ((char*)bev) - evutil_offsetof(struct bufferevent_filtered, bev.bev)); - EVUTIL_ASSERT(BEV_IS_FILTER(&bev_f->bev.bev)); + EVUTIL_ASSERT(BEV_IS_FILTER(&bev_f->bev.bev)); return bev_f; } @@ -160,7 +160,7 @@ be_null_filter(struct evbuffer *src, struct evbuffer *dst, ev_ssize_t lim, enum bufferevent_flush_mode state, void *ctx) { (void)state; - if (evbuffer_remove_buffer(src, dst, lim) >= 0) + if (evbuffer_remove_buffer(src, dst, lim) >= 0) return BEV_OK; else return BEV_ERROR; @@ -189,13 +189,13 @@ bufferevent_filter_new(struct bufferevent *underlying, if (!bufev_f) return NULL; - if (bufferevent_init_common_(&bufev_f->bev, underlying->ev_base, + if (bufferevent_init_common_(&bufev_f->bev, underlying->ev_base, &bufferevent_ops_filter, tmp_options) < 0) { mm_free(bufev_f); return NULL; } if (options & BEV_OPT_THREADSAFE) { - bufferevent_enable_locking_(downcast(bufev_f), NULL); + bufferevent_enable_locking_(downcast(bufev_f), NULL); } bufev_f->underlying = underlying; @@ -208,31 +208,31 @@ bufferevent_filter_new(struct bufferevent *underlying, bufferevent_setcb(bufev_f->underlying, be_filter_readcb, be_filter_writecb, be_filter_eventcb, bufev_f); - bufev_f->inbuf_cb = evbuffer_add_cb(downcast(bufev_f)->input, - bufferevent_filtered_inbuf_cb, bufev_f); - evbuffer_cb_clear_flags(downcast(bufev_f)->input, bufev_f->inbuf_cb, - EVBUFFER_CB_ENABLED); - + bufev_f->inbuf_cb = evbuffer_add_cb(downcast(bufev_f)->input, + bufferevent_filtered_inbuf_cb, bufev_f); + evbuffer_cb_clear_flags(downcast(bufev_f)->input, bufev_f->inbuf_cb, + EVBUFFER_CB_ENABLED); + bufev_f->outbuf_cb = evbuffer_add_cb(downcast(bufev_f)->output, bufferevent_filtered_outbuf_cb, bufev_f); - bufferevent_init_generic_timeout_cbs_(downcast(bufev_f)); - bufferevent_incref_(underlying); + bufferevent_init_generic_timeout_cbs_(downcast(bufev_f)); + bufferevent_incref_(underlying); bufferevent_enable(underlying, EV_READ|EV_WRITE); - bufferevent_suspend_read_(underlying, BEV_SUSPEND_FILT_READ); + bufferevent_suspend_read_(underlying, BEV_SUSPEND_FILT_READ); return downcast(bufev_f); } static void -be_filter_unlink(struct bufferevent *bev) +be_filter_unlink(struct bufferevent *bev) { struct bufferevent_filtered *bevf = upcast(bev); EVUTIL_ASSERT(bevf); if (bevf->bev.options & BEV_OPT_CLOSE_ON_FREE) { - /* Yes, there is also a decref in bufferevent_decref_. + /* Yes, there is also a decref in bufferevent_decref_. * That decref corresponds to the incref when we set * underlying for the first time. This decref is an * extra one to remove the last reference. @@ -248,25 +248,25 @@ be_filter_unlink(struct bufferevent *bev) if (bevf->underlying->errorcb == be_filter_eventcb) bufferevent_setcb(bevf->underlying, NULL, NULL, NULL, NULL); - bufferevent_unsuspend_read_(bevf->underlying, + bufferevent_unsuspend_read_(bevf->underlying, BEV_SUSPEND_FILT_READ); } } -} - -static void -be_filter_destruct(struct bufferevent *bev) -{ - struct bufferevent_filtered *bevf = upcast(bev); - EVUTIL_ASSERT(bevf); - if (bevf->free_context) - bevf->free_context(bevf->context); - - if (bevf->inbuf_cb) - evbuffer_remove_cb_entry(bev->input, bevf->inbuf_cb); - - if (bevf->outbuf_cb) - evbuffer_remove_cb_entry(bev->output, bevf->outbuf_cb); +} + +static void +be_filter_destruct(struct bufferevent *bev) +{ + struct bufferevent_filtered *bevf = upcast(bev); + EVUTIL_ASSERT(bevf); + if (bevf->free_context) + bevf->free_context(bevf->context); + + if (bevf->inbuf_cb) + evbuffer_remove_cb_entry(bev->input, bevf->inbuf_cb); + + if (bevf->outbuf_cb) + evbuffer_remove_cb_entry(bev->output, bevf->outbuf_cb); } static int @@ -278,7 +278,7 @@ be_filter_enable(struct bufferevent *bev, short event) if (event & EV_READ) { BEV_RESET_GENERIC_READ_TIMEOUT(bev); - bufferevent_unsuspend_read_(bevf->underlying, + bufferevent_unsuspend_read_(bevf->underlying, BEV_SUSPEND_FILT_READ); } return 0; @@ -292,7 +292,7 @@ be_filter_disable(struct bufferevent *bev, short event) BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); if (event & EV_READ) { BEV_DEL_GENERIC_READ_TIMEOUT(bev); - bufferevent_suspend_read_(bevf->underlying, + bufferevent_suspend_read_(bevf->underlying, BEV_SUSPEND_FILT_READ); } return 0; @@ -361,8 +361,8 @@ be_filter_process_output(struct bufferevent_filtered *bevf, /* disable the callback that calls this function when the user adds to the output buffer. */ - evbuffer_cb_clear_flags(bufev->output, bevf->outbuf_cb, - EVBUFFER_CB_ENABLED); + evbuffer_cb_clear_flags(bufev->output, bevf->outbuf_cb, + EVBUFFER_CB_ENABLED); do { int processed = 0; @@ -393,9 +393,9 @@ be_filter_process_output(struct bufferevent_filtered *bevf, /* Or if we have filled the underlying output buffer. */ !be_underlying_writebuf_full(bevf,state)); - if (processed) { + if (processed) { /* call the write callback.*/ - bufferevent_trigger_nolock_(bufev, EV_WRITE, 0); + bufferevent_trigger_nolock_(bufev, EV_WRITE, 0); if (res == BEV_OK && (bufev->enabled & EV_WRITE) && @@ -428,145 +428,145 @@ bufferevent_filtered_outbuf_cb(struct evbuffer *buf, int processed_any = 0; /* Somebody added more data to the output buffer. Try to * process it, if we should. */ - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); be_filter_process_output(bevf, BEV_NORMAL, &processed_any); - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); } } static void -be_filter_read_nolock_(struct bufferevent *underlying, void *me_) +be_filter_read_nolock_(struct bufferevent *underlying, void *me_) { - struct bufferevent_filtered *bevf = me_; + struct bufferevent_filtered *bevf = me_; enum bufferevent_filter_result res; enum bufferevent_flush_mode state; struct bufferevent *bufev = downcast(bevf); - struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bufev); int processed_any = 0; - // It's possible our refcount is 0 at this point if another thread free'd our filterevent - EVUTIL_ASSERT(bufev_private->refcnt >= 0); - - // If our refcount is > 0 - if (bufev_private->refcnt > 0) { - - if (bevf->got_eof) - state = BEV_FINISHED; - else - state = BEV_NORMAL; - - /* XXXX use return value */ - res = be_filter_process_input(bevf, state, &processed_any); - (void)res; - - /* XXX This should be in process_input, not here. There are - * other places that can call process-input, and they should - * force readcb calls as needed. */ - if (processed_any) { - bufferevent_trigger_nolock_(bufev, EV_READ, 0); - if (evbuffer_get_length(underlying->input) > 0 && - be_readbuf_full(bevf, state)) { - /* data left in underlying buffer and filter input buffer - * hit its read high watermark. - * Schedule callback to avoid data gets stuck in underlying - * input buffer. - */ - evbuffer_cb_set_flags(bufev->input, bevf->inbuf_cb, - EVBUFFER_CB_ENABLED); - } - } - } -} - -/* Called when the size of our inbuf changes. */ -static void -bufferevent_filtered_inbuf_cb(struct evbuffer *buf, - const struct evbuffer_cb_info *cbinfo, void *arg) -{ - struct bufferevent_filtered *bevf = arg; - enum bufferevent_flush_mode state; - struct bufferevent *bev = downcast(bevf); - - BEV_LOCK(bev); - + // It's possible our refcount is 0 at this point if another thread free'd our filterevent + EVUTIL_ASSERT(bufev_private->refcnt >= 0); + + // If our refcount is > 0 + if (bufev_private->refcnt > 0) { + + if (bevf->got_eof) + state = BEV_FINISHED; + else + state = BEV_NORMAL; + + /* XXXX use return value */ + res = be_filter_process_input(bevf, state, &processed_any); + (void)res; + + /* XXX This should be in process_input, not here. There are + * other places that can call process-input, and they should + * force readcb calls as needed. */ + if (processed_any) { + bufferevent_trigger_nolock_(bufev, EV_READ, 0); + if (evbuffer_get_length(underlying->input) > 0 && + be_readbuf_full(bevf, state)) { + /* data left in underlying buffer and filter input buffer + * hit its read high watermark. + * Schedule callback to avoid data gets stuck in underlying + * input buffer. + */ + evbuffer_cb_set_flags(bufev->input, bevf->inbuf_cb, + EVBUFFER_CB_ENABLED); + } + } + } +} + +/* Called when the size of our inbuf changes. */ +static void +bufferevent_filtered_inbuf_cb(struct evbuffer *buf, + const struct evbuffer_cb_info *cbinfo, void *arg) +{ + struct bufferevent_filtered *bevf = arg; + enum bufferevent_flush_mode state; + struct bufferevent *bev = downcast(bevf); + + BEV_LOCK(bev); + if (bevf->got_eof) state = BEV_FINISHED; else state = BEV_NORMAL; - if (!be_readbuf_full(bevf, state)) { - /* opportunity to read data which was left in underlying - * input buffer because filter input buffer hit read - * high watermark. - */ - evbuffer_cb_clear_flags(bev->input, bevf->inbuf_cb, - EVBUFFER_CB_ENABLED); - if (evbuffer_get_length(bevf->underlying->input) > 0) - be_filter_read_nolock_(bevf->underlying, bevf); - } + if (!be_readbuf_full(bevf, state)) { + /* opportunity to read data which was left in underlying + * input buffer because filter input buffer hit read + * high watermark. + */ + evbuffer_cb_clear_flags(bev->input, bevf->inbuf_cb, + EVBUFFER_CB_ENABLED); + if (evbuffer_get_length(bevf->underlying->input) > 0) + be_filter_read_nolock_(bevf->underlying, bevf); + } - BEV_UNLOCK(bev); -} - -/* Called when the underlying socket has read. */ -static void -be_filter_readcb(struct bufferevent *underlying, void *me_) -{ - struct bufferevent_filtered *bevf = me_; - struct bufferevent *bev = downcast(bevf); - - BEV_LOCK(bev); - - be_filter_read_nolock_(underlying, me_); - - BEV_UNLOCK(bev); + BEV_UNLOCK(bev); } +/* Called when the underlying socket has read. */ +static void +be_filter_readcb(struct bufferevent *underlying, void *me_) +{ + struct bufferevent_filtered *bevf = me_; + struct bufferevent *bev = downcast(bevf); + + BEV_LOCK(bev); + + be_filter_read_nolock_(underlying, me_); + + BEV_UNLOCK(bev); +} + /* Called when the underlying socket has drained enough that we can write to it. */ static void -be_filter_writecb(struct bufferevent *underlying, void *me_) +be_filter_writecb(struct bufferevent *underlying, void *me_) { - struct bufferevent_filtered *bevf = me_; + struct bufferevent_filtered *bevf = me_; struct bufferevent *bev = downcast(bevf); - struct bufferevent_private *bufev_private = BEV_UPCAST(bev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bev); int processed_any = 0; - BEV_LOCK(bev); - - // It's possible our refcount is 0 at this point if another thread free'd our filterevent - EVUTIL_ASSERT(bufev_private->refcnt >= 0); - - // If our refcount is > 0 - if (bufev_private->refcnt > 0) { - be_filter_process_output(bevf, BEV_NORMAL, &processed_any); - } - - BEV_UNLOCK(bev); + BEV_LOCK(bev); + + // It's possible our refcount is 0 at this point if another thread free'd our filterevent + EVUTIL_ASSERT(bufev_private->refcnt >= 0); + + // If our refcount is > 0 + if (bufev_private->refcnt > 0) { + be_filter_process_output(bevf, BEV_NORMAL, &processed_any); + } + + BEV_UNLOCK(bev); } /* Called when the underlying socket has given us an error */ static void -be_filter_eventcb(struct bufferevent *underlying, short what, void *me_) +be_filter_eventcb(struct bufferevent *underlying, short what, void *me_) { - struct bufferevent_filtered *bevf = me_; + struct bufferevent_filtered *bevf = me_; struct bufferevent *bev = downcast(bevf); - struct bufferevent_private *bufev_private = BEV_UPCAST(bev); - - BEV_LOCK(bev); - - // It's possible our refcount is 0 at this point if another thread free'd our filterevent - EVUTIL_ASSERT(bufev_private->refcnt >= 0); - - // If our refcount is > 0 - if (bufev_private->refcnt > 0) { - - /* All we can really to is tell our own eventcb. */ - bufferevent_run_eventcb_(bev, what, 0); - } - - BEV_UNLOCK(bev); + struct bufferevent_private *bufev_private = BEV_UPCAST(bev); + + BEV_LOCK(bev); + + // It's possible our refcount is 0 at this point if another thread free'd our filterevent + EVUTIL_ASSERT(bufev_private->refcnt >= 0); + + // If our refcount is > 0 + if (bufev_private->refcnt > 0) { + + /* All we can really to is tell our own eventcb. */ + bufferevent_run_eventcb_(bev, what, 0); + } + + BEV_UNLOCK(bev); } static int @@ -577,7 +577,7 @@ be_filter_flush(struct bufferevent *bufev, int processed_any = 0; EVUTIL_ASSERT(bevf); - bufferevent_incref_and_lock_(bufev); + bufferevent_incref_and_lock_(bufev); if (iotype & EV_READ) { be_filter_process_input(bevf, mode, &processed_any); @@ -589,7 +589,7 @@ be_filter_flush(struct bufferevent *bufev, /* XXX does this want to recursively call lower-level flushes? */ bufferevent_flush(bevf->underlying, iotype, mode); - bufferevent_decref_and_unlock_(bufev); + bufferevent_decref_and_unlock_(bufev); return processed_any; } @@ -604,22 +604,22 @@ be_filter_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, bevf = upcast(bev); data->ptr = bevf->underlying; return 0; - case BEV_CTRL_SET_FD: + case BEV_CTRL_SET_FD: case BEV_CTRL_GET_FD: - bevf = upcast(bev); - - if (bevf->underlying && - bevf->underlying->be_ops && - bevf->underlying->be_ops->ctrl) { - return (bevf->underlying->be_ops->ctrl)(bevf->underlying, op, data); - } - EVUTIL_FALLTHROUGH; - + bevf = upcast(bev); + + if (bevf->underlying && + bevf->underlying->be_ops && + bevf->underlying->be_ops->ctrl) { + return (bevf->underlying->be_ops->ctrl)(bevf->underlying, op, data); + } + EVUTIL_FALLTHROUGH; + case BEV_CTRL_CANCEL_ALL: - EVUTIL_FALLTHROUGH; + EVUTIL_FALLTHROUGH; default: return -1; } - - return -1; + + return -1; } diff --git a/contrib/libs/libevent/bufferevent_openssl.c b/contrib/libs/libevent/bufferevent_openssl.c index b51b834bca..30ecd07062 100644 --- a/contrib/libs/libevent/bufferevent_openssl.c +++ b/contrib/libs/libevent/bufferevent_openssl.c @@ -24,17 +24,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// Get rid of OSX 10.7 and greater deprecation warnings. -#if defined(__APPLE__) && defined(__clang__) -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif +// Get rid of OSX 10.7 and greater deprecation warnings. +#if defined(__APPLE__) && defined(__clang__) +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif #include "event2/event-config.h" -#include "evconfig-private.h" - -#include <sys/types.h> +#include "evconfig-private.h" -#ifdef EVENT__HAVE_SYS_TIME_H +#include <sys/types.h> + +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -42,14 +42,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_STDARG_H +#ifdef EVENT__HAVE_STDARG_H #include <stdarg.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #endif @@ -154,7 +154,7 @@ bio_bufferevent_read(BIO *b, char *out, int outlen) return r; } -/* Called to write data into the BIO */ +/* Called to write data into the BIO */ static int bio_bufferevent_write(BIO *b, const char *in, int inlen) { @@ -250,7 +250,7 @@ BIO_s_bufferevent(void) /* Create a new BIO to wrap communication around a bufferevent. If close_flag * is true, the bufferevent will be freed when the BIO is closed. */ static BIO * -BIO_new_bufferevent(struct bufferevent *bufferevent) +BIO_new_bufferevent(struct bufferevent *bufferevent) { BIO *result; if (!bufferevent) @@ -259,9 +259,9 @@ BIO_new_bufferevent(struct bufferevent *bufferevent) return NULL; BIO_set_init(result, 1); BIO_set_data(result, bufferevent); - /* We don't tell the BIO to close the bufferevent; we do it ourselves on - * be_openssl_destruct() */ - BIO_set_shutdown(result, 0); + /* We don't tell the BIO to close the bufferevent; we do it ourselves on + * be_openssl_destruct() */ + BIO_set_shutdown(result, 0); return result; } @@ -317,20 +317,20 @@ struct bufferevent_openssl { unsigned read_blocked_on_write : 1; /* When we next get data, we should say "write" instead of "read". */ unsigned write_blocked_on_read : 1; - /* Treat TCP close before SSL close on SSL >= v3 as clean EOF. */ + /* Treat TCP close before SSL close on SSL >= v3 as clean EOF. */ unsigned allow_dirty_shutdown : 1; /* XXX */ unsigned n_errors : 2; /* Are we currently connecting, accepting, or doing IO? */ unsigned state : 2; - /* If we reset fd, we sould reset state too */ - unsigned old_state : 2; + /* If we reset fd, we sould reset state too */ + unsigned old_state : 2; }; static int be_openssl_enable(struct bufferevent *, short); static int be_openssl_disable(struct bufferevent *, short); -static void be_openssl_unlink(struct bufferevent *); +static void be_openssl_unlink(struct bufferevent *); static void be_openssl_destruct(struct bufferevent *); static int be_openssl_adj_timeouts(struct bufferevent *); static int be_openssl_flush(struct bufferevent *bufev, @@ -342,7 +342,7 @@ const struct bufferevent_ops bufferevent_ops_openssl = { evutil_offsetof(struct bufferevent_openssl, bev.bev), be_openssl_enable, be_openssl_disable, - be_openssl_unlink, + be_openssl_unlink, be_openssl_destruct, be_openssl_adj_timeouts, be_openssl_flush, @@ -355,11 +355,11 @@ static inline struct bufferevent_openssl * upcast(struct bufferevent *bev) { struct bufferevent_openssl *bev_o; - if (!BEV_IS_OPENSSL(bev)) + if (!BEV_IS_OPENSSL(bev)) return NULL; bev_o = (void*)( ((char*)bev) - evutil_offsetof(struct bufferevent_openssl, bev.bev)); - EVUTIL_ASSERT(BEV_IS_OPENSSL(&bev_o->bev.bev)); + EVUTIL_ASSERT(BEV_IS_OPENSSL(&bev_o->bev.bev)); return bev_o; } @@ -383,15 +383,15 @@ static int start_reading(struct bufferevent_openssl *bev_ssl) { if (bev_ssl->underlying) { - bufferevent_unsuspend_read_(bev_ssl->underlying, + bufferevent_unsuspend_read_(bev_ssl->underlying, BEV_SUSPEND_FILT_READ); return 0; } else { struct bufferevent *bev = &bev_ssl->bev.bev; int r; - r = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); + r = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); if (r == 0 && bev_ssl->read_blocked_on_write) - r = bufferevent_add_event_(&bev->ev_write, + r = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); return r; } @@ -405,15 +405,15 @@ start_writing(struct bufferevent_openssl *bev_ssl) { int r = 0; if (bev_ssl->underlying) { - if (bev_ssl->write_blocked_on_read) { - bufferevent_unsuspend_read_(bev_ssl->underlying, - BEV_SUSPEND_FILT_READ); - } + if (bev_ssl->write_blocked_on_read) { + bufferevent_unsuspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); + } } else { struct bufferevent *bev = &bev_ssl->bev.bev; - r = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); + r = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); if (!r && bev_ssl->write_blocked_on_read) - r = bufferevent_add_event_(&bev->ev_read, + r = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); } return r; @@ -425,7 +425,7 @@ stop_reading(struct bufferevent_openssl *bev_ssl) if (bev_ssl->write_blocked_on_read) return; if (bev_ssl->underlying) { - bufferevent_suspend_read_(bev_ssl->underlying, + bufferevent_suspend_read_(bev_ssl->underlying, BEV_SUSPEND_FILT_READ); } else { struct bufferevent *bev = &bev_ssl->bev.bev; @@ -439,8 +439,8 @@ stop_writing(struct bufferevent_openssl *bev_ssl) if (bev_ssl->read_blocked_on_write) return; if (bev_ssl->underlying) { - bufferevent_unsuspend_read_(bev_ssl->underlying, - BEV_SUSPEND_FILT_READ); + bufferevent_unsuspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); } else { struct bufferevent *bev = &bev_ssl->bev.bev; event_del(&bev->ev_write); @@ -493,7 +493,7 @@ clear_wbor(struct bufferevent_openssl *bev_ssl) } static void -conn_closed(struct bufferevent_openssl *bev_ssl, int when, int errcode, int ret) +conn_closed(struct bufferevent_openssl *bev_ssl, int when, int errcode, int ret) { int event = BEV_EVENT_ERROR; int dirty_shutdown = 0; @@ -509,17 +509,17 @@ conn_closed(struct bufferevent_openssl *bev_ssl, int when, int errcode, int ret) break; case SSL_ERROR_SYSCALL: /* IO error; possibly a dirty shutdown. */ - if ((ret == 0 || ret == -1) && ERR_peek_error() == 0) + if ((ret == 0 || ret == -1) && ERR_peek_error() == 0) dirty_shutdown = 1; - put_error(bev_ssl, errcode); + put_error(bev_ssl, errcode); break; case SSL_ERROR_SSL: /* Protocol error. */ - put_error(bev_ssl, errcode); + put_error(bev_ssl, errcode); break; case SSL_ERROR_WANT_X509_LOOKUP: /* XXXX handle this. */ - put_error(bev_ssl, errcode); + put_error(bev_ssl, errcode); break; case SSL_ERROR_NONE: case SSL_ERROR_WANT_READ: @@ -542,20 +542,20 @@ conn_closed(struct bufferevent_openssl *bev_ssl, int when, int errcode, int ret) stop_reading(bev_ssl); stop_writing(bev_ssl); - /* when is BEV_EVENT_{READING|WRITING} */ - event = when | event; - bufferevent_run_eventcb_(&bev_ssl->bev.bev, event, 0); + /* when is BEV_EVENT_{READING|WRITING} */ + event = when | event; + bufferevent_run_eventcb_(&bev_ssl->bev.bev, event, 0); } static void init_bio_counts(struct bufferevent_openssl *bev_ssl) { - BIO *rbio, *wbio; - - wbio = SSL_get_wbio(bev_ssl->ssl); - bev_ssl->counts.n_written = wbio ? BIO_number_written(wbio) : 0; - rbio = SSL_get_rbio(bev_ssl->ssl); - bev_ssl->counts.n_read = rbio ? BIO_number_read(rbio) : 0; + BIO *rbio, *wbio; + + wbio = SSL_get_wbio(bev_ssl->ssl); + bev_ssl->counts.n_written = wbio ? BIO_number_written(wbio) : 0; + rbio = SSL_get_rbio(bev_ssl->ssl); + bev_ssl->counts.n_read = rbio ? BIO_number_read(rbio) : 0; } static inline void @@ -567,9 +567,9 @@ decrement_buckets(struct bufferevent_openssl *bev_ssl) unsigned long w = num_w - bev_ssl->counts.n_written; unsigned long r = num_r - bev_ssl->counts.n_read; if (w) - bufferevent_decrement_write_buckets_(&bev_ssl->bev, w); + bufferevent_decrement_write_buckets_(&bev_ssl->bev, w); if (r) - bufferevent_decrement_read_buckets_(&bev_ssl->bev, r); + bufferevent_decrement_read_buckets_(&bev_ssl->bev, r); bev_ssl->counts.n_written = num_w; bev_ssl->counts.n_read = num_r; } @@ -592,7 +592,7 @@ do_read(struct bufferevent_openssl *bev_ssl, int n_to_read) { if (bev_ssl->bev.read_suspended) return 0; - atmost = bufferevent_get_read_max_(&bev_ssl->bev); + atmost = bufferevent_get_read_max_(&bev_ssl->bev); if (n_to_read > atmost) n_to_read = atmost; @@ -603,7 +603,7 @@ do_read(struct bufferevent_openssl *bev_ssl, int n_to_read) { for (i=0; i<n; ++i) { if (bev_ssl->bev.read_suspended) break; - ERR_clear_error(); + ERR_clear_error(); r = SSL_read(bev_ssl->ssl, space[i].iov_base, space[i].iov_len); if (r>0) { result |= OP_MADE_PROGRESS; @@ -631,7 +631,7 @@ do_read(struct bufferevent_openssl *bev_ssl, int n_to_read) { return OP_ERR | result; break; default: - conn_closed(bev_ssl, BEV_EVENT_READING, err, r); + conn_closed(bev_ssl, BEV_EVENT_READING, err, r); break; } result |= OP_BLOCKED; @@ -662,7 +662,7 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost) if (bev_ssl->last_write > 0) atmost = bev_ssl->last_write; else - atmost = bufferevent_get_write_max_(&bev_ssl->bev); + atmost = bufferevent_get_write_max_(&bev_ssl->bev); n = evbuffer_peek(output, atmost, NULL, space, 8); if (n < 0) @@ -680,7 +680,7 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost) if (space[i].iov_len == 0) continue; - ERR_clear_error(); + ERR_clear_error(); r = SSL_write(bev_ssl->ssl, space[i].iov_base, space[i].iov_len); if (r > 0) { @@ -711,7 +711,7 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost) bev_ssl->last_write = space[i].iov_len; break; default: - conn_closed(bev_ssl, BEV_EVENT_WRITING, err, r); + conn_closed(bev_ssl, BEV_EVENT_WRITING, err, r); bev_ssl->last_write = -1; break; } @@ -724,7 +724,7 @@ do_write(struct bufferevent_openssl *bev_ssl, int atmost) if (bev_ssl->underlying) BEV_RESET_GENERIC_WRITE_TIMEOUT(bev); - bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); + bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); } return result; } @@ -768,7 +768,7 @@ bytes_to_read(struct bufferevent_openssl *bev) } /* Respect the rate limit */ - limit = bufferevent_get_read_max_(&bev->bev); + limit = bufferevent_get_read_max_(&bev->bev); if (result > limit) { result = limit; } @@ -807,7 +807,7 @@ consider_reading(struct bufferevent_openssl *bev_ssl) if (bev_ssl->bev.read_suspended) break; - + /* Read all pending data. This won't hit the network * again, and will (most importantly) put us in a state * where we don't need to read anything else until the @@ -839,7 +839,7 @@ consider_reading(struct bufferevent_openssl *bev_ssl) if (all_result_flags & OP_MADE_PROGRESS) { struct bufferevent *bev = &bev_ssl->bev.bev; - bufferevent_trigger_nolock_(bev, EV_READ, 0); + bufferevent_trigger_nolock_(bev, EV_READ, 0); } if (!bev_ssl->underlying) { @@ -864,7 +864,7 @@ consider_writing(struct bufferevent_openssl *bev_ssl) if (r & OP_MADE_PROGRESS) { struct bufferevent *bev = &bev_ssl->bev.bev; - bufferevent_trigger_nolock_(bev, EV_READ, 0); + bufferevent_trigger_nolock_(bev, EV_READ, 0); } if (r & (OP_ERR|OP_BLOCKED)) break; @@ -936,49 +936,49 @@ be_openssl_eventcb(struct bufferevent *bev_base, short what, void *ctx) eat it. */ } if (event) - bufferevent_run_eventcb_(&bev_ssl->bev.bev, event, 0); + bufferevent_run_eventcb_(&bev_ssl->bev.bev, event, 0); } static void be_openssl_readeventcb(evutil_socket_t fd, short what, void *ptr) { struct bufferevent_openssl *bev_ssl = ptr; - bufferevent_incref_and_lock_(&bev_ssl->bev.bev); + bufferevent_incref_and_lock_(&bev_ssl->bev.bev); if (what == EV_TIMEOUT) { - bufferevent_run_eventcb_(&bev_ssl->bev.bev, - BEV_EVENT_TIMEOUT|BEV_EVENT_READING, 0); + bufferevent_run_eventcb_(&bev_ssl->bev.bev, + BEV_EVENT_TIMEOUT|BEV_EVENT_READING, 0); } else { consider_reading(bev_ssl); } - bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); + bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); } static void be_openssl_writeeventcb(evutil_socket_t fd, short what, void *ptr) { struct bufferevent_openssl *bev_ssl = ptr; - bufferevent_incref_and_lock_(&bev_ssl->bev.bev); + bufferevent_incref_and_lock_(&bev_ssl->bev.bev); if (what == EV_TIMEOUT) { - bufferevent_run_eventcb_(&bev_ssl->bev.bev, - BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING, 0); + bufferevent_run_eventcb_(&bev_ssl->bev.bev, + BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING, 0); } else { consider_writing(bev_ssl); } - bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); -} - -static evutil_socket_t -be_openssl_auto_fd(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd) -{ - if (!bev_ssl->underlying) { - struct bufferevent *bev = &bev_ssl->bev.bev; - if (event_initialized(&bev->ev_read) && fd < 0) { - fd = event_get_fd(&bev->ev_read); - } - } - return fd; + bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); } +static evutil_socket_t +be_openssl_auto_fd(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd) +{ + if (!bev_ssl->underlying) { + struct bufferevent *bev = &bev_ssl->bev.bev; + if (event_initialized(&bev->ev_read) && fd < 0) { + fd = event_get_fd(&bev->ev_read); + } + } + return fd; +} + static int set_open_callbacks(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd) { @@ -990,27 +990,27 @@ set_open_callbacks(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd) } else { struct bufferevent *bev = &bev_ssl->bev.bev; int rpending=0, wpending=0, r1=0, r2=0; - - if (event_initialized(&bev->ev_read)) { + + if (event_initialized(&bev->ev_read)) { rpending = event_pending(&bev->ev_read, EV_READ, NULL); wpending = event_pending(&bev->ev_write, EV_WRITE, NULL); - + event_del(&bev->ev_read); event_del(&bev->ev_write); } - + event_assign(&bev->ev_read, bev->ev_base, fd, - EV_READ|EV_PERSIST|EV_FINALIZE, - be_openssl_readeventcb, bev_ssl); + EV_READ|EV_PERSIST|EV_FINALIZE, + be_openssl_readeventcb, bev_ssl); event_assign(&bev->ev_write, bev->ev_base, fd, - EV_WRITE|EV_PERSIST|EV_FINALIZE, - be_openssl_writeeventcb, bev_ssl); - + EV_WRITE|EV_PERSIST|EV_FINALIZE, + be_openssl_writeeventcb, bev_ssl); + if (rpending) - r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); + r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); if (wpending) - r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); - + r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); + return (r1<0 || r2<0) ? -1 : 0; } } @@ -1027,34 +1027,34 @@ do_handshake(struct bufferevent_openssl *bev_ssl) return -1; case BUFFEREVENT_SSL_CONNECTING: case BUFFEREVENT_SSL_ACCEPTING: - ERR_clear_error(); + ERR_clear_error(); r = SSL_do_handshake(bev_ssl->ssl); break; } decrement_buckets(bev_ssl); if (r==1) { - evutil_socket_t fd = event_get_fd(&bev_ssl->bev.bev.ev_read); + evutil_socket_t fd = event_get_fd(&bev_ssl->bev.bev.ev_read); /* We're done! */ bev_ssl->state = BUFFEREVENT_SSL_OPEN; - set_open_callbacks(bev_ssl, fd); /* XXXX handle failure */ + set_open_callbacks(bev_ssl, fd); /* XXXX handle failure */ /* Call do_read and do_write as needed */ bufferevent_enable(&bev_ssl->bev.bev, bev_ssl->bev.bev.enabled); - bufferevent_run_eventcb_(&bev_ssl->bev.bev, - BEV_EVENT_CONNECTED, 0); + bufferevent_run_eventcb_(&bev_ssl->bev.bev, + BEV_EVENT_CONNECTED, 0); return 1; } else { int err = SSL_get_error(bev_ssl->ssl, r); print_err(err); switch (err) { case SSL_ERROR_WANT_WRITE: - stop_reading(bev_ssl); - return start_writing(bev_ssl); + stop_reading(bev_ssl); + return start_writing(bev_ssl); case SSL_ERROR_WANT_READ: - stop_writing(bev_ssl); - return start_reading(bev_ssl); + stop_writing(bev_ssl); + return start_reading(bev_ssl); default: - conn_closed(bev_ssl, BEV_EVENT_READING, err, r); + conn_closed(bev_ssl, BEV_EVENT_READING, err, r); return -1; } } @@ -1072,12 +1072,12 @@ be_openssl_handshakeeventcb(evutil_socket_t fd, short what, void *ptr) { struct bufferevent_openssl *bev_ssl = ptr; - bufferevent_incref_and_lock_(&bev_ssl->bev.bev); + bufferevent_incref_and_lock_(&bev_ssl->bev.bev); if (what & EV_TIMEOUT) { - bufferevent_run_eventcb_(&bev_ssl->bev.bev, BEV_EVENT_TIMEOUT, 0); + bufferevent_run_eventcb_(&bev_ssl->bev.bev, BEV_EVENT_TIMEOUT, 0); } else do_handshake(bev_ssl);/* XXX handle failure */ - bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); + bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); } static int @@ -1088,31 +1088,31 @@ set_handshake_callbacks(struct bufferevent_openssl *bev_ssl, evutil_socket_t fd) be_openssl_handshakecb, be_openssl_handshakecb, be_openssl_eventcb, bev_ssl); - - if (fd < 0) - return 0; - - if (bufferevent_setfd(bev_ssl->underlying, fd)) - return 1; - + + if (fd < 0) + return 0; + + if (bufferevent_setfd(bev_ssl->underlying, fd)) + return 1; + return do_handshake(bev_ssl); } else { struct bufferevent *bev = &bev_ssl->bev.bev; - - if (event_initialized(&bev->ev_read)) { + + if (event_initialized(&bev->ev_read)) { event_del(&bev->ev_read); event_del(&bev->ev_write); } - + event_assign(&bev->ev_read, bev->ev_base, fd, - EV_READ|EV_PERSIST|EV_FINALIZE, - be_openssl_handshakeeventcb, bev_ssl); + EV_READ|EV_PERSIST|EV_FINALIZE, + be_openssl_handshakeeventcb, bev_ssl); event_assign(&bev->ev_write, bev->ev_base, fd, - EV_WRITE|EV_PERSIST|EV_FINALIZE, - be_openssl_handshakeeventcb, bev_ssl); - if (fd >= 0) - bufferevent_enable(bev, bev->enabled); - return 0; + EV_WRITE|EV_PERSIST|EV_FINALIZE, + be_openssl_handshakeeventcb, bev_ssl); + if (fd >= 0) + bufferevent_enable(bev, bev->enabled); + return 0; } } @@ -1125,7 +1125,7 @@ bufferevent_ssl_renegotiate(struct bufferevent *bev) if (SSL_renegotiate(bev_ssl->ssl) < 0) return -1; bev_ssl->state = BUFFEREVENT_SSL_CONNECTING; - if (set_handshake_callbacks(bev_ssl, be_openssl_auto_fd(bev_ssl, -1)) < 0) + if (set_handshake_callbacks(bev_ssl, be_openssl_auto_fd(bev_ssl, -1)) < 0) return -1; if (!bev_ssl->underlying) return do_handshake(bev_ssl); @@ -1142,14 +1142,14 @@ be_openssl_outbuf_cb(struct evbuffer *buf, if (cbinfo->n_added && bev_ssl->state == BUFFEREVENT_SSL_OPEN) { if (cbinfo->orig_size == 0) - r = bufferevent_add_event_(&bev_ssl->bev.bev.ev_write, + r = bufferevent_add_event_(&bev_ssl->bev.bev.ev_write, &bev_ssl->bev.bev.timeout_write); - - if (bev_ssl->underlying) - consider_writing(bev_ssl); + + if (bev_ssl->underlying) + consider_writing(bev_ssl); } /* XXX Handle r < 0 */ - (void)r; + (void)r; } @@ -1198,7 +1198,7 @@ be_openssl_disable(struct bufferevent *bev, short events) } static void -be_openssl_unlink(struct bufferevent *bev) +be_openssl_unlink(struct bufferevent *bev) { struct bufferevent_openssl *bev_ssl = upcast(bev); @@ -1209,9 +1209,9 @@ be_openssl_unlink(struct bufferevent *bev) "bufferevent with too few references"); } else { bufferevent_free(bev_ssl->underlying); - /* We still have a reference to it, via our - * BIO. So we don't drop this. */ - // bev_ssl->underlying = NULL; + /* We still have a reference to it, via our + * BIO. So we don't drop this. */ + // bev_ssl->underlying = NULL; } } } else { @@ -1219,39 +1219,39 @@ be_openssl_unlink(struct bufferevent *bev) if (bev_ssl->underlying->errorcb == be_openssl_eventcb) bufferevent_setcb(bev_ssl->underlying, NULL,NULL,NULL,NULL); - bufferevent_unsuspend_read_(bev_ssl->underlying, + bufferevent_unsuspend_read_(bev_ssl->underlying, BEV_SUSPEND_FILT_READ); } } } -static void -be_openssl_destruct(struct bufferevent *bev) -{ - struct bufferevent_openssl *bev_ssl = upcast(bev); - - if (bev_ssl->bev.options & BEV_OPT_CLOSE_ON_FREE) { - if (! bev_ssl->underlying) { - evutil_socket_t fd = EVUTIL_INVALID_SOCKET; - BIO *bio = SSL_get_wbio(bev_ssl->ssl); - if (bio) - fd = BIO_get_fd(bio, NULL); - if (fd >= 0) - evutil_closesocket(fd); - } - SSL_free(bev_ssl->ssl); - } -} - +static void +be_openssl_destruct(struct bufferevent *bev) +{ + struct bufferevent_openssl *bev_ssl = upcast(bev); + + if (bev_ssl->bev.options & BEV_OPT_CLOSE_ON_FREE) { + if (! bev_ssl->underlying) { + evutil_socket_t fd = EVUTIL_INVALID_SOCKET; + BIO *bio = SSL_get_wbio(bev_ssl->ssl); + if (bio) + fd = BIO_get_fd(bio, NULL); + if (fd >= 0) + evutil_closesocket(fd); + } + SSL_free(bev_ssl->ssl); + } +} + static int be_openssl_adj_timeouts(struct bufferevent *bev) { struct bufferevent_openssl *bev_ssl = upcast(bev); - if (bev_ssl->underlying) { - return bufferevent_generic_adj_timeouts_(bev); - } else { - return bufferevent_generic_adj_existing_timeouts_(bev); + if (bev_ssl->underlying) { + return bufferevent_generic_adj_timeouts_(bev); + } else { + return bufferevent_generic_adj_existing_timeouts_(bev); } } @@ -1264,61 +1264,61 @@ be_openssl_flush(struct bufferevent *bufev, } static int -be_openssl_set_fd(struct bufferevent_openssl *bev_ssl, - enum bufferevent_ssl_state state, evutil_socket_t fd) -{ - bev_ssl->state = state; - - switch (state) { - case BUFFEREVENT_SSL_ACCEPTING: - if (!SSL_clear(bev_ssl->ssl)) - return -1; - SSL_set_accept_state(bev_ssl->ssl); - if (set_handshake_callbacks(bev_ssl, fd) < 0) - return -1; - break; - case BUFFEREVENT_SSL_CONNECTING: - if (!SSL_clear(bev_ssl->ssl)) - return -1; - SSL_set_connect_state(bev_ssl->ssl); - if (set_handshake_callbacks(bev_ssl, fd) < 0) - return -1; - break; - case BUFFEREVENT_SSL_OPEN: - if (set_open_callbacks(bev_ssl, fd) < 0) - return -1; - break; - default: - return -1; - } - - return 0; -} - -static int +be_openssl_set_fd(struct bufferevent_openssl *bev_ssl, + enum bufferevent_ssl_state state, evutil_socket_t fd) +{ + bev_ssl->state = state; + + switch (state) { + case BUFFEREVENT_SSL_ACCEPTING: + if (!SSL_clear(bev_ssl->ssl)) + return -1; + SSL_set_accept_state(bev_ssl->ssl); + if (set_handshake_callbacks(bev_ssl, fd) < 0) + return -1; + break; + case BUFFEREVENT_SSL_CONNECTING: + if (!SSL_clear(bev_ssl->ssl)) + return -1; + SSL_set_connect_state(bev_ssl->ssl); + if (set_handshake_callbacks(bev_ssl, fd) < 0) + return -1; + break; + case BUFFEREVENT_SSL_OPEN: + if (set_open_callbacks(bev_ssl, fd) < 0) + return -1; + break; + default: + return -1; + } + + return 0; +} + +static int be_openssl_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data *data) { struct bufferevent_openssl *bev_ssl = upcast(bev); switch (op) { case BEV_CTRL_SET_FD: - if (!bev_ssl->underlying) { - BIO *bio; - bio = BIO_new_socket((int)data->fd, 0); - SSL_set_bio(bev_ssl->ssl, bio, bio); - } else { + if (!bev_ssl->underlying) { BIO *bio; - if (!(bio = BIO_new_bufferevent(bev_ssl->underlying))) - return -1; + bio = BIO_new_socket((int)data->fd, 0); SSL_set_bio(bev_ssl->ssl, bio, bio); + } else { + BIO *bio; + if (!(bio = BIO_new_bufferevent(bev_ssl->underlying))) + return -1; + SSL_set_bio(bev_ssl->ssl, bio, bio); } - - return be_openssl_set_fd(bev_ssl, bev_ssl->old_state, data->fd); - case BEV_CTRL_GET_FD: - if (bev_ssl->underlying) { - data->fd = event_get_fd(&bev_ssl->underlying->ev_read); - } else { - data->fd = event_get_fd(&bev->ev_read); + + return be_openssl_set_fd(bev_ssl, bev_ssl->old_state, data->fd); + case BEV_CTRL_GET_FD: + if (bev_ssl->underlying) { + data->fd = event_get_fd(&bev_ssl->underlying->ev_read); + } else { + data->fd = event_get_fd(&bev->ev_read); } return 0; case BEV_CTRL_GET_UNDERLYING: @@ -1351,16 +1351,16 @@ bufferevent_openssl_new_impl(struct event_base *base, struct bufferevent_private *bev_p = NULL; int tmp_options = options & ~BEV_OPT_THREADSAFE; - /* Only one can be set. */ + /* Only one can be set. */ if (underlying != NULL && fd >= 0) - goto err; + goto err; if (!(bev_ssl = mm_calloc(1, sizeof(struct bufferevent_openssl)))) goto err; bev_p = &bev_ssl->bev; - if (bufferevent_init_common_(bev_p, base, + if (bufferevent_init_common_(bev_p, base, &bufferevent_ops_openssl, tmp_options) < 0) goto err; @@ -1375,38 +1375,38 @@ bufferevent_openssl_new_impl(struct event_base *base, be_openssl_outbuf_cb, bev_ssl); if (options & BEV_OPT_THREADSAFE) - bufferevent_enable_locking_(&bev_ssl->bev.bev, NULL); + bufferevent_enable_locking_(&bev_ssl->bev.bev, NULL); if (underlying) { - bufferevent_init_generic_timeout_cbs_(&bev_ssl->bev.bev); - bufferevent_incref_(underlying); + bufferevent_init_generic_timeout_cbs_(&bev_ssl->bev.bev); + bufferevent_incref_(underlying); } - bev_ssl->old_state = state; + bev_ssl->old_state = state; bev_ssl->last_write = -1; init_bio_counts(bev_ssl); - fd = be_openssl_auto_fd(bev_ssl, fd); - if (be_openssl_set_fd(bev_ssl, state, fd)) + fd = be_openssl_auto_fd(bev_ssl, fd); + if (be_openssl_set_fd(bev_ssl, state, fd)) goto err; if (underlying) { bufferevent_setwatermark(underlying, EV_READ, 0, 0); bufferevent_enable(underlying, EV_READ|EV_WRITE); if (state == BUFFEREVENT_SSL_OPEN) - bufferevent_suspend_read_(underlying, + bufferevent_suspend_read_(underlying, BEV_SUSPEND_FILT_READ); } return &bev_ssl->bev.bev; err: - if (options & BEV_OPT_CLOSE_ON_FREE) - SSL_free(ssl); - if (bev_ssl) { - bev_ssl->ssl = NULL; + if (options & BEV_OPT_CLOSE_ON_FREE) + SSL_free(ssl); + if (bev_ssl) { + bev_ssl->ssl = NULL; bufferevent_free(&bev_ssl->bev.bev); - } + } return NULL; } @@ -1418,23 +1418,23 @@ bufferevent_openssl_filter_new(struct event_base *base, int options) { BIO *bio; - struct bufferevent *bev; - + struct bufferevent *bev; + if (!underlying) - goto err; - if (!(bio = BIO_new_bufferevent(underlying))) - goto err; + goto err; + if (!(bio = BIO_new_bufferevent(underlying))) + goto err; SSL_set_bio(ssl, bio, bio); - bev = bufferevent_openssl_new_impl( + bev = bufferevent_openssl_new_impl( base, underlying, -1, ssl, state, options); - return bev; - -err: - if (options & BEV_OPT_CLOSE_ON_FREE) - SSL_free(ssl); - return NULL; + return bev; + +err: + if (options & BEV_OPT_CLOSE_ON_FREE) + SSL_free(ssl); + return NULL; } struct bufferevent * @@ -1461,14 +1461,14 @@ bufferevent_openssl_socket_new(struct event_base *base, } else { /* We specified an fd different from that of the SSL. This is probably an error on our part. Fail. */ - goto err; + goto err; } - BIO_set_close(bio, 0); + BIO_set_close(bio, 0); } else { /* The SSL isn't configured with a BIO with an fd. */ if (fd >= 0) { /* ... and we have an fd we want to use. */ - bio = BIO_new_socket((int)fd, 0); + bio = BIO_new_socket((int)fd, 0); SSL_set_bio(ssl, bio, bio); } else { /* Leave the fd unset. */ @@ -1477,38 +1477,38 @@ bufferevent_openssl_socket_new(struct event_base *base, return bufferevent_openssl_new_impl( base, NULL, fd, ssl, state, options); - -err: - if (options & BEV_OPT_CLOSE_ON_FREE) - SSL_free(ssl); - return NULL; -} - -int -bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev) -{ - int allow_dirty_shutdown = -1; - struct bufferevent_openssl *bev_ssl; - BEV_LOCK(bev); - bev_ssl = upcast(bev); - if (bev_ssl) - allow_dirty_shutdown = bev_ssl->allow_dirty_shutdown; - BEV_UNLOCK(bev); - return allow_dirty_shutdown; -} - -void -bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev, - int allow_dirty_shutdown) -{ - struct bufferevent_openssl *bev_ssl; - BEV_LOCK(bev); - bev_ssl = upcast(bev); - if (bev_ssl) - bev_ssl->allow_dirty_shutdown = !!allow_dirty_shutdown; - BEV_UNLOCK(bev); + +err: + if (options & BEV_OPT_CLOSE_ON_FREE) + SSL_free(ssl); + return NULL; } +int +bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev) +{ + int allow_dirty_shutdown = -1; + struct bufferevent_openssl *bev_ssl; + BEV_LOCK(bev); + bev_ssl = upcast(bev); + if (bev_ssl) + allow_dirty_shutdown = bev_ssl->allow_dirty_shutdown; + BEV_UNLOCK(bev); + return allow_dirty_shutdown; +} + +void +bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev, + int allow_dirty_shutdown) +{ + struct bufferevent_openssl *bev_ssl; + BEV_LOCK(bev); + bev_ssl = upcast(bev); + if (bev_ssl) + bev_ssl->allow_dirty_shutdown = !!allow_dirty_shutdown; + BEV_UNLOCK(bev); +} + unsigned long bufferevent_get_openssl_error(struct bufferevent *bev) { diff --git a/contrib/libs/libevent/bufferevent_pair.c b/contrib/libs/libevent/bufferevent_pair.c index f88cd751de..d1c1d8ec8c 100644 --- a/contrib/libs/libevent/bufferevent_pair.c +++ b/contrib/libs/libevent/bufferevent_pair.c @@ -23,12 +23,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "event2/event-config.h" -#include "evconfig-private.h" +#include "event2/event-config.h" +#include "evconfig-private.h" #include <sys/types.h> -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #endif @@ -45,8 +45,8 @@ struct bufferevent_pair { struct bufferevent_private bev; struct bufferevent_pair *partner; - /* For ->destruct() lock checking */ - struct bufferevent_pair *unlinked_partner; + /* For ->destruct() lock checking */ + struct bufferevent_pair *unlinked_partner; }; @@ -56,10 +56,10 @@ static inline struct bufferevent_pair * upcast(struct bufferevent *bev) { struct bufferevent_pair *bev_p; - if (!BEV_IS_PAIR(bev)) + if (!BEV_IS_PAIR(bev)) return NULL; bev_p = EVUTIL_UPCAST(bev, struct bufferevent_pair, bev.bev); - EVUTIL_ASSERT(BEV_IS_PAIR(&bev_p->bev.bev)); + EVUTIL_ASSERT(BEV_IS_PAIR(&bev_p->bev.bev)); return bev_p; } @@ -69,10 +69,10 @@ static inline void incref_and_lock(struct bufferevent *b) { struct bufferevent_pair *bevp; - bufferevent_incref_and_lock_(b); + bufferevent_incref_and_lock_(b); bevp = upcast(b); if (bevp->partner) - bufferevent_incref_and_lock_(downcast(bevp->partner)); + bufferevent_incref_and_lock_(downcast(bevp->partner)); } static inline void @@ -80,8 +80,8 @@ decref_and_unlock(struct bufferevent *b) { struct bufferevent_pair *bevp = upcast(b); if (bevp->partner) - bufferevent_decref_and_unlock_(downcast(bevp->partner)); - bufferevent_decref_and_unlock_(b); + bufferevent_decref_and_unlock_(downcast(bevp->partner)); + bufferevent_decref_and_unlock_(b); } /* XXX Handle close */ @@ -96,7 +96,7 @@ bufferevent_pair_elt_new(struct event_base *base, struct bufferevent_pair *bufev; if (! (bufev = mm_calloc(1, sizeof(struct bufferevent_pair)))) return NULL; - if (bufferevent_init_common_(&bufev->bev, base, &bufferevent_ops_pair, + if (bufferevent_init_common_(&bufev->bev, base, &bufferevent_ops_pair, options)) { mm_free(bufev); return NULL; @@ -106,7 +106,7 @@ bufferevent_pair_elt_new(struct event_base *base, return NULL; } - bufferevent_init_generic_timeout_cbs_(&bufev->bev.bev); + bufferevent_init_generic_timeout_cbs_(&bufev->bev.bev); return bufev; } @@ -132,7 +132,7 @@ bufferevent_pair_new(struct event_base *base, int options, if (options & BEV_OPT_THREADSAFE) { /*XXXX check return */ - bufferevent_enable_locking_(downcast(bufev2), bufev1->bev.lock); + bufferevent_enable_locking_(downcast(bufev2), bufev1->bev.lock); } bufev1->partner = bufev2; @@ -153,7 +153,7 @@ static void be_pair_transfer(struct bufferevent *src, struct bufferevent *dst, int ignore_wm) { - size_t dst_size; + size_t dst_size; size_t n; evbuffer_unfreeze(src->output, 1); @@ -184,8 +184,8 @@ be_pair_transfer(struct bufferevent *src, struct bufferevent *dst, BEV_DEL_GENERIC_WRITE_TIMEOUT(dst); } - bufferevent_trigger_nolock_(dst, EV_READ, 0); - bufferevent_trigger_nolock_(src, EV_WRITE, 0); + bufferevent_trigger_nolock_(dst, EV_READ, 0); + bufferevent_trigger_nolock_(src, EV_WRITE, 0); done: evbuffer_freeze(src->output, 1); evbuffer_freeze(dst->input, 0); @@ -255,50 +255,50 @@ be_pair_disable(struct bufferevent *bev, short events) if (events & EV_READ) { BEV_DEL_GENERIC_READ_TIMEOUT(bev); } - if (events & EV_WRITE) { + if (events & EV_WRITE) { BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); - } + } return 0; } static void -be_pair_unlink(struct bufferevent *bev) +be_pair_unlink(struct bufferevent *bev) { struct bufferevent_pair *bev_p = upcast(bev); if (bev_p->partner) { - bev_p->unlinked_partner = bev_p->partner; + bev_p->unlinked_partner = bev_p->partner; bev_p->partner->partner = NULL; bev_p->partner = NULL; } -} - -/* Free *shared* lock in the latest be (since we share it between two of them). */ -static void -be_pair_destruct(struct bufferevent *bev) -{ - struct bufferevent_pair *bev_p = upcast(bev); - - /* Transfer ownership of the lock into partner, otherwise we will use - * already free'd lock during freeing second bev, see next example: - * - * bev1->own_lock = 1 - * bev2->own_lock = 0 - * bev2->lock = bev1->lock - * - * bufferevent_free(bev1) # refcnt == 0 -> unlink - * bufferevent_free(bev2) # refcnt == 0 -> unlink - * - * event_base_free() -> finilizers -> EVTHREAD_FREE_LOCK(bev1->lock) - * -> BEV_LOCK(bev2->lock) <-- already freed - * - * Where bev1 == pair[0], bev2 == pair[1]. - */ - if (bev_p->unlinked_partner && bev_p->bev.own_lock) { - bev_p->unlinked_partner->bev.own_lock = 1; - bev_p->bev.own_lock = 0; - } - bev_p->unlinked_partner = NULL; +} + +/* Free *shared* lock in the latest be (since we share it between two of them). */ +static void +be_pair_destruct(struct bufferevent *bev) +{ + struct bufferevent_pair *bev_p = upcast(bev); + + /* Transfer ownership of the lock into partner, otherwise we will use + * already free'd lock during freeing second bev, see next example: + * + * bev1->own_lock = 1 + * bev2->own_lock = 0 + * bev2->lock = bev1->lock + * + * bufferevent_free(bev1) # refcnt == 0 -> unlink + * bufferevent_free(bev2) # refcnt == 0 -> unlink + * + * event_base_free() -> finilizers -> EVTHREAD_FREE_LOCK(bev1->lock) + * -> BEV_LOCK(bev2->lock) <-- already freed + * + * Where bev1 == pair[0], bev2 == pair[1]. + */ + if (bev_p->unlinked_partner && bev_p->bev.own_lock) { + bev_p->unlinked_partner->bev.own_lock = 1; + bev_p->bev.own_lock = 0; + } + bev_p->unlinked_partner = NULL; } static int @@ -307,17 +307,17 @@ be_pair_flush(struct bufferevent *bev, short iotype, { struct bufferevent_pair *bev_p = upcast(bev); struct bufferevent *partner; - + if (!bev_p->partner) return -1; if (mode == BEV_NORMAL) return 0; - incref_and_lock(bev); - - partner = downcast(bev_p->partner); - + incref_and_lock(bev); + + partner = downcast(bev_p->partner); + if ((iotype & EV_READ) != 0) be_pair_transfer(partner, bev, 1); @@ -325,12 +325,12 @@ be_pair_flush(struct bufferevent *bev, short iotype, be_pair_transfer(bev, partner, 1); if (mode == BEV_FINISHED) { - short what = BEV_EVENT_EOF; - if (iotype & EV_READ) - what |= BEV_EVENT_WRITING; - if (iotype & EV_WRITE) - what |= BEV_EVENT_READING; - bufferevent_run_eventcb_(partner, what, 0); + short what = BEV_EVENT_EOF; + if (iotype & EV_READ) + what |= BEV_EVENT_WRITING; + if (iotype & EV_WRITE) + what |= BEV_EVENT_READING; + bufferevent_run_eventcb_(partner, what, 0); } decref_and_unlock(bev); return 0; @@ -357,9 +357,9 @@ const struct bufferevent_ops bufferevent_ops_pair = { evutil_offsetof(struct bufferevent_pair, bev.bev), be_pair_enable, be_pair_disable, - be_pair_unlink, + be_pair_unlink, be_pair_destruct, - bufferevent_generic_adj_timeouts_, + bufferevent_generic_adj_timeouts_, be_pair_flush, NULL, /* ctrl */ }; diff --git a/contrib/libs/libevent/bufferevent_ratelim.c b/contrib/libs/libevent/bufferevent_ratelim.c index 2587496853..915fd3a32e 100644 --- a/contrib/libs/libevent/bufferevent_ratelim.c +++ b/contrib/libs/libevent/bufferevent_ratelim.c @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "evconfig-private.h" +#include "evconfig-private.h" #include <sys/types.h> #include <limits.h> @@ -47,7 +47,7 @@ #include "event-internal.h" int -ev_token_bucket_init_(struct ev_token_bucket *bucket, +ev_token_bucket_init_(struct ev_token_bucket *bucket, const struct ev_token_bucket_cfg *cfg, ev_uint32_t current_tick, int reinitialize) @@ -71,7 +71,7 @@ ev_token_bucket_init_(struct ev_token_bucket *bucket, } int -ev_token_bucket_update_(struct ev_token_bucket *bucket, +ev_token_bucket_update_(struct ev_token_bucket *bucket, const struct ev_token_bucket_cfg *cfg, ev_uint32_t current_tick) { @@ -117,14 +117,14 @@ bufferevent_update_buckets(struct bufferevent_private *bev) struct timeval now; unsigned tick; event_base_gettimeofday_cached(bev->bev.ev_base, &now); - tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); + tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); if (tick != bev->rate_limiting->limit.last_updated) - ev_token_bucket_update_(&bev->rate_limiting->limit, + ev_token_bucket_update_(&bev->rate_limiting->limit, bev->rate_limiting->cfg, tick); } ev_uint32_t -ev_token_bucket_get_tick_(const struct timeval *tv, +ev_token_bucket_get_tick_(const struct timeval *tv, const struct ev_token_bucket_cfg *cfg) { /* This computation uses two multiplies and a divide. We could do @@ -178,27 +178,27 @@ ev_token_bucket_cfg_free(struct ev_token_bucket_cfg *cfg) mm_free(cfg); } -/* Default values for max_single_read & max_single_write variables. */ -#define MAX_SINGLE_READ_DEFAULT 16384 -#define MAX_SINGLE_WRITE_DEFAULT 16384 +/* Default values for max_single_read & max_single_write variables. */ +#define MAX_SINGLE_READ_DEFAULT 16384 +#define MAX_SINGLE_WRITE_DEFAULT 16384 #define LOCK_GROUP(g) EVLOCK_LOCK((g)->lock, 0) #define UNLOCK_GROUP(g) EVLOCK_UNLOCK((g)->lock, 0) -static int bev_group_suspend_reading_(struct bufferevent_rate_limit_group *g); -static int bev_group_suspend_writing_(struct bufferevent_rate_limit_group *g); -static void bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group *g); -static void bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group *g); +static int bev_group_suspend_reading_(struct bufferevent_rate_limit_group *g); +static int bev_group_suspend_writing_(struct bufferevent_rate_limit_group *g); +static void bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group *g); +static void bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group *g); /** Helper: figure out the maximum amount we should write if is_write, or the maximum amount we should read if is_read. Return that maximum, or 0 if our bucket is wholly exhausted. */ static inline ev_ssize_t -bufferevent_get_rlim_max_(struct bufferevent_private *bev, int is_write) +bufferevent_get_rlim_max_(struct bufferevent_private *bev, int is_write) { /* needs lock on bev. */ - ev_ssize_t max_so_far = is_write?bev->max_single_write:bev->max_single_read; + ev_ssize_t max_so_far = is_write?bev->max_single_write:bev->max_single_read; #define LIM(x) \ (is_write ? (x).write_limit : (x).read_limit) @@ -235,10 +235,10 @@ bufferevent_get_rlim_max_(struct bufferevent_private *bev, int is_write) * particular bufferevent while suspending the whole * group. */ if (is_write) - bufferevent_suspend_write_(&bev->bev, + bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW_GROUP); else - bufferevent_suspend_read_(&bev->bev, + bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW_GROUP); share = 0; } else { @@ -258,19 +258,19 @@ bufferevent_get_rlim_max_(struct bufferevent_private *bev, int is_write) } ev_ssize_t -bufferevent_get_read_max_(struct bufferevent_private *bev) +bufferevent_get_read_max_(struct bufferevent_private *bev) { - return bufferevent_get_rlim_max_(bev, 0); + return bufferevent_get_rlim_max_(bev, 0); } ev_ssize_t -bufferevent_get_write_max_(struct bufferevent_private *bev) +bufferevent_get_write_max_(struct bufferevent_private *bev) { - return bufferevent_get_rlim_max_(bev, 1); + return bufferevent_get_rlim_max_(bev, 1); } int -bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes) +bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes) { /* XXXXX Make sure all users of this function check its return value */ int r = 0; @@ -281,14 +281,14 @@ bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t if (bev->rate_limiting->cfg) { bev->rate_limiting->limit.read_limit -= bytes; if (bev->rate_limiting->limit.read_limit <= 0) { - bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW); + bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW); if (event_add(&bev->rate_limiting->refill_bucket_event, &bev->rate_limiting->cfg->tick_timeout) < 0) r = -1; } else if (bev->read_suspended & BEV_SUSPEND_BW) { if (!(bev->write_suspended & BEV_SUSPEND_BW)) event_del(&bev->rate_limiting->refill_bucket_event); - bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); } } @@ -297,9 +297,9 @@ bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t bev->rate_limiting->group->rate_limit.read_limit -= bytes; bev->rate_limiting->group->total_read += bytes; if (bev->rate_limiting->group->rate_limit.read_limit <= 0) { - bev_group_suspend_reading_(bev->rate_limiting->group); + bev_group_suspend_reading_(bev->rate_limiting->group); } else if (bev->rate_limiting->group->read_suspended) { - bev_group_unsuspend_reading_(bev->rate_limiting->group); + bev_group_unsuspend_reading_(bev->rate_limiting->group); } UNLOCK_GROUP(bev->rate_limiting->group); } @@ -308,7 +308,7 @@ bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t } int -bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes) +bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes) { /* XXXXX Make sure all users of this function check its return value */ int r = 0; @@ -319,14 +319,14 @@ bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t if (bev->rate_limiting->cfg) { bev->rate_limiting->limit.write_limit -= bytes; if (bev->rate_limiting->limit.write_limit <= 0) { - bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW); + bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW); if (event_add(&bev->rate_limiting->refill_bucket_event, &bev->rate_limiting->cfg->tick_timeout) < 0) r = -1; } else if (bev->write_suspended & BEV_SUSPEND_BW) { if (!(bev->read_suspended & BEV_SUSPEND_BW)) event_del(&bev->rate_limiting->refill_bucket_event); - bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); } } @@ -335,9 +335,9 @@ bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t bev->rate_limiting->group->rate_limit.write_limit -= bytes; bev->rate_limiting->group->total_written += bytes; if (bev->rate_limiting->group->rate_limit.write_limit <= 0) { - bev_group_suspend_writing_(bev->rate_limiting->group); + bev_group_suspend_writing_(bev->rate_limiting->group); } else if (bev->rate_limiting->group->write_suspended) { - bev_group_unsuspend_writing_(bev->rate_limiting->group); + bev_group_unsuspend_writing_(bev->rate_limiting->group); } UNLOCK_GROUP(bev->rate_limiting->group); } @@ -347,22 +347,22 @@ bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t /** Stop reading on every bufferevent in <b>g</b> */ static int -bev_group_suspend_reading_(struct bufferevent_rate_limit_group *g) +bev_group_suspend_reading_(struct bufferevent_rate_limit_group *g) { /* Needs group lock */ struct bufferevent_private *bev; g->read_suspended = 1; g->pending_unsuspend_read = 0; - /* Note that in this loop we call EVLOCK_TRY_LOCK_ instead of BEV_LOCK, + /* Note that in this loop we call EVLOCK_TRY_LOCK_ instead of BEV_LOCK, to prevent a deadlock. (Ordinarily, the group lock nests inside the bufferevent locks. If we are unable to lock any individual bufferevent, it will find out later when it looks at its limit - and sees that its group is suspended.) + and sees that its group is suspended.) */ - LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { - if (EVLOCK_TRY_LOCK_(bev->lock)) { - bufferevent_suspend_read_(&bev->bev, + LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW_GROUP); EVLOCK_UNLOCK(bev->lock, 0); } @@ -372,15 +372,15 @@ bev_group_suspend_reading_(struct bufferevent_rate_limit_group *g) /** Stop writing on every bufferevent in <b>g</b> */ static int -bev_group_suspend_writing_(struct bufferevent_rate_limit_group *g) +bev_group_suspend_writing_(struct bufferevent_rate_limit_group *g) { /* Needs group lock */ struct bufferevent_private *bev; g->write_suspended = 1; g->pending_unsuspend_write = 0; - LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { - if (EVLOCK_TRY_LOCK_(bev->lock)) { - bufferevent_suspend_write_(&bev->bev, + LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW_GROUP); EVLOCK_UNLOCK(bev->lock, 0); } @@ -391,7 +391,7 @@ bev_group_suspend_writing_(struct bufferevent_rate_limit_group *g) /** Timer callback invoked on a single bufferevent with one or more exhausted buckets when they are ready to refill. */ static void -bev_refill_callback_(evutil_socket_t fd, short what, void *arg) +bev_refill_callback_(evutil_socket_t fd, short what, void *arg) { unsigned tick; struct timeval now; @@ -405,22 +405,22 @@ bev_refill_callback_(evutil_socket_t fd, short what, void *arg) /* First, update the bucket */ event_base_gettimeofday_cached(bev->bev.ev_base, &now); - tick = ev_token_bucket_get_tick_(&now, + tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); - ev_token_bucket_update_(&bev->rate_limiting->limit, + ev_token_bucket_update_(&bev->rate_limiting->limit, bev->rate_limiting->cfg, tick); /* Now unsuspend any read/write operations as appropriate. */ if ((bev->read_suspended & BEV_SUSPEND_BW)) { if (bev->rate_limiting->limit.read_limit > 0) - bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); else again = 1; } if ((bev->write_suspended & BEV_SUSPEND_BW)) { if (bev->rate_limiting->limit.write_limit > 0) - bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); else again = 1; } @@ -438,12 +438,12 @@ bev_refill_callback_(evutil_socket_t fd, short what, void *arg) BEV_UNLOCK(&bev->bev); } -/** Helper: grab a random element from a bufferevent group. - * - * Requires that we hold the lock on the group. - */ +/** Helper: grab a random element from a bufferevent group. + * + * Requires that we hold the lock on the group. + */ static struct bufferevent_private * -bev_group_random_element_(struct bufferevent_rate_limit_group *group) +bev_group_random_element_(struct bufferevent_rate_limit_group *group) { int which; struct bufferevent_private *bev; @@ -453,13 +453,13 @@ bev_group_random_element_(struct bufferevent_rate_limit_group *group) if (!group->n_members) return NULL; - EVUTIL_ASSERT(! LIST_EMPTY(&group->members)); + EVUTIL_ASSERT(! LIST_EMPTY(&group->members)); - which = evutil_weakrand_range_(&group->weakrand_seed, group->n_members); + which = evutil_weakrand_range_(&group->weakrand_seed, group->n_members); - bev = LIST_FIRST(&group->members); + bev = LIST_FIRST(&group->members); while (which--) - bev = LIST_NEXT(bev, rate_limiting->next_in_group); + bev = LIST_NEXT(bev, rate_limiting->next_in_group); return bev; } @@ -473,27 +473,27 @@ bev_group_random_element_(struct bufferevent_rate_limit_group *group) */ #define FOREACH_RANDOM_ORDER(block) \ do { \ - first = bev_group_random_element_(g); \ - for (bev = first; bev != LIST_END(&g->members); \ - bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \ + first = bev_group_random_element_(g); \ + for (bev = first; bev != LIST_END(&g->members); \ + bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \ block ; \ } \ - for (bev = LIST_FIRST(&g->members); bev && bev != first; \ - bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \ + for (bev = LIST_FIRST(&g->members); bev && bev != first; \ + bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \ block ; \ } \ } while (0) static void -bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group *g) +bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group *g) { int again = 0; struct bufferevent_private *bev, *first; g->read_suspended = 0; FOREACH_RANDOM_ORDER({ - if (EVLOCK_TRY_LOCK_(bev->lock)) { - bufferevent_unsuspend_read_(&bev->bev, + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW_GROUP); EVLOCK_UNLOCK(bev->lock, 0); } else { @@ -504,15 +504,15 @@ bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group *g) } static void -bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group *g) +bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group *g) { int again = 0; struct bufferevent_private *bev, *first; g->write_suspended = 0; FOREACH_RANDOM_ORDER({ - if (EVLOCK_TRY_LOCK_(bev->lock)) { - bufferevent_unsuspend_write_(&bev->bev, + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW_GROUP); EVLOCK_UNLOCK(bev->lock, 0); } else { @@ -526,7 +526,7 @@ bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group *g) and unsuspend group members as needed. */ static void -bev_group_refill_callback_(evutil_socket_t fd, short what, void *arg) +bev_group_refill_callback_(evutil_socket_t fd, short what, void *arg) { struct bufferevent_rate_limit_group *g = arg; unsigned tick; @@ -536,16 +536,16 @@ bev_group_refill_callback_(evutil_socket_t fd, short what, void *arg) LOCK_GROUP(g); - tick = ev_token_bucket_get_tick_(&now, &g->rate_limit_cfg); - ev_token_bucket_update_(&g->rate_limit, &g->rate_limit_cfg, tick); + tick = ev_token_bucket_get_tick_(&now, &g->rate_limit_cfg); + ev_token_bucket_update_(&g->rate_limit, &g->rate_limit_cfg, tick); if (g->pending_unsuspend_read || (g->read_suspended && (g->rate_limit.read_limit >= g->min_share))) { - bev_group_unsuspend_reading_(g); + bev_group_unsuspend_reading_(g); } if (g->pending_unsuspend_write || (g->write_suspended && (g->rate_limit.write_limit >= g->min_share))){ - bev_group_unsuspend_writing_(g); + bev_group_unsuspend_writing_(g); } /* XXXX Rather than waiting to the next tick to unsuspend stuff @@ -560,7 +560,7 @@ int bufferevent_set_rate_limit(struct bufferevent *bev, struct ev_token_bucket_cfg *cfg) { - struct bufferevent_private *bevp = BEV_UPCAST(bev); + struct bufferevent_private *bevp = BEV_UPCAST(bev); int r = -1; struct bufferevent_rate_limit *rlim; struct timeval now; @@ -574,8 +574,8 @@ bufferevent_set_rate_limit(struct bufferevent *bev, if (bevp->rate_limiting) { rlim = bevp->rate_limiting; rlim->cfg = NULL; - bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); - bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); if (event_initialized(&rlim->refill_bucket_event)) event_del(&rlim->refill_bucket_event); } @@ -584,7 +584,7 @@ bufferevent_set_rate_limit(struct bufferevent *bev, } event_base_gettimeofday_cached(bev->ev_base, &now); - tick = ev_token_bucket_get_tick_(&now, cfg); + tick = ev_token_bucket_get_tick_(&now, cfg); if (bevp->rate_limiting && bevp->rate_limiting->cfg == cfg) { /* no-op */ @@ -602,25 +602,25 @@ bufferevent_set_rate_limit(struct bufferevent *bev, reinit = rlim->cfg != NULL; rlim->cfg = cfg; - ev_token_bucket_init_(&rlim->limit, cfg, tick, reinit); + ev_token_bucket_init_(&rlim->limit, cfg, tick, reinit); if (reinit) { EVUTIL_ASSERT(event_initialized(&rlim->refill_bucket_event)); event_del(&rlim->refill_bucket_event); } - event_assign(&rlim->refill_bucket_event, bev->ev_base, - -1, EV_FINALIZE, bev_refill_callback_, bevp); + event_assign(&rlim->refill_bucket_event, bev->ev_base, + -1, EV_FINALIZE, bev_refill_callback_, bevp); if (rlim->limit.read_limit > 0) { - bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); } else { - bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); + bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); suspended=1; } if (rlim->limit.write_limit > 0) { - bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); } else { - bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); + bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); suspended = 1; } @@ -643,18 +643,18 @@ bufferevent_rate_limit_group_new(struct event_base *base, ev_uint32_t tick; event_base_gettimeofday_cached(base, &now); - tick = ev_token_bucket_get_tick_(&now, cfg); + tick = ev_token_bucket_get_tick_(&now, cfg); g = mm_calloc(1, sizeof(struct bufferevent_rate_limit_group)); if (!g) return NULL; memcpy(&g->rate_limit_cfg, cfg, sizeof(g->rate_limit_cfg)); - LIST_INIT(&g->members); + LIST_INIT(&g->members); - ev_token_bucket_init_(&g->rate_limit, cfg, tick, 0); + ev_token_bucket_init_(&g->rate_limit, cfg, tick, 0); - event_assign(&g->master_refill_event, base, -1, EV_PERSIST|EV_FINALIZE, - bev_group_refill_callback_, g); + event_assign(&g->master_refill_event, base, -1, EV_PERSIST|EV_FINALIZE, + bev_group_refill_callback_, g); /*XXXX handle event_add failure */ event_add(&g->master_refill_event, &cfg->tick_timeout); @@ -662,9 +662,9 @@ bufferevent_rate_limit_group_new(struct event_base *base, bufferevent_rate_limit_group_set_min_share(g, 64); - evutil_weakrand_seed_(&g->weakrand_seed, - (ev_uint32_t) ((now.tv_sec + now.tv_usec) + (ev_intptr_t)g)); - + evutil_weakrand_seed_(&g->weakrand_seed, + (ev_uint32_t) ((now.tv_sec + now.tv_usec) + (ev_intptr_t)g)); + return g; } @@ -736,7 +736,7 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev, struct bufferevent_rate_limit_group *g) { int wsuspend, rsuspend; - struct bufferevent_private *bevp = BEV_UPCAST(bev); + struct bufferevent_private *bevp = BEV_UPCAST(bev); BEV_LOCK(bev); if (!bevp->rate_limiting) { @@ -746,8 +746,8 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev, BEV_UNLOCK(bev); return -1; } - event_assign(&rlim->refill_bucket_event, bev->ev_base, - -1, EV_FINALIZE, bev_refill_callback_, bevp); + event_assign(&rlim->refill_bucket_event, bev->ev_base, + -1, EV_FINALIZE, bev_refill_callback_, bevp); bevp->rate_limiting = rlim; } @@ -761,7 +761,7 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev, LOCK_GROUP(g); bevp->rate_limiting->group = g; ++g->n_members; - LIST_INSERT_HEAD(&g->members, bevp, rate_limiting->next_in_group); + LIST_INSERT_HEAD(&g->members, bevp, rate_limiting->next_in_group); rsuspend = g->read_suspended; wsuspend = g->write_suspended; @@ -769,9 +769,9 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev, UNLOCK_GROUP(g); if (rsuspend) - bufferevent_suspend_read_(bev, BEV_SUSPEND_BW_GROUP); + bufferevent_suspend_read_(bev, BEV_SUSPEND_BW_GROUP); if (wsuspend) - bufferevent_suspend_write_(bev, BEV_SUSPEND_BW_GROUP); + bufferevent_suspend_write_(bev, BEV_SUSPEND_BW_GROUP); BEV_UNLOCK(bev); return 0; @@ -780,14 +780,14 @@ bufferevent_add_to_rate_limit_group(struct bufferevent *bev, int bufferevent_remove_from_rate_limit_group(struct bufferevent *bev) { - return bufferevent_remove_from_rate_limit_group_internal_(bev, 1); + return bufferevent_remove_from_rate_limit_group_internal_(bev, 1); } int -bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, +bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, int unsuspend) { - struct bufferevent_private *bevp = BEV_UPCAST(bev); + struct bufferevent_private *bevp = BEV_UPCAST(bev); BEV_LOCK(bev); if (bevp->rate_limiting && bevp->rate_limiting->group) { struct bufferevent_rate_limit_group *g = @@ -795,12 +795,12 @@ bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, LOCK_GROUP(g); bevp->rate_limiting->group = NULL; --g->n_members; - LIST_REMOVE(bevp, rate_limiting->next_in_group); + LIST_REMOVE(bevp, rate_limiting->next_in_group); UNLOCK_GROUP(g); } if (unsuspend) { - bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW_GROUP); - bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW_GROUP); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW_GROUP); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW_GROUP); } BEV_UNLOCK(bev); return 0; @@ -814,7 +814,7 @@ bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, * === */ /* Mostly you don't want to use this function from inside libevent; - * bufferevent_get_read_max_() is more likely what you want*/ + * bufferevent_get_read_max_() is more likely what you want*/ ev_ssize_t bufferevent_get_read_limit(struct bufferevent *bev) { @@ -833,7 +833,7 @@ bufferevent_get_read_limit(struct bufferevent *bev) } /* Mostly you don't want to use this function from inside libevent; - * bufferevent_get_write_max_() is more likely what you want*/ + * bufferevent_get_write_max_() is more likely what you want*/ ev_ssize_t bufferevent_get_write_limit(struct bufferevent *bev) { @@ -851,62 +851,62 @@ bufferevent_get_write_limit(struct bufferevent *bev) return r; } -int -bufferevent_set_max_single_read(struct bufferevent *bev, size_t size) -{ - struct bufferevent_private *bevp; - BEV_LOCK(bev); - bevp = BEV_UPCAST(bev); - if (size == 0 || size > EV_SSIZE_MAX) - bevp->max_single_read = MAX_SINGLE_READ_DEFAULT; - else - bevp->max_single_read = size; - BEV_UNLOCK(bev); - return 0; -} - -int -bufferevent_set_max_single_write(struct bufferevent *bev, size_t size) -{ - struct bufferevent_private *bevp; - BEV_LOCK(bev); - bevp = BEV_UPCAST(bev); - if (size == 0 || size > EV_SSIZE_MAX) - bevp->max_single_write = MAX_SINGLE_WRITE_DEFAULT; - else - bevp->max_single_write = size; - BEV_UNLOCK(bev); - return 0; -} - -ev_ssize_t -bufferevent_get_max_single_read(struct bufferevent *bev) -{ - ev_ssize_t r; - - BEV_LOCK(bev); - r = BEV_UPCAST(bev)->max_single_read; - BEV_UNLOCK(bev); - return r; -} - -ev_ssize_t -bufferevent_get_max_single_write(struct bufferevent *bev) -{ - ev_ssize_t r; - - BEV_LOCK(bev); - r = BEV_UPCAST(bev)->max_single_write; - BEV_UNLOCK(bev); - return r; -} - +int +bufferevent_set_max_single_read(struct bufferevent *bev, size_t size) +{ + struct bufferevent_private *bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + if (size == 0 || size > EV_SSIZE_MAX) + bevp->max_single_read = MAX_SINGLE_READ_DEFAULT; + else + bevp->max_single_read = size; + BEV_UNLOCK(bev); + return 0; +} + +int +bufferevent_set_max_single_write(struct bufferevent *bev, size_t size) +{ + struct bufferevent_private *bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + if (size == 0 || size > EV_SSIZE_MAX) + bevp->max_single_write = MAX_SINGLE_WRITE_DEFAULT; + else + bevp->max_single_write = size; + BEV_UNLOCK(bev); + return 0; +} + ev_ssize_t +bufferevent_get_max_single_read(struct bufferevent *bev) +{ + ev_ssize_t r; + + BEV_LOCK(bev); + r = BEV_UPCAST(bev)->max_single_read; + BEV_UNLOCK(bev); + return r; +} + +ev_ssize_t +bufferevent_get_max_single_write(struct bufferevent *bev) +{ + ev_ssize_t r; + + BEV_LOCK(bev); + r = BEV_UPCAST(bev)->max_single_write; + BEV_UNLOCK(bev); + return r; +} + +ev_ssize_t bufferevent_get_max_to_read(struct bufferevent *bev) { ev_ssize_t r; BEV_LOCK(bev); - r = bufferevent_get_read_max_(BEV_UPCAST(bev)); + r = bufferevent_get_read_max_(BEV_UPCAST(bev)); BEV_UNLOCK(bev); return r; } @@ -916,31 +916,31 @@ bufferevent_get_max_to_write(struct bufferevent *bev) { ev_ssize_t r; BEV_LOCK(bev); - r = bufferevent_get_write_max_(BEV_UPCAST(bev)); + r = bufferevent_get_write_max_(BEV_UPCAST(bev)); BEV_UNLOCK(bev); return r; } -const struct ev_token_bucket_cfg * -bufferevent_get_token_bucket_cfg(const struct bufferevent *bev) { - struct bufferevent_private *bufev_private = BEV_UPCAST(bev); - struct ev_token_bucket_cfg *cfg; - - BEV_LOCK(bev); - - if (bufev_private->rate_limiting) { - cfg = bufev_private->rate_limiting->cfg; - } else { - cfg = NULL; - } - - BEV_UNLOCK(bev); - - return cfg; -} - +const struct ev_token_bucket_cfg * +bufferevent_get_token_bucket_cfg(const struct bufferevent *bev) { + struct bufferevent_private *bufev_private = BEV_UPCAST(bev); + struct ev_token_bucket_cfg *cfg; + + BEV_LOCK(bev); + + if (bufev_private->rate_limiting) { + cfg = bufev_private->rate_limiting->cfg; + } else { + cfg = NULL; + } + + BEV_UNLOCK(bev); + + return cfg; +} + /* Mostly you don't want to use this function from inside libevent; - * bufferevent_get_read_max_() is more likely what you want*/ + * bufferevent_get_read_max_() is more likely what you want*/ ev_ssize_t bufferevent_rate_limit_group_get_read_limit( struct bufferevent_rate_limit_group *grp) @@ -953,7 +953,7 @@ bufferevent_rate_limit_group_get_read_limit( } /* Mostly you don't want to use this function from inside libevent; - * bufferevent_get_write_max_() is more likely what you want. */ + * bufferevent_get_write_max_() is more likely what you want. */ ev_ssize_t bufferevent_rate_limit_group_get_write_limit( struct bufferevent_rate_limit_group *grp) @@ -978,14 +978,14 @@ bufferevent_decrement_read_limit(struct bufferevent *bev, ev_ssize_t decr) new_limit = (bevp->rate_limiting->limit.read_limit -= decr); if (old_limit > 0 && new_limit <= 0) { - bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); + bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); if (event_add(&bevp->rate_limiting->refill_bucket_event, &bevp->rate_limiting->cfg->tick_timeout) < 0) r = -1; } else if (old_limit <= 0 && new_limit > 0) { if (!(bevp->write_suspended & BEV_SUSPEND_BW)) event_del(&bevp->rate_limiting->refill_bucket_event); - bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); } BEV_UNLOCK(bev); @@ -1007,14 +1007,14 @@ bufferevent_decrement_write_limit(struct bufferevent *bev, ev_ssize_t decr) new_limit = (bevp->rate_limiting->limit.write_limit -= decr); if (old_limit > 0 && new_limit <= 0) { - bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); + bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); if (event_add(&bevp->rate_limiting->refill_bucket_event, &bevp->rate_limiting->cfg->tick_timeout) < 0) r = -1; } else if (old_limit <= 0 && new_limit > 0) { if (!(bevp->read_suspended & BEV_SUSPEND_BW)) event_del(&bevp->rate_limiting->refill_bucket_event); - bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); } BEV_UNLOCK(bev); @@ -1032,9 +1032,9 @@ bufferevent_rate_limit_group_decrement_read( new_limit = (grp->rate_limit.read_limit -= decr); if (old_limit > 0 && new_limit <= 0) { - bev_group_suspend_reading_(grp); + bev_group_suspend_reading_(grp); } else if (old_limit <= 0 && new_limit > 0) { - bev_group_unsuspend_reading_(grp); + bev_group_unsuspend_reading_(grp); } UNLOCK_GROUP(grp); @@ -1052,9 +1052,9 @@ bufferevent_rate_limit_group_decrement_write( new_limit = (grp->rate_limit.write_limit -= decr); if (old_limit > 0 && new_limit <= 0) { - bev_group_suspend_writing_(grp); + bev_group_suspend_writing_(grp); } else if (old_limit <= 0 && new_limit > 0) { - bev_group_unsuspend_writing_(grp); + bev_group_unsuspend_writing_(grp); } UNLOCK_GROUP(grp); @@ -1077,13 +1077,13 @@ bufferevent_rate_limit_group_reset_totals(struct bufferevent_rate_limit_group *g { grp->total_read = grp->total_written = 0; } - -int -bufferevent_ratelim_init_(struct bufferevent_private *bev) -{ - bev->rate_limiting = NULL; - bev->max_single_read = MAX_SINGLE_READ_DEFAULT; - bev->max_single_write = MAX_SINGLE_WRITE_DEFAULT; - - return 0; -} + +int +bufferevent_ratelim_init_(struct bufferevent_private *bev) +{ + bev->rate_limiting = NULL; + bev->max_single_read = MAX_SINGLE_READ_DEFAULT; + bev->max_single_write = MAX_SINGLE_WRITE_DEFAULT; + + return 0; +} diff --git a/contrib/libs/libevent/bufferevent_sock.c b/contrib/libs/libevent/bufferevent_sock.c index 003a5d3d0d..148a45fa7c 100644 --- a/contrib/libs/libevent/bufferevent_sock.c +++ b/contrib/libs/libevent/bufferevent_sock.c @@ -26,12 +26,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "event2/event-config.h" -#include "evconfig-private.h" - +#include "event2/event-config.h" +#include "evconfig-private.h" + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -39,27 +39,27 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_STDARG_H +#ifdef EVENT__HAVE_STDARG_H #include <stdarg.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #include <ws2tcpip.h> #endif -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif -#ifdef EVENT__HAVE_NETINET_IN_H +#ifdef EVENT__HAVE_NETINET_IN_H #include <netinet/in.h> #endif -#ifdef EVENT__HAVE_NETINET_IN6_H -#error #include <netinet/in6.h> -#endif +#ifdef EVENT__HAVE_NETINET_IN6_H +#error #include <netinet/in6.h> +#endif #include "event2/util.h" #include "event2/bufferevent.h" @@ -71,7 +71,7 @@ #include "mm-internal.h" #include "bufferevent-internal.h" #include "util-internal.h" -#ifdef _WIN32 +#ifdef _WIN32 #include "iocp-internal.h" #endif @@ -89,49 +89,49 @@ const struct bufferevent_ops bufferevent_ops_socket = { evutil_offsetof(struct bufferevent_private, bev), be_socket_enable, be_socket_disable, - NULL, /* unlink */ + NULL, /* unlink */ be_socket_destruct, - bufferevent_generic_adj_existing_timeouts_, + bufferevent_generic_adj_existing_timeouts_, be_socket_flush, be_socket_ctrl, }; -const struct sockaddr* -bufferevent_socket_get_conn_address_(struct bufferevent *bev) -{ - struct bufferevent_private *bev_p = BEV_UPCAST(bev); - return (struct sockaddr *)&bev_p->conn_address; -} - -void -bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, - evutil_socket_t fd) -{ - struct bufferevent_private *bev_p = BEV_UPCAST(bev); - - socklen_t len = sizeof(bev_p->conn_address); - - struct sockaddr *addr = (struct sockaddr *)&bev_p->conn_address; - if (addr->sa_family != AF_UNSPEC) - getpeername(fd, addr, &len); -} - -void -bufferevent_socket_set_conn_address_(struct bufferevent *bev, - struct sockaddr *addr, size_t addrlen) -{ - struct bufferevent_private *bev_p = BEV_UPCAST(bev); - EVUTIL_ASSERT(addrlen <= sizeof(bev_p->conn_address)); - memcpy(&bev_p->conn_address, addr, addrlen); -} - +const struct sockaddr* +bufferevent_socket_get_conn_address_(struct bufferevent *bev) +{ + struct bufferevent_private *bev_p = BEV_UPCAST(bev); + return (struct sockaddr *)&bev_p->conn_address; +} + +void +bufferevent_socket_set_conn_address_fd_(struct bufferevent *bev, + evutil_socket_t fd) +{ + struct bufferevent_private *bev_p = BEV_UPCAST(bev); + + socklen_t len = sizeof(bev_p->conn_address); + + struct sockaddr *addr = (struct sockaddr *)&bev_p->conn_address; + if (addr->sa_family != AF_UNSPEC) + getpeername(fd, addr, &len); +} + +void +bufferevent_socket_set_conn_address_(struct bufferevent *bev, + struct sockaddr *addr, size_t addrlen) +{ + struct bufferevent_private *bev_p = BEV_UPCAST(bev); + EVUTIL_ASSERT(addrlen <= sizeof(bev_p->conn_address)); + memcpy(&bev_p->conn_address, addr, addrlen); +} + static void bufferevent_socket_outbuf_cb(struct evbuffer *buf, const struct evbuffer_cb_info *cbinfo, void *arg) { struct bufferevent *bufev = arg; - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); if (cbinfo->n_added && (bufev->enabled & EV_WRITE) && @@ -139,7 +139,7 @@ bufferevent_socket_outbuf_cb(struct evbuffer *buf, !bufev_p->write_suspended) { /* Somebody added data to the buffer, and we would like to * write, and we were not writing. So, start writing. */ - if (bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) { + if (bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) { /* Should we log this? */ } } @@ -149,13 +149,13 @@ static void bufferevent_readcb(evutil_socket_t fd, short event, void *arg) { struct bufferevent *bufev = arg; - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); struct evbuffer *input; int res = 0; short what = BEV_EVENT_READING; ev_ssize_t howmuch = -1, readmax=-1; - bufferevent_incref_and_lock_(bufev); + bufferevent_incref_and_lock_(bufev); if (event == EV_TIMEOUT) { /* Note that we only check for event==EV_TIMEOUT. If @@ -179,7 +179,7 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg) goto done; } } - readmax = bufferevent_get_read_max_(bufev_p); + readmax = bufferevent_get_read_max_(bufev_p); if (howmuch < 0 || howmuch > readmax) /* The use of -1 for "unlimited" * uglifies this code. XXXX */ howmuch = readmax; @@ -194,10 +194,10 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg) int err = evutil_socket_geterror(fd); if (EVUTIL_ERR_RW_RETRIABLE(err)) goto reschedule; - if (EVUTIL_ERR_CONNECT_REFUSED(err)) { - bufev_p->connection_refused = 1; - goto done; - } + if (EVUTIL_ERR_CONNECT_REFUSED(err)) { + bufev_p->connection_refused = 1; + goto done; + } /* error case */ what |= BEV_EVENT_ERROR; } else if (res == 0) { @@ -208,10 +208,10 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg) if (res <= 0) goto error; - bufferevent_decrement_read_buckets_(bufev_p, res); + bufferevent_decrement_read_buckets_(bufev_p, res); /* Invoke the user callback - must always be called last */ - bufferevent_trigger_nolock_(bufev, EV_READ, 0); + bufferevent_trigger_nolock_(bufev, EV_READ, 0); goto done; @@ -220,23 +220,23 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg) error: bufferevent_disable(bufev, EV_READ); - bufferevent_run_eventcb_(bufev, what, 0); + bufferevent_run_eventcb_(bufev, what, 0); done: - bufferevent_decref_and_unlock_(bufev); + bufferevent_decref_and_unlock_(bufev); } static void bufferevent_writecb(evutil_socket_t fd, short event, void *arg) { struct bufferevent *bufev = arg; - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); int res = 0; short what = BEV_EVENT_WRITING; int connected = 0; ev_ssize_t atmost = -1; - bufferevent_incref_and_lock_(bufev); + bufferevent_incref_and_lock_(bufev); if (event == EV_TIMEOUT) { /* Note that we only check for event==EV_TIMEOUT. If @@ -246,12 +246,12 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) goto error; } if (bufev_p->connecting) { - int c = evutil_socket_finished_connecting_(fd); + int c = evutil_socket_finished_connecting_(fd); /* we need to fake the error if the connection was refused * immediately - usually connection to localhost on BSD */ if (bufev_p->connection_refused) { - bufev_p->connection_refused = 0; - c = -1; + bufev_p->connection_refused = 0; + c = -1; } if (c == 0) @@ -261,22 +261,22 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) if (c < 0) { event_del(&bufev->ev_write); event_del(&bufev->ev_read); - bufferevent_run_eventcb_(bufev, BEV_EVENT_ERROR, 0); + bufferevent_run_eventcb_(bufev, BEV_EVENT_ERROR, 0); goto done; } else { connected = 1; - bufferevent_socket_set_conn_address_fd_(bufev, fd); -#ifdef _WIN32 + bufferevent_socket_set_conn_address_fd_(bufev, fd); +#ifdef _WIN32 if (BEV_IS_ASYNC(bufev)) { event_del(&bufev->ev_write); - bufferevent_async_set_connected_(bufev); - bufferevent_run_eventcb_(bufev, - BEV_EVENT_CONNECTED, 0); + bufferevent_async_set_connected_(bufev); + bufferevent_run_eventcb_(bufev, + BEV_EVENT_CONNECTED, 0); goto done; } #endif - bufferevent_run_eventcb_(bufev, - BEV_EVENT_CONNECTED, 0); + bufferevent_run_eventcb_(bufev, + BEV_EVENT_CONNECTED, 0); if (!(bufev->enabled & EV_WRITE) || bufev_p->write_suspended) { event_del(&bufev->ev_write); @@ -285,7 +285,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) } } - atmost = bufferevent_get_write_max_(bufev_p); + atmost = bufferevent_get_write_max_(bufev_p); if (bufev_p->write_suspended) goto done; @@ -309,7 +309,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) if (res <= 0) goto error; - bufferevent_decrement_write_buckets_(bufev_p, res); + bufferevent_decrement_write_buckets_(bufev_p, res); } if (evbuffer_get_length(bufev->output) == 0) { @@ -320,8 +320,8 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) * Invoke the user callback if our buffer is drained or below the * low watermark. */ - if (res || !connected) { - bufferevent_trigger_nolock_(bufev, EV_WRITE, 0); + if (res || !connected) { + bufferevent_trigger_nolock_(bufev, EV_WRITE, 0); } goto done; @@ -334,10 +334,10 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) error: bufferevent_disable(bufev, EV_WRITE); - bufferevent_run_eventcb_(bufev, what, 0); + bufferevent_run_eventcb_(bufev, what, 0); done: - bufferevent_decref_and_unlock_(bufev); + bufferevent_decref_and_unlock_(bufev); } struct bufferevent * @@ -347,15 +347,15 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, struct bufferevent_private *bufev_p; struct bufferevent *bufev; -#ifdef _WIN32 - if (base && event_base_get_iocp_(base)) - return bufferevent_async_new_(base, fd, options); +#ifdef _WIN32 + if (base && event_base_get_iocp_(base)) + return bufferevent_async_new_(base, fd, options); #endif if ((bufev_p = mm_calloc(1, sizeof(struct bufferevent_private)))== NULL) return NULL; - if (bufferevent_init_common_(bufev_p, base, &bufferevent_ops_socket, + if (bufferevent_init_common_(bufev_p, base, &bufferevent_ops_socket, options) < 0) { mm_free(bufev_p); return NULL; @@ -364,9 +364,9 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, evbuffer_set_flags(bufev->output, EVBUFFER_FLAG_DRAINS_TO_FD); event_assign(&bufev->ev_read, bufev->ev_base, fd, - EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev); + EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev); event_assign(&bufev->ev_write, bufev->ev_base, fd, - EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev); + EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev); evbuffer_add_cb(bufev->output, bufferevent_socket_outbuf_cb, bufev); @@ -378,32 +378,32 @@ bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, int bufferevent_socket_connect(struct bufferevent *bev, - const struct sockaddr *sa, int socklen) + const struct sockaddr *sa, int socklen) { - struct bufferevent_private *bufev_p = BEV_UPCAST(bev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bev); evutil_socket_t fd; int r = 0; int result=-1; int ownfd = 0; - bufferevent_incref_and_lock_(bev); + bufferevent_incref_and_lock_(bev); fd = bufferevent_getfd(bev); if (fd < 0) { if (!sa) goto done; - fd = evutil_socket_(sa->sa_family, - SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0); + fd = evutil_socket_(sa->sa_family, + SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0); if (fd < 0) - goto freesock; + goto freesock; ownfd = 1; } if (sa) { -#ifdef _WIN32 - if (bufferevent_async_can_connect_(bev)) { +#ifdef _WIN32 + if (bufferevent_async_can_connect_(bev)) { bufferevent_setfd(bev, fd); - r = bufferevent_async_connect_(bev, fd, sa, socklen); + r = bufferevent_async_connect_(bev, fd, sa, socklen); if (r < 0) goto freesock; bufev_p->connecting = 1; @@ -411,17 +411,17 @@ bufferevent_socket_connect(struct bufferevent *bev, goto done; } else #endif - r = evutil_socket_connect_(&fd, sa, socklen); + r = evutil_socket_connect_(&fd, sa, socklen); if (r < 0) goto freesock; } -#ifdef _WIN32 +#ifdef _WIN32 /* ConnectEx() isn't always around, even when IOCP is enabled. * Here, we borrow the socket object's write handler to fall back * on a non-blocking connect() when ConnectEx() is unavailable. */ if (BEV_IS_ASYNC(bev)) { event_assign(&bev->ev_write, bev->ev_base, fd, - EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bev); + EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bev); } #endif bufferevent_setfd(bev, fd); @@ -435,12 +435,12 @@ bufferevent_socket_connect(struct bufferevent *bev, /* The connect succeeded already. How very BSD of it. */ result = 0; bufev_p->connecting = 1; - bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); + bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); } else { /* The connect failed already. How very BSD of it. */ result = 0; - bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS); - bufferevent_disable(bev, EV_WRITE|EV_READ); + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS); + bufferevent_disable(bev, EV_WRITE|EV_READ); } goto done; @@ -449,7 +449,7 @@ freesock: if (ownfd) evutil_closesocket(fd); done: - bufferevent_decref_and_unlock_(bev); + bufferevent_decref_and_unlock_(bev); return result; } @@ -458,24 +458,24 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai, void *arg) { struct bufferevent *bev = arg; - struct bufferevent_private *bev_p = BEV_UPCAST(bev); + struct bufferevent_private *bev_p = BEV_UPCAST(bev); int r; BEV_LOCK(bev); - bufferevent_unsuspend_write_(bev, BEV_SUSPEND_LOOKUP); - bufferevent_unsuspend_read_(bev, BEV_SUSPEND_LOOKUP); - - bev_p->dns_request = NULL; + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_LOOKUP); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_LOOKUP); - if (result == EVUTIL_EAI_CANCEL) { - bev_p->dns_error = result; - bufferevent_decref_and_unlock_(bev); - return; - } + bev_p->dns_request = NULL; + + if (result == EVUTIL_EAI_CANCEL) { + bev_p->dns_error = result; + bufferevent_decref_and_unlock_(bev); + return; + } if (result != 0) { bev_p->dns_error = result; - bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); - bufferevent_decref_and_unlock_(bev); + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); + bufferevent_decref_and_unlock_(bev); if (ai) evutil_freeaddrinfo(ai); return; @@ -486,11 +486,11 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai, while (found_ai->ai_addr->sa_family != AF_INET6 && found_ai->ai_next != NULL) { found_ai = found_ai->ai_next; } - bufferevent_socket_set_conn_address_(bev, found_ai->ai_addr, (int)found_ai->ai_addrlen); + bufferevent_socket_set_conn_address_(bev, found_ai->ai_addr, (int)found_ai->ai_addrlen); r = bufferevent_socket_connect(bev, found_ai->ai_addr, (int)found_ai->ai_addrlen); - if (r < 0) - bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); - bufferevent_decref_and_unlock_(bev); + if (r < 0) + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); + bufferevent_decref_and_unlock_(bev); evutil_freeaddrinfo(ai); } @@ -500,7 +500,7 @@ bufferevent_socket_connect_hostname(struct bufferevent *bev, { char portbuf[10]; struct evutil_addrinfo hint; - struct bufferevent_private *bev_p = BEV_UPCAST(bev); + struct bufferevent_private *bev_p = BEV_UPCAST(bev); if (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC) return -1; @@ -512,27 +512,27 @@ bufferevent_socket_connect_hostname(struct bufferevent *bev, hint.ai_protocol = IPPROTO_TCP; hint.ai_socktype = SOCK_STREAM; - evutil_snprintf(portbuf, sizeof(portbuf), "%d", port); - - BEV_LOCK(bev); - bev_p->dns_error = 0; - - bufferevent_suspend_write_(bev, BEV_SUSPEND_LOOKUP); - bufferevent_suspend_read_(bev, BEV_SUSPEND_LOOKUP); + evutil_snprintf(portbuf, sizeof(portbuf), "%d", port); - bufferevent_incref_(bev); - bev_p->dns_request = evutil_getaddrinfo_async_(evdns_base, hostname, - portbuf, &hint, bufferevent_connect_getaddrinfo_cb, bev); - BEV_UNLOCK(bev); + BEV_LOCK(bev); + bev_p->dns_error = 0; - return 0; + bufferevent_suspend_write_(bev, BEV_SUSPEND_LOOKUP); + bufferevent_suspend_read_(bev, BEV_SUSPEND_LOOKUP); + + bufferevent_incref_(bev); + bev_p->dns_request = evutil_getaddrinfo_async_(evdns_base, hostname, + portbuf, &hint, bufferevent_connect_getaddrinfo_cb, bev); + BEV_UNLOCK(bev); + + return 0; } int bufferevent_socket_get_dns_error(struct bufferevent *bev) { int rv; - struct bufferevent_private *bev_p = BEV_UPCAST(bev); + struct bufferevent_private *bev_p = BEV_UPCAST(bev); BEV_LOCK(bev); rv = bev_p->dns_error; @@ -571,11 +571,11 @@ bufferevent_new(evutil_socket_t fd, static int be_socket_enable(struct bufferevent *bufev, short event) { - if (event & EV_READ && - bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1) + if (event & EV_READ && + bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1) return -1; - if (event & EV_WRITE && - bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) + if (event & EV_WRITE && + bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) return -1; return 0; } @@ -583,7 +583,7 @@ be_socket_enable(struct bufferevent *bufev, short event) static int be_socket_disable(struct bufferevent *bufev, short event) { - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); if (event & EV_READ) { if (event_del(&bufev->ev_read) == -1) return -1; @@ -599,16 +599,16 @@ be_socket_disable(struct bufferevent *bufev, short event) static void be_socket_destruct(struct bufferevent *bufev) { - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); evutil_socket_t fd; - EVUTIL_ASSERT(BEV_IS_SOCKET(bufev)); + EVUTIL_ASSERT(BEV_IS_SOCKET(bufev)); fd = event_get_fd(&bufev->ev_read); if ((bufev_p->options & BEV_OPT_CLOSE_ON_FREE) && fd >= 0) EVUTIL_CLOSESOCKET(fd); - evutil_getaddrinfo_cancel_async_(bufev_p->dns_request); + evutil_getaddrinfo_cancel_async_(bufev_p->dns_request); } static int @@ -622,27 +622,27 @@ be_socket_flush(struct bufferevent *bev, short iotype, static void be_socket_setfd(struct bufferevent *bufev, evutil_socket_t fd) { - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); - + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + BEV_LOCK(bufev); - EVUTIL_ASSERT(BEV_IS_SOCKET(bufev)); + EVUTIL_ASSERT(BEV_IS_SOCKET(bufev)); event_del(&bufev->ev_read); event_del(&bufev->ev_write); - evbuffer_unfreeze(bufev->input, 0); - evbuffer_unfreeze(bufev->output, 1); - + evbuffer_unfreeze(bufev->input, 0); + evbuffer_unfreeze(bufev->output, 1); + event_assign(&bufev->ev_read, bufev->ev_base, fd, - EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev); + EV_READ|EV_PERSIST|EV_FINALIZE, bufferevent_readcb, bufev); event_assign(&bufev->ev_write, bufev->ev_base, fd, - EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev); + EV_WRITE|EV_PERSIST|EV_FINALIZE, bufferevent_writecb, bufev); if (fd >= 0) bufferevent_enable(bufev, bufev->enabled); - evutil_getaddrinfo_cancel_async_(bufev_p->dns_request); - + evutil_getaddrinfo_cancel_async_(bufev_p->dns_request); + BEV_UNLOCK(bufev); } @@ -651,7 +651,7 @@ int bufferevent_priority_set(struct bufferevent *bufev, int priority) { int r = -1; - struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); + struct bufferevent_private *bufev_p = BEV_UPCAST(bufev); BEV_LOCK(bufev); if (BEV_IS_ASYNC(bufev) || BEV_IS_FILTER(bufev) || BEV_IS_PAIR(bufev)) @@ -662,8 +662,8 @@ bufferevent_priority_set(struct bufferevent *bufev, int priority) if (event_priority_set(&bufev->ev_write, priority) == -1) goto done; - event_deferred_cb_set_priority_(&bufev_p->deferred, priority); - + event_deferred_cb_set_priority_(&bufev_p->deferred, priority); + r = 0; done: BEV_UNLOCK(bufev); @@ -677,7 +677,7 @@ bufferevent_base_set(struct event_base *base, struct bufferevent *bufev) int res = -1; BEV_LOCK(bufev); - if (!BEV_IS_SOCKET(bufev)) + if (!BEV_IS_SOCKET(bufev)) goto done; bufev->ev_base = base; diff --git a/contrib/libs/libevent/changelist-internal.h b/contrib/libs/libevent/changelist-internal.h index 98fc52aebf..6e9dc36673 100644 --- a/contrib/libs/libevent/changelist-internal.h +++ b/contrib/libs/libevent/changelist-internal.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CHANGELIST_INTERNAL_H_INCLUDED_ -#define CHANGELIST_INTERNAL_H_INCLUDED_ +#ifndef CHANGELIST_INTERNAL_H_INCLUDED_ +#define CHANGELIST_INTERNAL_H_INCLUDED_ /* A "changelist" is a list of all the fd status changes that should be made @@ -62,7 +62,7 @@ struct event_change { * and write_change is unused. */ ev_uint8_t read_change; ev_uint8_t write_change; - ev_uint8_t close_change; + ev_uint8_t close_change; }; /* Flags for read_change and write_change. */ @@ -83,20 +83,20 @@ struct event_change { #define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int) /** Set up the data fields in a changelist. */ -void event_changelist_init_(struct event_changelist *changelist); +void event_changelist_init_(struct event_changelist *changelist); /** Remove every change in the changelist, and make corresponding changes * in the event maps in the base. This function is generally used right * after making all the changes in the changelist. */ -void event_changelist_remove_all_(struct event_changelist *changelist, +void event_changelist_remove_all_(struct event_changelist *changelist, struct event_base *base); /** Free all memory held in a changelist. */ -void event_changelist_freemem_(struct event_changelist *changelist); +void event_changelist_freemem_(struct event_changelist *changelist); /** Implementation of eventop_add that queues the event in a changelist. */ -int event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events, +int event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events, void *p); /** Implementation of eventop_del that queues the event in a changelist. */ -int event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events, +int event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events, void *p); #endif diff --git a/contrib/libs/libevent/config.h b/contrib/libs/libevent/config.h index 8b87592052..e0f7daa6f9 100644 --- a/contrib/libs/libevent/config.h +++ b/contrib/libs/libevent/config.h @@ -1,555 +1,555 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if libevent should build without support for a debug mode */ -/* #undef DISABLE_DEBUG_MODE */ - -/* Define if libevent should not allow replacing the mm functions */ -/* #undef DISABLE_MM_REPLACEMENT */ - -/* Define if libevent should not be compiled with thread support */ -/* #undef DISABLE_THREAD_SUPPORT */ - -/* Define to 1 if you have the `accept4' function. */ -#define HAVE_ACCEPT4 1 - +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if libevent should build without support for a debug mode */ +/* #undef DISABLE_DEBUG_MODE */ + +/* Define if libevent should not allow replacing the mm functions */ +/* #undef DISABLE_MM_REPLACEMENT */ + +/* Define if libevent should not be compiled with thread support */ +/* #undef DISABLE_THREAD_SUPPORT */ + +/* Define to 1 if you have the `accept4' function. */ +#define HAVE_ACCEPT4 1 + /* Define to 1 if you have the <afunix.h> header file. */ /* #undef HAVE_AFUNIX_H */ -/* Define to 1 if you have the `arc4random' function. */ -/* #undef HAVE_ARC4RANDOM */ - -/* Define to 1 if you have the `arc4random_addrandom' function. */ -/* #undef HAVE_ARC4RANDOM_ADDRANDOM */ - -/* Define to 1 if you have the `arc4random_buf' function. */ -/* #undef HAVE_ARC4RANDOM_BUF */ - -/* Define to 1 if you have the <arpa/inet.h> header file. */ -#define HAVE_ARPA_INET_H 1 - -/* Define to 1 if you have the `clock_gettime' function. */ -#define HAVE_CLOCK_GETTIME 1 - -/* Define to 1 if you have the declaration of `CTL_KERN', and to 0 if you - don't. */ +/* Define to 1 if you have the `arc4random' function. */ +/* #undef HAVE_ARC4RANDOM */ + +/* Define to 1 if you have the `arc4random_addrandom' function. */ +/* #undef HAVE_ARC4RANDOM_ADDRANDOM */ + +/* Define to 1 if you have the `arc4random_buf' function. */ +/* #undef HAVE_ARC4RANDOM_BUF */ + +/* Define to 1 if you have the <arpa/inet.h> header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the declaration of `CTL_KERN', and to 0 if you + don't. */ /* #undef HAVE_DECL_CTL_KERN */ - -/* Define to 1 if you have the declaration of `KERN_ARND', and to 0 if you - don't. */ + +/* Define to 1 if you have the declaration of `KERN_ARND', and to 0 if you + don't. */ /* #undef HAVE_DECL_KERN_ARND */ - -/* Define if /dev/poll is available */ -/* #undef HAVE_DEVPOLL */ - -/* Define to 1 if you have the <dlfcn.h> header file. */ -#define HAVE_DLFCN_H 1 - -/* Define if your system supports the epoll system calls */ -#define HAVE_EPOLL 1 - -/* Define to 1 if you have the `epoll_create1' function. */ -#define HAVE_EPOLL_CREATE1 1 - -/* Define to 1 if you have the `epoll_ctl' function. */ -#define HAVE_EPOLL_CTL 1 - -/* Define to 1 if you have the <errno.h> header file. */ -#define HAVE_ERRNO_H 1 - -/* Define to 1 if you have the `eventfd' function. */ -#define HAVE_EVENTFD 1 - -/* Define if your system supports event ports */ -/* #undef HAVE_EVENT_PORTS */ - -/* Define to 1 if you have the `fcntl' function. */ -#define HAVE_FCNTL 1 - -/* Define to 1 if you have the <fcntl.h> header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if the system has the type `fd_mask'. */ -#define HAVE_FD_MASK 1 - -/* Do we have getaddrinfo()? */ -#define HAVE_GETADDRINFO 1 - -/* Define to 1 if you have the `getegid' function. */ -#define HAVE_GETEGID 1 - -/* Define to 1 if you have the `geteuid' function. */ -#define HAVE_GETEUID 1 - -/* Define this if you have any gethostbyname_r() */ -/* #undef HAVE_GETHOSTBYNAME_R */ - -/* Define this if gethostbyname_r takes 3 arguments */ -/* #undef HAVE_GETHOSTBYNAME_R_3_ARG */ - -/* Define this if gethostbyname_r takes 5 arguments */ -/* #undef HAVE_GETHOSTBYNAME_R_5_ARG */ - -/* Define this if gethostbyname_r takes 6 arguments */ -/* #undef HAVE_GETHOSTBYNAME_R_6_ARG */ - -/* Define to 1 if you have the `getifaddrs' function. */ -#define HAVE_GETIFADDRS 1 - -/* Define to 1 if you have the `getnameinfo' function. */ -#define HAVE_GETNAMEINFO 1 - -/* Define to 1 if you have the `getprotobynumber' function. */ -#define HAVE_GETPROTOBYNUMBER 1 - + +/* Define if /dev/poll is available */ +/* #undef HAVE_DEVPOLL */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H 1 + +/* Define if your system supports the epoll system calls */ +#define HAVE_EPOLL 1 + +/* Define to 1 if you have the `epoll_create1' function. */ +#define HAVE_EPOLL_CREATE1 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +#define HAVE_EPOLL_CTL 1 + +/* Define to 1 if you have the <errno.h> header file. */ +#define HAVE_ERRNO_H 1 + +/* Define to 1 if you have the `eventfd' function. */ +#define HAVE_EVENTFD 1 + +/* Define if your system supports event ports */ +/* #undef HAVE_EVENT_PORTS */ + +/* Define to 1 if you have the `fcntl' function. */ +#define HAVE_FCNTL 1 + +/* Define to 1 if you have the <fcntl.h> header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if the system has the type `fd_mask'. */ +#define HAVE_FD_MASK 1 + +/* Do we have getaddrinfo()? */ +#define HAVE_GETADDRINFO 1 + +/* Define to 1 if you have the `getegid' function. */ +#define HAVE_GETEGID 1 + +/* Define to 1 if you have the `geteuid' function. */ +#define HAVE_GETEUID 1 + +/* Define this if you have any gethostbyname_r() */ +/* #undef HAVE_GETHOSTBYNAME_R */ + +/* Define this if gethostbyname_r takes 3 arguments */ +/* #undef HAVE_GETHOSTBYNAME_R_3_ARG */ + +/* Define this if gethostbyname_r takes 5 arguments */ +/* #undef HAVE_GETHOSTBYNAME_R_5_ARG */ + +/* Define this if gethostbyname_r takes 6 arguments */ +/* #undef HAVE_GETHOSTBYNAME_R_6_ARG */ + +/* Define to 1 if you have the `getifaddrs' function. */ +#define HAVE_GETIFADDRS 1 + +/* Define to 1 if you have the `getnameinfo' function. */ +#define HAVE_GETNAMEINFO 1 + +/* Define to 1 if you have the `getprotobynumber' function. */ +#define HAVE_GETPROTOBYNUMBER 1 + /* Define to 1 if you have the `getrandom' function. */ #define HAVE_GETRANDOM 1 -/* Define to 1 if you have the `getservbyname' function. */ -#define HAVE_GETSERVBYNAME 1 - -/* Define to 1 if you have the `gettimeofday' function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define to 1 if you have the <ifaddrs.h> header file. */ -#define HAVE_IFADDRS_H 1 - -/* Define to 1 if you have the `inet_ntop' function. */ -#define HAVE_INET_NTOP 1 - -/* Define to 1 if you have the `inet_pton' function. */ -#define HAVE_INET_PTON 1 - -/* Define to 1 if you have the <inttypes.h> header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `issetugid' function. */ -/* #undef HAVE_ISSETUGID */ - -/* Define to 1 if you have the `kqueue' function. */ -/* #undef HAVE_KQUEUE */ - +/* Define to 1 if you have the `getservbyname' function. */ +#define HAVE_GETSERVBYNAME 1 + +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + +/* Define to 1 if you have the <ifaddrs.h> header file. */ +#define HAVE_IFADDRS_H 1 + +/* Define to 1 if you have the `inet_ntop' function. */ +#define HAVE_INET_NTOP 1 + +/* Define to 1 if you have the `inet_pton' function. */ +#define HAVE_INET_PTON 1 + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `issetugid' function. */ +/* #undef HAVE_ISSETUGID */ + +/* Define to 1 if you have the `kqueue' function. */ +/* #undef HAVE_KQUEUE */ + /* Define to 1 if you have the `ws2_32' library (-lws2_32). */ /* #undef HAVE_LIBWS2_32 */ -/* Define if the system has zlib */ -#define HAVE_LIBZ 1 - -/* Define to 1 if you have the `mach_absolute_time' function. */ -/* #undef HAVE_MACH_ABSOLUTE_TIME */ - +/* Define if the system has zlib */ +#define HAVE_LIBZ 1 + +/* Define to 1 if you have the `mach_absolute_time' function. */ +/* #undef HAVE_MACH_ABSOLUTE_TIME */ + /* Define to 1 if you have the <mach/mach.h> header file. */ /* #undef HAVE_MACH_MACH_H */ -/* Define to 1 if you have the <mach/mach_time.h> header file. */ -/* #undef HAVE_MACH_MACH_TIME_H */ - -/* Define to 1 if you have the <memory.h> header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `mmap' function. */ -#define HAVE_MMAP 1 - -/* Define to 1 if you have the `nanosleep' function. */ -#define HAVE_NANOSLEEP 1 - -/* Define to 1 if you have the <netdb.h> header file. */ -#define HAVE_NETDB_H 1 - -/* Define to 1 if you have the <netinet/in6.h> header file. */ -/* #undef HAVE_NETINET_IN6_H */ - -/* Define to 1 if you have the <netinet/in.h> header file. */ -#define HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the <netinet/tcp.h> header file. */ -#define HAVE_NETINET_TCP_H 1 - -/* Define if the system has openssl */ -#define HAVE_OPENSSL 1 - -/* Define to 1 if you have the <openssl/ssl.h> header file. */ -#define HAVE_OPENSSL_SSL_H 1 - -/* Define to 1 if you have the `pipe' function. */ -#define HAVE_PIPE 1 - -/* Define to 1 if you have the `pipe2' function. */ -#define HAVE_PIPE2 1 - -/* Define to 1 if you have the `poll' function. */ -#define HAVE_POLL 1 - -/* Define to 1 if you have the <poll.h> header file. */ -#define HAVE_POLL_H 1 - -/* Define to 1 if you have the `port_create' function. */ -/* #undef HAVE_PORT_CREATE */ - -/* Define to 1 if you have the <port.h> header file. */ -/* #undef HAVE_PORT_H */ - -/* Define if you have POSIX threads libraries and header files. */ -/* #undef HAVE_PTHREAD */ - -/* Define if we have pthreads on this system */ -#define HAVE_PTHREADS 1 - -/* Define to 1 if you have the `putenv' function. */ -#define HAVE_PUTENV 1 - -/* Define to 1 if the system has the type `sa_family_t'. */ -#define HAVE_SA_FAMILY_T 1 - -/* Define to 1 if you have the `select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the `sendfile' function. */ -#define HAVE_SENDFILE 1 - -/* Define to 1 if you have the `setenv' function. */ -#define HAVE_SETENV 1 - -/* Define if F_SETFD is defined in <fcntl.h> */ -#define HAVE_SETFD 1 - -/* Define to 1 if you have the `setrlimit' function. */ -#define HAVE_SETRLIMIT 1 - -/* Define to 1 if you have the `sigaction' function. */ -#define HAVE_SIGACTION 1 - -/* Define to 1 if you have the `signal' function. */ -#define HAVE_SIGNAL 1 - -/* Define to 1 if you have the `splice' function. */ -#define HAVE_SPLICE 1 - -/* Define to 1 if you have the <stdarg.h> header file. */ -#define HAVE_STDARG_H 1 - -/* Define to 1 if you have the <stddef.h> header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the <stdint.h> header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the <stdlib.h> header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the <strings.h> header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the <string.h> header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strlcpy' function. */ -/* #undef HAVE_STRLCPY */ - -/* Define to 1 if you have the `strsep' function. */ -#define HAVE_STRSEP 1 - -/* Define to 1 if you have the `strtok_r' function. */ -#define HAVE_STRTOK_R 1 - -/* Define to 1 if you have the `strtoll' function. */ -#define HAVE_STRTOLL 1 - -/* Define to 1 if the system has the type `struct addrinfo'. */ -#define HAVE_STRUCT_ADDRINFO 1 - -/* Define to 1 if the system has the type `struct in6_addr'. */ -#define HAVE_STRUCT_IN6_ADDR 1 - -/* Define to 1 if `s6_addr16' is a member of `struct in6_addr'. */ -#define HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 - -/* Define to 1 if `s6_addr32' is a member of `struct in6_addr'. */ -#define HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 - -/* Define to 1 if the system has the type `struct linger'. */ -#define HAVE_STRUCT_LINGER 1 - -/* Define to 1 if the system has the type `struct sockaddr_in6'. */ -#define HAVE_STRUCT_SOCKADDR_IN6 1 - -/* Define to 1 if `sin6_len' is a member of `struct sockaddr_in6'. */ -/* #undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */ - -/* Define to 1 if `sin_len' is a member of `struct sockaddr_in'. */ -/* #undef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ - -/* Define to 1 if the system has the type `struct sockaddr_storage'. */ -#define HAVE_STRUCT_SOCKADDR_STORAGE 1 - -/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */ -#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 - -/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */ -/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ - -/* Define to 1 if the system has the type `struct sockaddr_un'. */ -#define HAVE_STRUCT_SOCKADDR_UN 1 - -/* Define to 1 if you have the `sysctl' function. */ +/* Define to 1 if you have the <mach/mach_time.h> header file. */ +/* #undef HAVE_MACH_MACH_TIME_H */ + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the `nanosleep' function. */ +#define HAVE_NANOSLEEP 1 + +/* Define to 1 if you have the <netdb.h> header file. */ +#define HAVE_NETDB_H 1 + +/* Define to 1 if you have the <netinet/in6.h> header file. */ +/* #undef HAVE_NETINET_IN6_H */ + +/* Define to 1 if you have the <netinet/in.h> header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the <netinet/tcp.h> header file. */ +#define HAVE_NETINET_TCP_H 1 + +/* Define if the system has openssl */ +#define HAVE_OPENSSL 1 + +/* Define to 1 if you have the <openssl/ssl.h> header file. */ +#define HAVE_OPENSSL_SSL_H 1 + +/* Define to 1 if you have the `pipe' function. */ +#define HAVE_PIPE 1 + +/* Define to 1 if you have the `pipe2' function. */ +#define HAVE_PIPE2 1 + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the <poll.h> header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +/* #undef HAVE_PORT_CREATE */ + +/* Define to 1 if you have the <port.h> header file. */ +/* #undef HAVE_PORT_H */ + +/* Define if you have POSIX threads libraries and header files. */ +/* #undef HAVE_PTHREAD */ + +/* Define if we have pthreads on this system */ +#define HAVE_PTHREADS 1 + +/* Define to 1 if you have the `putenv' function. */ +#define HAVE_PUTENV 1 + +/* Define to 1 if the system has the type `sa_family_t'. */ +#define HAVE_SA_FAMILY_T 1 + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `sendfile' function. */ +#define HAVE_SENDFILE 1 + +/* Define to 1 if you have the `setenv' function. */ +#define HAVE_SETENV 1 + +/* Define if F_SETFD is defined in <fcntl.h> */ +#define HAVE_SETFD 1 + +/* Define to 1 if you have the `setrlimit' function. */ +#define HAVE_SETRLIMIT 1 + +/* Define to 1 if you have the `sigaction' function. */ +#define HAVE_SIGACTION 1 + +/* Define to 1 if you have the `signal' function. */ +#define HAVE_SIGNAL 1 + +/* Define to 1 if you have the `splice' function. */ +#define HAVE_SPLICE 1 + +/* Define to 1 if you have the <stdarg.h> header file. */ +#define HAVE_STDARG_H 1 + +/* Define to 1 if you have the <stddef.h> header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strlcpy' function. */ +/* #undef HAVE_STRLCPY */ + +/* Define to 1 if you have the `strsep' function. */ +#define HAVE_STRSEP 1 + +/* Define to 1 if you have the `strtok_r' function. */ +#define HAVE_STRTOK_R 1 + +/* Define to 1 if you have the `strtoll' function. */ +#define HAVE_STRTOLL 1 + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#define HAVE_STRUCT_ADDRINFO 1 + +/* Define to 1 if the system has the type `struct in6_addr'. */ +#define HAVE_STRUCT_IN6_ADDR 1 + +/* Define to 1 if `s6_addr16' is a member of `struct in6_addr'. */ +#define HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 + +/* Define to 1 if `s6_addr32' is a member of `struct in6_addr'. */ +#define HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 + +/* Define to 1 if the system has the type `struct linger'. */ +#define HAVE_STRUCT_LINGER 1 + +/* Define to 1 if the system has the type `struct sockaddr_in6'. */ +#define HAVE_STRUCT_SOCKADDR_IN6 1 + +/* Define to 1 if `sin6_len' is a member of `struct sockaddr_in6'. */ +/* #undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */ + +/* Define to 1 if `sin_len' is a member of `struct sockaddr_in'. */ +/* #undef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 + +/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */ +#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 + +/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */ +/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ + +/* Define to 1 if the system has the type `struct sockaddr_un'. */ +#define HAVE_STRUCT_SOCKADDR_UN 1 + +/* Define to 1 if you have the `sysctl' function. */ /* #undef HAVE_SYSCTL */ - -/* Define to 1 if you have the <sys/devpoll.h> header file. */ -/* #undef HAVE_SYS_DEVPOLL_H */ - -/* Define to 1 if you have the <sys/epoll.h> header file. */ -#define HAVE_SYS_EPOLL_H 1 - -/* Define to 1 if you have the <sys/eventfd.h> header file. */ -#define HAVE_SYS_EVENTFD_H 1 - -/* Define to 1 if you have the <sys/event.h> header file. */ -/* #undef HAVE_SYS_EVENT_H */ - -/* Define to 1 if you have the <sys/ioctl.h> header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the <sys/mman.h> header file. */ -#define HAVE_SYS_MMAN_H 1 - -/* Define to 1 if you have the <sys/param.h> header file. */ -#define HAVE_SYS_PARAM_H 1 - -/* Define to 1 if you have the <sys/queue.h> header file. */ -#define HAVE_SYS_QUEUE_H 1 - + +/* Define to 1 if you have the <sys/devpoll.h> header file. */ +/* #undef HAVE_SYS_DEVPOLL_H */ + +/* Define to 1 if you have the <sys/epoll.h> header file. */ +#define HAVE_SYS_EPOLL_H 1 + +/* Define to 1 if you have the <sys/eventfd.h> header file. */ +#define HAVE_SYS_EVENTFD_H 1 + +/* Define to 1 if you have the <sys/event.h> header file. */ +/* #undef HAVE_SYS_EVENT_H */ + +/* Define to 1 if you have the <sys/ioctl.h> header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the <sys/mman.h> header file. */ +#define HAVE_SYS_MMAN_H 1 + +/* Define to 1 if you have the <sys/param.h> header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the <sys/queue.h> header file. */ +#define HAVE_SYS_QUEUE_H 1 + /* Define to 1 if you have the <sys/random.h> header file. */ #define HAVE_SYS_RANDOM_H 1 -/* Define to 1 if you have the <sys/resource.h> header file. */ -#define HAVE_SYS_RESOURCE_H 1 - -/* Define to 1 if you have the <sys/select.h> header file. */ -#define HAVE_SYS_SELECT_H 1 - -/* Define to 1 if you have the <sys/sendfile.h> header file. */ -#define HAVE_SYS_SENDFILE_H 1 - -/* Define to 1 if you have the <sys/socket.h> header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the <sys/stat.h> header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the <sys/sysctl.h> header file. */ +/* Define to 1 if you have the <sys/resource.h> header file. */ +#define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the <sys/select.h> header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the <sys/sendfile.h> header file. */ +#define HAVE_SYS_SENDFILE_H 1 + +/* Define to 1 if you have the <sys/socket.h> header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/sysctl.h> header file. */ /* #undef HAVE_SYS_SYSCTL_H */ - -/* Define to 1 if you have the <sys/timerfd.h> header file. */ -#define HAVE_SYS_TIMERFD_H 1 - -/* Define to 1 if you have the <sys/time.h> header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the <sys/types.h> header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the <sys/uio.h> header file. */ -#define HAVE_SYS_UIO_H 1 - -/* Define to 1 if you have the <sys/un.h> header file. */ -#define HAVE_SYS_UN_H 1 - -/* Define to 1 if you have the <sys/wait.h> header file. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define if TAILQ_FOREACH is defined in <sys/queue.h> */ -#define HAVE_TAILQFOREACH 1 - -/* Define if timeradd is defined in <sys/time.h> */ -#define HAVE_TIMERADD 1 - -/* Define if timerclear is defined in <sys/time.h> */ -#define HAVE_TIMERCLEAR 1 - -/* Define if timercmp is defined in <sys/time.h> */ -#define HAVE_TIMERCMP 1 - -/* Define to 1 if you have the `timerfd_create' function. */ -#define HAVE_TIMERFD_CREATE 1 - -/* Define if timerisset is defined in <sys/time.h> */ -#define HAVE_TIMERISSET 1 - -/* Define to 1 if the system has the type `uint16_t'. */ -#define HAVE_UINT16_T 1 - -/* Define to 1 if the system has the type `uint32_t'. */ -#define HAVE_UINT32_T 1 - -/* Define to 1 if the system has the type `uint64_t'. */ -#define HAVE_UINT64_T 1 - -/* Define to 1 if the system has the type `uint8_t'. */ -#define HAVE_UINT8_T 1 - -/* Define to 1 if the system has the type `uintptr_t'. */ -#define HAVE_UINTPTR_T 1 - -/* Define to 1 if you have the `umask' function. */ -#define HAVE_UMASK 1 - -/* Define to 1 if you have the <unistd.h> header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the `unsetenv' function. */ -#define HAVE_UNSETENV 1 - -/* Define to 1 if you have the `usleep' function. */ -#define HAVE_USLEEP 1 - -/* Define to 1 if you have the `vasprintf' function. */ -#define HAVE_VASPRINTF 1 - -/* Define if kqueue works correctly with pipes */ -/* #undef HAVE_WORKING_KQUEUE */ - -/* Define to 1 if you have the <zlib.h> header file. */ -#define HAVE_ZLIB_H 1 - + +/* Define to 1 if you have the <sys/timerfd.h> header file. */ +#define HAVE_SYS_TIMERFD_H 1 + +/* Define to 1 if you have the <sys/time.h> header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <sys/uio.h> header file. */ +#define HAVE_SYS_UIO_H 1 + +/* Define to 1 if you have the <sys/un.h> header file. */ +#define HAVE_SYS_UN_H 1 + +/* Define to 1 if you have the <sys/wait.h> header file. */ +#define HAVE_SYS_WAIT_H 1 + +/* Define if TAILQ_FOREACH is defined in <sys/queue.h> */ +#define HAVE_TAILQFOREACH 1 + +/* Define if timeradd is defined in <sys/time.h> */ +#define HAVE_TIMERADD 1 + +/* Define if timerclear is defined in <sys/time.h> */ +#define HAVE_TIMERCLEAR 1 + +/* Define if timercmp is defined in <sys/time.h> */ +#define HAVE_TIMERCMP 1 + +/* Define to 1 if you have the `timerfd_create' function. */ +#define HAVE_TIMERFD_CREATE 1 + +/* Define if timerisset is defined in <sys/time.h> */ +#define HAVE_TIMERISSET 1 + +/* Define to 1 if the system has the type `uint16_t'. */ +#define HAVE_UINT16_T 1 + +/* Define to 1 if the system has the type `uint32_t'. */ +#define HAVE_UINT32_T 1 + +/* Define to 1 if the system has the type `uint64_t'. */ +#define HAVE_UINT64_T 1 + +/* Define to 1 if the system has the type `uint8_t'. */ +#define HAVE_UINT8_T 1 + +/* Define to 1 if the system has the type `uintptr_t'. */ +#define HAVE_UINTPTR_T 1 + +/* Define to 1 if you have the `umask' function. */ +#define HAVE_UMASK 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to 1 if you have the `unsetenv' function. */ +#define HAVE_UNSETENV 1 + +/* Define to 1 if you have the `usleep' function. */ +#define HAVE_USLEEP 1 + +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + +/* Define if kqueue works correctly with pipes */ +/* #undef HAVE_WORKING_KQUEUE */ + +/* Define to 1 if you have the <zlib.h> header file. */ +#define HAVE_ZLIB_H 1 + /* Define to 1 if you have the `_gmtime64' function. */ /* #undef HAVE__GMTIME64 */ /* Define to 1 if you have the `_gmtime64_s' function. */ /* #undef HAVE__GMTIME64_S */ -/* Define to 1 if compiler have __FUNCTION__ */ -#define HAVE___FUNCTION__ 1 - -/* Define to 1 if compiler have __func__ */ -#define HAVE___func__ 1 - -/* Define to the sub-directory where libtool stores uninstalled libraries. */ -#define LT_OBJDIR ".libs/" - -/* Numeric representation of the version */ +/* Define to 1 if compiler have __FUNCTION__ */ +#define HAVE___FUNCTION__ 1 + +/* Define to 1 if compiler have __func__ */ +#define HAVE___func__ 1 + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define LT_OBJDIR ".libs/" + +/* Numeric representation of the version */ #define NUMERIC_VERSION 0x02010c00 - -/* Name of package */ -#define PACKAGE "libevent" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "libevent" - -/* Define to the full name and version of this package. */ + +/* Name of package */ +#define PACKAGE "libevent" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "libevent" + +/* Define to the full name and version of this package. */ #define PACKAGE_STRING "libevent 2.1.12-stable" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "libevent" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "libevent" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ #define PACKAGE_VERSION "2.1.12-stable" - -/* Define to necessary symbol if this constant uses a non-standard name on - your system. */ -/* #undef PTHREAD_CREATE_JOINABLE */ - -/* The size of `int', as computed by sizeof. */ -#define SIZEOF_INT 4 - -/* The size of `long', as computed by sizeof. */ -#define SIZEOF_LONG 8 - -/* The size of `long long', as computed by sizeof. */ -#define SIZEOF_LONG_LONG 8 - -/* The size of `off_t', as computed by sizeof. */ -#define SIZEOF_OFF_T 8 - -/* The size of `pthread_t', as computed by sizeof. */ -#define SIZEOF_PTHREAD_T 8 - -/* The size of `short', as computed by sizeof. */ -#define SIZEOF_SHORT 2 - -/* The size of `size_t', as computed by sizeof. */ -#define SIZEOF_SIZE_T 8 - -/* The size of `time_t', as computed by sizeof. */ -#define SIZEOF_TIME_T 8 - -/* The size of `void *', as computed by sizeof. */ -#define SIZEOF_VOID_P 8 - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ -#define TIME_WITH_SYS_TIME 1 - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - - -/* Version number of package */ + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +/* #undef PTHREAD_CREATE_JOINABLE */ + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 8 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `off_t', as computed by sizeof. */ +#define SIZEOF_OFF_T 8 + +/* The size of `pthread_t', as computed by sizeof. */ +#define SIZEOF_PTHREAD_T 8 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* The size of `size_t', as computed by sizeof. */ +#define SIZEOF_SIZE_T 8 + +/* The size of `time_t', as computed by sizeof. */ +#define SIZEOF_TIME_T 8 + +/* The size of `void *', as computed by sizeof. */ +#define SIZEOF_VOID_P 8 + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ +#define TIME_WITH_SYS_TIME 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + +/* Version number of package */ #define VERSION "2.1.12-stable" - -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -/* #undef _FILE_OFFSET_BITS */ - -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ -#endif - -/* Define to `int' if <sys/types.h> does not define. */ -/* #undef pid_t */ - -/* Define to `unsigned int' if <sys/types.h> does not define. */ -/* #undef size_t */ - -/* Define to unsigned int if you dont have it */ -/* #undef socklen_t */ - -/* Define to `int' if <sys/types.h> does not define. */ -/* #undef ssize_t */ + +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `int' if <sys/types.h> does not define. */ +/* #undef pid_t */ + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +/* #undef size_t */ + +/* Define to unsigned int if you dont have it */ +/* #undef socklen_t */ + +/* Define to `int' if <sys/types.h> does not define. */ +/* #undef ssize_t */ diff --git a/contrib/libs/libevent/defer-internal.h b/contrib/libs/libevent/defer-internal.h index d6f80a1180..a59abd5121 100644 --- a/contrib/libs/libevent/defer-internal.h +++ b/contrib/libs/libevent/defer-internal.h @@ -23,51 +23,51 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef DEFER_INTERNAL_H_INCLUDED_ -#define DEFER_INTERNAL_H_INCLUDED_ +#ifndef DEFER_INTERNAL_H_INCLUDED_ +#define DEFER_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { #endif #include "event2/event-config.h" -#include "evconfig-private.h" - +#include "evconfig-private.h" + #include <sys/queue.h> -struct event_callback; -typedef void (*deferred_cb_fn)(struct event_callback *, void *); +struct event_callback; +typedef void (*deferred_cb_fn)(struct event_callback *, void *); /** - Initialize an empty, non-pending event_callback. + Initialize an empty, non-pending event_callback. - @param deferred The struct event_callback structure to initialize. - @param priority The priority that the callback should run at. - @param cb The function to run when the struct event_callback executes. + @param deferred The struct event_callback structure to initialize. + @param priority The priority that the callback should run at. + @param cb The function to run when the struct event_callback executes. @param arg The function's second argument. */ -EVENT2_EXPORT_SYMBOL -void event_deferred_cb_init_(struct event_callback *, ev_uint8_t, deferred_cb_fn, void *); +EVENT2_EXPORT_SYMBOL +void event_deferred_cb_init_(struct event_callback *, ev_uint8_t, deferred_cb_fn, void *); /** - Change the priority of a non-pending event_callback. + Change the priority of a non-pending event_callback. */ -void event_deferred_cb_set_priority_(struct event_callback *, ev_uint8_t); +void event_deferred_cb_set_priority_(struct event_callback *, ev_uint8_t); /** - Cancel a struct event_callback if it is currently scheduled in an event_base. + Cancel a struct event_callback if it is currently scheduled in an event_base. */ -EVENT2_EXPORT_SYMBOL -void event_deferred_cb_cancel_(struct event_base *, struct event_callback *); -/** - Activate a struct event_callback if it is not currently scheduled in an event_base. +EVENT2_EXPORT_SYMBOL +void event_deferred_cb_cancel_(struct event_base *, struct event_callback *); +/** + Activate a struct event_callback if it is not currently scheduled in an event_base. - Return true if it was not previously scheduled. - */ -EVENT2_EXPORT_SYMBOL -int event_deferred_cb_schedule_(struct event_base *, struct event_callback *); + Return true if it was not previously scheduled. + */ +EVENT2_EXPORT_SYMBOL +int event_deferred_cb_schedule_(struct event_base *, struct event_callback *); #ifdef __cplusplus } #endif -#endif /* EVENT_INTERNAL_H_INCLUDED_ */ +#endif /* EVENT_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/devpoll.c b/contrib/libs/libevent/devpoll.c index 3a2f86d6f1..7c2cfa8eb2 100644 --- a/contrib/libs/libevent/devpoll.c +++ b/contrib/libs/libevent/devpoll.c @@ -25,13 +25,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_DEVPOLL +#include "evconfig-private.h" +#ifdef EVENT__HAVE_DEVPOLL + #include <sys/types.h> #include <sys/resource.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> @@ -132,7 +132,7 @@ devpoll_init(struct event_base *base) nfiles = rl.rlim_cur; /* Initialize the kernel queue */ - if ((dpfd = evutil_open_closeonexec_("/dev/poll", O_RDWR, 0)) == -1) { + if ((dpfd = evutil_open_closeonexec_("/dev/poll", O_RDWR, 0)) == -1) { event_warn("open: /dev/poll"); mm_free(devpollop); return (NULL); @@ -159,7 +159,7 @@ devpoll_init(struct event_base *base) return (NULL); } - evsig_init_(base); + evsig_init_(base); return (devpollop); } @@ -217,7 +217,7 @@ devpoll_dispatch(struct event_base *base, struct timeval *tv) continue; /* XXX(niels): not sure if this works for devpoll */ - evmap_io_active_(base, events[i].fd, which); + evmap_io_active_(base, events[i].fd, which); } return (0); @@ -296,7 +296,7 @@ devpoll_dealloc(struct event_base *base) { struct devpollop *devpollop = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); if (devpollop->events) mm_free(devpollop->events); if (devpollop->changes) @@ -307,5 +307,5 @@ devpoll_dealloc(struct event_base *base) memset(devpollop, 0, sizeof(struct devpollop)); mm_free(devpollop); } - -#endif /* EVENT__HAVE_DEVPOLL */ + +#endif /* EVENT__HAVE_DEVPOLL */ diff --git a/contrib/libs/libevent/epoll.c b/contrib/libs/libevent/epoll.c index bdec2e4569..adffaa375a 100644 --- a/contrib/libs/libevent/epoll.c +++ b/contrib/libs/libevent/epoll.c @@ -25,14 +25,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_EPOLL +#include "evconfig-private.h" +#ifdef EVENT__HAVE_EPOLL + #include <stdint.h> #include <sys/types.h> #include <sys/resource.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> @@ -44,12 +44,12 @@ #include <string.h> #include <unistd.h> #include <errno.h> -#ifdef EVENT__HAVE_FCNTL_H +#ifdef EVENT__HAVE_FCNTL_H #include <fcntl.h> #endif -#ifdef EVENT__HAVE_SYS_TIMERFD_H -#include <sys/timerfd.h> -#endif +#ifdef EVENT__HAVE_SYS_TIMERFD_H +#include <sys/timerfd.h> +#endif #include "event-internal.h" #include "evsignal-internal.h" @@ -58,38 +58,38 @@ #include "log-internal.h" #include "evmap-internal.h" #include "changelist-internal.h" -#include "time-internal.h" - -/* Since Linux 2.6.17, epoll is able to report about peer half-closed connection - using special EPOLLRDHUP flag on a read event. -*/ -#if !defined(EPOLLRDHUP) -#define EPOLLRDHUP 0 -#define EARLY_CLOSE_IF_HAVE_RDHUP 0 -#else -#define EARLY_CLOSE_IF_HAVE_RDHUP EV_FEATURE_EARLY_CLOSE -#endif - -#include "epolltable-internal.h" - -#if defined(EVENT__HAVE_SYS_TIMERFD_H) && \ - defined(EVENT__HAVE_TIMERFD_CREATE) && \ - defined(HAVE_POSIX_MONOTONIC) && defined(TFD_NONBLOCK) && \ - defined(TFD_CLOEXEC) -/* Note that we only use timerfd if TFD_NONBLOCK and TFD_CLOEXEC are available - and working. This means that we can't support it on 2.6.25 (where timerfd - was introduced) or 2.6.26, since 2.6.27 introduced those flags. - */ -#define USING_TIMERFD -#endif - +#include "time-internal.h" + +/* Since Linux 2.6.17, epoll is able to report about peer half-closed connection + using special EPOLLRDHUP flag on a read event. +*/ +#if !defined(EPOLLRDHUP) +#define EPOLLRDHUP 0 +#define EARLY_CLOSE_IF_HAVE_RDHUP 0 +#else +#define EARLY_CLOSE_IF_HAVE_RDHUP EV_FEATURE_EARLY_CLOSE +#endif + +#include "epolltable-internal.h" + +#if defined(EVENT__HAVE_SYS_TIMERFD_H) && \ + defined(EVENT__HAVE_TIMERFD_CREATE) && \ + defined(HAVE_POSIX_MONOTONIC) && defined(TFD_NONBLOCK) && \ + defined(TFD_CLOEXEC) +/* Note that we only use timerfd if TFD_NONBLOCK and TFD_CLOEXEC are available + and working. This means that we can't support it on 2.6.25 (where timerfd + was introduced) or 2.6.26, since 2.6.27 introduced those flags. + */ +#define USING_TIMERFD +#endif + struct epollop { struct epoll_event *events; int nevents; int epfd; -#ifdef USING_TIMERFD - int timerfd; -#endif +#ifdef USING_TIMERFD + int timerfd; +#endif }; static void *epoll_init(struct event_base *); @@ -99,12 +99,12 @@ static void epoll_dealloc(struct event_base *); static const struct eventop epollops_changelist = { "epoll (with changelist)", epoll_init, - event_changelist_add_, - event_changelist_del_, + event_changelist_add_, + event_changelist_del_, epoll_dispatch, epoll_dealloc, 1, /* need reinit */ - EV_FEATURE_ET|EV_FEATURE_O1| EARLY_CLOSE_IF_HAVE_RDHUP, + EV_FEATURE_ET|EV_FEATURE_O1| EARLY_CLOSE_IF_HAVE_RDHUP, EVENT_CHANGELIST_FDINFO_SIZE }; @@ -122,7 +122,7 @@ const struct eventop epollops = { epoll_dispatch, epoll_dealloc, 1, /* need reinit */ - EV_FEATURE_ET|EV_FEATURE_O1|EV_FEATURE_EARLY_CLOSE, + EV_FEATURE_ET|EV_FEATURE_O1|EV_FEATURE_EARLY_CLOSE, 0 }; @@ -140,22 +140,22 @@ const struct eventop epollops = { static void * epoll_init(struct event_base *base) { - int epfd = -1; + int epfd = -1; struct epollop *epollop; -#ifdef EVENT__HAVE_EPOLL_CREATE1 - /* First, try the shiny new epoll_create1 interface, if we have it. */ - epfd = epoll_create1(EPOLL_CLOEXEC); -#endif - if (epfd == -1) { - /* Initialize the kernel queue using the old interface. (The - size field is ignored since 2.6.8.) */ - if ((epfd = epoll_create(32000)) == -1) { - if (errno != ENOSYS) - event_warn("epoll_create"); - return (NULL); - } - evutil_make_socket_closeonexec(epfd); +#ifdef EVENT__HAVE_EPOLL_CREATE1 + /* First, try the shiny new epoll_create1 interface, if we have it. */ + epfd = epoll_create1(EPOLL_CLOEXEC); +#endif + if (epfd == -1) { + /* Initialize the kernel queue using the old interface. (The + size field is ignored since 2.6.8.) */ + if ((epfd = epoll_create(32000)) == -1) { + if (errno != ENOSYS) + event_warn("epoll_create"); + return (NULL); + } + evutil_make_socket_closeonexec(epfd); } if (!(epollop = mm_calloc(1, sizeof(struct epollop)))) { @@ -176,49 +176,49 @@ epoll_init(struct event_base *base) if ((base->flags & EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST) != 0 || ((base->flags & EVENT_BASE_FLAG_IGNORE_ENV) == 0 && - evutil_getenv_("EVENT_EPOLL_USE_CHANGELIST") != NULL)) { - + evutil_getenv_("EVENT_EPOLL_USE_CHANGELIST") != NULL)) { + base->evsel = &epollops_changelist; - } - -#ifdef USING_TIMERFD - /* - The epoll interface ordinarily gives us one-millisecond precision, - so on Linux it makes perfect sense to use the CLOCK_MONOTONIC_COARSE - timer. But when the user has set the new PRECISE_TIMER flag for an - event_base, we can try to use timerfd to give them finer granularity. - */ - if ((base->flags & EVENT_BASE_FLAG_PRECISE_TIMER) && - base->monotonic_timer.monotonic_clock == CLOCK_MONOTONIC) { - int fd; - fd = epollop->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC); - if (epollop->timerfd >= 0) { - struct epoll_event epev; - memset(&epev, 0, sizeof(epev)); - epev.data.fd = epollop->timerfd; - epev.events = EPOLLIN; - if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, fd, &epev) < 0) { - event_warn("epoll_ctl(timerfd)"); - close(fd); - epollop->timerfd = -1; - } - } else { - if (errno != EINVAL && errno != ENOSYS) { - /* These errors probably mean that we were - * compiled with timerfd/TFD_* support, but - * we're running on a kernel that lacks those. - */ - event_warn("timerfd_create"); - } - epollop->timerfd = -1; - } - } else { - epollop->timerfd = -1; - } -#endif - - evsig_init_(base); - + } + +#ifdef USING_TIMERFD + /* + The epoll interface ordinarily gives us one-millisecond precision, + so on Linux it makes perfect sense to use the CLOCK_MONOTONIC_COARSE + timer. But when the user has set the new PRECISE_TIMER flag for an + event_base, we can try to use timerfd to give them finer granularity. + */ + if ((base->flags & EVENT_BASE_FLAG_PRECISE_TIMER) && + base->monotonic_timer.monotonic_clock == CLOCK_MONOTONIC) { + int fd; + fd = epollop->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC); + if (epollop->timerfd >= 0) { + struct epoll_event epev; + memset(&epev, 0, sizeof(epev)); + epev.data.fd = epollop->timerfd; + epev.events = EPOLLIN; + if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, fd, &epev) < 0) { + event_warn("epoll_ctl(timerfd)"); + close(fd); + epollop->timerfd = -1; + } + } else { + if (errno != EINVAL && errno != ENOSYS) { + /* These errors probably mean that we were + * compiled with timerfd/TFD_* support, but + * we're running on a kernel that lacks those. + */ + event_warn("timerfd_create"); + } + epollop->timerfd = -1; + } + } else { + epollop->timerfd = -1; + } +#endif + + evsig_init_(base); + return (epollop); } @@ -246,23 +246,23 @@ epoll_op_to_string(int op) "???"; } -#define PRINT_CHANGES(op, events, ch, status) \ - "Epoll %s(%d) on fd %d " status ". " \ - "Old events were %d; " \ - "read change was %d (%s); " \ - "write change was %d (%s); " \ - "close change was %d (%s)", \ - epoll_op_to_string(op), \ - events, \ - ch->fd, \ - ch->old_events, \ - ch->read_change, \ - change_to_string(ch->read_change), \ - ch->write_change, \ - change_to_string(ch->write_change), \ - ch->close_change, \ - change_to_string(ch->close_change) - +#define PRINT_CHANGES(op, events, ch, status) \ + "Epoll %s(%d) on fd %d " status ". " \ + "Old events were %d; " \ + "read change was %d (%s); " \ + "write change was %d (%s); " \ + "close change was %d (%s)", \ + epoll_op_to_string(op), \ + events, \ + ch->fd, \ + ch->old_events, \ + ch->read_change, \ + change_to_string(ch->read_change), \ + ch->write_change, \ + change_to_string(ch->write_change), \ + ch->close_change, \ + change_to_string(ch->close_change) + static int epoll_apply_one_change(struct event_base *base, struct epollop *epollop, @@ -270,86 +270,86 @@ epoll_apply_one_change(struct event_base *base, { struct epoll_event epev; int op, events = 0; - int idx; + int idx; - idx = EPOLL_OP_TABLE_INDEX(ch); - op = epoll_op_table[idx].op; - events = epoll_op_table[idx].events; + idx = EPOLL_OP_TABLE_INDEX(ch); + op = epoll_op_table[idx].op; + events = epoll_op_table[idx].events; - if (!events) { - EVUTIL_ASSERT(op == 0); - return 0; - } + if (!events) { + EVUTIL_ASSERT(op == 0); + return 0; + } if ((ch->read_change|ch->write_change|ch->close_change) & EV_CHANGE_ET) - events |= EPOLLET; - - memset(&epev, 0, sizeof(epev)); - epev.data.fd = ch->fd; - epev.events = events; - if (epoll_ctl(epollop->epfd, op, ch->fd, &epev) == 0) { - event_debug((PRINT_CHANGES(op, epev.events, ch, "okay"))); - return 0; - } - - switch (op) { - case EPOLL_CTL_MOD: - if (errno == ENOENT) { - /* If a MOD operation fails with ENOENT, the - * fd was probably closed and re-opened. We - * should retry the operation as an ADD. - */ - if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, ch->fd, &epev) == -1) { - event_warn("Epoll MOD(%d) on %d retried as ADD; that failed too", - (int)epev.events, ch->fd); - return -1; - } else { - event_debug(("Epoll MOD(%d) on %d retried as ADD; succeeded.", - (int)epev.events, - ch->fd)); - return 0; + events |= EPOLLET; + + memset(&epev, 0, sizeof(epev)); + epev.data.fd = ch->fd; + epev.events = events; + if (epoll_ctl(epollop->epfd, op, ch->fd, &epev) == 0) { + event_debug((PRINT_CHANGES(op, epev.events, ch, "okay"))); + return 0; + } + + switch (op) { + case EPOLL_CTL_MOD: + if (errno == ENOENT) { + /* If a MOD operation fails with ENOENT, the + * fd was probably closed and re-opened. We + * should retry the operation as an ADD. + */ + if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, ch->fd, &epev) == -1) { + event_warn("Epoll MOD(%d) on %d retried as ADD; that failed too", + (int)epev.events, ch->fd); + return -1; + } else { + event_debug(("Epoll MOD(%d) on %d retried as ADD; succeeded.", + (int)epev.events, + ch->fd)); + return 0; } } - break; - case EPOLL_CTL_ADD: - if (errno == EEXIST) { - /* If an ADD operation fails with EEXIST, - * either the operation was redundant (as with a - * precautionary add), or we ran into a fun - * kernel bug where using dup*() to duplicate the - * same file into the same fd gives you the same epitem - * rather than a fresh one. For the second case, - * we must retry with MOD. */ - if (epoll_ctl(epollop->epfd, EPOLL_CTL_MOD, ch->fd, &epev) == -1) { - event_warn("Epoll ADD(%d) on %d retried as MOD; that failed too", - (int)epev.events, ch->fd); - return -1; - } else { - event_debug(("Epoll ADD(%d) on %d retried as MOD; succeeded.", + break; + case EPOLL_CTL_ADD: + if (errno == EEXIST) { + /* If an ADD operation fails with EEXIST, + * either the operation was redundant (as with a + * precautionary add), or we ran into a fun + * kernel bug where using dup*() to duplicate the + * same file into the same fd gives you the same epitem + * rather than a fresh one. For the second case, + * we must retry with MOD. */ + if (epoll_ctl(epollop->epfd, EPOLL_CTL_MOD, ch->fd, &epev) == -1) { + event_warn("Epoll ADD(%d) on %d retried as MOD; that failed too", + (int)epev.events, ch->fd); + return -1; + } else { + event_debug(("Epoll ADD(%d) on %d retried as MOD; succeeded.", (int)epev.events, - ch->fd)); - return 0; + ch->fd)); + return 0; } - } - break; - case EPOLL_CTL_DEL: - if (errno == ENOENT || errno == EBADF || errno == EPERM) { - /* If a delete fails with one of these errors, - * that's fine too: we closed the fd before we - * got around to calling epoll_dispatch. */ - event_debug(("Epoll DEL(%d) on fd %d gave %s: DEL was unnecessary.", + } + break; + case EPOLL_CTL_DEL: + if (errno == ENOENT || errno == EBADF || errno == EPERM) { + /* If a delete fails with one of these errors, + * that's fine too: we closed the fd before we + * got around to calling epoll_dispatch. */ + event_debug(("Epoll DEL(%d) on fd %d gave %s: DEL was unnecessary.", (int)epev.events, - ch->fd, - strerror(errno))); - return 0; + ch->fd, + strerror(errno))); + return 0; } - break; - default: - break; + break; + default: + break; } - - event_warn(PRINT_CHANGES(op, epev.events, ch, "failed")); - return -1; + + event_warn(PRINT_CHANGES(op, epev.events, ch, "failed")); + return -1; } static int @@ -378,16 +378,16 @@ epoll_nochangelist_add(struct event_base *base, evutil_socket_t fd, struct event_change ch; ch.fd = fd; ch.old_events = old; - ch.read_change = ch.write_change = ch.close_change = 0; + ch.read_change = ch.write_change = ch.close_change = 0; if (events & EV_WRITE) ch.write_change = EV_CHANGE_ADD | (events & EV_ET); if (events & EV_READ) ch.read_change = EV_CHANGE_ADD | (events & EV_ET); - if (events & EV_CLOSED) - ch.close_change = EV_CHANGE_ADD | - (events & EV_ET); + if (events & EV_CLOSED) + ch.close_change = EV_CHANGE_ADD | + (events & EV_ET); return epoll_apply_one_change(base, base->evbase, &ch); } @@ -399,16 +399,16 @@ epoll_nochangelist_del(struct event_base *base, evutil_socket_t fd, struct event_change ch; ch.fd = fd; ch.old_events = old; - ch.read_change = ch.write_change = ch.close_change = 0; + ch.read_change = ch.write_change = ch.close_change = 0; if (events & EV_WRITE) - ch.write_change = EV_CHANGE_DEL | - (events & EV_ET); + ch.write_change = EV_CHANGE_DEL | + (events & EV_ET); if (events & EV_READ) - ch.read_change = EV_CHANGE_DEL | - (events & EV_ET); - if (events & EV_CLOSED) - ch.close_change = EV_CHANGE_DEL | - (events & EV_ET); + ch.read_change = EV_CHANGE_DEL | + (events & EV_ET); + if (events & EV_CLOSED) + ch.close_change = EV_CHANGE_DEL | + (events & EV_ET); return epoll_apply_one_change(base, base->evbase, &ch); } @@ -421,35 +421,35 @@ epoll_dispatch(struct event_base *base, struct timeval *tv) int i, res; long timeout = -1; -#ifdef USING_TIMERFD - if (epollop->timerfd >= 0) { - struct itimerspec is; - is.it_interval.tv_sec = 0; - is.it_interval.tv_nsec = 0; - if (tv == NULL) { - /* No timeout; disarm the timer. */ - is.it_value.tv_sec = 0; - is.it_value.tv_nsec = 0; - } else { - if (tv->tv_sec == 0 && tv->tv_usec == 0) { - /* we need to exit immediately; timerfd can't - * do that. */ - timeout = 0; - } - is.it_value.tv_sec = tv->tv_sec; - is.it_value.tv_nsec = tv->tv_usec * 1000; - } - /* TODO: we could avoid unnecessary syscalls here by only - calling timerfd_settime when the top timeout changes, or - when we're called with a different timeval. - */ - if (timerfd_settime(epollop->timerfd, 0, &is, NULL) < 0) { - event_warn("timerfd_settime"); - } - } else -#endif +#ifdef USING_TIMERFD + if (epollop->timerfd >= 0) { + struct itimerspec is; + is.it_interval.tv_sec = 0; + is.it_interval.tv_nsec = 0; + if (tv == NULL) { + /* No timeout; disarm the timer. */ + is.it_value.tv_sec = 0; + is.it_value.tv_nsec = 0; + } else { + if (tv->tv_sec == 0 && tv->tv_usec == 0) { + /* we need to exit immediately; timerfd can't + * do that. */ + timeout = 0; + } + is.it_value.tv_sec = tv->tv_sec; + is.it_value.tv_nsec = tv->tv_usec * 1000; + } + /* TODO: we could avoid unnecessary syscalls here by only + calling timerfd_settime when the top timeout changes, or + when we're called with a different timeval. + */ + if (timerfd_settime(epollop->timerfd, 0, &is, NULL) < 0) { + event_warn("timerfd_settime"); + } + } else +#endif if (tv != NULL) { - timeout = evutil_tv_to_msec_(tv); + timeout = evutil_tv_to_msec_(tv); if (timeout < 0 || timeout > MAX_EPOLL_TIMEOUT_MSEC) { /* Linux kernels can wait forever if the timeout is * too big; see comment on MAX_EPOLL_TIMEOUT_MSEC. */ @@ -458,7 +458,7 @@ epoll_dispatch(struct event_base *base, struct timeval *tv) } epoll_apply_changes(base); - event_changelist_remove_all_(&base->changelist, base); + event_changelist_remove_all_(&base->changelist, base); EVBASE_RELEASE_LOCK(base, th_base_lock); @@ -481,10 +481,10 @@ epoll_dispatch(struct event_base *base, struct timeval *tv) for (i = 0; i < res; i++) { int what = events[i].events; short ev = 0; -#ifdef USING_TIMERFD - if (events[i].data.fd == epollop->timerfd) - continue; -#endif +#ifdef USING_TIMERFD + if (events[i].data.fd == epollop->timerfd) + continue; +#endif if (what & EPOLLERR) { ev = EV_READ | EV_WRITE; @@ -495,14 +495,14 @@ epoll_dispatch(struct event_base *base, struct timeval *tv) ev |= EV_READ; if (what & EPOLLOUT) ev |= EV_WRITE; - if (what & EPOLLRDHUP) - ev |= EV_CLOSED; + if (what & EPOLLRDHUP) + ev |= EV_CLOSED; } if (!ev) continue; - evmap_io_active_(base, events[i].data.fd, ev | EV_ET); + evmap_io_active_(base, events[i].data.fd, ev | EV_ET); } if (res == epollop->nevents && epollop->nevents < MAX_NEVENT) { @@ -528,18 +528,18 @@ epoll_dealloc(struct event_base *base) { struct epollop *epollop = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); if (epollop->events) mm_free(epollop->events); if (epollop->epfd >= 0) close(epollop->epfd); -#ifdef USING_TIMERFD - if (epollop->timerfd >= 0) - close(epollop->timerfd); -#endif +#ifdef USING_TIMERFD + if (epollop->timerfd >= 0) + close(epollop->timerfd); +#endif memset(epollop, 0, sizeof(struct epollop)); mm_free(epollop); } - -#endif /* EVENT__HAVE_EPOLL */ + +#endif /* EVENT__HAVE_EPOLL */ diff --git a/contrib/libs/libevent/epoll_sub.c b/contrib/libs/libevent/epoll_sub.c index 3f01f6a699..69ab8e126a 100644 --- a/contrib/libs/libevent/epoll_sub.c +++ b/contrib/libs/libevent/epoll_sub.c @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "evconfig-private.h" +#include "evconfig-private.h" #include <stdint.h> #include <sys/param.h> diff --git a/contrib/libs/libevent/epolltable-internal.h b/contrib/libs/libevent/epolltable-internal.h index 73c2e3647e..000f1e0703 100644 --- a/contrib/libs/libevent/epolltable-internal.h +++ b/contrib/libs/libevent/epolltable-internal.h @@ -1,1166 +1,1166 @@ -/* - * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EPOLLTABLE_INTERNAL_H_INCLUDED_ -#define EPOLLTABLE_INTERNAL_H_INCLUDED_ - -/* - Here are the values we're masking off to decide what operations to do. - Note that since EV_READ|EV_WRITE. - - Note also that this table is a little sparse, since ADD+DEL is - nonsensical ("xxx" in the list below.) - - Note also that we are shifting old_events by only 5 bits, since - EV_READ is 2 and EV_WRITE is 4. - - The table was auto-generated with a python script, according to this - pseudocode:[*0] - - If either the read or the write change is add+del: - This is impossible; Set op==-1, events=0. - Else, if either the read or the write change is add: - Set events to 0. - If the read change is add, or - (the read change is not del, and ev_read is in old_events): - Add EPOLLIN to events. - If the write change is add, or - (the write change is not del, and ev_write is in old_events): - Add EPOLLOUT to events. - - If old_events is set: - Set op to EPOLL_CTL_MOD [*1,*2] - Else: - Set op to EPOLL_CTL_ADD [*3] - - Else, if the read or the write change is del: - Set op to EPOLL_CTL_DEL. - If the read change is del: - If the write change is del: - Set events to EPOLLIN|EPOLLOUT - Else if ev_write is in old_events: - Set events to EPOLLOUT - Set op to EPOLL_CTL_MOD - Else - Set events to EPOLLIN - Else: - {The write change is del.} - If ev_read is in old_events: - Set events to EPOLLIN - Set op to EPOLL_CTL_MOD - Else: - Set the events to EPOLLOUT - - Else: - There is no read or write change; set op to 0 and events to 0. - - The logic is a little tricky, since we had no events set on the fd before, - we need to set op="ADD" and set events=the events we want to add. If we - had any events set on the fd before, and we want any events to remain on - the fd, we need to say op="MOD" and set events=the events we want to - remain. But if we want to delete the last event, we say op="DEL" and - set events=(any non-null pointer). - - [*0] Actually, the Python script has gotten a bit more complicated, to - support EPOLLRDHUP. - - [*1] This MOD is only a guess. MOD might fail with ENOENT if the file was - closed and a new file was opened with the same fd. If so, we'll retry - with ADD. - - [*2] We can't replace this with a no-op even if old_events is the same as - the new events: if the file was closed and reopened, we need to retry - with an ADD. (We do a MOD in this case since "no change" is more - common than "close and reopen", so we'll usually wind up doing 1 - syscalls instead of 2.) - - [*3] This ADD is only a guess. There is a fun Linux kernel issue where if - you have two fds for the same file (via dup) and you ADD one to an - epfd, then close it, then re-create it with the same fd (via dup2 or an - unlucky dup), then try to ADD it again, you'll get an EEXIST, since the - struct epitem is not actually removed from the struct eventpoll until - the file itself is closed. - - EV_CHANGE_ADD==1 - EV_CHANGE_DEL==2 - EV_READ ==2 - EV_WRITE ==4 - EV_CLOSED ==0x80 - - Bit 0: close change is add - Bit 1: close change is del - Bit 2: read change is add - Bit 3: read change is del - Bit 4: write change is add - Bit 5: write change is del - Bit 6: old events had EV_READ - Bit 7: old events had EV_WRITE - Bit 8: old events had EV_CLOSED -*/ - -#define EPOLL_OP_TABLE_INDEX(c) \ - ( (((c)->close_change&(EV_CHANGE_ADD|EV_CHANGE_DEL))) | \ - (((c)->read_change&(EV_CHANGE_ADD|EV_CHANGE_DEL)) << 2) | \ - (((c)->write_change&(EV_CHANGE_ADD|EV_CHANGE_DEL)) << 4) | \ - (((c)->old_events&(EV_READ|EV_WRITE)) << 5) | \ - (((c)->old_events&(EV_CLOSED)) << 1) \ - ) - -#if EV_READ != 2 || EV_WRITE != 4 || EV_CLOSED != 0x80 || EV_CHANGE_ADD != 1 || EV_CHANGE_DEL != 2 -#error "Libevent's internals changed! Regenerate the op_table in epolltable-internal.h" -#endif - -static const struct operation { - int events; - int op; -} epoll_op_table[] = { - /* old= 0, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= 0, write: 0, read: 0, close:add */ - { EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write: 0, read: 0, close:del */ - { EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= 0, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= 0, write: 0, read:add, close: 0 */ - { EPOLLIN, EPOLL_CTL_ADD }, - /* old= 0, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write: 0, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_ADD }, - /* old= 0, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= 0, write: 0, read:del, close: 0 */ - { EPOLLIN, EPOLL_CTL_DEL }, - /* old= 0, write: 0, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write: 0, read:del, close:del */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= 0, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= 0, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= 0, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= 0, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= 0, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= 0, write:add, read: 0, close: 0 */ - { EPOLLOUT, EPOLL_CTL_ADD }, - /* old= 0, write:add, read: 0, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write:add, read: 0, close:del */ - { EPOLLOUT, EPOLL_CTL_ADD }, - /* old= 0, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= 0, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_ADD }, - /* old= 0, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_ADD }, - /* old= 0, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= 0, write:add, read:del, close: 0 */ - { EPOLLOUT, EPOLL_CTL_ADD }, - /* old= 0, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_ADD }, - /* old= 0, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= 0, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= 0, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= 0, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= 0, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= 0, write:del, read: 0, close: 0 */ - { EPOLLOUT, EPOLL_CTL_DEL }, - /* old= 0, write:del, read: 0, close:add */ - { EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write:del, read: 0, close:del */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= 0, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= 0, write:del, read:add, close: 0 */ - { EPOLLIN, EPOLL_CTL_ADD }, - /* old= 0, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_ADD }, - /* old= 0, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= 0, write:del, read:del, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, - /* old= 0, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_ADD }, - /* old= 0, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= 0, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= 0, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= 0, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= 0, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= 0, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= 0, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= 0, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= 0, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= 0, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= 0, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= 0, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= 0, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= 0, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= 0, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= 0, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= 0, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= 0, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= 0, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= 0, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= 0, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= 0, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old= r, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= r, write: 0, read: 0, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write: 0, read: 0, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= r, write: 0, read:add, close: 0 */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write: 0, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= r, write: 0, read:del, close: 0 */ - { EPOLLIN, EPOLL_CTL_DEL }, - /* old= r, write: 0, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write: 0, read:del, close:del */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= r, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= r, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= r, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= r, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= r, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= r, write:add, read: 0, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= r, write:add, read: 0, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write:add, read: 0, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= r, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= r, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= r, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= r, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= r, write:add, read:del, close: 0 */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= r, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= r, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= r, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= r, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= r, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= r, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= r, write:del, read: 0, close: 0 */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write:del, read: 0, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write:del, read: 0, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= r, write:del, read:add, close: 0 */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= r, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= r, write:del, read:del, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, - /* old= r, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= r, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= r, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= r, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= r, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= r, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= r, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= r, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= r, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= r, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= r, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= r, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= r, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= r, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= r, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= r, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= r, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= r, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= r, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= r, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= r, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= r, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= r, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old= w, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= w, write: 0, read: 0, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write: 0, read: 0, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= w, write: 0, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write: 0, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= w, write: 0, read:del, close: 0 */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write: 0, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write: 0, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= w, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= w, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= w, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= w, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= w, write:add, read: 0, close: 0 */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write:add, read: 0, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write:add, read: 0, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= w, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= w, write:add, read:del, close: 0 */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= w, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= w, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= w, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= w, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= w, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= w, write:del, read: 0, close: 0 */ - { EPOLLOUT, EPOLL_CTL_DEL }, - /* old= w, write:del, read: 0, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write:del, read: 0, close:del */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= w, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= w, write:del, read:add, close: 0 */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= w, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= w, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= w, write:del, read:del, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, - /* old= w, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= w, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= w, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= w, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= w, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= w, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= w, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= w, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= w, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= w, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= w, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= w, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= w, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= w, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= w, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= w, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= w, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= w, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= w, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= w, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= w, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= w, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= w, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old= rw, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= rw, write: 0, read: 0, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read: 0, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= rw, write: 0, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= rw, write: 0, read:del, close: 0 */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= rw, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= rw, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= rw, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= rw, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= rw, write:add, read: 0, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write:add, read: 0, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write:add, read: 0, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= rw, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= rw, write:add, read:del, close: 0 */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= rw, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= rw, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= rw, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= rw, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= rw, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= rw, write:del, read: 0, close: 0 */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= rw, write:del, read: 0, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write:del, read: 0, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= rw, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= rw, write:del, read:add, close: 0 */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= rw, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= rw, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= rw, write:del, read:del, close: 0 */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, - /* old= rw, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= rw, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= rw, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= rw, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= rw, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= rw, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= rw, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= rw, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= rw, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= rw, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= rw, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= rw, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= rw, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= rw, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= rw, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= rw, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= rw, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= rw, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= rw, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= rw, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= rw, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= rw, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= rw, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old= c, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= c, write: 0, read: 0, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write: 0, read: 0, close:del */ - { EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= c, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= c, write: 0, read:add, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write: 0, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= c, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= c, write: 0, read:del, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write: 0, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write: 0, read:del, close:del */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= c, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= c, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= c, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= c, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= c, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= c, write:add, read: 0, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:add, read: 0, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:add, read: 0, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= c, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= c, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= c, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= c, write:add, read:del, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= c, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= c, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= c, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= c, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= c, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= c, write:del, read: 0, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:del, read: 0, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:del, read: 0, close:del */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= c, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= c, write:del, read:add, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= c, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= c, write:del, read:del, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= c, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= c, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= c, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= c, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= c, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= c, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= c, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= c, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= c, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= c, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= c, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= c, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= c, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= c, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= c, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= c, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= c, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= c, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= c, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= c, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= c, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= c, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cr, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= cr, write: 0, read: 0, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read: 0, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= cr, write: 0, read:add, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= cr, write: 0, read:del, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write: 0, read:del, close:del */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= cr, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= cr, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cr, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= cr, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= cr, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cr, write:add, read: 0, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:add, read: 0, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:add, read: 0, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cr, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= cr, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cr, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= cr, write:add, read:del, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cr, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= cr, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cr, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= cr, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= cr, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cr, write:del, read: 0, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:del, read: 0, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:del, read: 0, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= cr, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= cr, write:del, read:add, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= cr, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= cr, write:del, read:del, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cr, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= cr, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= cr, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cr, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= cr, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= cr, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cr, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= cr, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= cr, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= cr, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= cr, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= cr, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= cr, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= cr, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= cr, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= cr, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= cr, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= cr, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= cr, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cr, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= cr, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= cr, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cw, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old= cw, write: 0, read: 0, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read: 0, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old= cw, write: 0, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old= cw, write: 0, read:del, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cw, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old= cw, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cw, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old= cw, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old= cw, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cw, write:add, read: 0, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:add, read: 0, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:add, read: 0, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cw, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old= cw, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cw, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old= cw, write:add, read:del, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old= cw, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old= cw, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cw, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old= cw, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old= cw, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cw, write:del, read: 0, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:del, read: 0, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:del, read: 0, close:del */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= cw, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old= cw, write:del, read:add, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old= cw, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old= cw, write:del, read:del, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old= cw, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old= cw, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old= cw, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cw, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old= cw, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old= cw, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old= cw, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old= cw, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old= cw, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old= cw, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old= cw, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old= cw, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old= cw, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old= cw, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old= cw, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old= cw, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old= cw, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old= cw, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old= cw, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old= cw, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old= cw, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old= cw, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, - /* old=crw, write: 0, read: 0, close: 0 */ - { 0, 0 }, - /* old=crw, write: 0, read: 0, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read: 0, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read: 0, close:xxx */ - { 0, 255 }, - /* old=crw, write: 0, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read:add, close:xxx */ - { 0, 255 }, - /* old=crw, write: 0, read:del, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old=crw, write: 0, read:del, close:xxx */ - { 0, 255 }, - /* old=crw, write: 0, read:xxx, close: 0 */ - { 0, 255 }, - /* old=crw, write: 0, read:xxx, close:add */ - { 0, 255 }, - /* old=crw, write: 0, read:xxx, close:del */ - { 0, 255 }, - /* old=crw, write: 0, read:xxx, close:xxx */ - { 0, 255 }, - /* old=crw, write:add, read: 0, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:add, read: 0, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:add, read: 0, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old=crw, write:add, read: 0, close:xxx */ - { 0, 255 }, - /* old=crw, write:add, read:add, close: 0 */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:add, read:add, close:add */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:add, read:add, close:del */ - { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, - /* old=crw, write:add, read:add, close:xxx */ - { 0, 255 }, - /* old=crw, write:add, read:del, close: 0 */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:add, read:del, close:add */ - { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:add, read:del, close:del */ - { EPOLLOUT, EPOLL_CTL_MOD }, - /* old=crw, write:add, read:del, close:xxx */ - { 0, 255 }, - /* old=crw, write:add, read:xxx, close: 0 */ - { 0, 255 }, - /* old=crw, write:add, read:xxx, close:add */ - { 0, 255 }, - /* old=crw, write:add, read:xxx, close:del */ - { 0, 255 }, - /* old=crw, write:add, read:xxx, close:xxx */ - { 0, 255 }, - /* old=crw, write:del, read: 0, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:del, read: 0, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:del, read: 0, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old=crw, write:del, read: 0, close:xxx */ - { 0, 255 }, - /* old=crw, write:del, read:add, close: 0 */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:del, read:add, close:add */ - { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:del, read:add, close:del */ - { EPOLLIN, EPOLL_CTL_MOD }, - /* old=crw, write:del, read:add, close:xxx */ - { 0, 255 }, - /* old=crw, write:del, read:del, close: 0 */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:del, read:del, close:add */ - { EPOLLRDHUP, EPOLL_CTL_MOD }, - /* old=crw, write:del, read:del, close:del */ - { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, - /* old=crw, write:del, read:del, close:xxx */ - { 0, 255 }, - /* old=crw, write:del, read:xxx, close: 0 */ - { 0, 255 }, - /* old=crw, write:del, read:xxx, close:add */ - { 0, 255 }, - /* old=crw, write:del, read:xxx, close:del */ - { 0, 255 }, - /* old=crw, write:del, read:xxx, close:xxx */ - { 0, 255 }, - /* old=crw, write:xxx, read: 0, close: 0 */ - { 0, 255 }, - /* old=crw, write:xxx, read: 0, close:add */ - { 0, 255 }, - /* old=crw, write:xxx, read: 0, close:del */ - { 0, 255 }, - /* old=crw, write:xxx, read: 0, close:xxx */ - { 0, 255 }, - /* old=crw, write:xxx, read:add, close: 0 */ - { 0, 255 }, - /* old=crw, write:xxx, read:add, close:add */ - { 0, 255 }, - /* old=crw, write:xxx, read:add, close:del */ - { 0, 255 }, - /* old=crw, write:xxx, read:add, close:xxx */ - { 0, 255 }, - /* old=crw, write:xxx, read:del, close: 0 */ - { 0, 255 }, - /* old=crw, write:xxx, read:del, close:add */ - { 0, 255 }, - /* old=crw, write:xxx, read:del, close:del */ - { 0, 255 }, - /* old=crw, write:xxx, read:del, close:xxx */ - { 0, 255 }, - /* old=crw, write:xxx, read:xxx, close: 0 */ - { 0, 255 }, - /* old=crw, write:xxx, read:xxx, close:add */ - { 0, 255 }, - /* old=crw, write:xxx, read:xxx, close:del */ - { 0, 255 }, - /* old=crw, write:xxx, read:xxx, close:xxx */ - { 0, 255 }, -}; - -#endif +/* + * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EPOLLTABLE_INTERNAL_H_INCLUDED_ +#define EPOLLTABLE_INTERNAL_H_INCLUDED_ + +/* + Here are the values we're masking off to decide what operations to do. + Note that since EV_READ|EV_WRITE. + + Note also that this table is a little sparse, since ADD+DEL is + nonsensical ("xxx" in the list below.) + + Note also that we are shifting old_events by only 5 bits, since + EV_READ is 2 and EV_WRITE is 4. + + The table was auto-generated with a python script, according to this + pseudocode:[*0] + + If either the read or the write change is add+del: + This is impossible; Set op==-1, events=0. + Else, if either the read or the write change is add: + Set events to 0. + If the read change is add, or + (the read change is not del, and ev_read is in old_events): + Add EPOLLIN to events. + If the write change is add, or + (the write change is not del, and ev_write is in old_events): + Add EPOLLOUT to events. + + If old_events is set: + Set op to EPOLL_CTL_MOD [*1,*2] + Else: + Set op to EPOLL_CTL_ADD [*3] + + Else, if the read or the write change is del: + Set op to EPOLL_CTL_DEL. + If the read change is del: + If the write change is del: + Set events to EPOLLIN|EPOLLOUT + Else if ev_write is in old_events: + Set events to EPOLLOUT + Set op to EPOLL_CTL_MOD + Else + Set events to EPOLLIN + Else: + {The write change is del.} + If ev_read is in old_events: + Set events to EPOLLIN + Set op to EPOLL_CTL_MOD + Else: + Set the events to EPOLLOUT + + Else: + There is no read or write change; set op to 0 and events to 0. + + The logic is a little tricky, since we had no events set on the fd before, + we need to set op="ADD" and set events=the events we want to add. If we + had any events set on the fd before, and we want any events to remain on + the fd, we need to say op="MOD" and set events=the events we want to + remain. But if we want to delete the last event, we say op="DEL" and + set events=(any non-null pointer). + + [*0] Actually, the Python script has gotten a bit more complicated, to + support EPOLLRDHUP. + + [*1] This MOD is only a guess. MOD might fail with ENOENT if the file was + closed and a new file was opened with the same fd. If so, we'll retry + with ADD. + + [*2] We can't replace this with a no-op even if old_events is the same as + the new events: if the file was closed and reopened, we need to retry + with an ADD. (We do a MOD in this case since "no change" is more + common than "close and reopen", so we'll usually wind up doing 1 + syscalls instead of 2.) + + [*3] This ADD is only a guess. There is a fun Linux kernel issue where if + you have two fds for the same file (via dup) and you ADD one to an + epfd, then close it, then re-create it with the same fd (via dup2 or an + unlucky dup), then try to ADD it again, you'll get an EEXIST, since the + struct epitem is not actually removed from the struct eventpoll until + the file itself is closed. + + EV_CHANGE_ADD==1 + EV_CHANGE_DEL==2 + EV_READ ==2 + EV_WRITE ==4 + EV_CLOSED ==0x80 + + Bit 0: close change is add + Bit 1: close change is del + Bit 2: read change is add + Bit 3: read change is del + Bit 4: write change is add + Bit 5: write change is del + Bit 6: old events had EV_READ + Bit 7: old events had EV_WRITE + Bit 8: old events had EV_CLOSED +*/ + +#define EPOLL_OP_TABLE_INDEX(c) \ + ( (((c)->close_change&(EV_CHANGE_ADD|EV_CHANGE_DEL))) | \ + (((c)->read_change&(EV_CHANGE_ADD|EV_CHANGE_DEL)) << 2) | \ + (((c)->write_change&(EV_CHANGE_ADD|EV_CHANGE_DEL)) << 4) | \ + (((c)->old_events&(EV_READ|EV_WRITE)) << 5) | \ + (((c)->old_events&(EV_CLOSED)) << 1) \ + ) + +#if EV_READ != 2 || EV_WRITE != 4 || EV_CLOSED != 0x80 || EV_CHANGE_ADD != 1 || EV_CHANGE_DEL != 2 +#error "Libevent's internals changed! Regenerate the op_table in epolltable-internal.h" +#endif + +static const struct operation { + int events; + int op; +} epoll_op_table[] = { + /* old= 0, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= 0, write: 0, read: 0, close:add */ + { EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write: 0, read: 0, close:del */ + { EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= 0, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= 0, write: 0, read:add, close: 0 */ + { EPOLLIN, EPOLL_CTL_ADD }, + /* old= 0, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write: 0, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_ADD }, + /* old= 0, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= 0, write: 0, read:del, close: 0 */ + { EPOLLIN, EPOLL_CTL_DEL }, + /* old= 0, write: 0, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write: 0, read:del, close:del */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= 0, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= 0, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= 0, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= 0, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= 0, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= 0, write:add, read: 0, close: 0 */ + { EPOLLOUT, EPOLL_CTL_ADD }, + /* old= 0, write:add, read: 0, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write:add, read: 0, close:del */ + { EPOLLOUT, EPOLL_CTL_ADD }, + /* old= 0, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= 0, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_ADD }, + /* old= 0, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_ADD }, + /* old= 0, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= 0, write:add, read:del, close: 0 */ + { EPOLLOUT, EPOLL_CTL_ADD }, + /* old= 0, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_ADD }, + /* old= 0, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= 0, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= 0, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= 0, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= 0, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= 0, write:del, read: 0, close: 0 */ + { EPOLLOUT, EPOLL_CTL_DEL }, + /* old= 0, write:del, read: 0, close:add */ + { EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write:del, read: 0, close:del */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= 0, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= 0, write:del, read:add, close: 0 */ + { EPOLLIN, EPOLL_CTL_ADD }, + /* old= 0, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_ADD }, + /* old= 0, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= 0, write:del, read:del, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, + /* old= 0, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_ADD }, + /* old= 0, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= 0, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= 0, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= 0, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= 0, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= 0, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= 0, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= 0, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= 0, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= 0, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= 0, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= 0, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= 0, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= 0, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= 0, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= 0, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= 0, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= 0, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= 0, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= 0, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= 0, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= 0, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old= r, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= r, write: 0, read: 0, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write: 0, read: 0, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= r, write: 0, read:add, close: 0 */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write: 0, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= r, write: 0, read:del, close: 0 */ + { EPOLLIN, EPOLL_CTL_DEL }, + /* old= r, write: 0, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write: 0, read:del, close:del */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= r, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= r, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= r, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= r, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= r, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= r, write:add, read: 0, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= r, write:add, read: 0, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write:add, read: 0, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= r, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= r, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= r, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= r, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= r, write:add, read:del, close: 0 */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= r, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= r, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= r, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= r, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= r, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= r, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= r, write:del, read: 0, close: 0 */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write:del, read: 0, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write:del, read: 0, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= r, write:del, read:add, close: 0 */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= r, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= r, write:del, read:del, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, + /* old= r, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= r, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= r, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= r, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= r, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= r, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= r, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= r, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= r, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= r, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= r, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= r, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= r, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= r, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= r, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= r, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= r, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= r, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= r, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= r, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= r, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= r, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= r, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old= w, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= w, write: 0, read: 0, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write: 0, read: 0, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= w, write: 0, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write: 0, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= w, write: 0, read:del, close: 0 */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write: 0, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write: 0, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= w, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= w, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= w, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= w, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= w, write:add, read: 0, close: 0 */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write:add, read: 0, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write:add, read: 0, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= w, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= w, write:add, read:del, close: 0 */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= w, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= w, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= w, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= w, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= w, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= w, write:del, read: 0, close: 0 */ + { EPOLLOUT, EPOLL_CTL_DEL }, + /* old= w, write:del, read: 0, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write:del, read: 0, close:del */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= w, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= w, write:del, read:add, close: 0 */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= w, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= w, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= w, write:del, read:del, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, + /* old= w, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= w, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= w, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= w, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= w, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= w, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= w, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= w, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= w, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= w, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= w, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= w, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= w, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= w, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= w, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= w, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= w, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= w, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= w, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= w, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= w, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= w, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= w, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old= rw, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= rw, write: 0, read: 0, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read: 0, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= rw, write: 0, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= rw, write: 0, read:del, close: 0 */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= rw, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= rw, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= rw, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= rw, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= rw, write:add, read: 0, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write:add, read: 0, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write:add, read: 0, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= rw, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= rw, write:add, read:del, close: 0 */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= rw, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= rw, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= rw, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= rw, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= rw, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= rw, write:del, read: 0, close: 0 */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= rw, write:del, read: 0, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write:del, read: 0, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= rw, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= rw, write:del, read:add, close: 0 */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= rw, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= rw, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= rw, write:del, read:del, close: 0 */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_DEL }, + /* old= rw, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= rw, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= rw, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= rw, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= rw, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= rw, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= rw, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= rw, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= rw, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= rw, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= rw, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= rw, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= rw, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= rw, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= rw, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= rw, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= rw, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= rw, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= rw, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= rw, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= rw, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= rw, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= rw, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old= c, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= c, write: 0, read: 0, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write: 0, read: 0, close:del */ + { EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= c, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= c, write: 0, read:add, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write: 0, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= c, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= c, write: 0, read:del, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write: 0, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write: 0, read:del, close:del */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= c, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= c, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= c, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= c, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= c, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= c, write:add, read: 0, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:add, read: 0, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:add, read: 0, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= c, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= c, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= c, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= c, write:add, read:del, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= c, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= c, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= c, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= c, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= c, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= c, write:del, read: 0, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:del, read: 0, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:del, read: 0, close:del */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= c, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= c, write:del, read:add, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= c, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= c, write:del, read:del, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= c, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= c, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= c, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= c, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= c, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= c, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= c, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= c, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= c, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= c, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= c, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= c, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= c, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= c, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= c, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= c, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= c, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= c, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= c, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= c, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= c, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= c, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cr, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= cr, write: 0, read: 0, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read: 0, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= cr, write: 0, read:add, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= cr, write: 0, read:del, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write: 0, read:del, close:del */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= cr, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= cr, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cr, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= cr, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= cr, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cr, write:add, read: 0, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:add, read: 0, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:add, read: 0, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cr, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= cr, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cr, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= cr, write:add, read:del, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cr, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= cr, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cr, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= cr, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= cr, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cr, write:del, read: 0, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:del, read: 0, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:del, read: 0, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= cr, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= cr, write:del, read:add, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= cr, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= cr, write:del, read:del, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cr, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= cr, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= cr, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cr, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= cr, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= cr, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cr, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= cr, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= cr, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= cr, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= cr, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= cr, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= cr, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= cr, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= cr, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= cr, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= cr, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= cr, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= cr, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cr, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= cr, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= cr, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cw, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old= cw, write: 0, read: 0, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read: 0, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old= cw, write: 0, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old= cw, write: 0, read:del, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cw, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old= cw, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cw, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old= cw, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old= cw, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cw, write:add, read: 0, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:add, read: 0, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:add, read: 0, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cw, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old= cw, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cw, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old= cw, write:add, read:del, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old= cw, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old= cw, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cw, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old= cw, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old= cw, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cw, write:del, read: 0, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:del, read: 0, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:del, read: 0, close:del */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= cw, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old= cw, write:del, read:add, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old= cw, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old= cw, write:del, read:del, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old= cw, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old= cw, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old= cw, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cw, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old= cw, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old= cw, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old= cw, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old= cw, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old= cw, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old= cw, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old= cw, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old= cw, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old= cw, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old= cw, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old= cw, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old= cw, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old= cw, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old= cw, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old= cw, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old= cw, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old= cw, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old= cw, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, + /* old=crw, write: 0, read: 0, close: 0 */ + { 0, 0 }, + /* old=crw, write: 0, read: 0, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read: 0, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read: 0, close:xxx */ + { 0, 255 }, + /* old=crw, write: 0, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read:add, close:xxx */ + { 0, 255 }, + /* old=crw, write: 0, read:del, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old=crw, write: 0, read:del, close:xxx */ + { 0, 255 }, + /* old=crw, write: 0, read:xxx, close: 0 */ + { 0, 255 }, + /* old=crw, write: 0, read:xxx, close:add */ + { 0, 255 }, + /* old=crw, write: 0, read:xxx, close:del */ + { 0, 255 }, + /* old=crw, write: 0, read:xxx, close:xxx */ + { 0, 255 }, + /* old=crw, write:add, read: 0, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:add, read: 0, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:add, read: 0, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old=crw, write:add, read: 0, close:xxx */ + { 0, 255 }, + /* old=crw, write:add, read:add, close: 0 */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:add, read:add, close:add */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:add, read:add, close:del */ + { EPOLLIN|EPOLLOUT, EPOLL_CTL_MOD }, + /* old=crw, write:add, read:add, close:xxx */ + { 0, 255 }, + /* old=crw, write:add, read:del, close: 0 */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:add, read:del, close:add */ + { EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:add, read:del, close:del */ + { EPOLLOUT, EPOLL_CTL_MOD }, + /* old=crw, write:add, read:del, close:xxx */ + { 0, 255 }, + /* old=crw, write:add, read:xxx, close: 0 */ + { 0, 255 }, + /* old=crw, write:add, read:xxx, close:add */ + { 0, 255 }, + /* old=crw, write:add, read:xxx, close:del */ + { 0, 255 }, + /* old=crw, write:add, read:xxx, close:xxx */ + { 0, 255 }, + /* old=crw, write:del, read: 0, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:del, read: 0, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:del, read: 0, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old=crw, write:del, read: 0, close:xxx */ + { 0, 255 }, + /* old=crw, write:del, read:add, close: 0 */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:del, read:add, close:add */ + { EPOLLIN|EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:del, read:add, close:del */ + { EPOLLIN, EPOLL_CTL_MOD }, + /* old=crw, write:del, read:add, close:xxx */ + { 0, 255 }, + /* old=crw, write:del, read:del, close: 0 */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:del, read:del, close:add */ + { EPOLLRDHUP, EPOLL_CTL_MOD }, + /* old=crw, write:del, read:del, close:del */ + { EPOLLIN|EPOLLOUT|EPOLLRDHUP, EPOLL_CTL_DEL }, + /* old=crw, write:del, read:del, close:xxx */ + { 0, 255 }, + /* old=crw, write:del, read:xxx, close: 0 */ + { 0, 255 }, + /* old=crw, write:del, read:xxx, close:add */ + { 0, 255 }, + /* old=crw, write:del, read:xxx, close:del */ + { 0, 255 }, + /* old=crw, write:del, read:xxx, close:xxx */ + { 0, 255 }, + /* old=crw, write:xxx, read: 0, close: 0 */ + { 0, 255 }, + /* old=crw, write:xxx, read: 0, close:add */ + { 0, 255 }, + /* old=crw, write:xxx, read: 0, close:del */ + { 0, 255 }, + /* old=crw, write:xxx, read: 0, close:xxx */ + { 0, 255 }, + /* old=crw, write:xxx, read:add, close: 0 */ + { 0, 255 }, + /* old=crw, write:xxx, read:add, close:add */ + { 0, 255 }, + /* old=crw, write:xxx, read:add, close:del */ + { 0, 255 }, + /* old=crw, write:xxx, read:add, close:xxx */ + { 0, 255 }, + /* old=crw, write:xxx, read:del, close: 0 */ + { 0, 255 }, + /* old=crw, write:xxx, read:del, close:add */ + { 0, 255 }, + /* old=crw, write:xxx, read:del, close:del */ + { 0, 255 }, + /* old=crw, write:xxx, read:del, close:xxx */ + { 0, 255 }, + /* old=crw, write:xxx, read:xxx, close: 0 */ + { 0, 255 }, + /* old=crw, write:xxx, read:xxx, close:add */ + { 0, 255 }, + /* old=crw, write:xxx, read:xxx, close:del */ + { 0, 255 }, + /* old=crw, write:xxx, read:xxx, close:xxx */ + { 0, 255 }, +}; + +#endif diff --git a/contrib/libs/libevent/evbuffer-internal.h b/contrib/libs/libevent/evbuffer-internal.h index d09b4f1ddd..815305c99c 100644 --- a/contrib/libs/libevent/evbuffer-internal.h +++ b/contrib/libs/libevent/evbuffer-internal.h @@ -24,17 +24,17 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVBUFFER_INTERNAL_H_INCLUDED_ -#define EVBUFFER_INTERNAL_H_INCLUDED_ +#ifndef EVBUFFER_INTERNAL_H_INCLUDED_ +#define EVBUFFER_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { #endif #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" #include "event2/util.h" -#include "event2/event_struct.h" +#include "event2/event_struct.h" #include "util-internal.h" #include "defer-internal.h" @@ -43,7 +43,7 @@ extern "C" { * arguments. */ #define EVBUFFER_CB_NODEFER 2 -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #endif #include <sys/queue.h> @@ -51,7 +51,7 @@ extern "C" { /* Minimum allocation for a chain. We define this so that we're burning no * more than 5% of each allocation on overhead. It would be nice to lose even * less space, though. */ -#if EVENT__SIZEOF_VOID_P < 8 +#if EVENT__SIZEOF_VOID_P < 8 #define MIN_BUFFER_SIZE 512 #else #define MIN_BUFFER_SIZE 1024 @@ -61,7 +61,7 @@ extern "C" { * when bytes are added to or removed from the evbuffer. */ struct evbuffer_cb_entry { /** Structures to implement a doubly-linked queue of callbacks */ - LIST_ENTRY(evbuffer_cb_entry) next; + LIST_ENTRY(evbuffer_cb_entry) next; /** The callback function to invoke when this callback is called. If EVBUFFER_CB_OBSOLETE is set in flags, the cb_obsolete field is valid; otherwise, cb_func is valid. */ @@ -92,7 +92,7 @@ struct evbuffer { * If the buffer has no chains, it is NULL. * * The last_with_datap pointer points at _whatever 'next' pointer_ - * pointing at the last_with_data chain. If the last_with_data chain + * pointing at the last_with_data chain. If the last_with_data chain * is the first chain, or it is NULL, then the last_with_datap pointer * is &buf->first. */ @@ -108,7 +108,7 @@ struct evbuffer { * tried to invoke callbacks. */ size_t n_del_for_cb; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT /** A lock used to mediate access to this buffer. */ void *lock; #endif @@ -127,7 +127,7 @@ struct evbuffer { * overflows when we have mutually recursive callbacks, and for * serializing callbacks in a single thread. */ unsigned deferred_cbs : 1; -#ifdef _WIN32 +#ifdef _WIN32 /** True iff this buffer is set up for overlapped IO. */ unsigned is_overlapped : 1; #endif @@ -135,7 +135,7 @@ struct evbuffer { ev_uint32_t flags; /** Used to implement deferred callbacks. */ - struct event_base *cb_queue; + struct event_base *cb_queue; /** A reference count on this evbuffer. When the reference count * reaches 0, the buffer is destroyed. Manipulated with @@ -143,24 +143,24 @@ struct evbuffer { * evbuffer_free. */ int refcnt; - /** A struct event_callback handle to make all of this buffer's callbacks + /** A struct event_callback handle to make all of this buffer's callbacks * invoked from the event loop. */ - struct event_callback deferred; + struct event_callback deferred; /** A doubly-linked-list of callback functions */ - LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks; + LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks; /** The parent bufferevent object this evbuffer belongs to. * NULL if the evbuffer stands alone. */ struct bufferevent *parent; }; -#if EVENT__SIZEOF_OFF_T < EVENT__SIZEOF_SIZE_T +#if EVENT__SIZEOF_OFF_T < EVENT__SIZEOF_SIZE_T typedef ev_ssize_t ev_misalign_t; #define EVBUFFER_CHAIN_MAX ((size_t)EV_SSIZE_MAX) #else typedef ev_off_t ev_misalign_t; -#if EVENT__SIZEOF_OFF_T > EVENT__SIZEOF_SIZE_T +#if EVENT__SIZEOF_OFF_T > EVENT__SIZEOF_SIZE_T #define EVBUFFER_CHAIN_MAX EV_SIZE_MAX #else #define EVBUFFER_CHAIN_MAX ((size_t)EV_SSIZE_MAX) @@ -186,8 +186,8 @@ struct evbuffer_chain { /** Set if special handling is required for this chain */ unsigned flags; -#define EVBUFFER_FILESEGMENT 0x0001 /**< A chain used for a file segment */ -#define EVBUFFER_SENDFILE 0x0002 /**< a chain used with sendfile */ +#define EVBUFFER_FILESEGMENT 0x0001 /**< A chain used for a file segment */ +#define EVBUFFER_SENDFILE 0x0002 /**< a chain used with sendfile */ #define EVBUFFER_REFERENCE 0x0004 /**< a chain with a mem reference */ #define EVBUFFER_IMMUTABLE 0x0008 /**< read-only chain */ /** a chain that mustn't be reallocated or freed, or have its contents @@ -198,12 +198,12 @@ struct evbuffer_chain { /** a chain that should be freed, but can't be freed until it is * un-pinned. */ #define EVBUFFER_DANGLING 0x0040 - /** a chain that is a referenced copy of another chain */ -#define EVBUFFER_MULTICAST 0x0080 - - /** number of references to this chain */ - int refcnt; + /** a chain that is a referenced copy of another chain */ +#define EVBUFFER_MULTICAST 0x0080 + /** number of references to this chain */ + int refcnt; + /** Usually points to the read-write memory belonging to this * buffer allocated as part of the evbuffer_chain allocation. * For mmap, this can be a read-only buffer and @@ -213,67 +213,67 @@ struct evbuffer_chain { unsigned char *buffer; }; -/** callback for a reference chain; lets us know what to do with it when - * we're done with it. Lives at the end of an evbuffer_chain with the - * EVBUFFER_REFERENCE flag set */ +/** callback for a reference chain; lets us know what to do with it when + * we're done with it. Lives at the end of an evbuffer_chain with the + * EVBUFFER_REFERENCE flag set */ struct evbuffer_chain_reference { evbuffer_ref_cleanup_cb cleanupfn; void *extra; }; -/** File segment for a file-segment chain. Lives at the end of an - * evbuffer_chain with the EVBUFFER_FILESEGMENT flag set. */ -struct evbuffer_chain_file_segment { - struct evbuffer_file_segment *segment; -#ifdef _WIN32 - /** If we're using CreateFileMapping, this is the handle to the view. */ - HANDLE view_handle; -#endif -}; - -/* Declared in event2/buffer.h; defined here. */ -struct evbuffer_file_segment { - void *lock; /**< lock prevent concurrent access to refcnt */ - int refcnt; /**< Reference count for this file segment */ - unsigned flags; /**< combination of EVBUF_FS_* flags */ - - /** What kind of file segment is this? */ - unsigned can_sendfile : 1; - unsigned is_mapping : 1; - - /** The fd that we read the data from. */ - int fd; - /** If we're using mmap, this is the raw mapped memory. */ - void *mapping; -#ifdef _WIN32 - /** If we're using CreateFileMapping, this is the mapping */ - HANDLE mapping_handle; -#endif - /** If we're using mmap or IO, this is the content of the file - * segment. */ - char *contents; - /** Position of this segment within the file. */ - ev_off_t file_offset; - /** If we're using mmap, this is the offset within 'mapping' where - * this data segment begins. */ - ev_off_t mmap_offset; - /** The length of this segment. */ - ev_off_t length; - /** Cleanup callback function */ - evbuffer_file_segment_cleanup_cb cleanup_cb; - /** Argument to be pass to cleanup callback function */ - void *cleanup_cb_arg; -}; - -/** Information about the multicast parent of a chain. Lives at the - * end of an evbuffer_chain with the EVBUFFER_MULTICAST flag set. */ -struct evbuffer_multicast_parent { - /** source buffer the multicast parent belongs to */ - struct evbuffer *source; - /** multicast parent for this chain */ - struct evbuffer_chain *parent; -}; - +/** File segment for a file-segment chain. Lives at the end of an + * evbuffer_chain with the EVBUFFER_FILESEGMENT flag set. */ +struct evbuffer_chain_file_segment { + struct evbuffer_file_segment *segment; +#ifdef _WIN32 + /** If we're using CreateFileMapping, this is the handle to the view. */ + HANDLE view_handle; +#endif +}; + +/* Declared in event2/buffer.h; defined here. */ +struct evbuffer_file_segment { + void *lock; /**< lock prevent concurrent access to refcnt */ + int refcnt; /**< Reference count for this file segment */ + unsigned flags; /**< combination of EVBUF_FS_* flags */ + + /** What kind of file segment is this? */ + unsigned can_sendfile : 1; + unsigned is_mapping : 1; + + /** The fd that we read the data from. */ + int fd; + /** If we're using mmap, this is the raw mapped memory. */ + void *mapping; +#ifdef _WIN32 + /** If we're using CreateFileMapping, this is the mapping */ + HANDLE mapping_handle; +#endif + /** If we're using mmap or IO, this is the content of the file + * segment. */ + char *contents; + /** Position of this segment within the file. */ + ev_off_t file_offset; + /** If we're using mmap, this is the offset within 'mapping' where + * this data segment begins. */ + ev_off_t mmap_offset; + /** The length of this segment. */ + ev_off_t length; + /** Cleanup callback function */ + evbuffer_file_segment_cleanup_cb cleanup_cb; + /** Argument to be pass to cleanup callback function */ + void *cleanup_cb_arg; +}; + +/** Information about the multicast parent of a chain. Lives at the + * end of an evbuffer_chain with the EVBUFFER_MULTICAST flag set. */ +struct evbuffer_multicast_parent { + /** source buffer the multicast parent belongs to */ + struct evbuffer *source; + /** multicast parent for this chain */ + struct evbuffer_chain *parent; +}; + #define EVBUFFER_CHAIN_SIZE sizeof(struct evbuffer_chain) /** Return a pointer to extra data allocated along with an evbuffer. */ #define EVBUFFER_CHAIN_EXTRA(t, c) (t *)((struct evbuffer_chain *)(c) + 1) @@ -300,21 +300,21 @@ struct evbuffer_multicast_parent { } while (0) /** Increase the reference count of buf by one. */ -void evbuffer_incref_(struct evbuffer *buf); +void evbuffer_incref_(struct evbuffer *buf); /** Increase the reference count of buf by one and acquire the lock. */ -void evbuffer_incref_and_lock_(struct evbuffer *buf); +void evbuffer_incref_and_lock_(struct evbuffer *buf); /** Pin a single buffer chain using a given flag. A pinned chunk may not be * moved or freed until it is unpinned. */ -void evbuffer_chain_pin_(struct evbuffer_chain *chain, unsigned flag); +void evbuffer_chain_pin_(struct evbuffer_chain *chain, unsigned flag); /** Unpin a single buffer chain using a given flag. */ -void evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag); +void evbuffer_chain_unpin_(struct evbuffer_chain *chain, unsigned flag); /** As evbuffer_free, but requires that we hold a lock on the buffer, and * releases the lock before freeing it and the buffer. */ -void evbuffer_decref_and_unlock_(struct evbuffer *buffer); +void evbuffer_decref_and_unlock_(struct evbuffer *buffer); /** As evbuffer_expand, but does not guarantee that the newly allocated memory * is contiguous. Instead, it may be split across two or more chunks. */ -int evbuffer_expand_fast_(struct evbuffer *, size_t, int); +int evbuffer_expand_fast_(struct evbuffer *, size_t, int); /** Helper: prepares for a readv/WSARecv call by expanding the buffer to * hold enough memory to read 'howmuch' bytes in possibly noncontiguous memory. @@ -322,7 +322,7 @@ int evbuffer_expand_fast_(struct evbuffer *, size_t, int); * extent, and *chainp to point to the first chain that we'll try to read into. * Returns the number of vecs used. */ -int evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, +int evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, struct evbuffer_iovec *vecs, int n_vecs, struct evbuffer_chain ***chainp, int exact); @@ -335,17 +335,17 @@ int evbuffer_read_setup_vecs_(struct evbuffer *buf, ev_ssize_t howmuch, * See note in buffer_iocp's launch_write function */ /** Set the parent bufferevent object for buf to bev */ -void evbuffer_set_parent_(struct evbuffer *buf, struct bufferevent *bev); - -void evbuffer_invoke_callbacks_(struct evbuffer *buf); - +void evbuffer_set_parent_(struct evbuffer *buf, struct bufferevent *bev); -int evbuffer_get_callbacks_(struct evbuffer *buffer, - struct event_callback **cbs, - int max_cbs); +void evbuffer_invoke_callbacks_(struct evbuffer *buf); + +int evbuffer_get_callbacks_(struct evbuffer *buffer, + struct event_callback **cbs, + int max_cbs); + #ifdef __cplusplus } #endif -#endif /* EVBUFFER_INTERNAL_H_INCLUDED_ */ +#endif /* EVBUFFER_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/evconfig-private.h b/contrib/libs/libevent/evconfig-private.h index 31e610040e..7353beaad7 100644 --- a/contrib/libs/libevent/evconfig-private.h +++ b/contrib/libs/libevent/evconfig-private.h @@ -1,56 +1,56 @@ -/* evconfig-private.h. Generated from evconfig-private.h.in by configure. */ -/* evconfig-private.h template - see "Configuration Header Templates" */ -/* in AC manual. Kevin Bowling <kevin.bowling@kev009.com */ -#ifndef EVCONFIG_PRIVATE_H_INCLUDED_ -#define EVCONFIG_PRIVATE_H_INCLUDED_ - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -/* #undef _FILE_OFFSET_BITS */ -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ - -/* Define to 1 if on MINIX. */ -#ifndef _MINIX -/* #undef _MINIX */ -#endif - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -#ifndef _POSIX_1_SOURCE -/* #undef _POSIX_1_SOURCE */ -#endif - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -#ifndef _POSIX_SOURCE -/* #undef _POSIX_SOURCE */ -#endif - -/* Enable POSIX.2 extensions on QNX for getopt */ -#ifdef __QNX__ -# ifndef __EXT_POSIX2 -# define __EXT_POSIX2 -# endif -#endif - -#endif +/* evconfig-private.h. Generated from evconfig-private.h.in by configure. */ +/* evconfig-private.h template - see "Configuration Header Templates" */ +/* in AC manual. Kevin Bowling <kevin.bowling@kev009.com */ +#ifndef EVCONFIG_PRIVATE_H_INCLUDED_ +#define EVCONFIG_PRIVATE_H_INCLUDED_ + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +#ifndef _MINIX +/* #undef _MINIX */ +#endif + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +#ifndef _POSIX_1_SOURCE +/* #undef _POSIX_1_SOURCE */ +#endif + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +#ifndef _POSIX_SOURCE +/* #undef _POSIX_SOURCE */ +#endif + +/* Enable POSIX.2 extensions on QNX for getopt */ +#ifdef __QNX__ +# ifndef __EXT_POSIX2 +# define __EXT_POSIX2 +# endif +#endif + +#endif diff --git a/contrib/libs/libevent/evdns.c b/contrib/libs/libevent/evdns.c index 3468721a6d..3db28df0e0 100644 --- a/contrib/libs/libevent/evdns.c +++ b/contrib/libs/libevent/evdns.c @@ -49,35 +49,35 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#include <sys/types.h> +#include "evconfig-private.h" +#include <sys/types.h> + #ifndef _FORTIFY_SOURCE #define _FORTIFY_SOURCE 3 #endif #include <string.h> #include <fcntl.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif -#ifdef EVENT__HAVE_STDINT_H +#ifdef EVENT__HAVE_STDINT_H #include <stdint.h> #endif #include <stdlib.h> #include <string.h> #include <errno.h> -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif #include <limits.h> #include <sys/stat.h> #include <stdio.h> #include <stdarg.h> -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> -#include <winerror.h> +#include <winerror.h> #include <ws2tcpip.h> #ifndef _WIN32_IE #define _WIN32_IE 0x400 @@ -100,7 +100,7 @@ #include "ipv6-internal.h" #include "util-internal.h" #include "evthread-internal.h" -#ifdef _WIN32 +#ifdef _WIN32 #include <ctype.h> #include <winsock2.h> #include <windows.h> @@ -112,13 +112,13 @@ #include <arpa/inet.h> #endif -#ifdef EVENT__HAVE_NETINET_IN6_H -#error #include <netinet/in6.h> -#endif - -#define EVDNS_LOG_DEBUG EVENT_LOG_DEBUG -#define EVDNS_LOG_WARN EVENT_LOG_WARN -#define EVDNS_LOG_MSG EVENT_LOG_MSG +#ifdef EVENT__HAVE_NETINET_IN6_H +#error #include <netinet/in6.h> +#endif + +#define EVDNS_LOG_DEBUG EVENT_LOG_DEBUG +#define EVDNS_LOG_WARN EVENT_LOG_WARN +#define EVDNS_LOG_MSG EVENT_LOG_MSG #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 255 @@ -233,10 +233,10 @@ struct nameserver { char choked; /* true if we have an EAGAIN from this server's socket */ char write_waiting; /* true if we are waiting for EV_WRITE events */ struct evdns_base *base; - - /* Number of currently inflight requests: used - * to track when we should add/del the event. */ - int requests_inflight; + + /* Number of currently inflight requests: used + * to track when we should add/del the event. */ + int requests_inflight; }; @@ -254,7 +254,7 @@ struct evdns_server_port { struct server_request *pending_replies; struct event_base *event_base; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT void *lock; #endif }; @@ -347,9 +347,9 @@ struct evdns_base { struct timeval global_getaddrinfo_allow_skew; - int so_rcvbuf; - int so_sndbuf; - + int so_rcvbuf; + int so_sndbuf; + int getaddrinfo_ipv4_timeouts; int getaddrinfo_ipv6_timeouts; int getaddrinfo_ipv4_answered; @@ -359,11 +359,11 @@ struct evdns_base { TAILQ_HEAD(hosts_list, hosts_entry) hostsdb; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT void *lock; #endif - - int disable_when_inactive; + + int disable_when_inactive; }; struct hosts_entry { @@ -416,14 +416,14 @@ static int evdns_base_resolv_conf_parse_impl(struct evdns_base *base, int flags, static int evdns_base_set_option_impl(struct evdns_base *base, const char *option, const char *val, int flags); static void evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests); -static void evdns_request_timeout_callback(evutil_socket_t fd, short events, void *arg); +static void evdns_request_timeout_callback(evutil_socket_t fd, short events, void *arg); static int strtoint(const char *const str); -#ifdef EVENT__DISABLE_THREAD_SUPPORT -#define EVDNS_LOCK(base) EVUTIL_NIL_STMT_ -#define EVDNS_UNLOCK(base) EVUTIL_NIL_STMT_ -#define ASSERT_LOCKED(base) EVUTIL_NIL_STMT_ +#ifdef EVENT__DISABLE_THREAD_SUPPORT +#define EVDNS_LOCK(base) EVUTIL_NIL_STMT_ +#define EVDNS_UNLOCK(base) EVUTIL_NIL_STMT_ +#define ASSERT_LOCKED(base) EVUTIL_NIL_STMT_ #else #define EVDNS_LOCK(base) \ EVLOCK_LOCK((base)->lock, 0) @@ -447,24 +447,24 @@ evdns_set_log_fn(evdns_debug_log_fn_type fn) #define EVDNS_LOG_CHECK #endif -static void evdns_log_(int severity, const char *fmt, ...) EVDNS_LOG_CHECK; +static void evdns_log_(int severity, const char *fmt, ...) EVDNS_LOG_CHECK; static void -evdns_log_(int severity, const char *fmt, ...) +evdns_log_(int severity, const char *fmt, ...) { va_list args; va_start(args,fmt); if (evdns_log_fn) { - char buf[512]; - int is_warn = (severity == EVDNS_LOG_WARN); - evutil_vsnprintf(buf, sizeof(buf), fmt, args); - evdns_log_fn(is_warn, buf); + char buf[512]; + int is_warn = (severity == EVDNS_LOG_WARN); + evutil_vsnprintf(buf, sizeof(buf), fmt, args); + evdns_log_fn(is_warn, buf); } else { - event_logv_(severity, NULL, fmt, args); + event_logv_(severity, NULL, fmt, args); } - va_end(args); + va_end(args); } -#define log evdns_log_ +#define log evdns_log_ /* This walks the list of inflight requests to find the */ /* one with a matching transaction id. Returns NULL on */ @@ -539,23 +539,23 @@ nameserver_probe_failed(struct nameserver *const ns) { char addrbuf[128]; log(EVDNS_LOG_WARN, "Error from libevent when adding timer event for %s", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ns->address, addrbuf, sizeof(addrbuf))); } } -static void -request_swap_ns(struct request *req, struct nameserver *ns) { - if (ns && req->ns != ns) { - EVUTIL_ASSERT(req->ns->requests_inflight > 0); - req->ns->requests_inflight--; - ns->requests_inflight++; - - req->ns = ns; - } -} - +static void +request_swap_ns(struct request *req, struct nameserver *ns) { + if (ns && req->ns != ns) { + EVUTIL_ASSERT(req->ns->requests_inflight > 0); + req->ns->requests_inflight--; + ns->requests_inflight++; + + req->ns = ns; + } +} + /* called when a nameserver has been deemed to have failed. For example, too */ /* many packets have timed out etc */ static void @@ -571,7 +571,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) { if (!ns->state) return; log(EVDNS_LOG_MSG, "Nameserver %s has failed: %s", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ns->address, addrbuf, sizeof(addrbuf)), msg); @@ -589,7 +589,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) { &base->global_nameserver_probe_initial_timeout) < 0) { log(EVDNS_LOG_WARN, "Error from libevent when adding timer event for %s", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ns->address, addrbuf, sizeof(addrbuf))); /* ???? Do more? */ @@ -610,7 +610,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) { if (req->tx_count == 0 && req->ns == ns) { /* still waiting to go out, can be moved */ /* to another server */ - request_swap_ns(req, nameserver_pick(base)); + request_swap_ns(req, nameserver_pick(base)); } req = req->next; } while (req != started_at); @@ -625,7 +625,7 @@ nameserver_up(struct nameserver *const ns) ASSERT_LOCKED(ns->base); if (ns->state) return; log(EVDNS_LOG_MSG, "Nameserver %s is back up", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ns->address, addrbuf, sizeof(addrbuf))); evtimer_del(&ns->timeout_event); @@ -663,20 +663,20 @@ request_finished(struct request *const req, struct request **head, int free_hand if (was_inflight) { evtimer_del(&req->timeout_event); base->global_requests_inflight--; - req->ns->requests_inflight--; + req->ns->requests_inflight--; } else { base->global_requests_waiting--; } /* it was initialized during request_new / evtimer_assign */ event_debug_unassign(&req->timeout_event); - if (req->ns && - req->ns->requests_inflight == 0 && - req->base->disable_when_inactive) { - event_del(&req->ns->event); - evtimer_del(&req->ns->timeout_event); - } - + if (req->ns && + req->ns->requests_inflight == 0 && + req->base->disable_when_inactive) { + event_del(&req->ns->event); + evtimer_del(&req->ns->timeout_event); + } + if (!req->request_appended) { /* need to free the request data on it's own */ mm_free(req->request); @@ -723,7 +723,7 @@ request_reissue(struct request *req) { /* the last nameserver should have been marked as failing */ /* by the caller of this function, therefore pick will try */ /* not to return it */ - request_swap_ns(req, nameserver_pick(req->base)); + request_swap_ns(req, nameserver_pick(req->base)); if (req->ns == last_ns) { /* ... but pick did return it */ /* not a lot of point in trying again with the */ @@ -758,8 +758,8 @@ evdns_requests_pump_waiting_queue(struct evdns_base *base) { return; /* move a request from the waiting queue to the inflight queue */ - req->ns->requests_inflight++; - + req->ns->requests_inflight++; + evdns_request_remove(req, &base->req_waiting_head); base->global_requests_waiting--; @@ -775,7 +775,7 @@ evdns_requests_pump_waiting_queue(struct evdns_base *base) { /* TODO(nickm) document */ struct deferred_reply_callback { - struct event_callback deferred; + struct event_callback deferred; struct evdns_request *handle; u8 request_type; u8 have_reply; @@ -786,7 +786,7 @@ struct deferred_reply_callback { }; static void -reply_run_callback(struct event_callback *d, void *user_pointer) +reply_run_callback(struct event_callback *d, void *user_pointer) { struct deferred_reply_callback *cb = EVUTIL_UPCAST(d, struct deferred_reply_callback, deferred); @@ -857,29 +857,29 @@ reply_schedule_callback(struct request *const req, u32 ttl, u32 err, struct repl d->handle = req->handle; } - event_deferred_cb_init_( - &d->deferred, - event_get_priority(&req->timeout_event), - reply_run_callback, + event_deferred_cb_init_( + &d->deferred, + event_get_priority(&req->timeout_event), + reply_run_callback, req->user_pointer); - event_deferred_cb_schedule_( - req->base->event_base, + event_deferred_cb_schedule_( + req->base->event_base, &d->deferred); } - -#define _QR_MASK 0x8000U -#define _OP_MASK 0x7800U -#define _AA_MASK 0x0400U -#define _TC_MASK 0x0200U -#define _RD_MASK 0x0100U -#define _RA_MASK 0x0080U -#define _Z_MASK 0x0040U -#define _AD_MASK 0x0020U -#define _CD_MASK 0x0010U -#define _RCODE_MASK 0x000fU -#define _Z_MASK_DEPRECATED 0x0070U - + +#define _QR_MASK 0x8000U +#define _OP_MASK 0x7800U +#define _AA_MASK 0x0400U +#define _TC_MASK 0x0200U +#define _RD_MASK 0x0100U +#define _RA_MASK 0x0080U +#define _Z_MASK 0x0040U +#define _AD_MASK 0x0020U +#define _CD_MASK 0x0010U +#define _RCODE_MASK 0x000fU +#define _Z_MASK_DEPRECATED 0x0070U + /* this processes a parsed reply packet */ static void reply_handle(struct request *const req, u16 flags, u32 ttl, struct reply *reply) { @@ -893,12 +893,12 @@ reply_handle(struct request *const req, u16 flags, u32 ttl, struct reply *reply) ASSERT_LOCKED(req->base); ASSERT_VALID_REQUEST(req); - if (flags & (_RCODE_MASK | _TC_MASK) || !reply || !reply->have_answer) { + if (flags & (_RCODE_MASK | _TC_MASK) || !reply || !reply->have_answer) { /* there was an error */ - if (flags & _TC_MASK) { + if (flags & _TC_MASK) { error = DNS_ERR_TRUNCATED; - } else if (flags & _RCODE_MASK) { - u16 error_code = (flags & _RCODE_MASK) - 1; + } else if (flags & _RCODE_MASK) { + u16 error_code = (flags & _RCODE_MASK) - 1; if (error_code > 4) { error = DNS_ERR_UNKNOWN; } else { @@ -930,12 +930,12 @@ reply_handle(struct request *const req, u16 flags, u32 ttl, struct reply *reply) */ log(EVDNS_LOG_DEBUG, "Got a SERVERFAILED from nameserver" "at %s; will allow the request to time out.", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&req->ns->address, addrbuf, sizeof(addrbuf))); - /* Call the timeout function */ - evdns_request_timeout_callback(0, 0, req); - return; + /* Call the timeout function */ + evdns_request_timeout_callback(0, 0, req); + return; default: /* we got a good reply from the nameserver: it is up. */ if (req->handle == req->ns->probe_request) { @@ -978,8 +978,8 @@ name_parse(u8 *packet, int length, int *idx, char *name_out, int name_out_len) { int name_end = -1; int j = *idx; int ptr_count = 0; -#define GET32(x) do { if (j + 4 > length) goto err; memcpy(&t32_, packet + j, 4); j += 4; x = ntohl(t32_); } while (0) -#define GET16(x) do { if (j + 2 > length) goto err; memcpy(&t_, packet + j, 2); j += 2; x = ntohs(t_); } while (0) +#define GET32(x) do { if (j + 4 > length) goto err; memcpy(&t32_, packet + j, 4); j += 4; x = ntohl(t32_); } while (0) +#define GET16(x) do { if (j + 2 > length) goto err; memcpy(&t_, packet + j, 2); j += 2; x = ntohs(t_); } while (0) #define GET8(x) do { if (j >= length) goto err; x = packet[j++]; } while (0) char *cp = name_out; @@ -1013,7 +1013,7 @@ name_parse(u8 *packet, int length, int *idx, char *name_out, int name_out_len) { *cp++ = '.'; } if (cp + label_len >= end) return -1; - if (j + label_len > length) return -1; + if (j + label_len > length) return -1; memcpy(cp, packet + j, label_len); cp += label_len; j += label_len; @@ -1033,8 +1033,8 @@ name_parse(u8 *packet, int length, int *idx, char *name_out, int name_out_len) { static int reply_parse(struct evdns_base *base, u8 *packet, int length) { int j = 0, k = 0; /* index into packet */ - u16 t_; /* used by the macros */ - u32 t32_; /* used by the macros */ + u16 t_; /* used by the macros */ + u32 t32_; /* used by the macros */ char tmp_name[256], cmp_name[256]; /* used by the macros */ int name_matches = 0; @@ -1063,8 +1063,8 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) { memset(&reply, 0, sizeof(reply)); /* If it's not an answer, it doesn't correspond to any request. */ - if (!(flags & _QR_MASK)) return -1; /* must be an answer */ - if ((flags & (_RCODE_MASK|_TC_MASK)) && (flags & (_RCODE_MASK|_TC_MASK)) != DNS_ERR_NOTEXIST) { + if (!(flags & _QR_MASK)) return -1; /* must be an answer */ + if ((flags & (_RCODE_MASK|_TC_MASK)) && (flags & (_RCODE_MASK|_TC_MASK)) != DNS_ERR_NOTEXIST) { /* there was an error and it's not NXDOMAIN */ goto err; } @@ -1085,25 +1085,25 @@ reply_parse(struct evdns_base *base, u8 *packet, int length) { /* the question looks like * <label:name><u16:type><u16:class> */ - tmp_name[0] = '\0'; - cmp_name[0] = '\0'; - k = j; - if (name_parse(packet, length, &j, tmp_name, sizeof(tmp_name)) < 0) - goto err; - if (name_parse(req->request, req->request_len, &k, - cmp_name, sizeof(cmp_name))<0) - goto err; - if (!base->global_randomize_case) { - if (strcmp(tmp_name, cmp_name) == 0) - name_matches = 1; - } else { - if (evutil_ascii_strcasecmp(tmp_name, cmp_name) == 0) - name_matches = 1; - } - + tmp_name[0] = '\0'; + cmp_name[0] = '\0'; + k = j; + if (name_parse(packet, length, &j, tmp_name, sizeof(tmp_name)) < 0) + goto err; + if (name_parse(req->request, req->request_len, &k, + cmp_name, sizeof(cmp_name))<0) + goto err; + if (!base->global_randomize_case) { + if (strcmp(tmp_name, cmp_name) == 0) + name_matches = 1; + } else { + if (evutil_ascii_strcasecmp(tmp_name, cmp_name) == 0) + name_matches = 1; + } + j += 4; - if (j > length) - goto err; + if (j > length) + goto err; } if (!name_matches) @@ -1233,7 +1233,7 @@ static int request_parse(u8 *packet, int length, struct evdns_server_port *port, struct sockaddr *addr, ev_socklen_t addrlen) { int j = 0; /* index into packet */ - u16 t_; /* used by the macros */ + u16 t_; /* used by the macros */ char tmp_name[256]; /* used by the macros */ int i; @@ -1253,8 +1253,8 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc (void)additional; (void)authority; - if (flags & _QR_MASK) return -1; /* Must not be an answer. */ - flags &= (_RD_MASK|_CD_MASK); /* Only RD and CD get preserved. */ + if (flags & _QR_MASK) return -1; /* Must not be an answer. */ + flags &= (_RD_MASK|_CD_MASK); /* Only RD and CD get preserved. */ server_req = mm_malloc(sizeof(struct server_request)); if (server_req == NULL) return -1; @@ -1294,7 +1294,7 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc port->refcnt++; /* Only standard queries are supported. */ - if (flags & _OP_MASK) { + if (flags & _OP_MASK) { evdns_server_request_respond(&(server_req->base), DNS_ERR_NOTIMPL); return -1; } @@ -1303,12 +1303,12 @@ request_parse(u8 *packet, int length, struct evdns_server_port *port, struct soc return 0; err: - if (server_req->base.questions) { - for (i = 0; i < server_req->base.nquestions; ++i) - mm_free(server_req->base.questions[i]); - mm_free(server_req->base.questions); + if (server_req->base.questions) { + for (i = 0; i < server_req->base.nquestions; ++i) + mm_free(server_req->base.questions[i]); + mm_free(server_req->base.questions); } - mm_free(server_req); + mm_free(server_req); return -1; #undef SKIP_NAME @@ -1406,7 +1406,7 @@ nameserver_read(struct nameserver *ns) { (struct sockaddr*)&ns->address, 0)) { log(EVDNS_LOG_WARN, "Address mismatch on received " "DNS packet. Apparent source was %s", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ss, addrbuf, sizeof(addrbuf))); return; @@ -1496,7 +1496,7 @@ nameserver_write_waiting(struct nameserver *ns, char waiting) { if (event_add(&ns->event, NULL) < 0) { char addrbuf[128]; log(EVDNS_LOG_WARN, "Error from libevent when adding event for %s", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ns->address, addrbuf, sizeof(addrbuf))); /* ???? Do more? */ @@ -1617,20 +1617,20 @@ dnsname_to_labels(u8 *const buf, size_t buf_len, off_t j, struct dnslabel_table *table) { const char *end = name + name_len; int ref = 0; - u16 t_; + u16 t_; #define APPEND16(x) do { \ if (j + 2 > (off_t)buf_len) \ goto overflow; \ - t_ = htons(x); \ - memcpy(buf + j, &t_, 2); \ + t_ = htons(x); \ + memcpy(buf + j, &t_, 2); \ j += 2; \ } while (0) #define APPEND32(x) do { \ if (j + 4 > (off_t)buf_len) \ goto overflow; \ - t32_ = htonl(x); \ - memcpy(buf + j, &t32_, 4); \ + t32_ = htonl(x); \ + memcpy(buf + j, &t32_, 4); \ j += 4; \ } while (0) @@ -1696,7 +1696,7 @@ evdns_request_data_build(const char *const name, const size_t name_len, const u16 trans_id, const u16 type, const u16 class, u8 *const buf, size_t buf_len) { off_t j = 0; /* current offset into buf */ - u16 t_; /* used by the macros */ + u16 t_; /* used by the macros */ APPEND16(trans_id); APPEND16(0x0100); /* standard query, recusion needed */ @@ -1766,15 +1766,15 @@ evdns_close_server_port(struct evdns_server_port *port) server_port_free(port); } else { port->closing = 1; - EVDNS_UNLOCK(port); + EVDNS_UNLOCK(port); } } /* exported function */ int -evdns_server_request_add_reply(struct evdns_server_request *req_, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data) +evdns_server_request_add_reply(struct evdns_server_request *req_, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data) { - struct server_request *req = TO_SERVER_REQUEST(req_); + struct server_request *req = TO_SERVER_REQUEST(req_); struct server_reply_item **itemp, *item; int *countp; int result = -1; @@ -1909,8 +1909,8 @@ evdns_server_request_format_response(struct server_request *req, int err) unsigned char buf[1500]; size_t buf_len = sizeof(buf); off_t j = 0, r; - u16 t_; - u32 t32_; + u16 t_; + u32 t32_; int i; u16 flags; struct dnslabel_table table; @@ -1920,7 +1920,7 @@ evdns_server_request_format_response(struct server_request *req, int err) /* Set response bit and error code; copy OPCODE and RD fields from * question; copy RA and AA if set by caller. */ flags = req->base.flags; - flags |= (_QR_MASK | err); + flags |= (_QR_MASK | err); dnslabel_table_init(&table); APPEND16(req->trans_id); @@ -1968,8 +1968,8 @@ evdns_server_request_format_response(struct server_request *req, int err) if (r < 0) goto overflow; j = r; - t_ = htons( (short) (j-name_start) ); - memcpy(buf+len_idx, &t_, 2); + t_ = htons( (short) (j-name_start) ); + memcpy(buf+len_idx, &t_, 2); } else { APPEND16(item->datalen); if (j+item->datalen > (off_t)buf_len) @@ -2002,9 +2002,9 @@ overflow: /* exported function */ int -evdns_server_request_respond(struct evdns_server_request *req_, int err) +evdns_server_request_respond(struct evdns_server_request *req_, int err) { - struct server_request *req = TO_SERVER_REQUEST(req_); + struct server_request *req = TO_SERVER_REQUEST(req_); struct evdns_server_port *port = req->port; int r = -1; @@ -2150,18 +2150,18 @@ server_port_free(struct evdns_server_port *port) /* exported function */ int -evdns_server_request_drop(struct evdns_server_request *req_) +evdns_server_request_drop(struct evdns_server_request *req_) { - struct server_request *req = TO_SERVER_REQUEST(req_); + struct server_request *req = TO_SERVER_REQUEST(req_); server_request_free(req); return 0; } /* exported function */ int -evdns_server_request_get_requesting_addr(struct evdns_server_request *req_, struct sockaddr *sa, int addr_len) +evdns_server_request_get_requesting_addr(struct evdns_server_request *req_, struct sockaddr *sa, int addr_len) { - struct server_request *req = TO_SERVER_REQUEST(req_); + struct server_request *req = TO_SERVER_REQUEST(req_); if (addr_len < (int)req->addrlen) return -1; memcpy(sa, &(req->addr), req->addrlen); @@ -2185,29 +2185,29 @@ evdns_request_timeout_callback(evutil_socket_t fd, short events, void *arg) { EVDNS_LOCK(base); if (req->tx_count >= req->base->global_max_retransmits) { - struct nameserver *ns = req->ns; + struct nameserver *ns = req->ns; /* this request has failed */ log(EVDNS_LOG_DEBUG, "Giving up on request %p; tx_count==%d", arg, req->tx_count); reply_schedule_callback(req, 0, DNS_ERR_TIMEOUT, NULL); - + request_finished(req, &REQ_HEAD(req->base, req->trans_id), 1); - nameserver_failed(ns, "request timed out."); + nameserver_failed(ns, "request timed out."); } else { /* retransmit it */ log(EVDNS_LOG_DEBUG, "Retransmitting request %p; tx_count==%d", arg, req->tx_count); (void) evtimer_del(&req->timeout_event); - request_swap_ns(req, nameserver_pick(base)); + request_swap_ns(req, nameserver_pick(base)); evdns_request_transmit(req); - - req->ns->timedout++; - if (req->ns->timedout > req->base->global_max_nameserver_timeout) { - req->ns->timedout = 0; - nameserver_failed(req->ns, "request timed out."); - } - } - + + req->ns->timedout++; + if (req->ns->timedout > req->base->global_max_nameserver_timeout) { + req->ns->timedout = 0; + nameserver_failed(req->ns, "request timed out."); + } + } + EVDNS_UNLOCK(base); } @@ -2222,13 +2222,13 @@ evdns_request_transmit_to(struct request *req, struct nameserver *server) { int r; ASSERT_LOCKED(req->base); ASSERT_VALID_REQUEST(req); - - if (server->requests_inflight == 1 && - req->base->disable_when_inactive && - event_add(&server->event, NULL) < 0) { - return 1; - } - + + if (server->requests_inflight == 1 && + req->base->disable_when_inactive && + event_add(&server->event, NULL) < 0) { + return 1; + } + r = sendto(server->socket, (void*)req->request, req->request_len, 0, (struct sockaddr *)&server->address, server->addrlen); if (r < 0) { @@ -2281,11 +2281,11 @@ evdns_request_transmit(struct request *req) { nameserver_write_waiting(req->ns, 1); return 1; case 2: - /* failed to transmit the request entirely. we can fallthrough since - * we'll set a timeout, which will time out, and make us retransmit the - * request anyway. */ + /* failed to transmit the request entirely. we can fallthrough since + * we'll set a timeout, which will time out, and make us retransmit the + * request anyway. */ retcode = 1; - EVUTIL_FALLTHROUGH; + EVUTIL_FALLTHROUGH; default: /* all ok */ log(EVDNS_LOG_DEBUG, @@ -2338,7 +2338,7 @@ nameserver_send_probe(struct nameserver *const ns) { ASSERT_LOCKED(ns->base); log(EVDNS_LOG_DEBUG, "Sending probe to %s", - evutil_format_sockaddr_port_( + evutil_format_sockaddr_port_( (struct sockaddr *)&ns->address, addrbuf, sizeof(addrbuf))); handle = mm_calloc(1, sizeof(*handle)); @@ -2499,7 +2499,7 @@ evdns_resume(void) } static int -evdns_nameserver_add_impl_(struct evdns_base *base, const struct sockaddr *address, int addrlen) { +evdns_nameserver_add_impl_(struct evdns_base *base, const struct sockaddr *address, int addrlen) { /* first check to see if we already have this nameserver */ const struct nameserver *server = base->server_head, *const started_at = base->server_head; @@ -2527,12 +2527,12 @@ evdns_nameserver_add_impl_(struct evdns_base *base, const struct sockaddr *addre evtimer_assign(&ns->timeout_event, ns->base->event_base, nameserver_prod_callback, ns); - ns->socket = evutil_socket_(address->sa_family, - SOCK_DGRAM|EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC, 0); + ns->socket = evutil_socket_(address->sa_family, + SOCK_DGRAM|EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC, 0); if (ns->socket < 0) { err = 1; goto out1; } if (base->global_outgoing_addrlen && - !evutil_sockaddr_is_loopback_(address)) { + !evutil_sockaddr_is_loopback_(address)) { if (bind(ns->socket, (struct sockaddr*)&base->global_outgoing_address, base->global_outgoing_addrlen) < 0) { @@ -2542,35 +2542,35 @@ evdns_nameserver_add_impl_(struct evdns_base *base, const struct sockaddr *addre } } - if (base->so_rcvbuf) { - if (setsockopt(ns->socket, SOL_SOCKET, SO_RCVBUF, - (void *)&base->so_rcvbuf, sizeof(base->so_rcvbuf))) { - log(EVDNS_LOG_WARN, "Couldn't set SO_RCVBUF to %i", base->so_rcvbuf); - err = -SO_RCVBUF; - goto out2; - } - } - if (base->so_sndbuf) { - if (setsockopt(ns->socket, SOL_SOCKET, SO_SNDBUF, - (void *)&base->so_sndbuf, sizeof(base->so_sndbuf))) { - log(EVDNS_LOG_WARN, "Couldn't set SO_SNDBUF to %i", base->so_sndbuf); - err = -SO_SNDBUF; - goto out2; - } - } - + if (base->so_rcvbuf) { + if (setsockopt(ns->socket, SOL_SOCKET, SO_RCVBUF, + (void *)&base->so_rcvbuf, sizeof(base->so_rcvbuf))) { + log(EVDNS_LOG_WARN, "Couldn't set SO_RCVBUF to %i", base->so_rcvbuf); + err = -SO_RCVBUF; + goto out2; + } + } + if (base->so_sndbuf) { + if (setsockopt(ns->socket, SOL_SOCKET, SO_SNDBUF, + (void *)&base->so_sndbuf, sizeof(base->so_sndbuf))) { + log(EVDNS_LOG_WARN, "Couldn't set SO_SNDBUF to %i", base->so_sndbuf); + err = -SO_SNDBUF; + goto out2; + } + } + memcpy(&ns->address, address, addrlen); ns->addrlen = addrlen; ns->state = 1; - event_assign(&ns->event, ns->base->event_base, ns->socket, - EV_READ | EV_PERSIST, nameserver_ready_callback, ns); - if (!base->disable_when_inactive && event_add(&ns->event, NULL) < 0) { + event_assign(&ns->event, ns->base->event_base, ns->socket, + EV_READ | EV_PERSIST, nameserver_ready_callback, ns); + if (!base->disable_when_inactive && event_add(&ns->event, NULL) < 0) { err = 2; goto out2; } log(EVDNS_LOG_DEBUG, "Added nameserver %s as %p", - evutil_format_sockaddr_port_(address, addrbuf, sizeof(addrbuf)), ns); + evutil_format_sockaddr_port_(address, addrbuf, sizeof(addrbuf)), ns); /* insert this nameserver into the list of them */ if (!base->server_head) { @@ -2593,7 +2593,7 @@ out1: event_debug_unassign(&ns->event); mm_free(ns); log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", - evutil_format_sockaddr_port_(address, addrbuf, sizeof(addrbuf)), err); + evutil_format_sockaddr_port_(address, addrbuf, sizeof(addrbuf)), err); return err; } @@ -2608,7 +2608,7 @@ evdns_base_nameserver_add(struct evdns_base *base, unsigned long int address) sin.sin_port = htons(53); sin.sin_family = AF_INET; EVDNS_LOCK(base); - res = evdns_nameserver_add_impl_(base, (struct sockaddr*)&sin, sizeof(sin)); + res = evdns_nameserver_add_impl_(base, (struct sockaddr*)&sin, sizeof(sin)); EVDNS_UNLOCK(base); return res; } @@ -2660,7 +2660,7 @@ evdns_base_nameserver_ip_add(struct evdns_base *base, const char *ip_as_string) sockaddr_setport(sa, 53); EVDNS_LOCK(base); - res = evdns_nameserver_add_impl_(base, sa, len); + res = evdns_nameserver_add_impl_(base, sa, len); EVDNS_UNLOCK(base); return res; } @@ -2679,39 +2679,39 @@ evdns_base_nameserver_sockaddr_add(struct evdns_base *base, int res; EVUTIL_ASSERT(base); EVDNS_LOCK(base); - res = evdns_nameserver_add_impl_(base, sa, len); + res = evdns_nameserver_add_impl_(base, sa, len); EVDNS_UNLOCK(base); return res; } -int -evdns_base_get_nameserver_addr(struct evdns_base *base, int idx, - struct sockaddr *sa, ev_socklen_t len) -{ - int result = -1; - int i; - struct nameserver *server; - EVDNS_LOCK(base); - server = base->server_head; - for (i = 0; i < idx && server; ++i, server = server->next) { - if (server->next == base->server_head) - goto done; - } - if (! server) - goto done; - - if (server->addrlen > len) { - result = (int) server->addrlen; - goto done; - } - - memcpy(sa, &server->address, server->addrlen); - result = (int) server->addrlen; -done: - EVDNS_UNLOCK(base); - return result; -} - +int +evdns_base_get_nameserver_addr(struct evdns_base *base, int idx, + struct sockaddr *sa, ev_socklen_t len) +{ + int result = -1; + int i; + struct nameserver *server; + EVDNS_LOCK(base); + server = base->server_head; + for (i = 0; i < idx && server; ++i, server = server->next) { + if (server->next == base->server_head) + goto done; + } + if (! server) + goto done; + + if (server->addrlen > len) { + result = (int) server->addrlen; + goto done; + } + + memcpy(sa, &server->address, server->addrlen); + result = (int) server->addrlen; +done: + EVDNS_UNLOCK(base); + return result; +} + /* remove from the queue */ static void evdns_request_remove(struct request *req, struct request **head) @@ -2815,7 +2815,7 @@ request_new(struct evdns_base *base, struct evdns_request *handle, int type, strlcpy(namebuf, name, sizeof(namebuf)); evutil_secure_rng_get_bytes(randbits, (name_len+7)/8); for (i = 0; i < name_len; ++i) { - if (EVUTIL_ISALPHA_(namebuf[i])) { + if (EVUTIL_ISALPHA_(namebuf[i])) { if ((randbits[i >> 3] & (1<<(i & 7)))) namebuf[i] |= 0x20; else @@ -2863,10 +2863,10 @@ request_submit(struct request *const req) { /* if it has a nameserver assigned then this is going */ /* straight into the inflight queue */ evdns_request_insert(req, &REQ_HEAD(base, req->trans_id)); - + base->global_requests_inflight++; - req->ns->requests_inflight++; - + req->ns->requests_inflight++; + evdns_request_transmit(req); } else { evdns_request_insert(req, &base->req_waiting_head); @@ -3209,12 +3209,12 @@ search_set_from_hostname(struct evdns_base *base) { static char * search_make_new(const struct search_state *const state, int n, const char *const base_name) { const size_t base_len = strlen(base_name); - char need_to_append_dot; + char need_to_append_dot; struct search_domain *dom; - if (!base_len) return NULL; - need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1; - + if (!base_len) return NULL; + need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1; + for (dom = state->head; dom; dom = dom->next) { if (!n--) { /* this is the postfix we want */ @@ -3347,19 +3347,19 @@ search_request_finished(struct evdns_request *const handle) { static void evdns_resolv_set_defaults(struct evdns_base *base, int flags) { - int add_default = flags & DNS_OPTION_NAMESERVERS; - if (flags & DNS_OPTION_NAMESERVERS_NO_DEFAULT) - add_default = 0; - + int add_default = flags & DNS_OPTION_NAMESERVERS; + if (flags & DNS_OPTION_NAMESERVERS_NO_DEFAULT) + add_default = 0; + /* if the file isn't found then we assume a local resolver */ ASSERT_LOCKED(base); - if (flags & DNS_OPTION_SEARCH) - search_set_from_hostname(base); - if (add_default) - evdns_base_nameserver_ip_add(base, "127.0.0.1"); + if (flags & DNS_OPTION_SEARCH) + search_set_from_hostname(base); + if (add_default) + evdns_base_nameserver_ip_add(base, "127.0.0.1"); } -#ifndef EVENT__HAVE_STRTOK_R +#ifndef EVENT__HAVE_STRTOK_R static char * strtok_r(char *s, const char *delim, char **state) { char *cp, *start; @@ -3393,7 +3393,7 @@ strtoint(const char *const str) /* Parse a number of seconds into a timeval; return -1 on error. */ static int -evdns_strtotimeval(const char *const str, struct timeval *out) +evdns_strtotimeval(const char *const str, struct timeval *out) { double d; char *endptr; @@ -3496,13 +3496,13 @@ evdns_base_set_option_impl(struct evdns_base *base, base->global_search_state->ndots = ndots; } else if (str_matches_option(option, "timeout:")) { struct timeval tv; - if (evdns_strtotimeval(val, &tv) == -1) return -1; + if (evdns_strtotimeval(val, &tv) == -1) return -1; if (!(flags & DNS_OPTION_MISC)) return 0; log(EVDNS_LOG_DEBUG, "Setting timeout to %s", val); memcpy(&base->global_timeout, &tv, sizeof(struct timeval)); } else if (str_matches_option(option, "getaddrinfo-allow-skew:")) { struct timeval tv; - if (evdns_strtotimeval(val, &tv) == -1) return -1; + if (evdns_strtotimeval(val, &tv) == -1) return -1; if (!(flags & DNS_OPTION_MISC)) return 0; log(EVDNS_LOG_DEBUG, "Setting getaddrinfo-allow-skew to %s", val); @@ -3545,7 +3545,7 @@ evdns_base_set_option_impl(struct evdns_base *base, base->global_outgoing_addrlen = len; } else if (str_matches_option(option, "initial-probe-timeout:")) { struct timeval tv; - if (evdns_strtotimeval(val, &tv) == -1) return -1; + if (evdns_strtotimeval(val, &tv) == -1) return -1; if (tv.tv_sec > 3600) tv.tv_sec = 3600; if (!(flags & DNS_OPTION_MISC)) return 0; @@ -3553,18 +3553,18 @@ evdns_base_set_option_impl(struct evdns_base *base, val); memcpy(&base->global_nameserver_probe_initial_timeout, &tv, sizeof(tv)); - } else if (str_matches_option(option, "so-rcvbuf:")) { - int buf = strtoint(val); + } else if (str_matches_option(option, "so-rcvbuf:")) { + int buf = strtoint(val); if (buf == -1) return -1; - if (!(flags & DNS_OPTION_MISC)) return 0; - log(EVDNS_LOG_DEBUG, "Setting SO_RCVBUF to %s", val); - base->so_rcvbuf = buf; - } else if (str_matches_option(option, "so-sndbuf:")) { - int buf = strtoint(val); + if (!(flags & DNS_OPTION_MISC)) return 0; + log(EVDNS_LOG_DEBUG, "Setting SO_RCVBUF to %s", val); + base->so_rcvbuf = buf; + } else if (str_matches_option(option, "so-sndbuf:")) { + int buf = strtoint(val); if (buf == -1) return -1; - if (!(flags & DNS_OPTION_MISC)) return 0; - log(EVDNS_LOG_DEBUG, "Setting SO_SNDBUF to %s", val); - base->so_sndbuf = buf; + if (!(flags & DNS_OPTION_MISC)) return 0; + log(EVDNS_LOG_DEBUG, "Setting SO_SNDBUF to %s", val); + base->so_sndbuf = buf; } return 0; } @@ -3637,7 +3637,7 @@ evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *con static char * evdns_get_default_hosts_filename(void) { -#ifdef _WIN32 +#ifdef _WIN32 /* Windows is a little coy about where it puts its configuration * files. Sure, they're _usually_ in C:\windows\system32, but * there's no reason in principle they couldn't be in @@ -3650,8 +3650,8 @@ evdns_get_default_hosts_filename(void) if (! SHGetSpecialFolderPathA(NULL, path, CSIDL_SYSTEM, 0)) return NULL; - len_out = strlen(path)+strlen(hostfile)+1; - path_out = mm_malloc(len_out); + len_out = strlen(path)+strlen(hostfile)+1; + path_out = mm_malloc(len_out); evutil_snprintf(path_out, len_out, "%s%s", path, hostfile); return path_out; #else @@ -3665,14 +3665,14 @@ evdns_base_resolv_conf_parse_impl(struct evdns_base *base, int flags, const char char *resolv; char *start; int err = 0; - int add_default; + int add_default; log(EVDNS_LOG_DEBUG, "Parsing resolv.conf file %s", filename); - add_default = flags & DNS_OPTION_NAMESERVERS; - if (flags & DNS_OPTION_NAMESERVERS_NO_DEFAULT) - add_default = 0; - + add_default = flags & DNS_OPTION_NAMESERVERS; + if (flags & DNS_OPTION_NAMESERVERS_NO_DEFAULT) + add_default = 0; + if (flags & DNS_OPTION_HOSTSFILE) { char *fname = evdns_get_default_hosts_filename(); evdns_base_load_hosts(base, fname); @@ -3680,12 +3680,12 @@ evdns_base_resolv_conf_parse_impl(struct evdns_base *base, int flags, const char mm_free(fname); } - if (!filename) { - evdns_resolv_set_defaults(base, flags); - return 1; - } - - if ((err = evutil_read_file_(filename, &resolv, &n, 0)) < 0) { + if (!filename) { + evdns_resolv_set_defaults(base, flags); + return 1; + } + + if ((err = evutil_read_file_(filename, &resolv, &n, 0)) < 0) { if (err == -1) { /* No file. */ evdns_resolv_set_defaults(base, flags); @@ -3708,7 +3708,7 @@ evdns_base_resolv_conf_parse_impl(struct evdns_base *base, int flags, const char } } - if (!base->server_head && add_default) { + if (!base->server_head && add_default) { /* no nameservers were configured. */ evdns_base_nameserver_ip_add(base, "127.0.0.1"); err = 6; @@ -3729,7 +3729,7 @@ evdns_resolv_conf_parse(int flags, const char *const filename) { } -#ifdef _WIN32 +#ifdef _WIN32 /* Add multiple nameservers from a space-or-comma-separated list. */ static int evdns_nameserver_ip_add_line(struct evdns_base *base, const char *ips) { @@ -3772,7 +3772,7 @@ load_nameservers_with_getnetworkparams(struct evdns_base *base) GetNetworkParams_fn_t fn; ASSERT_LOCKED(base); - if (!(handle = evutil_load_windows_system_library_( + if (!(handle = evutil_load_windows_system_library_( TEXT("iphlpapi.dll")))) { log(EVDNS_LOG_WARN, "Could not open iphlpapi.dll"); status = -1; @@ -3931,12 +3931,12 @@ evdns_base_config_windows_nameservers(struct evdns_base *base) if (base == NULL) return -1; EVDNS_LOCK(base); - fname = evdns_get_default_hosts_filename(); - log(EVDNS_LOG_DEBUG, "Loading hosts entries from %s", fname); - evdns_base_load_hosts(base, fname); - if (fname) - mm_free(fname); - + fname = evdns_get_default_hosts_filename(); + log(EVDNS_LOG_DEBUG, "Loading hosts entries from %s", fname); + evdns_base_load_hosts(base, fname); + if (fname) + mm_free(fname); + if (load_nameservers_with_getnetworkparams(base) == 0) { EVDNS_UNLOCK(base); return 0; @@ -3960,7 +3960,7 @@ evdns_config_windows_nameservers(void) #endif struct evdns_base * -evdns_base_new(struct event_base *event_base, int flags) +evdns_base_new(struct event_base *event_base, int flags) { struct evdns_base *base; @@ -3973,8 +3973,8 @@ evdns_base_new(struct event_base *event_base, int flags) /* Give the evutil library a hook into its evdns-enabled * functionality. We can't just call evdns_getaddrinfo directly or * else libevent-core will depend on libevent-extras. */ - evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo); - evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel); + evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo); + evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel); base = mm_malloc(sizeof(struct evdns_base)); if (base == NULL) @@ -4009,41 +4009,41 @@ evdns_base_new(struct event_base *event_base, int flags) TAILQ_INIT(&base->hostsdb); -#define EVDNS_BASE_ALL_FLAGS ( \ - EVDNS_BASE_INITIALIZE_NAMESERVERS | \ - EVDNS_BASE_DISABLE_WHEN_INACTIVE | \ - EVDNS_BASE_NAMESERVERS_NO_DEFAULT | \ - 0) - - if (flags & ~EVDNS_BASE_ALL_FLAGS) { - flags = EVDNS_BASE_INITIALIZE_NAMESERVERS; - log(EVDNS_LOG_WARN, - "Unrecognized flag passed to evdns_base_new(). Assuming " - "you meant EVDNS_BASE_INITIALIZE_NAMESERVERS."); - } -#undef EVDNS_BASE_ALL_FLAGS - - if (flags & EVDNS_BASE_INITIALIZE_NAMESERVERS) { +#define EVDNS_BASE_ALL_FLAGS ( \ + EVDNS_BASE_INITIALIZE_NAMESERVERS | \ + EVDNS_BASE_DISABLE_WHEN_INACTIVE | \ + EVDNS_BASE_NAMESERVERS_NO_DEFAULT | \ + 0) + + if (flags & ~EVDNS_BASE_ALL_FLAGS) { + flags = EVDNS_BASE_INITIALIZE_NAMESERVERS; + log(EVDNS_LOG_WARN, + "Unrecognized flag passed to evdns_base_new(). Assuming " + "you meant EVDNS_BASE_INITIALIZE_NAMESERVERS."); + } +#undef EVDNS_BASE_ALL_FLAGS + + if (flags & EVDNS_BASE_INITIALIZE_NAMESERVERS) { int r; - int opts = DNS_OPTIONS_ALL; - if (flags & EVDNS_BASE_NAMESERVERS_NO_DEFAULT) { - opts |= DNS_OPTION_NAMESERVERS_NO_DEFAULT; - } - -#ifdef _WIN32 + int opts = DNS_OPTIONS_ALL; + if (flags & EVDNS_BASE_NAMESERVERS_NO_DEFAULT) { + opts |= DNS_OPTION_NAMESERVERS_NO_DEFAULT; + } + +#ifdef _WIN32 r = evdns_base_config_windows_nameservers(base); #else - r = evdns_base_resolv_conf_parse(base, opts, "/etc/resolv.conf"); + r = evdns_base_resolv_conf_parse(base, opts, "/etc/resolv.conf"); #endif if (r) { evdns_base_free_and_unlock(base, 0); return NULL; } } - if (flags & EVDNS_BASE_DISABLE_WHEN_INACTIVE) { - base->disable_when_inactive = 1; - } - + if (flags & EVDNS_BASE_DISABLE_WHEN_INACTIVE) { + base->disable_when_inactive = 1; + } + EVDNS_UNLOCK(base); return base; } @@ -4085,7 +4085,7 @@ static void evdns_nameserver_free(struct nameserver *server) { if (server->socket >= 0) - evutil_closesocket(server->socket); + evutil_closesocket(server->socket); (void) event_del(&server->event); event_debug_unassign(&server->event); if (server->state == 0) @@ -4123,16 +4123,16 @@ evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests) } base->global_requests_inflight = base->global_requests_waiting = 0; - for (server = base->server_head; server; server = server_next) { - server_next = server->next; - /** already done something before */ - server->probe_request = NULL; - evdns_nameserver_free(server); - if (server_next == base->server_head) - break; - } - base->server_head = NULL; - base->global_good_nameservers = 0; + for (server = base->server_head; server; server = server_next) { + server_next = server->next; + /** already done something before */ + server->probe_request = NULL; + evdns_nameserver_free(server); + if (server_next == base->server_head) + break; + } + base->server_head = NULL; + base->global_good_nameservers = 0; if (base->global_search_state) { for (dom = base->global_search_state->head; dom; dom = dom_next) { @@ -4167,18 +4167,18 @@ evdns_base_free(struct evdns_base *base, int fail_requests) } void -evdns_base_clear_host_addresses(struct evdns_base *base) -{ - struct hosts_entry *victim; - EVDNS_LOCK(base); - while ((victim = TAILQ_FIRST(&base->hostsdb))) { - TAILQ_REMOVE(&base->hostsdb, victim, next); - mm_free(victim); - } - EVDNS_UNLOCK(base); -} - -void +evdns_base_clear_host_addresses(struct evdns_base *base) +{ + struct hosts_entry *victim; + EVDNS_LOCK(base); + while ((victim = TAILQ_FIRST(&base->hostsdb))) { + TAILQ_REMOVE(&base->hostsdb, victim, next); + mm_free(victim); + } + EVDNS_UNLOCK(base); +} + +void evdns_shutdown(int fail_requests) { if (current_base) { @@ -4253,7 +4253,7 @@ evdns_base_load_hosts_impl(struct evdns_base *base, const char *hosts_fname) ASSERT_LOCKED(base); if (hosts_fname == NULL || - (err = evutil_read_file_(hosts_fname, &str, &len, 0)) < 0) { + (err = evutil_read_file_(hosts_fname, &str, &len, 0)) < 0) { char tmp[64]; strlcpy(tmp, "127.0.0.1 localhost", sizeof(tmp)); evdns_base_parse_hosts_line(base, tmp); @@ -4482,22 +4482,22 @@ evdns_getaddrinfo_gotresolve(int result, char type, int count, other_req = &data->ipv4_request; } - /** Called from evdns_base_free() with @fail_requests == 1 */ - if (result != DNS_ERR_SHUTDOWN) { - EVDNS_LOCK(data->evdns_base); - if (evdns_result_is_answer(result)) { - if (req->type == DNS_IPv4_A) - ++data->evdns_base->getaddrinfo_ipv4_answered; - else - ++data->evdns_base->getaddrinfo_ipv6_answered; - } - user_canceled = data->user_canceled; - if (other_req->r == NULL) - data->request_done = 1; - EVDNS_UNLOCK(data->evdns_base); - } else { - data->evdns_base = NULL; - user_canceled = data->user_canceled; + /** Called from evdns_base_free() with @fail_requests == 1 */ + if (result != DNS_ERR_SHUTDOWN) { + EVDNS_LOCK(data->evdns_base); + if (evdns_result_is_answer(result)) { + if (req->type == DNS_IPv4_A) + ++data->evdns_base->getaddrinfo_ipv4_answered; + else + ++data->evdns_base->getaddrinfo_ipv6_answered; + } + user_canceled = data->user_canceled; + if (other_req->r == NULL) + data->request_done = 1; + EVDNS_UNLOCK(data->evdns_base); + } else { + data->evdns_base = NULL; + user_canceled = data->user_canceled; } req->r = NULL; @@ -4532,9 +4532,9 @@ evdns_getaddrinfo_gotresolve(int result, char type, int count, /* The other request is still working; maybe it will * succeed. */ /* XXXX handle failure from set_timeout */ - if (result != DNS_ERR_SHUTDOWN) { - evdns_getaddrinfo_set_timeout(data->evdns_base, data); - } + if (result != DNS_ERR_SHUTDOWN) { + evdns_getaddrinfo_set_timeout(data->evdns_base, data); + } data->pending_error = err; return; } @@ -4595,7 +4595,7 @@ evdns_getaddrinfo_gotresolve(int result, char type, int count, for (i=0; i < count; ++i) { struct evutil_addrinfo *ai; memcpy(addrp, ((char*)addresses)+i*addrlen, addrlen); - ai = evutil_new_addrinfo_(sa, socklen, &data->hints); + ai = evutil_new_addrinfo_(sa, socklen, &data->hints); if (!ai) { if (other_req->r) { evdns_cancel_request(NULL, other_req->r); @@ -4608,7 +4608,7 @@ evdns_getaddrinfo_gotresolve(int result, char type, int count, free_getaddrinfo_request(data); return; } - res = evutil_addrinfo_append_(res, ai); + res = evutil_addrinfo_append_(res, ai); } if (other_req->r) { @@ -4622,10 +4622,10 @@ evdns_getaddrinfo_gotresolve(int result, char type, int count, * results (if any) and return them. */ if (data->pending_result) { if (req->type == DNS_IPv4_A) - res = evutil_addrinfo_append_(res, + res = evutil_addrinfo_append_(res, data->pending_result); else - res = evutil_addrinfo_append_( + res = evutil_addrinfo_append_( data->pending_result, res); data->pending_result = NULL; } @@ -4675,13 +4675,13 @@ evdns_getaddrinfo_fromhosts(struct evdns_base *base, if ((e->addr.sa.sa_family == AF_INET && f == PF_INET6) || (e->addr.sa.sa_family == AF_INET6 && f == PF_INET)) continue; - ai_new = evutil_new_addrinfo_(&e->addr.sa, e->addrlen, hints); + ai_new = evutil_new_addrinfo_(&e->addr.sa, e->addrlen, hints); if (!ai_new) { n_found = 0; goto out; } sockaddr_setport(ai_new->ai_addr, port); - ai = evutil_addrinfo_append_(ai, ai_new); + ai = evutil_addrinfo_append_(ai, ai_new); } EVDNS_UNLOCK(base); out: @@ -4709,7 +4709,7 @@ evdns_getaddrinfo(struct evdns_base *dns_base, int err; int port = 0; int want_cname = 0; - int started = 0; + int started = 0; if (!dns_base) { dns_base = current_base; @@ -4737,14 +4737,14 @@ evdns_getaddrinfo(struct evdns_base *dns_base, hints.ai_family = PF_UNSPEC; } - evutil_adjust_hints_for_addrconfig_(&hints); + evutil_adjust_hints_for_addrconfig_(&hints); /* Now try to see if we _can_ answer immediately. */ /* (It would be nice to do this by calling getaddrinfo directly, with * AI_NUMERICHOST, on plaforms that have it, but we can't: there isn't * a reliable way to distinguish the "that wasn't a numeric host!" case * from any other EAI_NONAME cases.) */ - err = evutil_getaddrinfo_common_(nodename, servname, &hints, &res, &port); + err = evutil_getaddrinfo_common_(nodename, servname, &hints, &res, &port); if (err != EVUTIL_EAI_NEED_RESOLVE) { cb(err, res, arg); return NULL; @@ -4788,8 +4788,8 @@ evdns_getaddrinfo(struct evdns_base *dns_base, * launching those requests. (XXX we don't do that yet.) */ - EVDNS_LOCK(dns_base); - + EVDNS_LOCK(dns_base); + if (hints.ai_family != PF_INET6) { log(EVDNS_LOG_DEBUG, "Sending request for %s on ipv4 as %p", nodename, &data->ipv4_request); @@ -4797,7 +4797,7 @@ evdns_getaddrinfo(struct evdns_base *dns_base, data->ipv4_request.r = evdns_base_resolve_ipv4(dns_base, nodename, 0, evdns_getaddrinfo_gotresolve, &data->ipv4_request); - if (want_cname && data->ipv4_request.r) + if (want_cname && data->ipv4_request.r) data->ipv4_request.r->current_req->put_cname_in_ptr = &data->cname_result; } @@ -4808,7 +4808,7 @@ evdns_getaddrinfo(struct evdns_base *dns_base, data->ipv6_request.r = evdns_base_resolve_ipv6(dns_base, nodename, 0, evdns_getaddrinfo_gotresolve, &data->ipv6_request); - if (want_cname && data->ipv6_request.r) + if (want_cname && data->ipv6_request.r) data->ipv6_request.r->current_req->put_cname_in_ptr = &data->cname_result; } @@ -4816,11 +4816,11 @@ evdns_getaddrinfo(struct evdns_base *dns_base, evtimer_assign(&data->timeout, dns_base->event_base, evdns_getaddrinfo_timeout_cb, data); - started = (data->ipv4_request.r || data->ipv6_request.r); - - EVDNS_UNLOCK(dns_base); - - if (started) { + started = (data->ipv4_request.r || data->ipv6_request.r); + + EVDNS_UNLOCK(dns_base); + + if (started) { return data; } else { mm_free(data); diff --git a/contrib/libs/libevent/event-internal.h b/contrib/libs/libevent/event-internal.h index 9e5ff42447..05a595febf 100644 --- a/contrib/libs/libevent/event-internal.h +++ b/contrib/libs/libevent/event-internal.h @@ -24,16 +24,16 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT_INTERNAL_H_INCLUDED_ -#define EVENT_INTERNAL_H_INCLUDED_ +#ifndef EVENT_INTERNAL_H_INCLUDED_ +#define EVENT_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { #endif #include "event2/event-config.h" -#include "evconfig-private.h" - +#include "evconfig-private.h" + #include <time.h> #include <sys/queue.h> #include "event2/event_struct.h" @@ -45,43 +45,43 @@ extern "C" { /* map union members back */ /* mutually exclusive */ -#define ev_signal_next ev_.ev_signal.ev_signal_next -#define ev_io_next ev_.ev_io.ev_io_next -#define ev_io_timeout ev_.ev_io.ev_timeout +#define ev_signal_next ev_.ev_signal.ev_signal_next +#define ev_io_next ev_.ev_io.ev_io_next +#define ev_io_timeout ev_.ev_io.ev_timeout /* used only by signals */ -#define ev_ncalls ev_.ev_signal.ev_ncalls -#define ev_pncalls ev_.ev_signal.ev_pncalls - -#define ev_pri ev_evcallback.evcb_pri -#define ev_flags ev_evcallback.evcb_flags -#define ev_closure ev_evcallback.evcb_closure -#define ev_callback ev_evcallback.evcb_cb_union.evcb_callback -#define ev_arg ev_evcallback.evcb_arg - -/** @name Event closure codes - - Possible values for evcb_closure in struct event_callback - - @{ - */ -/** A regular event. Uses the evcb_callback callback */ -#define EV_CLOSURE_EVENT 0 -/** A signal event. Uses the evcb_callback callback */ -#define EV_CLOSURE_EVENT_SIGNAL 1 -/** A persistent non-signal event. Uses the evcb_callback callback */ -#define EV_CLOSURE_EVENT_PERSIST 2 -/** A simple callback. Uses the evcb_selfcb callback. */ -#define EV_CLOSURE_CB_SELF 3 -/** A finalizing callback. Uses the evcb_cbfinalize callback. */ -#define EV_CLOSURE_CB_FINALIZE 4 -/** A finalizing event. Uses the evcb_evfinalize callback. */ -#define EV_CLOSURE_EVENT_FINALIZE 5 -/** A finalizing event that should get freed after. Uses the evcb_evfinalize - * callback. */ -#define EV_CLOSURE_EVENT_FINALIZE_FREE 6 -/** @} */ - +#define ev_ncalls ev_.ev_signal.ev_ncalls +#define ev_pncalls ev_.ev_signal.ev_pncalls + +#define ev_pri ev_evcallback.evcb_pri +#define ev_flags ev_evcallback.evcb_flags +#define ev_closure ev_evcallback.evcb_closure +#define ev_callback ev_evcallback.evcb_cb_union.evcb_callback +#define ev_arg ev_evcallback.evcb_arg + +/** @name Event closure codes + + Possible values for evcb_closure in struct event_callback + + @{ + */ +/** A regular event. Uses the evcb_callback callback */ +#define EV_CLOSURE_EVENT 0 +/** A signal event. Uses the evcb_callback callback */ +#define EV_CLOSURE_EVENT_SIGNAL 1 +/** A persistent non-signal event. Uses the evcb_callback callback */ +#define EV_CLOSURE_EVENT_PERSIST 2 +/** A simple callback. Uses the evcb_selfcb callback. */ +#define EV_CLOSURE_CB_SELF 3 +/** A finalizing callback. Uses the evcb_cbfinalize callback. */ +#define EV_CLOSURE_CB_FINALIZE 4 +/** A finalizing event. Uses the evcb_evfinalize callback. */ +#define EV_CLOSURE_EVENT_FINALIZE 5 +/** A finalizing event that should get freed after. Uses the evcb_evfinalize + * callback. */ +#define EV_CLOSURE_EVENT_FINALIZE_FREE 6 +/** @} */ + /** Structure to define the backend of a given event_base. */ struct eventop { /** The name of this backend. */ @@ -125,7 +125,7 @@ struct eventop { size_t fdinfo_len; }; -#ifdef _WIN32 +#ifdef _WIN32 /* If we're on win32, then file descriptors are not nice low densely packed integers. Instead, they are pointer-like windows handles, and we want to use a hashtable instead of an array to map fds to events. @@ -136,7 +136,7 @@ struct eventop { /* #define HT_CACHE_HASH_VALS */ #ifdef EVMAP_USE_HT -#define HT_NO_CACHE_HASH_VALUES +#define HT_NO_CACHE_HASH_VALUES #include "ht-internal.h" struct event_map_entry; HT_HEAD(event_io_map, event_map_entry); @@ -186,25 +186,25 @@ struct event_changelist { int changes_size; }; -#ifndef EVENT__DISABLE_DEBUG_MODE +#ifndef EVENT__DISABLE_DEBUG_MODE /* Global internal flag: set to one if debug mode is on. */ -extern int event_debug_mode_on_; -#define EVENT_DEBUG_MODE_IS_ON() (event_debug_mode_on_) +extern int event_debug_mode_on_; +#define EVENT_DEBUG_MODE_IS_ON() (event_debug_mode_on_) #else #define EVENT_DEBUG_MODE_IS_ON() (0) #endif -TAILQ_HEAD(evcallback_list, event_callback); - -/* Sets up an event for processing once */ -struct event_once { - LIST_ENTRY(event_once) next_once; - struct event ev; - - void (*cb)(evutil_socket_t, short, void *); - void *arg; -}; - +TAILQ_HEAD(evcallback_list, event_callback); + +/* Sets up an event for processing once */ +struct event_once { + LIST_ENTRY(event_once) next_once; + struct event ev; + + void (*cb)(evutil_socket_t, short, void *); + void *arg; +}; + struct event_base { /** Function pointers and other data to describe this event_base's * backend. */ @@ -219,21 +219,21 @@ struct event_base { /** Function pointers used to describe the backend that this event_base * uses for signals */ const struct eventop *evsigsel; - /** Data to implement the common signal handler code. */ + /** Data to implement the common signal handler code. */ struct evsig_info sig; /** Number of virtual events */ int virtual_event_count; - /** Maximum number of virtual events active */ - int virtual_event_count_max; + /** Maximum number of virtual events active */ + int virtual_event_count_max; /** Number of total events added to this event_base */ int event_count; - /** Maximum number of total events added to this event_base */ - int event_count_max; + /** Maximum number of total events added to this event_base */ + int event_count_max; /** Number of total events active in this event_base */ int event_count_active; - /** Maximum number of total events active in this event_base */ - int event_count_active_max; + /** Maximum number of total events active in this event_base */ + int event_count_active_max; /** Set if we should terminate the loop once we're done processing * events. */ @@ -250,23 +250,23 @@ struct event_base { * reentrant invocation. */ int running_loop; - /** Set to the number of deferred_cbs we've made 'active' in the - * loop. This is a hack to prevent starvation; it would be smarter - * to just use event_config_set_max_dispatch_interval's max_callbacks - * feature */ - int n_deferreds_queued; - + /** Set to the number of deferred_cbs we've made 'active' in the + * loop. This is a hack to prevent starvation; it would be smarter + * to just use event_config_set_max_dispatch_interval's max_callbacks + * feature */ + int n_deferreds_queued; + /* Active event management. */ - /** An array of nactivequeues queues for active event_callbacks (ones - * that have triggered, and whose callbacks need to be called). Low + /** An array of nactivequeues queues for active event_callbacks (ones + * that have triggered, and whose callbacks need to be called). Low * priority numbers are more important, and stall higher ones. */ - struct evcallback_list *activequeues; + struct evcallback_list *activequeues; /** The length of the activequeues array */ int nactivequeues; - /** A list of event_callbacks that should become active the next time - * we process events, but not this time. */ - struct evcallback_list active_later_queue; + /** A list of event_callbacks that should become active the next time + * we process events, but not this time. */ + struct evcallback_list active_later_queue; /* common timeout logic */ @@ -291,15 +291,15 @@ struct event_base { * too often. */ struct timeval tv_cache; - struct evutil_monotonic_timer monotonic_timer; - + struct evutil_monotonic_timer monotonic_timer; + /** Difference between internal time (maybe from clock_gettime) and * gettimeofday. */ struct timeval tv_clock_diff; /** Second in which we last updated tv_clock_diff, in monotonic time. */ time_t last_updated_clock_diff; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT /* threading support */ /** The thread currently running the event_loop for this base */ unsigned long th_owner_id; @@ -311,10 +311,10 @@ struct event_base { /** Number of threads blocking on current_event_cond. */ int current_event_waiters; #endif - /** The event whose callback is executing right now */ - struct event_callback *current_event; + /** The event whose callback is executing right now */ + struct event_callback *current_event; -#ifdef _WIN32 +#ifdef _WIN32 /** IOCP support structure, if IOCP is enabled. */ struct event_iocp_port *iocp; #endif @@ -322,10 +322,10 @@ struct event_base { /** Flags that this base was configured with */ enum event_base_config_flag flags; - struct timeval max_dispatch_time; - int max_dispatch_callbacks; - int limit_callbacks_after_prio; - + struct timeval max_dispatch_time; + int max_dispatch_callbacks; + int limit_callbacks_after_prio; + /* Notify main thread to wake up break, etc. */ /** True if the base already has a pending notify, and we don't need * to add any more. */ @@ -338,14 +338,14 @@ struct event_base { struct event th_notify; /** A function used to wake up the main thread from another thread. */ int (*th_notify_fn)(struct event_base *base); - - /** Saved seed for weak random number generator. Some backends use - * this to produce fairness among sockets. Protected by th_base_lock. */ - struct evutil_weakrand_state weakrand_seed; - - /** List of event_onces that have not yet fired. */ - LIST_HEAD(once_event_list, event_once) once_events; - + + /** Saved seed for weak random number generator. Some backends use + * this to produce fairness among sockets. Protected by th_base_lock. */ + struct evutil_weakrand_state weakrand_seed; + + /** List of event_onces that have not yet fired. */ + LIST_HEAD(once_event_list, event_once) once_events; + }; struct event_config_entry { @@ -360,18 +360,18 @@ struct event_config { TAILQ_HEAD(event_configq, event_config_entry) entries; int n_cpus_hint; - struct timeval max_dispatch_interval; - int max_dispatch_callbacks; - int limit_callbacks_after_prio; + struct timeval max_dispatch_interval; + int max_dispatch_callbacks; + int limit_callbacks_after_prio; enum event_method_feature require_features; enum event_base_config_flag flags; }; /* Internal use only: Functions that might be missing from <sys/queue.h> */ -#ifndef LIST_END -#define LIST_END(head) NULL -#endif - +#ifndef LIST_END +#define LIST_END(head) NULL +#endif + #ifndef TAILQ_FIRST #define TAILQ_FIRST(head) ((head)->tqh_first) #endif @@ -399,58 +399,58 @@ struct event_config { #endif #define N_ACTIVE_CALLBACKS(base) \ - ((base)->event_count_active) + ((base)->event_count_active) -int evsig_set_handler_(struct event_base *base, int evsignal, +int evsig_set_handler_(struct event_base *base, int evsignal, void (*fn)(int)); -int evsig_restore_handler_(struct event_base *base, int evsignal); - -int event_add_nolock_(struct event *ev, - const struct timeval *tv, int tv_is_absolute); -/** Argument for event_del_nolock_. Tells event_del not to block on the event - * if it's running in another thread. */ -#define EVENT_DEL_NOBLOCK 0 -/** Argument for event_del_nolock_. Tells event_del to block on the event - * if it's running in another thread, regardless of its value for EV_FINALIZE - */ -#define EVENT_DEL_BLOCK 1 -/** Argument for event_del_nolock_. Tells event_del to block on the event - * if it is running in another thread and it doesn't have EV_FINALIZE set. - */ -#define EVENT_DEL_AUTOBLOCK 2 +int evsig_restore_handler_(struct event_base *base, int evsignal); + +int event_add_nolock_(struct event *ev, + const struct timeval *tv, int tv_is_absolute); +/** Argument for event_del_nolock_. Tells event_del not to block on the event + * if it's running in another thread. */ +#define EVENT_DEL_NOBLOCK 0 +/** Argument for event_del_nolock_. Tells event_del to block on the event + * if it's running in another thread, regardless of its value for EV_FINALIZE + */ +#define EVENT_DEL_BLOCK 1 +/** Argument for event_del_nolock_. Tells event_del to block on the event + * if it is running in another thread and it doesn't have EV_FINALIZE set. + */ +#define EVENT_DEL_AUTOBLOCK 2 /** Argument for event_del_nolock_. Tells event_del to proceed even if the - * event is set up for finalization rather for regular use.*/ -#define EVENT_DEL_EVEN_IF_FINALIZING 3 -int event_del_nolock_(struct event *ev, int blocking); -int event_remove_timer_nolock_(struct event *ev); - -void event_active_nolock_(struct event *ev, int res, short count); -EVENT2_EXPORT_SYMBOL -int event_callback_activate_(struct event_base *, struct event_callback *); -int event_callback_activate_nolock_(struct event_base *, struct event_callback *); -int event_callback_cancel_(struct event_base *base, - struct event_callback *evcb); - -void event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)); -EVENT2_EXPORT_SYMBOL -void event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)); -int event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcb, void (*cb)(struct event_callback *, void *)); - - -EVENT2_EXPORT_SYMBOL -void event_active_later_(struct event *ev, int res); -void event_active_later_nolock_(struct event *ev, int res); -int event_callback_activate_later_nolock_(struct event_base *base, - struct event_callback *evcb); -int event_callback_cancel_nolock_(struct event_base *base, - struct event_callback *evcb, int even_if_finalizing); -void event_callback_init_(struct event_base *base, - struct event_callback *cb); - + * event is set up for finalization rather for regular use.*/ +#define EVENT_DEL_EVEN_IF_FINALIZING 3 +int event_del_nolock_(struct event *ev, int blocking); +int event_remove_timer_nolock_(struct event *ev); + +void event_active_nolock_(struct event *ev, int res, short count); +EVENT2_EXPORT_SYMBOL +int event_callback_activate_(struct event_base *, struct event_callback *); +int event_callback_activate_nolock_(struct event_base *, struct event_callback *); +int event_callback_cancel_(struct event_base *base, + struct event_callback *evcb); + +void event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)); +EVENT2_EXPORT_SYMBOL +void event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)); +int event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcb, void (*cb)(struct event_callback *, void *)); + + +EVENT2_EXPORT_SYMBOL +void event_active_later_(struct event *ev, int res); +void event_active_later_nolock_(struct event *ev, int res); +int event_callback_activate_later_nolock_(struct event_base *base, + struct event_callback *evcb); +int event_callback_cancel_nolock_(struct event_base *base, + struct event_callback *evcb, int even_if_finalizing); +void event_callback_init_(struct event_base *base, + struct event_callback *cb); + /* FIXME document. */ -EVENT2_EXPORT_SYMBOL -void event_base_add_virtual_(struct event_base *base); -void event_base_del_virtual_(struct event_base *base); +EVENT2_EXPORT_SYMBOL +void event_base_add_virtual_(struct event_base *base); +void event_base_del_virtual_(struct event_base *base); /** For debugging: unless assertions are disabled, verify the referential integrity of the internal data structures of 'base'. This operation can @@ -458,31 +458,31 @@ void event_base_del_virtual_(struct event_base *base); Returns on success; aborts on failure. */ -EVENT2_EXPORT_SYMBOL -void event_base_assert_ok_(struct event_base *base); -void event_base_assert_ok_nolock_(struct event_base *base); - - -/* Helper function: Call 'fn' exactly once every inserted or active event in - * the event_base 'base'. - * - * If fn returns 0, continue on to the next event. Otherwise, return the same - * value that fn returned. - * - * Requires that 'base' be locked. - */ -int event_base_foreach_event_nolock_(struct event_base *base, - event_base_foreach_event_cb cb, void *arg); - -/* Cleanup function to reset debug mode during shutdown. - * - * Calling this function doesn't mean it'll be possible to re-enable - * debug mode if any events were added. - */ -void event_disable_debug_mode(void); - +EVENT2_EXPORT_SYMBOL +void event_base_assert_ok_(struct event_base *base); +void event_base_assert_ok_nolock_(struct event_base *base); + + +/* Helper function: Call 'fn' exactly once every inserted or active event in + * the event_base 'base'. + * + * If fn returns 0, continue on to the next event. Otherwise, return the same + * value that fn returned. + * + * Requires that 'base' be locked. + */ +int event_base_foreach_event_nolock_(struct event_base *base, + event_base_foreach_event_cb cb, void *arg); + +/* Cleanup function to reset debug mode during shutdown. + * + * Calling this function doesn't mean it'll be possible to re-enable + * debug mode if any events were added. + */ +void event_disable_debug_mode(void); + #ifdef __cplusplus } #endif -#endif /* EVENT_INTERNAL_H_INCLUDED_ */ +#endif /* EVENT_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/event.c b/contrib/libs/libevent/event.c index 7a42b73191..fe147e54a2 100644 --- a/contrib/libs/libevent/event.c +++ b/contrib/libs/libevent/event.c @@ -25,25 +25,25 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #undef WIN32_LEAN_AND_MEAN #endif #include <sys/types.h> -#if !defined(_WIN32) && defined(EVENT__HAVE_SYS_TIME_H) +#if !defined(_WIN32) && defined(EVENT__HAVE_SYS_TIME_H) #include <sys/time.h> #endif #include <sys/queue.h> -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #include <stdio.h> #include <stdlib.h> -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif #include <ctype.h> @@ -51,10 +51,10 @@ #include <signal.h> #include <string.h> #include <time.h> -#include <limits.h> -#ifdef EVENT__HAVE_FCNTL_H -#include <fcntl.h> -#endif +#include <limits.h> +#ifdef EVENT__HAVE_FCNTL_H +#include <fcntl.h> +#endif #include "event2/event.h" #include "event2/event_struct.h" @@ -68,91 +68,91 @@ #include "evmap-internal.h" #include "iocp-internal.h" #include "changelist-internal.h" -#define HT_NO_CACHE_HASH_VALUES +#define HT_NO_CACHE_HASH_VALUES #include "ht-internal.h" #include "util-internal.h" - -#ifdef EVENT__HAVE_WORKING_KQUEUE -#include "kqueue-internal.h" -#endif - -#ifdef EVENT__HAVE_EVENT_PORTS + +#ifdef EVENT__HAVE_WORKING_KQUEUE +#include "kqueue-internal.h" +#endif + +#ifdef EVENT__HAVE_EVENT_PORTS extern const struct eventop evportops; #endif -#ifdef EVENT__HAVE_SELECT +#ifdef EVENT__HAVE_SELECT extern const struct eventop selectops; #endif -#ifdef EVENT__HAVE_POLL +#ifdef EVENT__HAVE_POLL extern const struct eventop pollops; #endif -#ifdef EVENT__HAVE_EPOLL +#ifdef EVENT__HAVE_EPOLL extern const struct eventop epollops; #endif -#ifdef EVENT__HAVE_WORKING_KQUEUE +#ifdef EVENT__HAVE_WORKING_KQUEUE extern const struct eventop kqops; #endif -#ifdef EVENT__HAVE_DEVPOLL +#ifdef EVENT__HAVE_DEVPOLL extern const struct eventop devpollops; #endif -#ifdef _WIN32 +#ifdef _WIN32 extern const struct eventop win32ops; #endif /* Array of backends in order of preference. */ static const struct eventop *eventops[] = { -#ifdef EVENT__HAVE_EVENT_PORTS +#ifdef EVENT__HAVE_EVENT_PORTS &evportops, #endif -#ifdef EVENT__HAVE_WORKING_KQUEUE +#ifdef EVENT__HAVE_WORKING_KQUEUE &kqops, #endif -#ifdef EVENT__HAVE_EPOLL +#ifdef EVENT__HAVE_EPOLL &epollops, #endif -#ifdef EVENT__HAVE_DEVPOLL +#ifdef EVENT__HAVE_DEVPOLL &devpollops, #endif -#ifdef EVENT__HAVE_POLL +#ifdef EVENT__HAVE_POLL &pollops, #endif -#ifdef EVENT__HAVE_SELECT +#ifdef EVENT__HAVE_SELECT &selectops, #endif -#ifdef _WIN32 +#ifdef _WIN32 &win32ops, #endif NULL }; /* Global state; deprecated */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *event_global_current_base_ = NULL; #define current_base event_global_current_base_ /* Global state */ -static void *event_self_cbarg_ptr_ = NULL; +static void *event_self_cbarg_ptr_ = NULL; /* Prototypes */ -static void event_queue_insert_active(struct event_base *, struct event_callback *); -static void event_queue_insert_active_later(struct event_base *, struct event_callback *); -static void event_queue_insert_timeout(struct event_base *, struct event *); -static void event_queue_insert_inserted(struct event_base *, struct event *); -static void event_queue_remove_active(struct event_base *, struct event_callback *); -static void event_queue_remove_active_later(struct event_base *, struct event_callback *); -static void event_queue_remove_timeout(struct event_base *, struct event *); -static void event_queue_remove_inserted(struct event_base *, struct event *); -static void event_queue_make_later_events_active(struct event_base *base); - -static int evthread_make_base_notifiable_nolock_(struct event_base *base); -static int event_del_(struct event *ev, int blocking); - -#ifdef USE_REINSERT_TIMEOUT -/* This code seems buggy; only turn it on if we find out what the trouble is. */ -static void event_queue_reinsert_timeout(struct event_base *,struct event *, int was_common, int is_common, int old_timeout_idx); -#endif - +static void event_queue_insert_active(struct event_base *, struct event_callback *); +static void event_queue_insert_active_later(struct event_base *, struct event_callback *); +static void event_queue_insert_timeout(struct event_base *, struct event *); +static void event_queue_insert_inserted(struct event_base *, struct event *); +static void event_queue_remove_active(struct event_base *, struct event_callback *); +static void event_queue_remove_active_later(struct event_base *, struct event_callback *); +static void event_queue_remove_timeout(struct event_base *, struct event *); +static void event_queue_remove_inserted(struct event_base *, struct event *); +static void event_queue_make_later_events_active(struct event_base *base); + +static int evthread_make_base_notifiable_nolock_(struct event_base *base); +static int event_del_(struct event *ev, int blocking); + +#ifdef USE_REINSERT_TIMEOUT +/* This code seems buggy; only turn it on if we find out what the trouble is. */ +static void event_queue_reinsert_timeout(struct event_base *,struct event *, int was_common, int is_common, int old_timeout_idx); +#endif + static int event_haveevents(struct event_base *); static int event_process_active(struct event_base *); @@ -165,10 +165,10 @@ static inline void event_persist_closure(struct event_base *, struct event *ev); static int evthread_notify_base(struct event_base *base); -static void insert_common_timeout_inorder(struct common_timeout_list *ctl, - struct event *ev); - -#ifndef EVENT__DISABLE_DEBUG_MODE +static void insert_common_timeout_inorder(struct common_timeout_list *ctl, + struct event *ev); + +#ifndef EVENT__DISABLE_DEBUG_MODE /* These functions implement a hashtable of which 'struct event *' structures * have been setup or added. We don't want to trust the content of the struct * event itself, since we're trying to work through cases where an event gets @@ -202,27 +202,27 @@ eq_debug_entry(const struct event_debug_entry *a, return a->ptr == b->ptr; } -int event_debug_mode_on_ = 0; - - -#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && !defined(EVENT__DISABLE_DEBUG_MODE) -/** - * @brief debug mode variable which is set for any function/structure that needs - * to be shared across threads (if thread support is enabled). - * - * When and if evthreads are initialized, this variable will be evaluated, - * and if set to something other than zero, this means the evthread setup - * functions were called out of order. - * - * See: "Locks and threading" in the documentation. - */ -int event_debug_created_threadable_ctx_ = 0; -#endif - +int event_debug_mode_on_ = 0; + + +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && !defined(EVENT__DISABLE_DEBUG_MODE) +/** + * @brief debug mode variable which is set for any function/structure that needs + * to be shared across threads (if thread support is enabled). + * + * When and if evthreads are initialized, this variable will be evaluated, + * and if set to something other than zero, this means the evthread setup + * functions were called out of order. + * + * See: "Locks and threading" in the documentation. + */ +int event_debug_created_threadable_ctx_ = 0; +#endif + /* Set if it's too late to enable event_debug_mode. */ static int event_debug_mode_too_late = 0; -#ifndef EVENT__DISABLE_THREAD_SUPPORT -static void *event_debug_map_lock_ = NULL; +#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void *event_debug_map_lock_ = NULL; #endif static HT_HEAD(event_debug_map, event_debug_entry) global_debug_map = HT_INITIALIZER(); @@ -232,177 +232,177 @@ HT_PROTOTYPE(event_debug_map, event_debug_entry, node, hash_debug_entry, HT_GENERATE(event_debug_map, event_debug_entry, node, hash_debug_entry, eq_debug_entry, 0.5, mm_malloc, mm_realloc, mm_free) -/* record that ev is now setup (that is, ready for an add) */ -static void event_debug_note_setup_(const struct event *ev) -{ - struct event_debug_entry *dent, find; - - if (!event_debug_mode_on_) - goto out; - - find.ptr = ev; - EVLOCK_LOCK(event_debug_map_lock_, 0); - dent = HT_FIND(event_debug_map, &global_debug_map, &find); - if (dent) { - dent->added = 0; - } else { - dent = mm_malloc(sizeof(*dent)); - if (!dent) - event_err(1, - "Out of memory in debugging code"); - dent->ptr = ev; - dent->added = 0; - HT_INSERT(event_debug_map, &global_debug_map, dent); - } - EVLOCK_UNLOCK(event_debug_map_lock_, 0); - -out: - event_debug_mode_too_late = 1; -} -/* record that ev is no longer setup */ -static void event_debug_note_teardown_(const struct event *ev) -{ - struct event_debug_entry *dent, find; - - if (!event_debug_mode_on_) - goto out; - - find.ptr = ev; - EVLOCK_LOCK(event_debug_map_lock_, 0); - dent = HT_REMOVE(event_debug_map, &global_debug_map, &find); - if (dent) - mm_free(dent); - EVLOCK_UNLOCK(event_debug_map_lock_, 0); - -out: - event_debug_mode_too_late = 1; -} +/* record that ev is now setup (that is, ready for an add) */ +static void event_debug_note_setup_(const struct event *ev) +{ + struct event_debug_entry *dent, find; + + if (!event_debug_mode_on_) + goto out; + + find.ptr = ev; + EVLOCK_LOCK(event_debug_map_lock_, 0); + dent = HT_FIND(event_debug_map, &global_debug_map, &find); + if (dent) { + dent->added = 0; + } else { + dent = mm_malloc(sizeof(*dent)); + if (!dent) + event_err(1, + "Out of memory in debugging code"); + dent->ptr = ev; + dent->added = 0; + HT_INSERT(event_debug_map, &global_debug_map, dent); + } + EVLOCK_UNLOCK(event_debug_map_lock_, 0); + +out: + event_debug_mode_too_late = 1; +} +/* record that ev is no longer setup */ +static void event_debug_note_teardown_(const struct event *ev) +{ + struct event_debug_entry *dent, find; + + if (!event_debug_mode_on_) + goto out; + + find.ptr = ev; + EVLOCK_LOCK(event_debug_map_lock_, 0); + dent = HT_REMOVE(event_debug_map, &global_debug_map, &find); + if (dent) + mm_free(dent); + EVLOCK_UNLOCK(event_debug_map_lock_, 0); + +out: + event_debug_mode_too_late = 1; +} /* Macro: record that ev is now added */ -static void event_debug_note_add_(const struct event *ev) -{ - struct event_debug_entry *dent,find; - - if (!event_debug_mode_on_) - goto out; - - find.ptr = ev; - EVLOCK_LOCK(event_debug_map_lock_, 0); - dent = HT_FIND(event_debug_map, &global_debug_map, &find); - if (dent) { - dent->added = 1; - } else { - event_errx(EVENT_ERR_ABORT_, - "%s: noting an add on a non-setup event %p" - " (events: 0x%x, fd: "EV_SOCK_FMT - ", flags: 0x%x)", - __func__, ev, ev->ev_events, - EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); - } - EVLOCK_UNLOCK(event_debug_map_lock_, 0); - -out: - event_debug_mode_too_late = 1; -} -/* record that ev is no longer added */ -static void event_debug_note_del_(const struct event *ev) -{ - struct event_debug_entry *dent, find; - - if (!event_debug_mode_on_) - goto out; - - find.ptr = ev; - EVLOCK_LOCK(event_debug_map_lock_, 0); - dent = HT_FIND(event_debug_map, &global_debug_map, &find); - if (dent) { - dent->added = 0; - } else { - event_errx(EVENT_ERR_ABORT_, - "%s: noting a del on a non-setup event %p" - " (events: 0x%x, fd: "EV_SOCK_FMT - ", flags: 0x%x)", - __func__, ev, ev->ev_events, - EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); - } - EVLOCK_UNLOCK(event_debug_map_lock_, 0); - -out: - event_debug_mode_too_late = 1; -} -/* assert that ev is setup (i.e., okay to add or inspect) */ -static void event_debug_assert_is_setup_(const struct event *ev) -{ - struct event_debug_entry *dent, find; - - if (!event_debug_mode_on_) +static void event_debug_note_add_(const struct event *ev) +{ + struct event_debug_entry *dent,find; + + if (!event_debug_mode_on_) + goto out; + + find.ptr = ev; + EVLOCK_LOCK(event_debug_map_lock_, 0); + dent = HT_FIND(event_debug_map, &global_debug_map, &find); + if (dent) { + dent->added = 1; + } else { + event_errx(EVENT_ERR_ABORT_, + "%s: noting an add on a non-setup event %p" + " (events: 0x%x, fd: "EV_SOCK_FMT + ", flags: 0x%x)", + __func__, ev, ev->ev_events, + EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); + } + EVLOCK_UNLOCK(event_debug_map_lock_, 0); + +out: + event_debug_mode_too_late = 1; +} +/* record that ev is no longer added */ +static void event_debug_note_del_(const struct event *ev) +{ + struct event_debug_entry *dent, find; + + if (!event_debug_mode_on_) + goto out; + + find.ptr = ev; + EVLOCK_LOCK(event_debug_map_lock_, 0); + dent = HT_FIND(event_debug_map, &global_debug_map, &find); + if (dent) { + dent->added = 0; + } else { + event_errx(EVENT_ERR_ABORT_, + "%s: noting a del on a non-setup event %p" + " (events: 0x%x, fd: "EV_SOCK_FMT + ", flags: 0x%x)", + __func__, ev, ev->ev_events, + EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); + } + EVLOCK_UNLOCK(event_debug_map_lock_, 0); + +out: + event_debug_mode_too_late = 1; +} +/* assert that ev is setup (i.e., okay to add or inspect) */ +static void event_debug_assert_is_setup_(const struct event *ev) +{ + struct event_debug_entry *dent, find; + + if (!event_debug_mode_on_) return; - find.ptr = ev; - EVLOCK_LOCK(event_debug_map_lock_, 0); - dent = HT_FIND(event_debug_map, &global_debug_map, &find); - if (!dent) { - event_errx(EVENT_ERR_ABORT_, - "%s called on a non-initialized event %p" - " (events: 0x%x, fd: "EV_SOCK_FMT - ", flags: 0x%x)", - __func__, ev, ev->ev_events, - EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); - } - EVLOCK_UNLOCK(event_debug_map_lock_, 0); -} -/* assert that ev is not added (i.e., okay to tear down or set up again) */ -static void event_debug_assert_not_added_(const struct event *ev) -{ - struct event_debug_entry *dent, find; - - if (!event_debug_mode_on_) - return; - - find.ptr = ev; - EVLOCK_LOCK(event_debug_map_lock_, 0); - dent = HT_FIND(event_debug_map, &global_debug_map, &find); - if (dent && dent->added) { - event_errx(EVENT_ERR_ABORT_, - "%s called on an already added event %p" - " (events: 0x%x, fd: "EV_SOCK_FMT", " - "flags: 0x%x)", - __func__, ev, ev->ev_events, - EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); - } - EVLOCK_UNLOCK(event_debug_map_lock_, 0); -} -static void event_debug_assert_socket_nonblocking_(evutil_socket_t fd) -{ - if (!event_debug_mode_on_) - return; - if (fd < 0) - return; - -#ifndef _WIN32 - { - int flags; - if ((flags = fcntl(fd, F_GETFL, NULL)) >= 0) { - EVUTIL_ASSERT(flags & O_NONBLOCK); - } - } + find.ptr = ev; + EVLOCK_LOCK(event_debug_map_lock_, 0); + dent = HT_FIND(event_debug_map, &global_debug_map, &find); + if (!dent) { + event_errx(EVENT_ERR_ABORT_, + "%s called on a non-initialized event %p" + " (events: 0x%x, fd: "EV_SOCK_FMT + ", flags: 0x%x)", + __func__, ev, ev->ev_events, + EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); + } + EVLOCK_UNLOCK(event_debug_map_lock_, 0); +} +/* assert that ev is not added (i.e., okay to tear down or set up again) */ +static void event_debug_assert_not_added_(const struct event *ev) +{ + struct event_debug_entry *dent, find; + + if (!event_debug_mode_on_) + return; + + find.ptr = ev; + EVLOCK_LOCK(event_debug_map_lock_, 0); + dent = HT_FIND(event_debug_map, &global_debug_map, &find); + if (dent && dent->added) { + event_errx(EVENT_ERR_ABORT_, + "%s called on an already added event %p" + " (events: 0x%x, fd: "EV_SOCK_FMT", " + "flags: 0x%x)", + __func__, ev, ev->ev_events, + EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); + } + EVLOCK_UNLOCK(event_debug_map_lock_, 0); +} +static void event_debug_assert_socket_nonblocking_(evutil_socket_t fd) +{ + if (!event_debug_mode_on_) + return; + if (fd < 0) + return; + +#ifndef _WIN32 + { + int flags; + if ((flags = fcntl(fd, F_GETFL, NULL)) >= 0) { + EVUTIL_ASSERT(flags & O_NONBLOCK); + } + } #endif } -#else -static void event_debug_note_setup_(const struct event *ev) { (void)ev; } -static void event_debug_note_teardown_(const struct event *ev) { (void)ev; } -static void event_debug_note_add_(const struct event *ev) { (void)ev; } -static void event_debug_note_del_(const struct event *ev) { (void)ev; } -static void event_debug_assert_is_setup_(const struct event *ev) { (void)ev; } -static void event_debug_assert_not_added_(const struct event *ev) { (void)ev; } -static void event_debug_assert_socket_nonblocking_(evutil_socket_t fd) { (void)fd; } -#endif - -#define EVENT_BASE_ASSERT_LOCKED(base) \ - EVLOCK_ASSERT_LOCKED((base)->th_base_lock) - +#else +static void event_debug_note_setup_(const struct event *ev) { (void)ev; } +static void event_debug_note_teardown_(const struct event *ev) { (void)ev; } +static void event_debug_note_add_(const struct event *ev) { (void)ev; } +static void event_debug_note_del_(const struct event *ev) { (void)ev; } +static void event_debug_assert_is_setup_(const struct event *ev) { (void)ev; } +static void event_debug_assert_not_added_(const struct event *ev) { (void)ev; } +static void event_debug_assert_socket_nonblocking_(evutil_socket_t fd) { (void)fd; } +#endif + +#define EVENT_BASE_ASSERT_LOCKED(base) \ + EVLOCK_ASSERT_LOCKED((base)->th_base_lock) + /* How often (in seconds) do we check for changes in wall clock time relative * to monotonic time? Set this to -1 for 'never.' */ -#define CLOCK_SYNC_INTERVAL 5 +#define CLOCK_SYNC_INTERVAL 5 /** Set 'tp' to the current time according to 'base'. We must hold the lock * on 'base'. If there is a cached time, return it. Otherwise, use @@ -419,19 +419,19 @@ gettime(struct event_base *base, struct timeval *tp) return (0); } - if (evutil_gettime_monotonic_(&base->monotonic_timer, tp) == -1) { - return -1; - } + if (evutil_gettime_monotonic_(&base->monotonic_timer, tp) == -1) { + return -1; + } - if (base->last_updated_clock_diff + CLOCK_SYNC_INTERVAL - < tp->tv_sec) { - struct timeval tv; - evutil_gettimeofday(&tv,NULL); - evutil_timersub(&tv, tp, &base->tv_clock_diff); - base->last_updated_clock_diff = tp->tv_sec; + if (base->last_updated_clock_diff + CLOCK_SYNC_INTERVAL + < tp->tv_sec) { + struct timeval tv; + evutil_gettimeofday(&tv,NULL); + evutil_timersub(&tv, tp, &base->tv_clock_diff); + base->last_updated_clock_diff = tp->tv_sec; } - return 0; + return 0; } int @@ -471,36 +471,36 @@ update_time_cache(struct event_base *base) gettime(base, &base->tv_cache); } -int -event_base_update_cache_time(struct event_base *base) -{ - - if (!base) { - base = current_base; - if (!current_base) - return -1; - } - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - if (base->running_loop) - update_time_cache(base); - EVBASE_RELEASE_LOCK(base, th_base_lock); - return 0; -} - -static inline struct event * -event_callback_to_event(struct event_callback *evcb) -{ - EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_INIT)); - return EVUTIL_UPCAST(evcb, struct event, ev_evcallback); -} - -static inline struct event_callback * -event_to_event_callback(struct event *ev) -{ - return &ev->ev_evcallback; -} - +int +event_base_update_cache_time(struct event_base *base) +{ + + if (!base) { + base = current_base; + if (!current_base) + return -1; + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (base->running_loop) + update_time_cache(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return 0; +} + +static inline struct event * +event_callback_to_event(struct event_callback *evcb) +{ + EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_INIT)); + return EVUTIL_UPCAST(evcb, struct event, ev_evcallback); +} + +static inline struct event_callback * +event_to_event_callback(struct event *ev) +{ + return &ev->ev_evcallback; +} + struct event_base * event_init(void) { @@ -554,10 +554,10 @@ event_is_method_disabled(const char *name) evutil_snprintf(environment, sizeof(environment), "EVENT_NO%s", name); for (i = 8; environment[i] != '\0'; ++i) - environment[i] = EVUTIL_TOUPPER_(environment[i]); - /* Note that evutil_getenv_() ignores the environment entirely if + environment[i] = EVUTIL_TOUPPER_(environment[i]); + /* Note that evutil_getenv_() ignores the environment entirely if * we're setuid */ - return (evutil_getenv_(environment) != NULL); + return (evutil_getenv_(environment) != NULL); } int @@ -569,14 +569,14 @@ event_base_get_features(const struct event_base *base) void event_enable_debug_mode(void) { -#ifndef EVENT__DISABLE_DEBUG_MODE - if (event_debug_mode_on_) +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) event_errx(1, "%s was called twice!", __func__); if (event_debug_mode_too_late) event_errx(1, "%s must be called *before* creating any events " "or event_bases",__func__); - event_debug_mode_on_ = 1; + event_debug_mode_on_ = 1; HT_INIT(event_debug_map, &global_debug_map); #endif @@ -585,20 +585,20 @@ event_enable_debug_mode(void) void event_disable_debug_mode(void) { -#ifndef EVENT__DISABLE_DEBUG_MODE +#ifndef EVENT__DISABLE_DEBUG_MODE struct event_debug_entry **ent, *victim; - EVLOCK_LOCK(event_debug_map_lock_, 0); + EVLOCK_LOCK(event_debug_map_lock_, 0); for (ent = HT_START(event_debug_map, &global_debug_map); ent; ) { victim = *ent; - ent = HT_NEXT_RMV(event_debug_map, &global_debug_map, ent); + ent = HT_NEXT_RMV(event_debug_map, &global_debug_map, ent); mm_free(victim); } HT_CLEAR(event_debug_map, &global_debug_map); - EVLOCK_UNLOCK(event_debug_map_lock_ , 0); - - event_debug_mode_on_ = 0; -#endif + EVLOCK_UNLOCK(event_debug_map_lock_ , 0); + + event_debug_mode_on_ = 0; +#endif } struct event_base * @@ -608,7 +608,7 @@ event_base_new_with_config(const struct event_config *cfg) struct event_base *base; int should_check_environment; -#ifndef EVENT__DISABLE_DEBUG_MODE +#ifndef EVENT__DISABLE_DEBUG_MODE event_debug_mode_too_late = 1; #endif @@ -617,61 +617,61 @@ event_base_new_with_config(const struct event_config *cfg) return NULL; } - if (cfg) - base->flags = cfg->flags; - - should_check_environment = - !(cfg && (cfg->flags & EVENT_BASE_FLAG_IGNORE_ENV)); - - { - struct timeval tmp; - int precise_time = - cfg && (cfg->flags & EVENT_BASE_FLAG_PRECISE_TIMER); - int flags; - if (should_check_environment && !precise_time) { - precise_time = evutil_getenv_("EVENT_PRECISE_TIMER") != NULL; - if (precise_time) { - base->flags |= EVENT_BASE_FLAG_PRECISE_TIMER; - } - } - flags = precise_time ? EV_MONOT_PRECISE : 0; - evutil_configure_monotonic_time_(&base->monotonic_timer, flags); - - gettime(base, &tmp); - } - - min_heap_ctor_(&base->timeheap); - + if (cfg) + base->flags = cfg->flags; + + should_check_environment = + !(cfg && (cfg->flags & EVENT_BASE_FLAG_IGNORE_ENV)); + + { + struct timeval tmp; + int precise_time = + cfg && (cfg->flags & EVENT_BASE_FLAG_PRECISE_TIMER); + int flags; + if (should_check_environment && !precise_time) { + precise_time = evutil_getenv_("EVENT_PRECISE_TIMER") != NULL; + if (precise_time) { + base->flags |= EVENT_BASE_FLAG_PRECISE_TIMER; + } + } + flags = precise_time ? EV_MONOT_PRECISE : 0; + evutil_configure_monotonic_time_(&base->monotonic_timer, flags); + + gettime(base, &tmp); + } + + min_heap_ctor_(&base->timeheap); + base->sig.ev_signal_pair[0] = -1; base->sig.ev_signal_pair[1] = -1; base->th_notify_fd[0] = -1; base->th_notify_fd[1] = -1; - TAILQ_INIT(&base->active_later_queue); + TAILQ_INIT(&base->active_later_queue); - evmap_io_initmap_(&base->io); - evmap_signal_initmap_(&base->sigmap); - event_changelist_init_(&base->changelist); + evmap_io_initmap_(&base->io); + evmap_signal_initmap_(&base->sigmap); + event_changelist_init_(&base->changelist); base->evbase = NULL; - if (cfg) { - memcpy(&base->max_dispatch_time, - &cfg->max_dispatch_interval, sizeof(struct timeval)); - base->limit_callbacks_after_prio = - cfg->limit_callbacks_after_prio; - } else { - base->max_dispatch_time.tv_sec = -1; - base->limit_callbacks_after_prio = 1; - } - if (cfg && cfg->max_dispatch_callbacks >= 0) { - base->max_dispatch_callbacks = cfg->max_dispatch_callbacks; - } else { - base->max_dispatch_callbacks = INT_MAX; - } - if (base->max_dispatch_callbacks == INT_MAX && - base->max_dispatch_time.tv_sec == -1) - base->limit_callbacks_after_prio = INT_MAX; + if (cfg) { + memcpy(&base->max_dispatch_time, + &cfg->max_dispatch_interval, sizeof(struct timeval)); + base->limit_callbacks_after_prio = + cfg->limit_callbacks_after_prio; + } else { + base->max_dispatch_time.tv_sec = -1; + base->limit_callbacks_after_prio = 1; + } + if (cfg && cfg->max_dispatch_callbacks >= 0) { + base->max_dispatch_callbacks = cfg->max_dispatch_callbacks; + } else { + base->max_dispatch_callbacks = INT_MAX; + } + if (base->max_dispatch_callbacks == INT_MAX && + base->max_dispatch_time.tv_sec == -1) + base->limit_callbacks_after_prio = INT_MAX; for (i = 0; eventops[i] && !base->evbase; i++) { if (cfg != NULL) { @@ -702,7 +702,7 @@ event_base_new_with_config(const struct event_config *cfg) return NULL; } - if (evutil_getenv_("EVENT_SHOW_METHOD")) + if (evutil_getenv_("EVENT_SHOW_METHOD")) event_msgx("libevent using: %s", base->evsel->name); /* allocate a single active event queue */ @@ -713,15 +713,15 @@ event_base_new_with_config(const struct event_config *cfg) /* prepare for threading */ -#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && !defined(EVENT__DISABLE_DEBUG_MODE) - event_debug_created_threadable_ctx_ = 1; -#endif - -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && !defined(EVENT__DISABLE_DEBUG_MODE) + event_debug_created_threadable_ctx_ = 1; +#endif + +#ifndef EVENT__DISABLE_THREAD_SUPPORT if (EVTHREAD_LOCKING_ENABLED() && (!cfg || !(cfg->flags & EVENT_BASE_FLAG_NOLOCK))) { int r; - EVTHREAD_ALLOC_LOCK(base->th_base_lock, 0); + EVTHREAD_ALLOC_LOCK(base->th_base_lock, 0); EVTHREAD_ALLOC_COND(base->current_event_cond); r = evthread_make_base_notifiable(base); if (r<0) { @@ -732,21 +732,21 @@ event_base_new_with_config(const struct event_config *cfg) } #endif -#ifdef _WIN32 +#ifdef _WIN32 if (cfg && (cfg->flags & EVENT_BASE_FLAG_STARTUP_IOCP)) - event_base_start_iocp_(base, cfg->n_cpus_hint); + event_base_start_iocp_(base, cfg->n_cpus_hint); #endif return (base); } int -event_base_start_iocp_(struct event_base *base, int n_cpus) +event_base_start_iocp_(struct event_base *base, int n_cpus) { -#ifdef _WIN32 +#ifdef _WIN32 if (base->iocp) return 0; - base->iocp = event_iocp_port_launch_(n_cpus); + base->iocp = event_iocp_port_launch_(n_cpus); if (!base->iocp) { event_warnx("%s: Couldn't launch IOCP", __func__); return -1; @@ -758,85 +758,85 @@ event_base_start_iocp_(struct event_base *base, int n_cpus) } void -event_base_stop_iocp_(struct event_base *base) +event_base_stop_iocp_(struct event_base *base) { -#ifdef _WIN32 +#ifdef _WIN32 int rv; if (!base->iocp) return; - rv = event_iocp_shutdown_(base->iocp, -1); + rv = event_iocp_shutdown_(base->iocp, -1); EVUTIL_ASSERT(rv >= 0); base->iocp = NULL; #endif } -static int -event_base_cancel_single_callback_(struct event_base *base, - struct event_callback *evcb, - int run_finalizers) -{ - int result = 0; - - if (evcb->evcb_flags & EVLIST_INIT) { - struct event *ev = event_callback_to_event(evcb); - if (!(ev->ev_flags & EVLIST_INTERNAL)) { - event_del_(ev, EVENT_DEL_EVEN_IF_FINALIZING); - result = 1; - } - } else { - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - event_callback_cancel_nolock_(base, evcb, 1); - EVBASE_RELEASE_LOCK(base, th_base_lock); - result = 1; - } - - if (run_finalizers && (evcb->evcb_flags & EVLIST_FINALIZING)) { - switch (evcb->evcb_closure) { - case EV_CLOSURE_EVENT_FINALIZE: - case EV_CLOSURE_EVENT_FINALIZE_FREE: { - struct event *ev = event_callback_to_event(evcb); - ev->ev_evcallback.evcb_cb_union.evcb_evfinalize(ev, ev->ev_arg); - if (evcb->evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE) - mm_free(ev); - break; - } - case EV_CLOSURE_CB_FINALIZE: - evcb->evcb_cb_union.evcb_cbfinalize(evcb, evcb->evcb_arg); - break; - default: - break; - } - } - return result; -} - -static int event_base_free_queues_(struct event_base *base, int run_finalizers) -{ - int deleted = 0, i; - - for (i = 0; i < base->nactivequeues; ++i) { - struct event_callback *evcb, *next; - for (evcb = TAILQ_FIRST(&base->activequeues[i]); evcb; ) { - next = TAILQ_NEXT(evcb, evcb_active_next); - deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); - evcb = next; - } - } - - { - struct event_callback *evcb; - while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { - deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); - } - } - - return deleted; -} - -static void -event_base_free_(struct event_base *base, int run_finalizers) -{ +static int +event_base_cancel_single_callback_(struct event_base *base, + struct event_callback *evcb, + int run_finalizers) +{ + int result = 0; + + if (evcb->evcb_flags & EVLIST_INIT) { + struct event *ev = event_callback_to_event(evcb); + if (!(ev->ev_flags & EVLIST_INTERNAL)) { + event_del_(ev, EVENT_DEL_EVEN_IF_FINALIZING); + result = 1; + } + } else { + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + event_callback_cancel_nolock_(base, evcb, 1); + EVBASE_RELEASE_LOCK(base, th_base_lock); + result = 1; + } + + if (run_finalizers && (evcb->evcb_flags & EVLIST_FINALIZING)) { + switch (evcb->evcb_closure) { + case EV_CLOSURE_EVENT_FINALIZE: + case EV_CLOSURE_EVENT_FINALIZE_FREE: { + struct event *ev = event_callback_to_event(evcb); + ev->ev_evcallback.evcb_cb_union.evcb_evfinalize(ev, ev->ev_arg); + if (evcb->evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE) + mm_free(ev); + break; + } + case EV_CLOSURE_CB_FINALIZE: + evcb->evcb_cb_union.evcb_cbfinalize(evcb, evcb->evcb_arg); + break; + default: + break; + } + } + return result; +} + +static int event_base_free_queues_(struct event_base *base, int run_finalizers) +{ + int deleted = 0, i; + + for (i = 0; i < base->nactivequeues; ++i) { + struct event_callback *evcb, *next; + for (evcb = TAILQ_FIRST(&base->activequeues[i]); evcb; ) { + next = TAILQ_NEXT(evcb, evcb_active_next); + deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); + evcb = next; + } + } + + { + struct event_callback *evcb; + while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { + deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); + } + } + + return deleted; +} + +static void +event_base_free_(struct event_base *base, int run_finalizers) +{ int i, n_deleted=0; struct event *ev; /* XXXX grab the lock? If there is contention when one thread frees @@ -853,8 +853,8 @@ event_base_free_(struct event_base *base, int run_finalizers) } /* XXX(niels) - check for internal events first */ -#ifdef _WIN32 - event_base_stop_iocp_(base); +#ifdef _WIN32 + event_base_stop_iocp_(base); #endif /* threading fds if we have them */ @@ -869,9 +869,9 @@ event_base_free_(struct event_base *base, int run_finalizers) } /* Delete all non-internal events. */ - evmap_delete_all_(base); - - while ((ev = min_heap_top_(&base->timeheap)) != NULL) { + evmap_delete_all_(base); + + while ((ev = min_heap_top_(&base->timeheap)) != NULL) { event_del(ev); ++n_deleted; } @@ -894,88 +894,88 @@ event_base_free_(struct event_base *base, int run_finalizers) if (base->common_timeout_queues) mm_free(base->common_timeout_queues); - for (;;) { - /* For finalizers we can register yet another finalizer out from - * finalizer, and iff finalizer will be in active_later_queue we can - * add finalizer to activequeues, and we will have events in - * activequeues after this function returns, which is not what we want - * (we even have an assertion for this). - * - * A simple case is bufferevent with underlying (i.e. filters). - */ - int i = event_base_free_queues_(base, run_finalizers); - event_debug(("%s: %d events freed", __func__, i)); - if (!i) { - break; + for (;;) { + /* For finalizers we can register yet another finalizer out from + * finalizer, and iff finalizer will be in active_later_queue we can + * add finalizer to activequeues, and we will have events in + * activequeues after this function returns, which is not what we want + * (we even have an assertion for this). + * + * A simple case is bufferevent with underlying (i.e. filters). + */ + int i = event_base_free_queues_(base, run_finalizers); + event_debug(("%s: %d events freed", __func__, i)); + if (!i) { + break; } - n_deleted += i; + n_deleted += i; } if (n_deleted) event_debug(("%s: %d events were still set in base", __func__, n_deleted)); - while (LIST_FIRST(&base->once_events)) { - struct event_once *eonce = LIST_FIRST(&base->once_events); - LIST_REMOVE(eonce, next_once); - mm_free(eonce); - } - + while (LIST_FIRST(&base->once_events)) { + struct event_once *eonce = LIST_FIRST(&base->once_events); + LIST_REMOVE(eonce, next_once); + mm_free(eonce); + } + if (base->evsel != NULL && base->evsel->dealloc != NULL) base->evsel->dealloc(base); for (i = 0; i < base->nactivequeues; ++i) EVUTIL_ASSERT(TAILQ_EMPTY(&base->activequeues[i])); - EVUTIL_ASSERT(min_heap_empty_(&base->timeheap)); - min_heap_dtor_(&base->timeheap); + EVUTIL_ASSERT(min_heap_empty_(&base->timeheap)); + min_heap_dtor_(&base->timeheap); mm_free(base->activequeues); - evmap_io_clear_(&base->io); - evmap_signal_clear_(&base->sigmap); - event_changelist_freemem_(&base->changelist); + evmap_io_clear_(&base->io); + evmap_signal_clear_(&base->sigmap); + event_changelist_freemem_(&base->changelist); - EVTHREAD_FREE_LOCK(base->th_base_lock, 0); + EVTHREAD_FREE_LOCK(base->th_base_lock, 0); EVTHREAD_FREE_COND(base->current_event_cond); - /* If we're freeing current_base, there won't be a current_base. */ - if (base == current_base) - current_base = NULL; + /* If we're freeing current_base, there won't be a current_base. */ + if (base == current_base) + current_base = NULL; mm_free(base); } -void -event_base_free_nofinalize(struct event_base *base) -{ - event_base_free_(base, 0); -} - -void -event_base_free(struct event_base *base) -{ - event_base_free_(base, 1); -} - -/* Fake eventop; used to disable the backend temporarily inside event_reinit - * so that we can call event_del() on an event without telling the backend. - */ -static int -nil_backend_del(struct event_base *b, evutil_socket_t fd, short old, - short events, void *fdinfo) -{ - return 0; -} -const struct eventop nil_eventop = { - "nil", - NULL, /* init: unused. */ - NULL, /* add: unused. */ - nil_backend_del, /* del: used, so needs to be killed. */ - NULL, /* dispatch: unused. */ - NULL, /* dealloc: unused. */ - 0, 0, 0 -}; - +void +event_base_free_nofinalize(struct event_base *base) +{ + event_base_free_(base, 0); +} + +void +event_base_free(struct event_base *base) +{ + event_base_free_(base, 1); +} + +/* Fake eventop; used to disable the backend temporarily inside event_reinit + * so that we can call event_del() on an event without telling the backend. + */ +static int +nil_backend_del(struct event_base *b, evutil_socket_t fd, short old, + short events, void *fdinfo) +{ + return 0; +} +const struct eventop nil_eventop = { + "nil", + NULL, /* init: unused. */ + NULL, /* add: unused. */ + nil_backend_del, /* del: used, so needs to be killed. */ + NULL, /* dispatch: unused. */ + NULL, /* dealloc: unused. */ + 0, 0, 0 +}; + /* reinitialize the event base after a fork */ int event_reinit(struct event_base *base) @@ -983,48 +983,48 @@ event_reinit(struct event_base *base) const struct eventop *evsel; int res = 0; int was_notifiable = 0; - int had_signal_added = 0; + int had_signal_added = 0; EVBASE_ACQUIRE_LOCK(base, th_base_lock); evsel = base->evsel; - /* check if this event mechanism requires reinit on the backend */ - if (evsel->need_reinit) { - /* We're going to call event_del() on our notify events (the - * ones that tell about signals and wakeup events). But we - * don't actually want to tell the backend to change its - * state, since it might still share some resource (a kqueue, - * an epoll fd) with the parent process, and we don't want to - * delete the fds from _that_ backend, we temporarily stub out - * the evsel with a replacement. - */ - base->evsel = &nil_eventop; - } - - /* We need to re-create a new signal-notification fd and a new - * thread-notification fd. Otherwise, we'll still share those with - * the parent process, which would make any notification sent to them - * get received by one or both of the event loops, more or less at - * random. + /* check if this event mechanism requires reinit on the backend */ + if (evsel->need_reinit) { + /* We're going to call event_del() on our notify events (the + * ones that tell about signals and wakeup events). But we + * don't actually want to tell the backend to change its + * state, since it might still share some resource (a kqueue, + * an epoll fd) with the parent process, and we don't want to + * delete the fds from _that_ backend, we temporarily stub out + * the evsel with a replacement. + */ + base->evsel = &nil_eventop; + } + + /* We need to re-create a new signal-notification fd and a new + * thread-notification fd. Otherwise, we'll still share those with + * the parent process, which would make any notification sent to them + * get received by one or both of the event loops, more or less at + * random. */ if (base->sig.ev_signal_added) { - event_del_nolock_(&base->sig.ev_signal, EVENT_DEL_AUTOBLOCK); - event_debug_unassign(&base->sig.ev_signal); - memset(&base->sig.ev_signal, 0, sizeof(base->sig.ev_signal)); - had_signal_added = 1; + event_del_nolock_(&base->sig.ev_signal, EVENT_DEL_AUTOBLOCK); + event_debug_unassign(&base->sig.ev_signal); + memset(&base->sig.ev_signal, 0, sizeof(base->sig.ev_signal)); + had_signal_added = 1; base->sig.ev_signal_added = 0; } - if (base->sig.ev_signal_pair[0] != -1) - EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); - if (base->sig.ev_signal_pair[1] != -1) - EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); - if (base->th_notify_fn != NULL) { - was_notifiable = 1; - base->th_notify_fn = NULL; - } + if (base->sig.ev_signal_pair[0] != -1) + EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); + if (base->sig.ev_signal_pair[1] != -1) + EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); + if (base->th_notify_fn != NULL) { + was_notifiable = 1; + base->th_notify_fn = NULL; + } if (base->th_notify_fd[0] != -1) { - event_del_nolock_(&base->th_notify, EVENT_DEL_AUTOBLOCK); + event_del_nolock_(&base->th_notify, EVENT_DEL_AUTOBLOCK); EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); if (base->th_notify_fd[1] != -1) EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); @@ -1033,73 +1033,73 @@ event_reinit(struct event_base *base) event_debug_unassign(&base->th_notify); } - /* Replace the original evsel. */ - base->evsel = evsel; - - if (evsel->need_reinit) { - /* Reconstruct the backend through brute-force, so that we do - * not share any structures with the parent process. For some - * backends, this is necessary: epoll and kqueue, for - * instance, have events associated with a kernel - * structure. If didn't reinitialize, we'd share that - * structure with the parent process, and any changes made by - * the parent would affect our backend's behavior (and vice - * versa). - */ - if (base->evsel->dealloc != NULL) - base->evsel->dealloc(base); - base->evbase = evsel->init(base); - if (base->evbase == NULL) { - event_errx(1, - "%s: could not reinitialize event mechanism", - __func__); - res = -1; - goto done; - } - - /* Empty out the changelist (if any): we are starting from a - * blank slate. */ - event_changelist_freemem_(&base->changelist); - - /* Tell the event maps to re-inform the backend about all - * pending events. This will make the signal notification - * event get re-created if necessary. */ - if (evmap_reinit_(base) < 0) - res = -1; - } else { - res = evsig_init_(base); - if (res == 0 && had_signal_added) { - res = event_add_nolock_(&base->sig.ev_signal, NULL, 0); - if (res == 0) - base->sig.ev_signal_added = 1; + /* Replace the original evsel. */ + base->evsel = evsel; + + if (evsel->need_reinit) { + /* Reconstruct the backend through brute-force, so that we do + * not share any structures with the parent process. For some + * backends, this is necessary: epoll and kqueue, for + * instance, have events associated with a kernel + * structure. If didn't reinitialize, we'd share that + * structure with the parent process, and any changes made by + * the parent would affect our backend's behavior (and vice + * versa). + */ + if (base->evsel->dealloc != NULL) + base->evsel->dealloc(base); + base->evbase = evsel->init(base); + if (base->evbase == NULL) { + event_errx(1, + "%s: could not reinitialize event mechanism", + __func__); + res = -1; + goto done; + } + + /* Empty out the changelist (if any): we are starting from a + * blank slate. */ + event_changelist_freemem_(&base->changelist); + + /* Tell the event maps to re-inform the backend about all + * pending events. This will make the signal notification + * event get re-created if necessary. */ + if (evmap_reinit_(base) < 0) + res = -1; + } else { + res = evsig_init_(base); + if (res == 0 && had_signal_added) { + res = event_add_nolock_(&base->sig.ev_signal, NULL, 0); + if (res == 0) + base->sig.ev_signal_added = 1; } } - /* If we were notifiable before, and nothing just exploded, become - * notifiable again. */ + /* If we were notifiable before, and nothing just exploded, become + * notifiable again. */ if (was_notifiable && res == 0) - res = evthread_make_base_notifiable_nolock_(base); + res = evthread_make_base_notifiable_nolock_(base); done: EVBASE_RELEASE_LOCK(base, th_base_lock); return (res); } -/* Get the monotonic time for this event_base' timer */ -int -event_gettime_monotonic(struct event_base *base, struct timeval *tv) -{ - int rv = -1; - - if (base && tv) { - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - rv = evutil_gettime_monotonic_(&(base->monotonic_timer), tv); - EVBASE_RELEASE_LOCK(base, th_base_lock); - } - - return rv; -} - +/* Get the monotonic time for this event_base' timer */ +int +event_gettime_monotonic(struct event_base *base, struct timeval *tv) +{ + int rv = -1; + + if (base && tv) { + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + rv = evutil_gettime_monotonic_(&(base->monotonic_timer), tv); + EVBASE_RELEASE_LOCK(base, th_base_lock); + } + + return rv; +} + const char ** event_get_supported_methods(void) { @@ -1141,9 +1141,9 @@ event_config_new(void) return (NULL); TAILQ_INIT(&cfg->entries); - cfg->max_dispatch_interval.tv_sec = -1; - cfg->max_dispatch_callbacks = INT_MAX; - cfg->limit_callbacks_after_prio = 1; + cfg->max_dispatch_interval.tv_sec = -1; + cfg->max_dispatch_callbacks = INT_MAX; + cfg->limit_callbacks_after_prio = 1; return (cfg); } @@ -1214,23 +1214,23 @@ event_config_set_num_cpus_hint(struct event_config *cfg, int cpus) } int -event_config_set_max_dispatch_interval(struct event_config *cfg, - const struct timeval *max_interval, int max_callbacks, int min_priority) -{ - if (max_interval) - memcpy(&cfg->max_dispatch_interval, max_interval, - sizeof(struct timeval)); - else - cfg->max_dispatch_interval.tv_sec = -1; - cfg->max_dispatch_callbacks = - max_callbacks >= 0 ? max_callbacks : INT_MAX; - if (min_priority < 0) - min_priority = 0; - cfg->limit_callbacks_after_prio = min_priority; - return (0); -} - -int +event_config_set_max_dispatch_interval(struct event_config *cfg, + const struct timeval *max_interval, int max_callbacks, int min_priority) +{ + if (max_interval) + memcpy(&cfg->max_dispatch_interval, max_interval, + sizeof(struct timeval)); + else + cfg->max_dispatch_interval.tv_sec = -1; + cfg->max_dispatch_callbacks = + max_callbacks >= 0 ? max_callbacks : INT_MAX; + if (min_priority < 0) + min_priority = 0; + cfg->limit_callbacks_after_prio = min_priority; + return (0); +} + +int event_priority_init(int npriorities) { return event_base_priority_init(current_base, npriorities); @@ -1239,17 +1239,17 @@ event_priority_init(int npriorities) int event_base_priority_init(struct event_base *base, int npriorities) { - int i, r; - r = -1; - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); + int i, r; + r = -1; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (N_ACTIVE_CALLBACKS(base) || npriorities < 1 || npriorities >= EVENT_MAX_PRIORITIES) - goto err; + goto err; if (npriorities == base->nactivequeues) - goto ok; + goto ok; if (base->nactivequeues) { mm_free(base->activequeues); @@ -1257,11 +1257,11 @@ event_base_priority_init(struct event_base *base, int npriorities) } /* Allocate our priority queues */ - base->activequeues = (struct evcallback_list *) - mm_calloc(npriorities, sizeof(struct evcallback_list)); + base->activequeues = (struct evcallback_list *) + mm_calloc(npriorities, sizeof(struct evcallback_list)); if (base->activequeues == NULL) { event_warn("%s: calloc", __func__); - goto err; + goto err; } base->nactivequeues = npriorities; @@ -1269,78 +1269,78 @@ event_base_priority_init(struct event_base *base, int npriorities) TAILQ_INIT(&base->activequeues[i]); } -ok: - r = 0; -err: - EVBASE_RELEASE_LOCK(base, th_base_lock); - return (r); -} - -int -event_base_get_npriorities(struct event_base *base) -{ - - int n; - if (base == NULL) - base = current_base; - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - n = base->nactivequeues; - EVBASE_RELEASE_LOCK(base, th_base_lock); - return (n); -} - -int -event_base_get_num_events(struct event_base *base, unsigned int type) -{ - int r = 0; - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - - if (type & EVENT_BASE_COUNT_ACTIVE) - r += base->event_count_active; - - if (type & EVENT_BASE_COUNT_VIRTUAL) - r += base->virtual_event_count; - - if (type & EVENT_BASE_COUNT_ADDED) - r += base->event_count; - - EVBASE_RELEASE_LOCK(base, th_base_lock); - - return r; -} - -int -event_base_get_max_events(struct event_base *base, unsigned int type, int clear) -{ - int r = 0; - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - - if (type & EVENT_BASE_COUNT_ACTIVE) { - r += base->event_count_active_max; - if (clear) - base->event_count_active_max = 0; - } - - if (type & EVENT_BASE_COUNT_VIRTUAL) { - r += base->virtual_event_count_max; - if (clear) - base->virtual_event_count_max = 0; - } - - if (type & EVENT_BASE_COUNT_ADDED) { - r += base->event_count_max; - if (clear) - base->event_count_max = 0; - } - - EVBASE_RELEASE_LOCK(base, th_base_lock); - - return r; -} - +ok: + r = 0; +err: + EVBASE_RELEASE_LOCK(base, th_base_lock); + return (r); +} + +int +event_base_get_npriorities(struct event_base *base) +{ + + int n; + if (base == NULL) + base = current_base; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + n = base->nactivequeues; + EVBASE_RELEASE_LOCK(base, th_base_lock); + return (n); +} + +int +event_base_get_num_events(struct event_base *base, unsigned int type) +{ + int r = 0; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (type & EVENT_BASE_COUNT_ACTIVE) + r += base->event_count_active; + + if (type & EVENT_BASE_COUNT_VIRTUAL) + r += base->virtual_event_count; + + if (type & EVENT_BASE_COUNT_ADDED) + r += base->event_count; + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + return r; +} + +int +event_base_get_max_events(struct event_base *base, unsigned int type, int clear) +{ + int r = 0; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (type & EVENT_BASE_COUNT_ACTIVE) { + r += base->event_count_active_max; + if (clear) + base->event_count_active_max = 0; + } + + if (type & EVENT_BASE_COUNT_VIRTUAL) { + r += base->virtual_event_count_max; + if (clear) + base->virtual_event_count_max = 0; + } + + if (type & EVENT_BASE_COUNT_ADDED) { + r += base->event_count_max; + if (clear) + base->event_count_max = 0; + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + return r; +} + /* Returns true iff we're currently watching any events. */ static int event_haveevents(struct event_base *base) @@ -1452,7 +1452,7 @@ common_timeout_schedule(struct common_timeout_list *ctl, { struct timeval timeout = head->ev_timeout; timeout.tv_usec &= MICROSECONDS_MASK; - event_add_nolock_(&ctl->timeout_event, &timeout, 1); + event_add_nolock_(&ctl->timeout_event, &timeout, 1); } /* Callback: invoked when the timeout for a common timeout queue triggers. @@ -1473,8 +1473,8 @@ common_timeout_callback(evutil_socket_t fd, short what, void *arg) (ev->ev_timeout.tv_sec == now.tv_sec && (ev->ev_timeout.tv_usec&MICROSECONDS_MASK) > now.tv_usec)) break; - event_del_nolock_(ev, EVENT_DEL_NOBLOCK); - event_active_nolock_(ev, EV_TIMEOUT, 1); + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + event_active_nolock_(ev, EV_TIMEOUT, 1); } if (ev) common_timeout_schedule(ctl, &now, ev); @@ -1607,7 +1607,7 @@ event_persist_closure(struct event_base *base, struct event *ev) evutil_timeradd(&now, &delay, &run_at); } run_at.tv_usec |= usec_mask; - event_add_nolock_(ev, &run_at, 1); + event_add_nolock_(ev, &run_at, 1); } // Save our callback before we release the lock @@ -1628,105 +1628,105 @@ event_persist_closure(struct event_base *base, struct event *ev) releasing the lock as we go. This function requires that the lock be held when it's invoked. Returns -1 if we get a signal or an event_break that means we should stop processing any active events now. Otherwise returns - the number of non-internal event_callbacks that we processed. + the number of non-internal event_callbacks that we processed. */ static int event_process_active_single_queue(struct event_base *base, - struct evcallback_list *activeq, - int max_to_process, const struct timeval *endtime) + struct evcallback_list *activeq, + int max_to_process, const struct timeval *endtime) { - struct event_callback *evcb; + struct event_callback *evcb; int count = 0; EVUTIL_ASSERT(activeq != NULL); - for (evcb = TAILQ_FIRST(activeq); evcb; evcb = TAILQ_FIRST(activeq)) { - struct event *ev=NULL; - if (evcb->evcb_flags & EVLIST_INIT) { - ev = event_callback_to_event(evcb); - - if (ev->ev_events & EV_PERSIST || ev->ev_flags & EVLIST_FINALIZING) - event_queue_remove_active(base, evcb); - else - event_del_nolock_(ev, EVENT_DEL_NOBLOCK); - event_debug(( - "event_process_active: event: %p, %s%s%scall %p", - ev, - ev->ev_res & EV_READ ? "EV_READ " : " ", - ev->ev_res & EV_WRITE ? "EV_WRITE " : " ", - ev->ev_res & EV_CLOSED ? "EV_CLOSED " : " ", - ev->ev_callback)); - } else { - event_queue_remove_active(base, evcb); - event_debug(("event_process_active: event_callback %p, " - "closure %d, call %p", - evcb, evcb->evcb_closure, evcb->evcb_cb_union.evcb_callback)); - } - - if (!(evcb->evcb_flags & EVLIST_INTERNAL)) + for (evcb = TAILQ_FIRST(activeq); evcb; evcb = TAILQ_FIRST(activeq)) { + struct event *ev=NULL; + if (evcb->evcb_flags & EVLIST_INIT) { + ev = event_callback_to_event(evcb); + + if (ev->ev_events & EV_PERSIST || ev->ev_flags & EVLIST_FINALIZING) + event_queue_remove_active(base, evcb); + else + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + event_debug(( + "event_process_active: event: %p, %s%s%scall %p", + ev, + ev->ev_res & EV_READ ? "EV_READ " : " ", + ev->ev_res & EV_WRITE ? "EV_WRITE " : " ", + ev->ev_res & EV_CLOSED ? "EV_CLOSED " : " ", + ev->ev_callback)); + } else { + event_queue_remove_active(base, evcb); + event_debug(("event_process_active: event_callback %p, " + "closure %d, call %p", + evcb, evcb->evcb_closure, evcb->evcb_cb_union.evcb_callback)); + } + + if (!(evcb->evcb_flags & EVLIST_INTERNAL)) ++count; - base->current_event = evcb; -#ifndef EVENT__DISABLE_THREAD_SUPPORT + base->current_event = evcb; +#ifndef EVENT__DISABLE_THREAD_SUPPORT base->current_event_waiters = 0; #endif - switch (evcb->evcb_closure) { - case EV_CLOSURE_EVENT_SIGNAL: - EVUTIL_ASSERT(ev != NULL); + switch (evcb->evcb_closure) { + case EV_CLOSURE_EVENT_SIGNAL: + EVUTIL_ASSERT(ev != NULL); event_signal_closure(base, ev); break; - case EV_CLOSURE_EVENT_PERSIST: - EVUTIL_ASSERT(ev != NULL); + case EV_CLOSURE_EVENT_PERSIST: + EVUTIL_ASSERT(ev != NULL); event_persist_closure(base, ev); break; - case EV_CLOSURE_EVENT: { - void (*evcb_callback)(evutil_socket_t, short, void *); - short res; - EVUTIL_ASSERT(ev != NULL); - evcb_callback = *ev->ev_callback; - res = ev->ev_res; - EVBASE_RELEASE_LOCK(base, th_base_lock); - evcb_callback(ev->ev_fd, res, ev->ev_arg); - } - break; - case EV_CLOSURE_CB_SELF: { - void (*evcb_selfcb)(struct event_callback *, void *) = evcb->evcb_cb_union.evcb_selfcb; + case EV_CLOSURE_EVENT: { + void (*evcb_callback)(evutil_socket_t, short, void *); + short res; + EVUTIL_ASSERT(ev != NULL); + evcb_callback = *ev->ev_callback; + res = ev->ev_res; EVBASE_RELEASE_LOCK(base, th_base_lock); - evcb_selfcb(evcb, evcb->evcb_arg); + evcb_callback(ev->ev_fd, res, ev->ev_arg); } - break; - case EV_CLOSURE_EVENT_FINALIZE: - case EV_CLOSURE_EVENT_FINALIZE_FREE: { - void (*evcb_evfinalize)(struct event *, void *); - int evcb_closure = evcb->evcb_closure; - EVUTIL_ASSERT(ev != NULL); - base->current_event = NULL; - evcb_evfinalize = ev->ev_evcallback.evcb_cb_union.evcb_evfinalize; - EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING)); - EVBASE_RELEASE_LOCK(base, th_base_lock); + break; + case EV_CLOSURE_CB_SELF: { + void (*evcb_selfcb)(struct event_callback *, void *) = evcb->evcb_cb_union.evcb_selfcb; + EVBASE_RELEASE_LOCK(base, th_base_lock); + evcb_selfcb(evcb, evcb->evcb_arg); + } + break; + case EV_CLOSURE_EVENT_FINALIZE: + case EV_CLOSURE_EVENT_FINALIZE_FREE: { + void (*evcb_evfinalize)(struct event *, void *); + int evcb_closure = evcb->evcb_closure; + EVUTIL_ASSERT(ev != NULL); + base->current_event = NULL; + evcb_evfinalize = ev->ev_evcallback.evcb_cb_union.evcb_evfinalize; + EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING)); + EVBASE_RELEASE_LOCK(base, th_base_lock); event_debug_note_teardown_(ev); - evcb_evfinalize(ev, ev->ev_arg); - if (evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE) - mm_free(ev); - } - break; - case EV_CLOSURE_CB_FINALIZE: { - void (*evcb_cbfinalize)(struct event_callback *, void *) = evcb->evcb_cb_union.evcb_cbfinalize; - base->current_event = NULL; - EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING)); - EVBASE_RELEASE_LOCK(base, th_base_lock); - evcb_cbfinalize(evcb, evcb->evcb_arg); - } - break; - default: - EVUTIL_ASSERT(0); - } + evcb_evfinalize(ev, ev->ev_arg); + if (evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE) + mm_free(ev); + } + break; + case EV_CLOSURE_CB_FINALIZE: { + void (*evcb_cbfinalize)(struct event_callback *, void *) = evcb->evcb_cb_union.evcb_cbfinalize; + base->current_event = NULL; + EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING)); + EVBASE_RELEASE_LOCK(base, th_base_lock); + evcb_cbfinalize(evcb, evcb->evcb_arg); + } + break; + default: + EVUTIL_ASSERT(0); + } EVBASE_ACQUIRE_LOCK(base, th_base_lock); base->current_event = NULL; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT if (base->current_event_waiters) { base->current_event_waiters = 0; EVTHREAD_COND_BROADCAST(base->current_event_cond); @@ -1735,15 +1735,15 @@ event_process_active_single_queue(struct event_base *base, if (base->event_break) return -1; - if (count >= max_to_process) - return count; - if (count && endtime) { - struct timeval now; - update_time_cache(base); - gettime(base, &now); - if (evutil_timercmp(&now, endtime, >=)) - return count; - } + if (count >= max_to_process) + return count; + if (count && endtime) { + struct timeval now; + update_time_cache(base); + gettime(base, &now); + if (evutil_timercmp(&now, endtime, >=)) + return count; + } if (base->event_continue) break; } @@ -1760,33 +1760,33 @@ static int event_process_active(struct event_base *base) { /* Caller must hold th_base_lock */ - struct evcallback_list *activeq = NULL; + struct evcallback_list *activeq = NULL; int i, c = 0; - const struct timeval *endtime; - struct timeval tv; - const int maxcb = base->max_dispatch_callbacks; - const int limit_after_prio = base->limit_callbacks_after_prio; - if (base->max_dispatch_time.tv_sec >= 0) { - update_time_cache(base); - gettime(base, &tv); - evutil_timeradd(&base->max_dispatch_time, &tv, &tv); - endtime = &tv; - } else { - endtime = NULL; - } + const struct timeval *endtime; + struct timeval tv; + const int maxcb = base->max_dispatch_callbacks; + const int limit_after_prio = base->limit_callbacks_after_prio; + if (base->max_dispatch_time.tv_sec >= 0) { + update_time_cache(base); + gettime(base, &tv); + evutil_timeradd(&base->max_dispatch_time, &tv, &tv); + endtime = &tv; + } else { + endtime = NULL; + } for (i = 0; i < base->nactivequeues; ++i) { if (TAILQ_FIRST(&base->activequeues[i]) != NULL) { base->event_running_priority = i; activeq = &base->activequeues[i]; - if (i < limit_after_prio) - c = event_process_active_single_queue(base, activeq, - INT_MAX, NULL); - else - c = event_process_active_single_queue(base, activeq, - maxcb, endtime); + if (i < limit_after_prio) + c = event_process_active_single_queue(base, activeq, + INT_MAX, NULL); + else + c = event_process_active_single_queue(base, activeq, + maxcb, endtime); if (c < 0) { - goto done; + goto done; } else if (c > 0) break; /* Processed a real event; do not * consider lower-priority events */ @@ -1795,9 +1795,9 @@ event_process_active(struct event_base *base) } } -done: +done: base->event_running_priority = -1; - + return c; } @@ -1873,25 +1873,25 @@ event_base_loopbreak(struct event_base *event_base) } int -event_base_loopcontinue(struct event_base *event_base) -{ - int r = 0; - if (event_base == NULL) - return (-1); - - EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); - event_base->event_continue = 1; - - if (EVBASE_NEED_NOTIFY(event_base)) { - r = evthread_notify_base(event_base); - } else { - r = (0); - } - EVBASE_RELEASE_LOCK(event_base, th_base_lock); - return r; -} - -int +event_base_loopcontinue(struct event_base *event_base) +{ + int r = 0; + if (event_base == NULL) + return (-1); + + EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); + event_base->event_continue = 1; + + if (EVBASE_NEED_NOTIFY(event_base)) { + r = evthread_notify_base(event_base); + } else { + r = (0); + } + EVBASE_RELEASE_LOCK(event_base, th_base_lock); + return r; +} + +int event_base_got_break(struct event_base *event_base) { int res; @@ -1943,11 +1943,11 @@ event_base_loop(struct event_base *base, int flags) clear_time_cache(base); if (base->sig.ev_signal_added && base->sig.ev_n_signals_added) - evsig_set_base_(base); + evsig_set_base_(base); done = 0; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT base->th_owner_id = EVTHREAD_GET_ID(); #endif @@ -1955,7 +1955,7 @@ event_base_loop(struct event_base *base, int flags) while (!done) { base->event_continue = 0; - base->n_deferreds_queued = 0; + base->n_deferreds_queued = 0; /* Terminate the loop if we have been asked to */ if (base->event_gotterm) { @@ -1978,14 +1978,14 @@ event_base_loop(struct event_base *base, int flags) } /* If we have no events, we just exit */ - if (0==(flags&EVLOOP_NO_EXIT_ON_EMPTY) && - !event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) { + if (0==(flags&EVLOOP_NO_EXIT_ON_EMPTY) && + !event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) { event_debug(("%s: no events registered.", __func__)); retval = 1; goto done; } - event_queue_make_later_events_active(base); + event_queue_make_later_events_active(base); clear_time_cache(base); @@ -2030,9 +2030,9 @@ event_once_cb(evutil_socket_t fd, short events, void *arg) struct event_once *eonce = arg; (*eonce->cb)(fd, events, eonce->arg); - EVBASE_ACQUIRE_LOCK(eonce->ev.ev_base, th_base_lock); - LIST_REMOVE(eonce, next_once); - EVBASE_RELEASE_LOCK(eonce->ev.ev_base, th_base_lock); + EVBASE_ACQUIRE_LOCK(eonce->ev.ev_base, th_base_lock); + LIST_REMOVE(eonce, next_once); + EVBASE_RELEASE_LOCK(eonce->ev.ev_base, th_base_lock); event_debug_unassign(&eonce->ev); mm_free(eonce); } @@ -2054,7 +2054,7 @@ event_base_once(struct event_base *base, evutil_socket_t fd, short events, { struct event_once *eonce; int res = 0; - int activate = 0; + int activate = 0; if (!base) return (-1); @@ -2070,18 +2070,18 @@ event_base_once(struct event_base *base, evutil_socket_t fd, short events, eonce->cb = callback; eonce->arg = arg; - if ((events & (EV_TIMEOUT|EV_SIGNAL|EV_READ|EV_WRITE|EV_CLOSED)) == EV_TIMEOUT) { - evtimer_assign(&eonce->ev, base, event_once_cb, eonce); - - if (tv == NULL || ! evutil_timerisset(tv)) { - /* If the event is going to become active immediately, - * don't put it on the timeout queue. This is one - * idiom for scheduling a callback, so let's make - * it fast (and order-preserving). */ - activate = 1; + if ((events & (EV_TIMEOUT|EV_SIGNAL|EV_READ|EV_WRITE|EV_CLOSED)) == EV_TIMEOUT) { + evtimer_assign(&eonce->ev, base, event_once_cb, eonce); + + if (tv == NULL || ! evutil_timerisset(tv)) { + /* If the event is going to become active immediately, + * don't put it on the timeout queue. This is one + * idiom for scheduling a callback, so let's make + * it fast (and order-preserving). */ + activate = 1; } - } else if (events & (EV_READ|EV_WRITE|EV_CLOSED)) { - events &= EV_READ|EV_WRITE|EV_CLOSED; + } else if (events & (EV_READ|EV_WRITE|EV_CLOSED)) { + events &= EV_READ|EV_WRITE|EV_CLOSED; event_assign(&eonce->ev, base, fd, events, event_once_cb, eonce); } else { @@ -2090,20 +2090,20 @@ event_base_once(struct event_base *base, evutil_socket_t fd, short events, return (-1); } - if (res == 0) { - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - if (activate) - event_active_nolock_(&eonce->ev, EV_TIMEOUT, 1); - else - res = event_add_nolock_(&eonce->ev, tv, 0); - - if (res != 0) { - mm_free(eonce); - return (res); - } else { - LIST_INSERT_HEAD(&base->once_events, eonce, next_once); - } - EVBASE_RELEASE_LOCK(base, th_base_lock); + if (res == 0) { + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (activate) + event_active_nolock_(&eonce->ev, EV_TIMEOUT, 1); + else + res = event_add_nolock_(&eonce->ev, tv, 0); + + if (res != 0) { + mm_free(eonce); + return (res); + } else { + LIST_INSERT_HEAD(&base->once_events, eonce, next_once); + } + EVBASE_RELEASE_LOCK(base, th_base_lock); } return (0); @@ -2114,12 +2114,12 @@ event_assign(struct event *ev, struct event_base *base, evutil_socket_t fd, shor { if (!base) base = current_base; - if (arg == &event_self_cbarg_ptr_) - arg = ev; + if (arg == &event_self_cbarg_ptr_) + arg = ev; - if (!(events & EV_SIGNAL)) - event_debug_assert_socket_nonblocking_(fd); - event_debug_assert_not_added_(ev); + if (!(events & EV_SIGNAL)) + event_debug_assert_socket_nonblocking_(fd); + event_debug_assert_not_added_(ev); ev->ev_base = base; @@ -2133,29 +2133,29 @@ event_assign(struct event *ev, struct event_base *base, evutil_socket_t fd, shor ev->ev_pncalls = NULL; if (events & EV_SIGNAL) { - if ((events & (EV_READ|EV_WRITE|EV_CLOSED)) != 0) { + if ((events & (EV_READ|EV_WRITE|EV_CLOSED)) != 0) { event_warnx("%s: EV_SIGNAL is not compatible with " - "EV_READ, EV_WRITE or EV_CLOSED", __func__); + "EV_READ, EV_WRITE or EV_CLOSED", __func__); return -1; } - ev->ev_closure = EV_CLOSURE_EVENT_SIGNAL; + ev->ev_closure = EV_CLOSURE_EVENT_SIGNAL; } else { if (events & EV_PERSIST) { evutil_timerclear(&ev->ev_io_timeout); - ev->ev_closure = EV_CLOSURE_EVENT_PERSIST; + ev->ev_closure = EV_CLOSURE_EVENT_PERSIST; } else { - ev->ev_closure = EV_CLOSURE_EVENT; + ev->ev_closure = EV_CLOSURE_EVENT; } } - min_heap_elem_init_(ev); + min_heap_elem_init_(ev); if (base != NULL) { /* by default, we put new events into the middle priority */ ev->ev_pri = base->nactivequeues / 2; } - event_debug_note_setup_(ev); + event_debug_note_setup_(ev); return 0; } @@ -2167,7 +2167,7 @@ event_base_set(struct event_base *base, struct event *ev) if (ev->ev_flags != EVLIST_INIT) return (-1); - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); ev->ev_base = base; ev->ev_pri = base->nactivequeues/2; @@ -2184,27 +2184,27 @@ event_set(struct event *ev, evutil_socket_t fd, short events, EVUTIL_ASSERT(r == 0); } -void * -event_self_cbarg(void) -{ - return &event_self_cbarg_ptr_; -} - -struct event * -event_base_get_running_event(struct event_base *base) -{ - struct event *ev = NULL; - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - if (EVBASE_IN_THREAD(base)) { - struct event_callback *evcb = base->current_event; - if (evcb->evcb_flags & EVLIST_INIT) - ev = event_callback_to_event(evcb); - } - EVBASE_RELEASE_LOCK(base, th_base_lock); - return ev; -} - +void * +event_self_cbarg(void) +{ + return &event_self_cbarg_ptr_; +} + struct event * +event_base_get_running_event(struct event_base *base) +{ + struct event *ev = NULL; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (EVBASE_IN_THREAD(base)) { + struct event_callback *evcb = base->current_event; + if (evcb->evcb_flags & EVLIST_INIT) + ev = event_callback_to_event(evcb); + } + EVBASE_RELEASE_LOCK(base, th_base_lock); + return ev; +} + +struct event * event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, short, void *), void *arg) { struct event *ev; @@ -2222,13 +2222,13 @@ event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)( void event_free(struct event *ev) { - /* This is disabled, so that events which have been finalized be a - * valid target for event_free(). That's */ - // event_debug_assert_is_setup_(ev); + /* This is disabled, so that events which have been finalized be a + * valid target for event_free(). That's */ + // event_debug_assert_is_setup_(ev); /* make sure that this event won't be coming back to haunt us. */ event_del(ev); - event_debug_note_teardown_(ev); + event_debug_note_teardown_(ev); mm_free(ev); } @@ -2236,117 +2236,117 @@ event_free(struct event *ev) void event_debug_unassign(struct event *ev) { - event_debug_assert_not_added_(ev); - event_debug_note_teardown_(ev); + event_debug_assert_not_added_(ev); + event_debug_note_teardown_(ev); ev->ev_flags &= ~EVLIST_INIT; } -#define EVENT_FINALIZE_FREE_ 0x10000 -static int -event_finalize_nolock_(struct event_base *base, unsigned flags, struct event *ev, event_finalize_callback_fn cb) -{ - ev_uint8_t closure = (flags & EVENT_FINALIZE_FREE_) ? - EV_CLOSURE_EVENT_FINALIZE_FREE : EV_CLOSURE_EVENT_FINALIZE; - - event_del_nolock_(ev, EVENT_DEL_NOBLOCK); - ev->ev_closure = closure; - ev->ev_evcallback.evcb_cb_union.evcb_evfinalize = cb; - event_active_nolock_(ev, EV_FINALIZE, 1); - ev->ev_flags |= EVLIST_FINALIZING; - return 0; -} - -static int -event_finalize_impl_(unsigned flags, struct event *ev, event_finalize_callback_fn cb) -{ - int r; - struct event_base *base = ev->ev_base; - if (EVUTIL_FAILURE_CHECK(!base)) { - event_warnx("%s: event has no event_base set.", __func__); - return -1; - } - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - r = event_finalize_nolock_(base, flags, ev, cb); - EVBASE_RELEASE_LOCK(base, th_base_lock); - return r; -} - -int -event_finalize(unsigned flags, struct event *ev, event_finalize_callback_fn cb) -{ - return event_finalize_impl_(flags, ev, cb); -} - -int -event_free_finalize(unsigned flags, struct event *ev, event_finalize_callback_fn cb) -{ - return event_finalize_impl_(flags|EVENT_FINALIZE_FREE_, ev, cb); -} - -void -event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)) -{ - struct event *ev = NULL; - if (evcb->evcb_flags & EVLIST_INIT) { - ev = event_callback_to_event(evcb); - event_del_nolock_(ev, EVENT_DEL_NOBLOCK); - } else { - event_callback_cancel_nolock_(base, evcb, 0); /*XXX can this fail?*/ - } - - evcb->evcb_closure = EV_CLOSURE_CB_FINALIZE; - evcb->evcb_cb_union.evcb_cbfinalize = cb; - event_callback_activate_nolock_(base, evcb); /* XXX can this really fail?*/ - evcb->evcb_flags |= EVLIST_FINALIZING; -} - -void -event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)) -{ - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - event_callback_finalize_nolock_(base, flags, evcb, cb); - EVBASE_RELEASE_LOCK(base, th_base_lock); -} - -/** Internal: Finalize all of the n_cbs callbacks in evcbs. The provided - * callback will be invoked on *one of them*, after they have *all* been - * finalized. */ -int -event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcbs, void (*cb)(struct event_callback *, void *)) -{ - int n_pending = 0, i; - - if (base == NULL) - base = current_base; - - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - - event_debug(("%s: %d events finalizing", __func__, n_cbs)); - - /* At most one can be currently executing; the rest we just - * cancel... But we always make sure that the finalize callback - * runs. */ - for (i = 0; i < n_cbs; ++i) { - struct event_callback *evcb = evcbs[i]; - if (evcb == base->current_event) { - event_callback_finalize_nolock_(base, 0, evcb, cb); - ++n_pending; - } else { - event_callback_cancel_nolock_(base, evcb, 0); - } - } - - if (n_pending == 0) { - /* Just do the first one. */ - event_callback_finalize_nolock_(base, 0, evcbs[0], cb); - } - - EVBASE_RELEASE_LOCK(base, th_base_lock); - return 0; -} - +#define EVENT_FINALIZE_FREE_ 0x10000 +static int +event_finalize_nolock_(struct event_base *base, unsigned flags, struct event *ev, event_finalize_callback_fn cb) +{ + ev_uint8_t closure = (flags & EVENT_FINALIZE_FREE_) ? + EV_CLOSURE_EVENT_FINALIZE_FREE : EV_CLOSURE_EVENT_FINALIZE; + + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + ev->ev_closure = closure; + ev->ev_evcallback.evcb_cb_union.evcb_evfinalize = cb; + event_active_nolock_(ev, EV_FINALIZE, 1); + ev->ev_flags |= EVLIST_FINALIZING; + return 0; +} + +static int +event_finalize_impl_(unsigned flags, struct event *ev, event_finalize_callback_fn cb) +{ + int r; + struct event_base *base = ev->ev_base; + if (EVUTIL_FAILURE_CHECK(!base)) { + event_warnx("%s: event has no event_base set.", __func__); + return -1; + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_finalize_nolock_(base, flags, ev, cb); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +int +event_finalize(unsigned flags, struct event *ev, event_finalize_callback_fn cb) +{ + return event_finalize_impl_(flags, ev, cb); +} + +int +event_free_finalize(unsigned flags, struct event *ev, event_finalize_callback_fn cb) +{ + return event_finalize_impl_(flags|EVENT_FINALIZE_FREE_, ev, cb); +} + +void +event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)) +{ + struct event *ev = NULL; + if (evcb->evcb_flags & EVLIST_INIT) { + ev = event_callback_to_event(evcb); + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + } else { + event_callback_cancel_nolock_(base, evcb, 0); /*XXX can this fail?*/ + } + + evcb->evcb_closure = EV_CLOSURE_CB_FINALIZE; + evcb->evcb_cb_union.evcb_cbfinalize = cb; + event_callback_activate_nolock_(base, evcb); /* XXX can this really fail?*/ + evcb->evcb_flags |= EVLIST_FINALIZING; +} + +void +event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void (*cb)(struct event_callback *, void *)) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + event_callback_finalize_nolock_(base, flags, evcb, cb); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +/** Internal: Finalize all of the n_cbs callbacks in evcbs. The provided + * callback will be invoked on *one of them*, after they have *all* been + * finalized. */ +int +event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcbs, void (*cb)(struct event_callback *, void *)) +{ + int n_pending = 0, i; + + if (base == NULL) + base = current_base; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + event_debug(("%s: %d events finalizing", __func__, n_cbs)); + + /* At most one can be currently executing; the rest we just + * cancel... But we always make sure that the finalize callback + * runs. */ + for (i = 0; i < n_cbs; ++i) { + struct event_callback *evcb = evcbs[i]; + if (evcb == base->current_event) { + event_callback_finalize_nolock_(base, 0, evcb, cb); + ++n_pending; + } else { + event_callback_cancel_nolock_(base, evcb, 0); + } + } + + if (n_pending == 0) { + /* Just do the first one. */ + event_callback_finalize_nolock_(base, 0, evcbs[0], cb); + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + return 0; +} + /* * Set's the priority of an event - if an event is already scheduled * changing the priority is going to fail. @@ -2355,7 +2355,7 @@ event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_c int event_priority_set(struct event *ev, int pri) { - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); if (ev->ev_flags & EVLIST_ACTIVE) return (-1); @@ -2382,16 +2382,16 @@ event_pending(const struct event *ev, short event, struct timeval *tv) } EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); if (ev->ev_flags & EVLIST_INSERTED) - flags |= (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL)); - if (ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) + flags |= (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL)); + if (ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) flags |= ev->ev_res; if (ev->ev_flags & EVLIST_TIMEOUT) flags |= EV_TIMEOUT; - event &= (EV_TIMEOUT|EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL); + event &= (EV_TIMEOUT|EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL); /* See if there is a timeout that we should report */ if (tv != NULL && (flags & event & EV_TIMEOUT)) { @@ -2418,7 +2418,7 @@ event_initialized(const struct event *ev) void event_get_assignment(const struct event *event, struct event_base **base_out, evutil_socket_t *fd_out, short *events_out, event_callback_fn *callback_out, void **arg_out) { - event_debug_assert_is_setup_(event); + event_debug_assert_is_setup_(event); if (base_out) *base_out = event->ev_base; @@ -2441,46 +2441,46 @@ event_get_struct_event_size(void) evutil_socket_t event_get_fd(const struct event *ev) { - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); return ev->ev_fd; } struct event_base * event_get_base(const struct event *ev) { - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); return ev->ev_base; } short event_get_events(const struct event *ev) { - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); return ev->ev_events; } event_callback_fn event_get_callback(const struct event *ev) { - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); return ev->ev_callback; } void * event_get_callback_arg(const struct event *ev) { - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); return ev->ev_arg; } int -event_get_priority(const struct event *ev) -{ - event_debug_assert_is_setup_(ev); - return ev->ev_pri; -} - -int +event_get_priority(const struct event *ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_pri; +} + +int event_add(struct event *ev, const struct timeval *tv) { int res; @@ -2492,7 +2492,7 @@ event_add(struct event *ev, const struct timeval *tv) EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); - res = event_add_nolock_(ev, tv, 0); + res = event_add_nolock_(ev, tv, 0); EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); @@ -2509,15 +2509,15 @@ evthread_notify_base_default(struct event_base *base) char buf[1]; int r; buf[0] = (char) 0; -#ifdef _WIN32 +#ifdef _WIN32 r = send(base->th_notify_fd[1], buf, 1, 0); #else r = write(base->th_notify_fd[1], buf, 1); #endif - return (r < 0 && ! EVUTIL_ERR_IS_EAGAIN(errno)) ? -1 : 0; + return (r < 0 && ! EVUTIL_ERR_IS_EAGAIN(errno)) ? -1 : 0; } -#ifdef EVENT__HAVE_EVENTFD +#ifdef EVENT__HAVE_EVENTFD /* Helper callback: wake an event_base from another thread. This version * assumes that you have a working eventfd() implementation. */ static int @@ -2533,10 +2533,10 @@ evthread_notify_base_eventfd(struct event_base *base) } #endif - + /** Tell the thread currently running the event_loop for base (if any) that it * needs to stop waiting in its dispatch function (if it is) and process all - * active callbacks. */ + * active callbacks. */ static int evthread_notify_base(struct event_base *base) { @@ -2549,52 +2549,52 @@ evthread_notify_base(struct event_base *base) return base->th_notify_fn(base); } -/* Implementation function to remove a timeout on a currently pending event. - */ -int -event_remove_timer_nolock_(struct event *ev) -{ - struct event_base *base = ev->ev_base; - - EVENT_BASE_ASSERT_LOCKED(base); - event_debug_assert_is_setup_(ev); - - event_debug(("event_remove_timer_nolock: event: %p", ev)); - - /* If it's not pending on a timeout, we don't need to do anything. */ - if (ev->ev_flags & EVLIST_TIMEOUT) { - event_queue_remove_timeout(base, ev); - evutil_timerclear(&ev->ev_.ev_io.ev_timeout); - } - - return (0); -} - -int -event_remove_timer(struct event *ev) -{ - int res; - - if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { - event_warnx("%s: event has no event_base set.", __func__); - return -1; - } - - EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); - - res = event_remove_timer_nolock_(ev); - - EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); - - return (res); -} - +/* Implementation function to remove a timeout on a currently pending event. + */ +int +event_remove_timer_nolock_(struct event *ev) +{ + struct event_base *base = ev->ev_base; + + EVENT_BASE_ASSERT_LOCKED(base); + event_debug_assert_is_setup_(ev); + + event_debug(("event_remove_timer_nolock: event: %p", ev)); + + /* If it's not pending on a timeout, we don't need to do anything. */ + if (ev->ev_flags & EVLIST_TIMEOUT) { + event_queue_remove_timeout(base, ev); + evutil_timerclear(&ev->ev_.ev_io.ev_timeout); + } + + return (0); +} + +int +event_remove_timer(struct event *ev) +{ + int res; + + if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { + event_warnx("%s: event has no event_base set.", __func__); + return -1; + } + + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + + res = event_remove_timer_nolock_(ev); + + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); + + return (res); +} + /* Implementation function to add an event. Works just like event_add, * except: 1) it requires that we have the lock. 2) if tv_is_absolute is set, * we treat tv as an absolute time, not as an interval to add to the current * time */ -int -event_add_nolock_(struct event *ev, const struct timeval *tv, +int +event_add_nolock_(struct event *ev, const struct timeval *tv, int tv_is_absolute) { struct event_base *base = ev->ev_base; @@ -2602,32 +2602,32 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, int notify = 0; EVENT_BASE_ASSERT_LOCKED(base); - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); event_debug(( - "event_add: event: %p (fd "EV_SOCK_FMT"), %s%s%s%scall %p", + "event_add: event: %p (fd "EV_SOCK_FMT"), %s%s%s%scall %p", ev, EV_SOCK_ARG(ev->ev_fd), ev->ev_events & EV_READ ? "EV_READ " : " ", ev->ev_events & EV_WRITE ? "EV_WRITE " : " ", - ev->ev_events & EV_CLOSED ? "EV_CLOSED " : " ", + ev->ev_events & EV_CLOSED ? "EV_CLOSED " : " ", tv ? "EV_TIMEOUT " : " ", ev->ev_callback)); EVUTIL_ASSERT(!(ev->ev_flags & ~EVLIST_ALL)); - if (ev->ev_flags & EVLIST_FINALIZING) { - /* XXXX debug */ - return (-1); - } - + if (ev->ev_flags & EVLIST_FINALIZING) { + /* XXXX debug */ + return (-1); + } + /* * prepare for timeout insertion further below, if we get a * failure on any step, we should not change any state. */ if (tv != NULL && !(ev->ev_flags & EVLIST_TIMEOUT)) { - if (min_heap_reserve_(&base->timeheap, - 1 + min_heap_size_(&base->timeheap)) == -1) + if (min_heap_reserve_(&base->timeheap, + 1 + min_heap_size_(&base->timeheap)) == -1) return (-1); /* ENOMEM == errno */ } @@ -2635,23 +2635,23 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, * callback, and we are not the main thread, then we want to wait * until the callback is done before we mess with the event, or else * we can race on ev_ncalls and ev_pncalls below. */ -#ifndef EVENT__DISABLE_THREAD_SUPPORT - if (base->current_event == event_to_event_callback(ev) && - (ev->ev_events & EV_SIGNAL) +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (base->current_event == event_to_event_callback(ev) && + (ev->ev_events & EV_SIGNAL) && !EVBASE_IN_THREAD(base)) { ++base->current_event_waiters; EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); } #endif - if ((ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL)) && - !(ev->ev_flags & (EVLIST_INSERTED|EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { - if (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED)) - res = evmap_io_add_(base, ev->ev_fd, ev); + if ((ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL)) && + !(ev->ev_flags & (EVLIST_INSERTED|EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { + if (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED)) + res = evmap_io_add_(base, ev->ev_fd, ev); else if (ev->ev_events & EV_SIGNAL) - res = evmap_signal_add_(base, (int)ev->ev_fd, ev); + res = evmap_signal_add_(base, (int)ev->ev_fd, ev); if (res != -1) - event_queue_insert_inserted(base, ev); + event_queue_insert_inserted(base, ev); if (res == 1) { /* evmap says we need to notify the main thread. */ notify = 1; @@ -2666,10 +2666,10 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, if (res != -1 && tv != NULL) { struct timeval now; int common_timeout; -#ifdef USE_REINSERT_TIMEOUT - int was_common; - int old_timeout_idx; -#endif +#ifdef USE_REINSERT_TIMEOUT + int was_common; + int old_timeout_idx; +#endif /* * for persistent timeout events, we remember the @@ -2677,14 +2677,14 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, * * If tv_is_absolute, this was already set. */ - if (ev->ev_closure == EV_CLOSURE_EVENT_PERSIST && !tv_is_absolute) + if (ev->ev_closure == EV_CLOSURE_EVENT_PERSIST && !tv_is_absolute) ev->ev_io_timeout = *tv; -#ifndef USE_REINSERT_TIMEOUT +#ifndef USE_REINSERT_TIMEOUT if (ev->ev_flags & EVLIST_TIMEOUT) { - event_queue_remove_timeout(base, ev); + event_queue_remove_timeout(base, ev); } -#endif +#endif /* Check if it is active due to a timeout. Rescheduling * this timeout before the callback can be executed @@ -2701,17 +2701,17 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, } } - event_queue_remove_active(base, event_to_event_callback(ev)); + event_queue_remove_active(base, event_to_event_callback(ev)); } gettime(base, &now); common_timeout = is_common_timeout(tv, base); -#ifdef USE_REINSERT_TIMEOUT - was_common = is_common_timeout(&ev->ev_timeout, base); - old_timeout_idx = COMMON_TIMEOUT_IDX(&ev->ev_timeout); -#endif - +#ifdef USE_REINSERT_TIMEOUT + was_common = is_common_timeout(&ev->ev_timeout, base); + old_timeout_idx = COMMON_TIMEOUT_IDX(&ev->ev_timeout); +#endif + if (tv_is_absolute) { ev->ev_timeout = *tv; } else if (common_timeout) { @@ -2725,15 +2725,15 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, } event_debug(( - "event_add: event %p, timeout in %d seconds %d useconds, call %p", - ev, (int)tv->tv_sec, (int)tv->tv_usec, ev->ev_callback)); - -#ifdef USE_REINSERT_TIMEOUT - event_queue_reinsert_timeout(base, ev, was_common, common_timeout, old_timeout_idx); -#else - event_queue_insert_timeout(base, ev); -#endif - + "event_add: event %p, timeout in %d seconds %d useconds, call %p", + ev, (int)tv->tv_sec, (int)tv->tv_usec, ev->ev_callback)); + +#ifdef USE_REINSERT_TIMEOUT + event_queue_reinsert_timeout(base, ev, was_common, common_timeout, old_timeout_idx); +#else + event_queue_insert_timeout(base, ev); +#endif + if (common_timeout) { struct common_timeout_list *ctl = get_common_timeout_list(base, &ev->ev_timeout); @@ -2741,18 +2741,18 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, common_timeout_schedule(ctl, &now, ev); } } else { - struct event* top = NULL; + struct event* top = NULL; /* See if the earliest timeout is now earlier than it * was before: if so, we will need to tell the main - * thread to wake up earlier than it would otherwise. - * We double check the timeout of the top element to - * handle time distortions due to system suspension. - */ - if (min_heap_elt_is_top_(ev)) - notify = 1; - else if ((top = min_heap_top_(&base->timeheap)) != NULL && - evutil_timercmp(&top->ev_timeout, &now, <)) + * thread to wake up earlier than it would otherwise. + * We double check the timeout of the top element to + * handle time distortions due to system suspension. + */ + if (min_heap_elt_is_top_(ev)) notify = 1; + else if ((top = min_heap_top_(&base->timeheap)) != NULL && + evutil_timercmp(&top->ev_timeout, &now, <)) + notify = 1; } } @@ -2760,55 +2760,55 @@ event_add_nolock_(struct event *ev, const struct timeval *tv, if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) evthread_notify_base(base); - event_debug_note_add_(ev); + event_debug_note_add_(ev); return (res); } -static int -event_del_(struct event *ev, int blocking) +static int +event_del_(struct event *ev, int blocking) { int res; - struct event_base *base = ev->ev_base; + struct event_base *base = ev->ev_base; - if (EVUTIL_FAILURE_CHECK(!base)) { + if (EVUTIL_FAILURE_CHECK(!base)) { event_warnx("%s: event has no event_base set.", __func__); return -1; } - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - res = event_del_nolock_(ev, blocking); - EVBASE_RELEASE_LOCK(base, th_base_lock); + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + res = event_del_nolock_(ev, blocking); + EVBASE_RELEASE_LOCK(base, th_base_lock); - return (res); -} + return (res); +} -int -event_del(struct event *ev) -{ - return event_del_(ev, EVENT_DEL_AUTOBLOCK); -} +int +event_del(struct event *ev) +{ + return event_del_(ev, EVENT_DEL_AUTOBLOCK); +} -int -event_del_block(struct event *ev) -{ - return event_del_(ev, EVENT_DEL_BLOCK); +int +event_del_block(struct event *ev) +{ + return event_del_(ev, EVENT_DEL_BLOCK); } -int -event_del_noblock(struct event *ev) -{ - return event_del_(ev, EVENT_DEL_NOBLOCK); -} - -/** Helper for event_del: always called with th_base_lock held. - * - * "blocking" must be one of the EVENT_DEL_{BLOCK, NOBLOCK, AUTOBLOCK, - * EVEN_IF_FINALIZING} values. See those for more information. - */ -int -event_del_nolock_(struct event *ev, int blocking) +int +event_del_noblock(struct event *ev) { + return event_del_(ev, EVENT_DEL_NOBLOCK); +} + +/** Helper for event_del: always called with th_base_lock held. + * + * "blocking" must be one of the EVENT_DEL_{BLOCK, NOBLOCK, AUTOBLOCK, + * EVEN_IF_FINALIZING} values. See those for more information. + */ +int +event_del_nolock_(struct event *ev, int blocking) +{ struct event_base *base; int res = 0, notify = 0; @@ -2821,15 +2821,15 @@ event_del_nolock_(struct event *ev, int blocking) EVENT_BASE_ASSERT_LOCKED(ev->ev_base); - if (blocking != EVENT_DEL_EVEN_IF_FINALIZING) { - if (ev->ev_flags & EVLIST_FINALIZING) { - /* XXXX Debug */ - return 0; - } + if (blocking != EVENT_DEL_EVEN_IF_FINALIZING) { + if (ev->ev_flags & EVLIST_FINALIZING) { + /* XXXX Debug */ + return 0; + } } - base = ev->ev_base; - + base = ev->ev_base; + EVUTIL_ASSERT(!(ev->ev_flags & ~EVLIST_ALL)); /* See if we are just active executing this event in a loop */ @@ -2848,52 +2848,52 @@ event_del_nolock_(struct event *ev, int blocking) * dispatch loop early anyway, so we wouldn't gain anything by * doing it. */ - event_queue_remove_timeout(base, ev); + event_queue_remove_timeout(base, ev); } if (ev->ev_flags & EVLIST_ACTIVE) - event_queue_remove_active(base, event_to_event_callback(ev)); - else if (ev->ev_flags & EVLIST_ACTIVE_LATER) - event_queue_remove_active_later(base, event_to_event_callback(ev)); + event_queue_remove_active(base, event_to_event_callback(ev)); + else if (ev->ev_flags & EVLIST_ACTIVE_LATER) + event_queue_remove_active_later(base, event_to_event_callback(ev)); if (ev->ev_flags & EVLIST_INSERTED) { - event_queue_remove_inserted(base, ev); - if (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED)) - res = evmap_io_del_(base, ev->ev_fd, ev); + event_queue_remove_inserted(base, ev); + if (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED)) + res = evmap_io_del_(base, ev->ev_fd, ev); else - res = evmap_signal_del_(base, (int)ev->ev_fd, ev); + res = evmap_signal_del_(base, (int)ev->ev_fd, ev); if (res == 1) { /* evmap says we need to notify the main thread. */ notify = 1; res = 0; } - /* If we do not have events, let's notify event base so it can - * exit without waiting */ - if (!event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) - notify = 1; + /* If we do not have events, let's notify event base so it can + * exit without waiting */ + if (!event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) + notify = 1; } /* if we are not in the right thread, we need to wake up the loop */ if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) evthread_notify_base(base); - event_debug_note_del_(ev); - - /* If the main thread is currently executing this event's callback, - * and we are not the main thread, then we want to wait until the - * callback is done before returning. That way, when this function - * returns, it will be safe to free the user-supplied argument. - */ -#ifndef EVENT__DISABLE_THREAD_SUPPORT - if (blocking != EVENT_DEL_NOBLOCK && - base->current_event == event_to_event_callback(ev) && - !EVBASE_IN_THREAD(base) && - (blocking == EVENT_DEL_BLOCK || !(ev->ev_events & EV_FINALIZE))) { - ++base->current_event_waiters; - EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); - } -#endif - + event_debug_note_del_(ev); + + /* If the main thread is currently executing this event's callback, + * and we are not the main thread, then we want to wait until the + * callback is done before returning. That way, when this function + * returns, it will be safe to free the user-supplied argument. + */ +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (blocking != EVENT_DEL_NOBLOCK && + base->current_event == event_to_event_callback(ev) && + !EVBASE_IN_THREAD(base) && + (blocking == EVENT_DEL_BLOCK || !(ev->ev_events & EV_FINALIZE))) { + ++base->current_event_waiters; + EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); + } +#endif + return (res); } @@ -2907,54 +2907,54 @@ event_active(struct event *ev, int res, short ncalls) EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); - event_debug_assert_is_setup_(ev); + event_debug_assert_is_setup_(ev); - event_active_nolock_(ev, res, ncalls); + event_active_nolock_(ev, res, ncalls); EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); } void -event_active_nolock_(struct event *ev, int res, short ncalls) +event_active_nolock_(struct event *ev, int res, short ncalls) { struct event_base *base; event_debug(("event_active: %p (fd "EV_SOCK_FMT"), res %d, callback %p", ev, EV_SOCK_ARG(ev->ev_fd), (int)res, ev->ev_callback)); - base = ev->ev_base; - EVENT_BASE_ASSERT_LOCKED(base); - - if (ev->ev_flags & EVLIST_FINALIZING) { - /* XXXX debug */ - return; - } - - switch ((ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { - default: - case EVLIST_ACTIVE|EVLIST_ACTIVE_LATER: - EVUTIL_ASSERT(0); - break; - case EVLIST_ACTIVE: - /* We get different kinds of events, add them together */ + base = ev->ev_base; + EVENT_BASE_ASSERT_LOCKED(base); + + if (ev->ev_flags & EVLIST_FINALIZING) { + /* XXXX debug */ + return; + } + + switch ((ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { + default: + case EVLIST_ACTIVE|EVLIST_ACTIVE_LATER: + EVUTIL_ASSERT(0); + break; + case EVLIST_ACTIVE: + /* We get different kinds of events, add them together */ ev->ev_res |= res; return; - case EVLIST_ACTIVE_LATER: - ev->ev_res |= res; - break; - case 0: - ev->ev_res = res; - break; + case EVLIST_ACTIVE_LATER: + ev->ev_res |= res; + break; + case 0: + ev->ev_res = res; + break; } if (ev->ev_pri < base->event_running_priority) base->event_continue = 1; if (ev->ev_events & EV_SIGNAL) { -#ifndef EVENT__DISABLE_THREAD_SUPPORT - if (base->current_event == event_to_event_callback(ev) && - !EVBASE_IN_THREAD(base)) { +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (base->current_event == event_to_event_callback(ev) && + !EVBASE_IN_THREAD(base)) { ++base->current_event_waiters; EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); } @@ -2963,180 +2963,180 @@ event_active_nolock_(struct event *ev, int res, short ncalls) ev->ev_pncalls = NULL; } - event_callback_activate_nolock_(base, event_to_event_callback(ev)); -} - -void -event_active_later_(struct event *ev, int res) -{ - EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); - event_active_later_nolock_(ev, res); - EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); -} - -void -event_active_later_nolock_(struct event *ev, int res) -{ - struct event_base *base = ev->ev_base; - EVENT_BASE_ASSERT_LOCKED(base); - - if (ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) { - /* We get different kinds of events, add them together */ - ev->ev_res |= res; - return; - } - - ev->ev_res = res; - - event_callback_activate_later_nolock_(base, event_to_event_callback(ev)); -} - -int -event_callback_activate_(struct event_base *base, - struct event_callback *evcb) -{ - int r; - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - r = event_callback_activate_nolock_(base, evcb); - EVBASE_RELEASE_LOCK(base, th_base_lock); - return r; -} - -int -event_callback_activate_nolock_(struct event_base *base, - struct event_callback *evcb) -{ - int r = 1; - - if (evcb->evcb_flags & EVLIST_FINALIZING) - return 0; - - switch (evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) { - default: - EVUTIL_ASSERT(0); - EVUTIL_FALLTHROUGH; - case EVLIST_ACTIVE_LATER: - event_queue_remove_active_later(base, evcb); - r = 0; - break; - case EVLIST_ACTIVE: - return 0; - case 0: - break; - } - - event_queue_insert_active(base, evcb); - - if (EVBASE_NEED_NOTIFY(base)) - evthread_notify_base(base); - - return r; -} - -int -event_callback_activate_later_nolock_(struct event_base *base, - struct event_callback *evcb) -{ - if (evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) - return 0; - - event_queue_insert_active_later(base, evcb); - if (EVBASE_NEED_NOTIFY(base)) - evthread_notify_base(base); - return 1; -} - -void -event_callback_init_(struct event_base *base, - struct event_callback *cb) -{ - memset(cb, 0, sizeof(*cb)); - cb->evcb_pri = base->nactivequeues - 1; -} - -int -event_callback_cancel_(struct event_base *base, - struct event_callback *evcb) -{ - int r; - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - r = event_callback_cancel_nolock_(base, evcb, 0); - EVBASE_RELEASE_LOCK(base, th_base_lock); - return r; -} - -int -event_callback_cancel_nolock_(struct event_base *base, - struct event_callback *evcb, int even_if_finalizing) -{ - if ((evcb->evcb_flags & EVLIST_FINALIZING) && !even_if_finalizing) - return 0; - - if (evcb->evcb_flags & EVLIST_INIT) - return event_del_nolock_(event_callback_to_event(evcb), - even_if_finalizing ? EVENT_DEL_EVEN_IF_FINALIZING : EVENT_DEL_AUTOBLOCK); - - switch ((evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { - default: - case EVLIST_ACTIVE|EVLIST_ACTIVE_LATER: - EVUTIL_ASSERT(0); - break; - case EVLIST_ACTIVE: - /* We get different kinds of events, add them together */ - event_queue_remove_active(base, evcb); - return 0; - case EVLIST_ACTIVE_LATER: - event_queue_remove_active_later(base, evcb); - break; - case 0: - break; - } - - return 0; + event_callback_activate_nolock_(base, event_to_event_callback(ev)); } void -event_deferred_cb_init_(struct event_callback *cb, ev_uint8_t priority, deferred_cb_fn fn, void *arg) +event_active_later_(struct event *ev, int res) { - memset(cb, 0, sizeof(*cb)); - cb->evcb_cb_union.evcb_selfcb = fn; - cb->evcb_arg = arg; - cb->evcb_pri = priority; - cb->evcb_closure = EV_CLOSURE_CB_SELF; + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + event_active_later_nolock_(ev, res); + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); } void -event_deferred_cb_set_priority_(struct event_callback *cb, ev_uint8_t priority) -{ - cb->evcb_pri = priority; -} - +event_active_later_nolock_(struct event *ev, int res) +{ + struct event_base *base = ev->ev_base; + EVENT_BASE_ASSERT_LOCKED(base); + + if (ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) { + /* We get different kinds of events, add them together */ + ev->ev_res |= res; + return; + } + + ev->ev_res = res; + + event_callback_activate_later_nolock_(base, event_to_event_callback(ev)); +} + +int +event_callback_activate_(struct event_base *base, + struct event_callback *evcb) +{ + int r; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_callback_activate_nolock_(base, evcb); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +int +event_callback_activate_nolock_(struct event_base *base, + struct event_callback *evcb) +{ + int r = 1; + + if (evcb->evcb_flags & EVLIST_FINALIZING) + return 0; + + switch (evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) { + default: + EVUTIL_ASSERT(0); + EVUTIL_FALLTHROUGH; + case EVLIST_ACTIVE_LATER: + event_queue_remove_active_later(base, evcb); + r = 0; + break; + case EVLIST_ACTIVE: + return 0; + case 0: + break; + } + + event_queue_insert_active(base, evcb); + + if (EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + + return r; +} + +int +event_callback_activate_later_nolock_(struct event_base *base, + struct event_callback *evcb) +{ + if (evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) + return 0; + + event_queue_insert_active_later(base, evcb); + if (EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + return 1; +} + void -event_deferred_cb_cancel_(struct event_base *base, struct event_callback *cb) -{ - if (!base) - base = current_base; - event_callback_cancel_(base, cb); -} - -#define MAX_DEFERREDS_QUEUED 32 -int -event_deferred_cb_schedule_(struct event_base *base, struct event_callback *cb) -{ - int r = 1; - if (!base) - base = current_base; - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - if (base->n_deferreds_queued > MAX_DEFERREDS_QUEUED) { - r = event_callback_activate_later_nolock_(base, cb); - } else { - r = event_callback_activate_nolock_(base, cb); - if (r) { - ++base->n_deferreds_queued; - } - } - EVBASE_RELEASE_LOCK(base, th_base_lock); - return r; +event_callback_init_(struct event_base *base, + struct event_callback *cb) +{ + memset(cb, 0, sizeof(*cb)); + cb->evcb_pri = base->nactivequeues - 1; +} + +int +event_callback_cancel_(struct event_base *base, + struct event_callback *evcb) +{ + int r; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_callback_cancel_nolock_(base, evcb, 0); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +int +event_callback_cancel_nolock_(struct event_base *base, + struct event_callback *evcb, int even_if_finalizing) +{ + if ((evcb->evcb_flags & EVLIST_FINALIZING) && !even_if_finalizing) + return 0; + + if (evcb->evcb_flags & EVLIST_INIT) + return event_del_nolock_(event_callback_to_event(evcb), + even_if_finalizing ? EVENT_DEL_EVEN_IF_FINALIZING : EVENT_DEL_AUTOBLOCK); + + switch ((evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { + default: + case EVLIST_ACTIVE|EVLIST_ACTIVE_LATER: + EVUTIL_ASSERT(0); + break; + case EVLIST_ACTIVE: + /* We get different kinds of events, add them together */ + event_queue_remove_active(base, evcb); + return 0; + case EVLIST_ACTIVE_LATER: + event_queue_remove_active_later(base, evcb); + break; + case 0: + break; + } + + return 0; +} + +void +event_deferred_cb_init_(struct event_callback *cb, ev_uint8_t priority, deferred_cb_fn fn, void *arg) +{ + memset(cb, 0, sizeof(*cb)); + cb->evcb_cb_union.evcb_selfcb = fn; + cb->evcb_arg = arg; + cb->evcb_pri = priority; + cb->evcb_closure = EV_CLOSURE_CB_SELF; +} + +void +event_deferred_cb_set_priority_(struct event_callback *cb, ev_uint8_t priority) +{ + cb->evcb_pri = priority; +} + +void +event_deferred_cb_cancel_(struct event_base *base, struct event_callback *cb) +{ + if (!base) + base = current_base; + event_callback_cancel_(base, cb); +} + +#define MAX_DEFERREDS_QUEUED 32 +int +event_deferred_cb_schedule_(struct event_base *base, struct event_callback *cb) +{ + int r = 1; + if (!base) + base = current_base; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (base->n_deferreds_queued > MAX_DEFERREDS_QUEUED) { + r = event_callback_activate_later_nolock_(base, cb); + } else { + r = event_callback_activate_nolock_(base, cb); + if (r) { + ++base->n_deferreds_queued; + } + } + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; } static int @@ -3148,7 +3148,7 @@ timeout_next(struct event_base *base, struct timeval **tv_p) struct timeval *tv = *tv_p; int res = 0; - ev = min_heap_top_(&base->timeheap); + ev = min_heap_top_(&base->timeheap); if (ev == NULL) { /* if no time-based events are active wait for I/O */ @@ -3170,7 +3170,7 @@ timeout_next(struct event_base *base, struct timeval **tv_p) EVUTIL_ASSERT(tv->tv_sec >= 0); EVUTIL_ASSERT(tv->tv_usec >= 0); - event_debug(("timeout_next: event: %p, in %d seconds, %d useconds", ev, (int)tv->tv_sec, (int)tv->tv_usec)); + event_debug(("timeout_next: event: %p, in %d seconds, %d useconds", ev, (int)tv->tv_sec, (int)tv->tv_usec)); out: return (res); @@ -3184,147 +3184,147 @@ timeout_process(struct event_base *base) struct timeval now; struct event *ev; - if (min_heap_empty_(&base->timeheap)) { + if (min_heap_empty_(&base->timeheap)) { return; } gettime(base, &now); - while ((ev = min_heap_top_(&base->timeheap))) { + while ((ev = min_heap_top_(&base->timeheap))) { if (evutil_timercmp(&ev->ev_timeout, &now, >)) break; /* delete this event from the I/O queues */ - event_del_nolock_(ev, EVENT_DEL_NOBLOCK); - - event_debug(("timeout_process: event: %p, call %p", - ev, ev->ev_callback)); - event_active_nolock_(ev, EV_TIMEOUT, 1); - } -} - -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - -#define MAX_EVENT_COUNT(var, v) var = MAX(var, v) - -/* These are a fancy way to spell - if (~flags & EVLIST_INTERNAL) - base->event_count--/++; -*/ -#define DECR_EVENT_COUNT(base,flags) \ - ((base)->event_count -= !((flags) & EVLIST_INTERNAL)) -#define INCR_EVENT_COUNT(base,flags) do { \ - ((base)->event_count += !((flags) & EVLIST_INTERNAL)); \ - MAX_EVENT_COUNT((base)->event_count_max, (base)->event_count); \ -} while (0) - -static void -event_queue_remove_inserted(struct event_base *base, struct event *ev) -{ - EVENT_BASE_ASSERT_LOCKED(base); - if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_INSERTED))) { - event_errx(1, "%s: %p(fd "EV_SOCK_FMT") not on queue %x", __func__, - ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_INSERTED); - return; - } - DECR_EVENT_COUNT(base, ev->ev_flags); - ev->ev_flags &= ~EVLIST_INSERTED; -} -static void -event_queue_remove_active(struct event_base *base, struct event_callback *evcb) -{ - EVENT_BASE_ASSERT_LOCKED(base); - if (EVUTIL_FAILURE_CHECK(!(evcb->evcb_flags & EVLIST_ACTIVE))) { - event_errx(1, "%s: %p not on queue %x", __func__, - evcb, EVLIST_ACTIVE); - return; - } - DECR_EVENT_COUNT(base, evcb->evcb_flags); - evcb->evcb_flags &= ~EVLIST_ACTIVE; - base->event_count_active--; - - TAILQ_REMOVE(&base->activequeues[evcb->evcb_pri], - evcb, evcb_active_next); -} -static void -event_queue_remove_active_later(struct event_base *base, struct event_callback *evcb) -{ - EVENT_BASE_ASSERT_LOCKED(base); - if (EVUTIL_FAILURE_CHECK(!(evcb->evcb_flags & EVLIST_ACTIVE_LATER))) { - event_errx(1, "%s: %p not on queue %x", __func__, - evcb, EVLIST_ACTIVE_LATER); - return; - } - DECR_EVENT_COUNT(base, evcb->evcb_flags); - evcb->evcb_flags &= ~EVLIST_ACTIVE_LATER; - base->event_count_active--; - - TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); -} + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + + event_debug(("timeout_process: event: %p, call %p", + ev, ev->ev_callback)); + event_active_nolock_(ev, EV_TIMEOUT, 1); + } +} + +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +#define MAX_EVENT_COUNT(var, v) var = MAX(var, v) + +/* These are a fancy way to spell + if (~flags & EVLIST_INTERNAL) + base->event_count--/++; +*/ +#define DECR_EVENT_COUNT(base,flags) \ + ((base)->event_count -= !((flags) & EVLIST_INTERNAL)) +#define INCR_EVENT_COUNT(base,flags) do { \ + ((base)->event_count += !((flags) & EVLIST_INTERNAL)); \ + MAX_EVENT_COUNT((base)->event_count_max, (base)->event_count); \ +} while (0) + static void -event_queue_remove_timeout(struct event_base *base, struct event *ev) +event_queue_remove_inserted(struct event_base *base, struct event *ev) { EVENT_BASE_ASSERT_LOCKED(base); - if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_TIMEOUT))) { + if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_INSERTED))) { + event_errx(1, "%s: %p(fd "EV_SOCK_FMT") not on queue %x", __func__, + ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_INSERTED); + return; + } + DECR_EVENT_COUNT(base, ev->ev_flags); + ev->ev_flags &= ~EVLIST_INSERTED; +} +static void +event_queue_remove_active(struct event_base *base, struct event_callback *evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(evcb->evcb_flags & EVLIST_ACTIVE))) { + event_errx(1, "%s: %p not on queue %x", __func__, + evcb, EVLIST_ACTIVE); + return; + } + DECR_EVENT_COUNT(base, evcb->evcb_flags); + evcb->evcb_flags &= ~EVLIST_ACTIVE; + base->event_count_active--; + + TAILQ_REMOVE(&base->activequeues[evcb->evcb_pri], + evcb, evcb_active_next); +} +static void +event_queue_remove_active_later(struct event_base *base, struct event_callback *evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(evcb->evcb_flags & EVLIST_ACTIVE_LATER))) { + event_errx(1, "%s: %p not on queue %x", __func__, + evcb, EVLIST_ACTIVE_LATER); + return; + } + DECR_EVENT_COUNT(base, evcb->evcb_flags); + evcb->evcb_flags &= ~EVLIST_ACTIVE_LATER; + base->event_count_active--; + + TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); +} +static void +event_queue_remove_timeout(struct event_base *base, struct event *ev) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_TIMEOUT))) { event_errx(1, "%s: %p(fd "EV_SOCK_FMT") not on queue %x", __func__, - ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_TIMEOUT); - return; - } - DECR_EVENT_COUNT(base, ev->ev_flags); - ev->ev_flags &= ~EVLIST_TIMEOUT; - - if (is_common_timeout(&ev->ev_timeout, base)) { - struct common_timeout_list *ctl = - get_common_timeout_list(base, &ev->ev_timeout); - TAILQ_REMOVE(&ctl->events, ev, - ev_timeout_pos.ev_next_with_common_timeout); - } else { - min_heap_erase_(&base->timeheap, ev); - } -} - -#ifdef USE_REINSERT_TIMEOUT -/* Remove and reinsert 'ev' into the timeout queue. */ -static void -event_queue_reinsert_timeout(struct event_base *base, struct event *ev, - int was_common, int is_common, int old_timeout_idx) -{ - struct common_timeout_list *ctl; - if (!(ev->ev_flags & EVLIST_TIMEOUT)) { - event_queue_insert_timeout(base, ev); + ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_TIMEOUT); return; } - - switch ((was_common<<1) | is_common) { - case 3: /* Changing from one common timeout to another */ - ctl = base->common_timeout_queues[old_timeout_idx]; - TAILQ_REMOVE(&ctl->events, ev, - ev_timeout_pos.ev_next_with_common_timeout); - ctl = get_common_timeout_list(base, &ev->ev_timeout); - insert_common_timeout_inorder(ctl, ev); - break; - case 2: /* Was common; is no longer common */ - ctl = base->common_timeout_queues[old_timeout_idx]; - TAILQ_REMOVE(&ctl->events, ev, - ev_timeout_pos.ev_next_with_common_timeout); - min_heap_push_(&base->timeheap, ev); + DECR_EVENT_COUNT(base, ev->ev_flags); + ev->ev_flags &= ~EVLIST_TIMEOUT; + + if (is_common_timeout(&ev->ev_timeout, base)) { + struct common_timeout_list *ctl = + get_common_timeout_list(base, &ev->ev_timeout); + TAILQ_REMOVE(&ctl->events, ev, + ev_timeout_pos.ev_next_with_common_timeout); + } else { + min_heap_erase_(&base->timeheap, ev); + } +} + +#ifdef USE_REINSERT_TIMEOUT +/* Remove and reinsert 'ev' into the timeout queue. */ +static void +event_queue_reinsert_timeout(struct event_base *base, struct event *ev, + int was_common, int is_common, int old_timeout_idx) +{ + struct common_timeout_list *ctl; + if (!(ev->ev_flags & EVLIST_TIMEOUT)) { + event_queue_insert_timeout(base, ev); + return; + } + + switch ((was_common<<1) | is_common) { + case 3: /* Changing from one common timeout to another */ + ctl = base->common_timeout_queues[old_timeout_idx]; + TAILQ_REMOVE(&ctl->events, ev, + ev_timeout_pos.ev_next_with_common_timeout); + ctl = get_common_timeout_list(base, &ev->ev_timeout); + insert_common_timeout_inorder(ctl, ev); break; - case 1: /* Wasn't common; has become common. */ - min_heap_erase_(&base->timeheap, ev); - ctl = get_common_timeout_list(base, &ev->ev_timeout); - insert_common_timeout_inorder(ctl, ev); + case 2: /* Was common; is no longer common */ + ctl = base->common_timeout_queues[old_timeout_idx]; + TAILQ_REMOVE(&ctl->events, ev, + ev_timeout_pos.ev_next_with_common_timeout); + min_heap_push_(&base->timeheap, ev); break; - case 0: /* was in heap; is still on heap. */ - min_heap_adjust_(&base->timeheap, ev); + case 1: /* Wasn't common; has become common. */ + min_heap_erase_(&base->timeheap, ev); + ctl = get_common_timeout_list(base, &ev->ev_timeout); + insert_common_timeout_inorder(ctl, ev); break; + case 0: /* was in heap; is still on heap. */ + min_heap_adjust_(&base->timeheap, ev); + break; default: - EVUTIL_ASSERT(0); /* unreachable */ - break; + EVUTIL_ASSERT(0); /* unreachable */ + break; } } -#endif +#endif /* Add 'ev' to the common timeout list in 'ev'. */ static void @@ -3358,110 +3358,110 @@ insert_common_timeout_inorder(struct common_timeout_list *ctl, } static void -event_queue_insert_inserted(struct event_base *base, struct event *ev) -{ - EVENT_BASE_ASSERT_LOCKED(base); - - if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_INSERTED)) { - event_errx(1, "%s: %p(fd "EV_SOCK_FMT") already inserted", __func__, - ev, EV_SOCK_ARG(ev->ev_fd)); - return; - } - - INCR_EVENT_COUNT(base, ev->ev_flags); - - ev->ev_flags |= EVLIST_INSERTED; -} - -static void -event_queue_insert_active(struct event_base *base, struct event_callback *evcb) +event_queue_insert_inserted(struct event_base *base, struct event *ev) { EVENT_BASE_ASSERT_LOCKED(base); - if (evcb->evcb_flags & EVLIST_ACTIVE) { + if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_INSERTED)) { + event_errx(1, "%s: %p(fd "EV_SOCK_FMT") already inserted", __func__, + ev, EV_SOCK_ARG(ev->ev_fd)); + return; + } + + INCR_EVENT_COUNT(base, ev->ev_flags); + + ev->ev_flags |= EVLIST_INSERTED; +} + +static void +event_queue_insert_active(struct event_base *base, struct event_callback *evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + + if (evcb->evcb_flags & EVLIST_ACTIVE) { /* Double insertion is possible for active events */ + return; + } + + INCR_EVENT_COUNT(base, evcb->evcb_flags); + + evcb->evcb_flags |= EVLIST_ACTIVE; + + base->event_count_active++; + MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); + EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); + TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], + evcb, evcb_active_next); +} + +static void +event_queue_insert_active_later(struct event_base *base, struct event_callback *evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (evcb->evcb_flags & (EVLIST_ACTIVE_LATER|EVLIST_ACTIVE)) { + /* Double insertion is possible */ return; } - INCR_EVENT_COUNT(base, evcb->evcb_flags); - - evcb->evcb_flags |= EVLIST_ACTIVE; - - base->event_count_active++; - MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); - EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); - TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], - evcb, evcb_active_next); -} - -static void -event_queue_insert_active_later(struct event_base *base, struct event_callback *evcb) -{ - EVENT_BASE_ASSERT_LOCKED(base); - if (evcb->evcb_flags & (EVLIST_ACTIVE_LATER|EVLIST_ACTIVE)) { - /* Double insertion is possible */ - return; - } - - INCR_EVENT_COUNT(base, evcb->evcb_flags); - evcb->evcb_flags |= EVLIST_ACTIVE_LATER; - base->event_count_active++; - MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); - EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); - TAILQ_INSERT_TAIL(&base->active_later_queue, evcb, evcb_active_next); -} - -static void -event_queue_insert_timeout(struct event_base *base, struct event *ev) -{ - EVENT_BASE_ASSERT_LOCKED(base); - - if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_TIMEOUT)) { - event_errx(1, "%s: %p(fd "EV_SOCK_FMT") already on timeout", __func__, - ev, EV_SOCK_ARG(ev->ev_fd)); - return; - } - - INCR_EVENT_COUNT(base, ev->ev_flags); - - ev->ev_flags |= EVLIST_TIMEOUT; - - if (is_common_timeout(&ev->ev_timeout, base)) { - struct common_timeout_list *ctl = - get_common_timeout_list(base, &ev->ev_timeout); - insert_common_timeout_inorder(ctl, ev); - } else { - min_heap_push_(&base->timeheap, ev); - } -} - -static void -event_queue_make_later_events_active(struct event_base *base) -{ - struct event_callback *evcb; - EVENT_BASE_ASSERT_LOCKED(base); - - while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { - TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); - evcb->evcb_flags = (evcb->evcb_flags & ~EVLIST_ACTIVE_LATER) | EVLIST_ACTIVE; - EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); - TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); - base->n_deferreds_queued += (evcb->evcb_closure == EV_CLOSURE_CB_SELF); - } -} - + INCR_EVENT_COUNT(base, evcb->evcb_flags); + evcb->evcb_flags |= EVLIST_ACTIVE_LATER; + base->event_count_active++; + MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); + EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); + TAILQ_INSERT_TAIL(&base->active_later_queue, evcb, evcb_active_next); +} + +static void +event_queue_insert_timeout(struct event_base *base, struct event *ev) +{ + EVENT_BASE_ASSERT_LOCKED(base); + + if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_TIMEOUT)) { + event_errx(1, "%s: %p(fd "EV_SOCK_FMT") already on timeout", __func__, + ev, EV_SOCK_ARG(ev->ev_fd)); + return; + } + + INCR_EVENT_COUNT(base, ev->ev_flags); + + ev->ev_flags |= EVLIST_TIMEOUT; + + if (is_common_timeout(&ev->ev_timeout, base)) { + struct common_timeout_list *ctl = + get_common_timeout_list(base, &ev->ev_timeout); + insert_common_timeout_inorder(ctl, ev); + } else { + min_heap_push_(&base->timeheap, ev); + } +} + +static void +event_queue_make_later_events_active(struct event_base *base) +{ + struct event_callback *evcb; + EVENT_BASE_ASSERT_LOCKED(base); + + while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { + TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); + evcb->evcb_flags = (evcb->evcb_flags & ~EVLIST_ACTIVE_LATER) | EVLIST_ACTIVE; + EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); + TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); + base->n_deferreds_queued += (evcb->evcb_closure == EV_CLOSURE_CB_SELF); + } +} + /* Functions for debugging */ const char * event_get_version(void) { - return (EVENT__VERSION); + return (EVENT__VERSION); } ev_uint32_t event_get_version_number(void) { - return (EVENT__NUMERIC_VERSION); + return (EVENT__NUMERIC_VERSION); } /* @@ -3475,19 +3475,19 @@ event_get_method(void) return (current_base->evsel->name); } -#ifndef EVENT__DISABLE_MM_REPLACEMENT -static void *(*mm_malloc_fn_)(size_t sz) = NULL; -static void *(*mm_realloc_fn_)(void *p, size_t sz) = NULL; -static void (*mm_free_fn_)(void *p) = NULL; +#ifndef EVENT__DISABLE_MM_REPLACEMENT +static void *(*mm_malloc_fn_)(size_t sz) = NULL; +static void *(*mm_realloc_fn_)(void *p, size_t sz) = NULL; +static void (*mm_free_fn_)(void *p) = NULL; void * event_mm_malloc_(size_t sz) { - if (sz == 0) - return NULL; - - if (mm_malloc_fn_) - return mm_malloc_fn_(sz); + if (sz == 0) + return NULL; + + if (mm_malloc_fn_) + return mm_malloc_fn_(sz); else return malloc(sz); } @@ -3495,65 +3495,65 @@ event_mm_malloc_(size_t sz) void * event_mm_calloc_(size_t count, size_t size) { - if (count == 0 || size == 0) - return NULL; - - if (mm_malloc_fn_) { + if (count == 0 || size == 0) + return NULL; + + if (mm_malloc_fn_) { size_t sz = count * size; - void *p = NULL; - if (count > EV_SIZE_MAX / size) - goto error; - p = mm_malloc_fn_(sz); + void *p = NULL; + if (count > EV_SIZE_MAX / size) + goto error; + p = mm_malloc_fn_(sz); if (p) - return memset(p, 0, sz); - } else { - void *p = calloc(count, size); -#ifdef _WIN32 - /* Windows calloc doesn't reliably set ENOMEM */ - if (p == NULL) - goto error; -#endif + return memset(p, 0, sz); + } else { + void *p = calloc(count, size); +#ifdef _WIN32 + /* Windows calloc doesn't reliably set ENOMEM */ + if (p == NULL) + goto error; +#endif return p; - } - -error: - errno = ENOMEM; - return NULL; + } + +error: + errno = ENOMEM; + return NULL; } char * event_mm_strdup_(const char *str) { - if (!str) { - errno = EINVAL; - return NULL; - } - - if (mm_malloc_fn_) { + if (!str) { + errno = EINVAL; + return NULL; + } + + if (mm_malloc_fn_) { size_t ln = strlen(str); - void *p = NULL; - if (ln == EV_SIZE_MAX) - goto error; - p = mm_malloc_fn_(ln+1); + void *p = NULL; + if (ln == EV_SIZE_MAX) + goto error; + p = mm_malloc_fn_(ln+1); if (p) - return memcpy(p, str, ln+1); + return memcpy(p, str, ln+1); } else -#ifdef _WIN32 +#ifdef _WIN32 return _strdup(str); #else return strdup(str); #endif - -error: - errno = ENOMEM; - return NULL; + +error: + errno = ENOMEM; + return NULL; } void * event_mm_realloc_(void *ptr, size_t sz) { - if (mm_realloc_fn_) - return mm_realloc_fn_(ptr, sz); + if (mm_realloc_fn_) + return mm_realloc_fn_(ptr, sz); else return realloc(ptr, sz); } @@ -3561,8 +3561,8 @@ event_mm_realloc_(void *ptr, size_t sz) void event_mm_free_(void *ptr) { - if (mm_free_fn_) - mm_free_fn_(ptr); + if (mm_free_fn_) + mm_free_fn_(ptr); else free(ptr); } @@ -3572,13 +3572,13 @@ event_set_mem_functions(void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void (*free_fn)(void *ptr)) { - mm_malloc_fn_ = malloc_fn; - mm_realloc_fn_ = realloc_fn; - mm_free_fn_ = free_fn; + mm_malloc_fn_ = malloc_fn; + mm_realloc_fn_ = realloc_fn; + mm_free_fn_ = free_fn; } #endif -#ifdef EVENT__HAVE_EVENTFD +#ifdef EVENT__HAVE_EVENTFD static void evthread_notify_drain_eventfd(evutil_socket_t fd, short what, void *arg) { @@ -3601,7 +3601,7 @@ evthread_notify_drain_default(evutil_socket_t fd, short what, void *arg) { unsigned char buf[1024]; struct event_base *base = arg; -#ifdef _WIN32 +#ifdef _WIN32 while (recv(fd, (char*)buf, sizeof(buf), 0) > 0) ; #else @@ -3617,50 +3617,50 @@ evthread_notify_drain_default(evutil_socket_t fd, short what, void *arg) int evthread_make_base_notifiable(struct event_base *base) { - int r; + int r; if (!base) return -1; - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - r = evthread_make_base_notifiable_nolock_(base); - EVBASE_RELEASE_LOCK(base, th_base_lock); - return r; -} - -static int -evthread_make_base_notifiable_nolock_(struct event_base *base) -{ - void (*cb)(evutil_socket_t, short, void *); - int (*notify)(struct event_base *); - - if (base->th_notify_fn != NULL) { - /* The base is already notifiable: we're doing fine. */ - return 0; - } - -#if defined(EVENT__HAVE_WORKING_KQUEUE) - if (base->evsel == &kqops && event_kq_add_notify_event_(base) == 0) { - base->th_notify_fn = event_kq_notify_base_; - /* No need to add an event here; the backend can wake - * itself up just fine. */ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = evthread_make_base_notifiable_nolock_(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +static int +evthread_make_base_notifiable_nolock_(struct event_base *base) +{ + void (*cb)(evutil_socket_t, short, void *); + int (*notify)(struct event_base *); + + if (base->th_notify_fn != NULL) { + /* The base is already notifiable: we're doing fine. */ return 0; - } + } + +#if defined(EVENT__HAVE_WORKING_KQUEUE) + if (base->evsel == &kqops && event_kq_add_notify_event_(base) == 0) { + base->th_notify_fn = event_kq_notify_base_; + /* No need to add an event here; the backend can wake + * itself up just fine. */ + return 0; + } #endif - -#ifdef EVENT__HAVE_EVENTFD - base->th_notify_fd[0] = evutil_eventfd_(0, - EVUTIL_EFD_CLOEXEC|EVUTIL_EFD_NONBLOCK); + +#ifdef EVENT__HAVE_EVENTFD + base->th_notify_fd[0] = evutil_eventfd_(0, + EVUTIL_EFD_CLOEXEC|EVUTIL_EFD_NONBLOCK); if (base->th_notify_fd[0] >= 0) { - base->th_notify_fd[1] = -1; + base->th_notify_fd[1] = -1; notify = evthread_notify_base_eventfd; cb = evthread_notify_drain_eventfd; - } else + } else #endif - if (evutil_make_internal_pipe_(base->th_notify_fd) == 0) { - notify = evthread_notify_base_default; - cb = evthread_notify_drain_default; - } else { - return -1; + if (evutil_make_internal_pipe_(base->th_notify_fd) == 0) { + notify = evthread_notify_base_default; + cb = evthread_notify_drain_default; + } else { + return -1; } base->th_notify_fn = notify; @@ -3673,211 +3673,211 @@ evthread_make_base_notifiable_nolock_(struct event_base *base) base->th_notify.ev_flags |= EVLIST_INTERNAL; event_priority_set(&base->th_notify, 0); - return event_add_nolock_(&base->th_notify, NULL, 0); -} - -int -event_base_foreach_event_nolock_(struct event_base *base, - event_base_foreach_event_cb fn, void *arg) -{ - int r, i; - unsigned u; - struct event *ev; - - /* Start out with all the EVLIST_INSERTED events. */ - if ((r = evmap_foreach_event_(base, fn, arg))) - return r; - - /* Okay, now we deal with those events that have timeouts and are in - * the min-heap. */ - for (u = 0; u < base->timeheap.n; ++u) { - ev = base->timeheap.p[u]; - if (ev->ev_flags & EVLIST_INSERTED) { - /* we already processed this one */ - continue; - } - if ((r = fn(base, ev, arg))) - return r; - } - - /* Now for the events in one of the timeout queues. - * the min-heap. */ - for (i = 0; i < base->n_common_timeouts; ++i) { - struct common_timeout_list *ctl = - base->common_timeout_queues[i]; - TAILQ_FOREACH(ev, &ctl->events, - ev_timeout_pos.ev_next_with_common_timeout) { - if (ev->ev_flags & EVLIST_INSERTED) { - /* we already processed this one */ - continue; - } - if ((r = fn(base, ev, arg))) - return r; - } - } - - /* Finally, we deal wit all the active events that we haven't touched - * yet. */ - for (i = 0; i < base->nactivequeues; ++i) { - struct event_callback *evcb; - TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { - if ((evcb->evcb_flags & (EVLIST_INIT|EVLIST_INSERTED|EVLIST_TIMEOUT)) != EVLIST_INIT) { - /* This isn't an event (evlist_init clear), or - * we already processed it. (inserted or - * timeout set */ - continue; - } - ev = event_callback_to_event(evcb); - if ((r = fn(base, ev, arg))) - return r; - } - } - - return 0; -} - -/* Helper for event_base_dump_events: called on each event in the event base; - * dumps only the inserted events. */ -static int -dump_inserted_event_fn(const struct event_base *base, const struct event *e, void *arg) -{ - FILE *output = arg; - const char *gloss = (e->ev_events & EV_SIGNAL) ? - "sig" : "fd "; - - if (! (e->ev_flags & (EVLIST_INSERTED|EVLIST_TIMEOUT))) - return 0; - - fprintf(output, " %p [%s "EV_SOCK_FMT"]%s%s%s%s%s%s%s", - (void*)e, gloss, EV_SOCK_ARG(e->ev_fd), - (e->ev_events&EV_READ)?" Read":"", - (e->ev_events&EV_WRITE)?" Write":"", - (e->ev_events&EV_CLOSED)?" EOF":"", - (e->ev_events&EV_SIGNAL)?" Signal":"", - (e->ev_events&EV_PERSIST)?" Persist":"", - (e->ev_events&EV_ET)?" ET":"", - (e->ev_flags&EVLIST_INTERNAL)?" Internal":""); - if (e->ev_flags & EVLIST_TIMEOUT) { - struct timeval tv; - tv.tv_sec = e->ev_timeout.tv_sec; - tv.tv_usec = e->ev_timeout.tv_usec & MICROSECONDS_MASK; - evutil_timeradd(&tv, &base->tv_clock_diff, &tv); - fprintf(output, " Timeout=%ld.%06d", - (long)tv.tv_sec, (int)(tv.tv_usec & MICROSECONDS_MASK)); - } - fputc('\n', output); - - return 0; -} - -/* Helper for event_base_dump_events: called on each event in the event base; - * dumps only the active events. */ -static int -dump_active_event_fn(const struct event_base *base, const struct event *e, void *arg) -{ - FILE *output = arg; - const char *gloss = (e->ev_events & EV_SIGNAL) ? - "sig" : "fd "; - - if (! (e->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) - return 0; - - fprintf(output, " %p [%s "EV_SOCK_FMT", priority=%d]%s%s%s%s%s active%s%s\n", - (void*)e, gloss, EV_SOCK_ARG(e->ev_fd), e->ev_pri, - (e->ev_res&EV_READ)?" Read":"", - (e->ev_res&EV_WRITE)?" Write":"", - (e->ev_res&EV_CLOSED)?" EOF":"", - (e->ev_res&EV_SIGNAL)?" Signal":"", - (e->ev_res&EV_TIMEOUT)?" Timeout":"", - (e->ev_flags&EVLIST_INTERNAL)?" [Internal]":"", - (e->ev_flags&EVLIST_ACTIVE_LATER)?" [NextTime]":""); - - return 0; -} - -int -event_base_foreach_event(struct event_base *base, - event_base_foreach_event_cb fn, void *arg) -{ - int r; - if ((!fn) || (!base)) { - return -1; - } - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - r = event_base_foreach_event_nolock_(base, fn, arg); - EVBASE_RELEASE_LOCK(base, th_base_lock); - return r; -} - - + return event_add_nolock_(&base->th_notify, NULL, 0); +} + +int +event_base_foreach_event_nolock_(struct event_base *base, + event_base_foreach_event_cb fn, void *arg) +{ + int r, i; + unsigned u; + struct event *ev; + + /* Start out with all the EVLIST_INSERTED events. */ + if ((r = evmap_foreach_event_(base, fn, arg))) + return r; + + /* Okay, now we deal with those events that have timeouts and are in + * the min-heap. */ + for (u = 0; u < base->timeheap.n; ++u) { + ev = base->timeheap.p[u]; + if (ev->ev_flags & EVLIST_INSERTED) { + /* we already processed this one */ + continue; + } + if ((r = fn(base, ev, arg))) + return r; + } + + /* Now for the events in one of the timeout queues. + * the min-heap. */ + for (i = 0; i < base->n_common_timeouts; ++i) { + struct common_timeout_list *ctl = + base->common_timeout_queues[i]; + TAILQ_FOREACH(ev, &ctl->events, + ev_timeout_pos.ev_next_with_common_timeout) { + if (ev->ev_flags & EVLIST_INSERTED) { + /* we already processed this one */ + continue; + } + if ((r = fn(base, ev, arg))) + return r; + } + } + + /* Finally, we deal wit all the active events that we haven't touched + * yet. */ + for (i = 0; i < base->nactivequeues; ++i) { + struct event_callback *evcb; + TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { + if ((evcb->evcb_flags & (EVLIST_INIT|EVLIST_INSERTED|EVLIST_TIMEOUT)) != EVLIST_INIT) { + /* This isn't an event (evlist_init clear), or + * we already processed it. (inserted or + * timeout set */ + continue; + } + ev = event_callback_to_event(evcb); + if ((r = fn(base, ev, arg))) + return r; + } + } + + return 0; +} + +/* Helper for event_base_dump_events: called on each event in the event base; + * dumps only the inserted events. */ +static int +dump_inserted_event_fn(const struct event_base *base, const struct event *e, void *arg) +{ + FILE *output = arg; + const char *gloss = (e->ev_events & EV_SIGNAL) ? + "sig" : "fd "; + + if (! (e->ev_flags & (EVLIST_INSERTED|EVLIST_TIMEOUT))) + return 0; + + fprintf(output, " %p [%s "EV_SOCK_FMT"]%s%s%s%s%s%s%s", + (void*)e, gloss, EV_SOCK_ARG(e->ev_fd), + (e->ev_events&EV_READ)?" Read":"", + (e->ev_events&EV_WRITE)?" Write":"", + (e->ev_events&EV_CLOSED)?" EOF":"", + (e->ev_events&EV_SIGNAL)?" Signal":"", + (e->ev_events&EV_PERSIST)?" Persist":"", + (e->ev_events&EV_ET)?" ET":"", + (e->ev_flags&EVLIST_INTERNAL)?" Internal":""); + if (e->ev_flags & EVLIST_TIMEOUT) { + struct timeval tv; + tv.tv_sec = e->ev_timeout.tv_sec; + tv.tv_usec = e->ev_timeout.tv_usec & MICROSECONDS_MASK; + evutil_timeradd(&tv, &base->tv_clock_diff, &tv); + fprintf(output, " Timeout=%ld.%06d", + (long)tv.tv_sec, (int)(tv.tv_usec & MICROSECONDS_MASK)); + } + fputc('\n', output); + + return 0; +} + +/* Helper for event_base_dump_events: called on each event in the event base; + * dumps only the active events. */ +static int +dump_active_event_fn(const struct event_base *base, const struct event *e, void *arg) +{ + FILE *output = arg; + const char *gloss = (e->ev_events & EV_SIGNAL) ? + "sig" : "fd "; + + if (! (e->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) + return 0; + + fprintf(output, " %p [%s "EV_SOCK_FMT", priority=%d]%s%s%s%s%s active%s%s\n", + (void*)e, gloss, EV_SOCK_ARG(e->ev_fd), e->ev_pri, + (e->ev_res&EV_READ)?" Read":"", + (e->ev_res&EV_WRITE)?" Write":"", + (e->ev_res&EV_CLOSED)?" EOF":"", + (e->ev_res&EV_SIGNAL)?" Signal":"", + (e->ev_res&EV_TIMEOUT)?" Timeout":"", + (e->ev_flags&EVLIST_INTERNAL)?" [Internal]":"", + (e->ev_flags&EVLIST_ACTIVE_LATER)?" [NextTime]":""); + + return 0; +} + +int +event_base_foreach_event(struct event_base *base, + event_base_foreach_event_cb fn, void *arg) +{ + int r; + if ((!fn) || (!base)) { + return -1; + } + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_base_foreach_event_nolock_(base, fn, arg); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + + void event_base_dump_events(struct event_base *base, FILE *output) { - EVBASE_ACQUIRE_LOCK(base, th_base_lock); + EVBASE_ACQUIRE_LOCK(base, th_base_lock); fprintf(output, "Inserted events:\n"); - event_base_foreach_event_nolock_(base, dump_inserted_event_fn, output); - - fprintf(output, "Active events:\n"); - event_base_foreach_event_nolock_(base, dump_active_event_fn, output); - EVBASE_RELEASE_LOCK(base, th_base_lock); -} - -void -event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events) -{ - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - - /* Activate any non timer events */ - if (!(events & EV_TIMEOUT)) { - evmap_io_active_(base, fd, events & (EV_READ|EV_WRITE|EV_CLOSED)); - } else { - /* If we want to activate timer events, loop and activate each event with - * the same fd in both the timeheap and common timeouts list */ - int i; - unsigned u; - struct event *ev; - - for (u = 0; u < base->timeheap.n; ++u) { - ev = base->timeheap.p[u]; - if (ev->ev_fd == fd) { - event_active_nolock_(ev, EV_TIMEOUT, 1); - } - } - - for (i = 0; i < base->n_common_timeouts; ++i) { - struct common_timeout_list *ctl = base->common_timeout_queues[i]; - TAILQ_FOREACH(ev, &ctl->events, - ev_timeout_pos.ev_next_with_common_timeout) { - if (ev->ev_fd == fd) { - event_active_nolock_(ev, EV_TIMEOUT, 1); - } - } + event_base_foreach_event_nolock_(base, dump_inserted_event_fn, output); + + fprintf(output, "Active events:\n"); + event_base_foreach_event_nolock_(base, dump_active_event_fn, output); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void +event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + /* Activate any non timer events */ + if (!(events & EV_TIMEOUT)) { + evmap_io_active_(base, fd, events & (EV_READ|EV_WRITE|EV_CLOSED)); + } else { + /* If we want to activate timer events, loop and activate each event with + * the same fd in both the timeheap and common timeouts list */ + int i; + unsigned u; + struct event *ev; + + for (u = 0; u < base->timeheap.n; ++u) { + ev = base->timeheap.p[u]; + if (ev->ev_fd == fd) { + event_active_nolock_(ev, EV_TIMEOUT, 1); + } } + + for (i = 0; i < base->n_common_timeouts; ++i) { + struct common_timeout_list *ctl = base->common_timeout_queues[i]; + TAILQ_FOREACH(ev, &ctl->events, + ev_timeout_pos.ev_next_with_common_timeout) { + if (ev->ev_fd == fd) { + event_active_nolock_(ev, EV_TIMEOUT, 1); + } + } + } } - - EVBASE_RELEASE_LOCK(base, th_base_lock); + + EVBASE_RELEASE_LOCK(base, th_base_lock); } void -event_base_active_by_signal(struct event_base *base, int sig) -{ - EVBASE_ACQUIRE_LOCK(base, th_base_lock); - evmap_signal_active_(base, sig, 1); - EVBASE_RELEASE_LOCK(base, th_base_lock); -} - - -void -event_base_add_virtual_(struct event_base *base) +event_base_active_by_signal(struct event_base *base, int sig) { EVBASE_ACQUIRE_LOCK(base, th_base_lock); + evmap_signal_active_(base, sig, 1); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + + +void +event_base_add_virtual_(struct event_base *base) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); base->virtual_event_count++; - MAX_EVENT_COUNT(base->virtual_event_count_max, base->virtual_event_count); + MAX_EVENT_COUNT(base->virtual_event_count_max, base->virtual_event_count); EVBASE_RELEASE_LOCK(base, th_base_lock); } void -event_base_del_virtual_(struct event_base *base) +event_base_del_virtual_(struct event_base *base) { EVBASE_ACQUIRE_LOCK(base, th_base_lock); EVUTIL_ASSERT(base->virtual_event_count > 0); @@ -3887,65 +3887,65 @@ event_base_del_virtual_(struct event_base *base) EVBASE_RELEASE_LOCK(base, th_base_lock); } -static void -event_free_debug_globals_locks(void) -{ -#ifndef EVENT__DISABLE_THREAD_SUPPORT -#ifndef EVENT__DISABLE_DEBUG_MODE - if (event_debug_map_lock_ != NULL) { - EVTHREAD_FREE_LOCK(event_debug_map_lock_, 0); - event_debug_map_lock_ = NULL; - evthreadimpl_disable_lock_debugging_(); - } -#endif /* EVENT__DISABLE_DEBUG_MODE */ -#endif /* EVENT__DISABLE_THREAD_SUPPORT */ - return; -} - -static void -event_free_debug_globals(void) -{ - event_free_debug_globals_locks(); -} - -static void -event_free_evsig_globals(void) -{ - evsig_free_globals_(); -} - -static void -event_free_evutil_globals(void) -{ - evutil_free_globals_(); -} - -static void -event_free_globals(void) -{ - event_free_debug_globals(); - event_free_evsig_globals(); - event_free_evutil_globals(); -} - -void -libevent_global_shutdown(void) -{ - event_disable_debug_mode(); - event_free_globals(); -} - -#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void +event_free_debug_globals_locks(void) +{ +#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_map_lock_ != NULL) { + EVTHREAD_FREE_LOCK(event_debug_map_lock_, 0); + event_debug_map_lock_ = NULL; + evthreadimpl_disable_lock_debugging_(); + } +#endif /* EVENT__DISABLE_DEBUG_MODE */ +#endif /* EVENT__DISABLE_THREAD_SUPPORT */ + return; +} + +static void +event_free_debug_globals(void) +{ + event_free_debug_globals_locks(); +} + +static void +event_free_evsig_globals(void) +{ + evsig_free_globals_(); +} + +static void +event_free_evutil_globals(void) +{ + evutil_free_globals_(); +} + +static void +event_free_globals(void) +{ + event_free_debug_globals(); + event_free_evsig_globals(); + event_free_evutil_globals(); +} + +void +libevent_global_shutdown(void) +{ + event_disable_debug_mode(); + event_free_globals(); +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT int event_global_setup_locks_(const int enable_locks) { -#ifndef EVENT__DISABLE_DEBUG_MODE - EVTHREAD_SETUP_GLOBAL_LOCK(event_debug_map_lock_, 0); +#ifndef EVENT__DISABLE_DEBUG_MODE + EVTHREAD_SETUP_GLOBAL_LOCK(event_debug_map_lock_, 0); #endif if (evsig_global_setup_locks_(enable_locks) < 0) return -1; - if (evutil_global_setup_locks_(enable_locks) < 0) - return -1; + if (evutil_global_setup_locks_(enable_locks) < 0) + return -1; if (evutil_secure_rng_global_setup_locks_(enable_locks) < 0) return -1; return 0; @@ -3953,29 +3953,29 @@ event_global_setup_locks_(const int enable_locks) #endif void -event_base_assert_ok_(struct event_base *base) +event_base_assert_ok_(struct event_base *base) { EVBASE_ACQUIRE_LOCK(base, th_base_lock); - event_base_assert_ok_nolock_(base); - EVBASE_RELEASE_LOCK(base, th_base_lock); -} - -void -event_base_assert_ok_nolock_(struct event_base *base) -{ - int i; - int count; - - /* First do checks on the per-fd and per-signal lists */ - evmap_check_integrity_(base); - + event_base_assert_ok_nolock_(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void +event_base_assert_ok_nolock_(struct event_base *base) +{ + int i; + int count; + + /* First do checks on the per-fd and per-signal lists */ + evmap_check_integrity_(base); + /* Check the heap property */ for (i = 1; i < (int)base->timeheap.n; ++i) { int parent = (i - 1) / 2; struct event *ev, *p_ev; ev = base->timeheap.p[i]; p_ev = base->timeheap.p[parent]; - EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); + EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); EVUTIL_ASSERT(evutil_timercmp(&p_ev->ev_timeout, &ev->ev_timeout, <=)); EVUTIL_ASSERT(ev->ev_timeout_pos.min_heap_idx == i); } @@ -3984,37 +3984,37 @@ event_base_assert_ok_nolock_(struct event_base *base) for (i = 0; i < base->n_common_timeouts; ++i) { struct common_timeout_list *ctl = base->common_timeout_queues[i]; struct event *last=NULL, *ev; - - EVUTIL_ASSERT_TAILQ_OK(&ctl->events, event, ev_timeout_pos.ev_next_with_common_timeout); - + + EVUTIL_ASSERT_TAILQ_OK(&ctl->events, event, ev_timeout_pos.ev_next_with_common_timeout); + TAILQ_FOREACH(ev, &ctl->events, ev_timeout_pos.ev_next_with_common_timeout) { if (last) EVUTIL_ASSERT(evutil_timercmp(&last->ev_timeout, &ev->ev_timeout, <=)); - EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); + EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); EVUTIL_ASSERT(is_common_timeout(&ev->ev_timeout,base)); EVUTIL_ASSERT(COMMON_TIMEOUT_IDX(&ev->ev_timeout) == i); last = ev; } } - /* Check the active queues. */ - count = 0; - for (i = 0; i < base->nactivequeues; ++i) { - struct event_callback *evcb; - EVUTIL_ASSERT_TAILQ_OK(&base->activequeues[i], event_callback, evcb_active_next); - TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { - EVUTIL_ASSERT((evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) == EVLIST_ACTIVE); - EVUTIL_ASSERT(evcb->evcb_pri == i); - ++count; - } - } - - { - struct event_callback *evcb; - TAILQ_FOREACH(evcb, &base->active_later_queue, evcb_active_next) { - EVUTIL_ASSERT((evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) == EVLIST_ACTIVE_LATER); - ++count; - } - } - EVUTIL_ASSERT(count == base->event_count_active); + /* Check the active queues. */ + count = 0; + for (i = 0; i < base->nactivequeues; ++i) { + struct event_callback *evcb; + EVUTIL_ASSERT_TAILQ_OK(&base->activequeues[i], event_callback, evcb_active_next); + TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { + EVUTIL_ASSERT((evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) == EVLIST_ACTIVE); + EVUTIL_ASSERT(evcb->evcb_pri == i); + ++count; + } + } + + { + struct event_callback *evcb; + TAILQ_FOREACH(evcb, &base->active_later_queue, evcb_active_next) { + EVUTIL_ASSERT((evcb->evcb_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) == EVLIST_ACTIVE_LATER); + ++count; + } + } + EVUTIL_ASSERT(count == base->event_count_active); } diff --git a/contrib/libs/libevent/event_core/ya.make b/contrib/libs/libevent/event_core/ya.make index 3988de817a..06d292321c 100644 --- a/contrib/libs/libevent/event_core/ya.make +++ b/contrib/libs/libevent/event_core/ya.make @@ -1,7 +1,7 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() OWNER( @@ -13,68 +13,68 @@ OWNER( LICENSE(BSD-3-Clause) -PEERDIR( - contrib/libs/libc_compat -) - -ADDINCL( - contrib/libs/libevent - contrib/libs/libevent/include -) - -NO_COMPILER_WARNINGS() - -NO_RUNTIME() - -CFLAGS( - -DHAVE_CONFIG_H - -DEVENT__HAVE_STRLCPY=1 -) - -SRCDIR(contrib/libs/libevent) - -SRCS( - buffer.c - bufferevent.c - bufferevent_filter.c - bufferevent_pair.c - bufferevent_ratelim.c - bufferevent_sock.c - event.c - evmap.c - evthread.c - evutil.c - evutil_rand.c - evutil_time.c - listener.c - log.c - signal.c -) - -IF (OS_WINDOWS) - SRCS( - buffer_iocp.c - bufferevent_async.c - event_iocp.c - win32select.c - ) -ELSE() - SRCS( - poll.c - select.c - ) -ENDIF() - -IF (OS_LINUX) - SRCS( - epoll.c - ) -ENDIF() - -IF (OS_FREEBSD OR OS_DARWIN) - SRCS( - kqueue.c - ) -ENDIF() - -END() +PEERDIR( + contrib/libs/libc_compat +) + +ADDINCL( + contrib/libs/libevent + contrib/libs/libevent/include +) + +NO_COMPILER_WARNINGS() + +NO_RUNTIME() + +CFLAGS( + -DHAVE_CONFIG_H + -DEVENT__HAVE_STRLCPY=1 +) + +SRCDIR(contrib/libs/libevent) + +SRCS( + buffer.c + bufferevent.c + bufferevent_filter.c + bufferevent_pair.c + bufferevent_ratelim.c + bufferevent_sock.c + event.c + evmap.c + evthread.c + evutil.c + evutil_rand.c + evutil_time.c + listener.c + log.c + signal.c +) + +IF (OS_WINDOWS) + SRCS( + buffer_iocp.c + bufferevent_async.c + event_iocp.c + win32select.c + ) +ELSE() + SRCS( + poll.c + select.c + ) +ENDIF() + +IF (OS_LINUX) + SRCS( + epoll.c + ) +ENDIF() + +IF (OS_FREEBSD OR OS_DARWIN) + SRCS( + kqueue.c + ) +ENDIF() + +END() diff --git a/contrib/libs/libevent/event_extra/ya.make b/contrib/libs/libevent/event_extra/ya.make index 9f4c289e62..0970f6e372 100644 --- a/contrib/libs/libevent/event_extra/ya.make +++ b/contrib/libs/libevent/event_extra/ya.make @@ -1,7 +1,7 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() OWNER( @@ -13,31 +13,31 @@ OWNER( LICENSE(BSD-3-Clause) -PEERDIR( - contrib/libs/libc_compat -) - -ADDINCL( - contrib/libs/libevent - contrib/libs/libevent/include -) - -NO_COMPILER_WARNINGS() - -NO_RUNTIME() - -CFLAGS( - -DHAVE_CONFIG_H - -DEVENT__HAVE_STRLCPY=1 -) - -SRCDIR(contrib/libs/libevent) - -SRCS( - evdns.c - event_tagging.c - evrpc.c - http.c -) - -END() +PEERDIR( + contrib/libs/libc_compat +) + +ADDINCL( + contrib/libs/libevent + contrib/libs/libevent/include +) + +NO_COMPILER_WARNINGS() + +NO_RUNTIME() + +CFLAGS( + -DHAVE_CONFIG_H + -DEVENT__HAVE_STRLCPY=1 +) + +SRCDIR(contrib/libs/libevent) + +SRCS( + evdns.c + event_tagging.c + evrpc.c + http.c +) + +END() diff --git a/contrib/libs/libevent/event_iocp.c b/contrib/libs/libevent/event_iocp.c index 6b2a2e15ef..9acaf650cc 100644 --- a/contrib/libs/libevent/event_iocp.c +++ b/contrib/libs/libevent/event_iocp.c @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "evconfig-private.h" +#include "evconfig-private.h" #ifndef _WIN32_WINNT /* Minimum required for InitializeCriticalSectionAndSpinCount */ @@ -46,7 +46,7 @@ #define NOTIFICATION_KEY ((ULONG_PTR)-1) void -event_overlapped_init_(struct event_overlapped *o, iocp_callback cb) +event_overlapped_init_(struct event_overlapped *o, iocp_callback cb) { memset(o, 0, sizeof(struct event_overlapped)); o->cb = cb; @@ -61,9 +61,9 @@ handle_entry(OVERLAPPED *o, ULONG_PTR completion_key, DWORD nBytes, int ok) } static void -loop(void *port_) +loop(void *port_) { - struct event_iocp_port *port = port_; + struct event_iocp_port *port = port_; long ms = port->ms; HANDLE p = port->port; @@ -99,7 +99,7 @@ loop(void *port_) } int -event_iocp_port_associate_(struct event_iocp_port *port, evutil_socket_t fd, +event_iocp_port_associate_(struct event_iocp_port *port, evutil_socket_t fd, ev_uintptr_t key) { HANDLE h; @@ -151,7 +151,7 @@ init_extension_functions(struct win32_extension_fns *ext) const GUID connectex = WSAID_CONNECTEX; const GUID getacceptexsockaddrs = WSAID_GETACCEPTEXSOCKADDRS; SOCKET s = socket(AF_INET, SOCK_STREAM, 0); - if (s == EVUTIL_INVALID_SOCKET) + if (s == EVUTIL_INVALID_SOCKET) return; ext->AcceptEx = get_extension_function(s, &acceptex); ext->ConnectEx = get_extension_function(s, &connectex); @@ -165,7 +165,7 @@ init_extension_functions(struct win32_extension_fns *ext) static struct win32_extension_fns the_extension_fns; const struct win32_extension_fns * -event_get_win32_extension_fns_(void) +event_get_win32_extension_fns_(void) { return &the_extension_fns; } @@ -173,7 +173,7 @@ event_get_win32_extension_fns_(void) #define N_CPUS_DEFAULT 2 struct event_iocp_port * -event_iocp_port_launch_(int n_cpus) +event_iocp_port_launch_(int n_cpus) { struct event_iocp_port *port; int i; @@ -224,7 +224,7 @@ err: } static void -event_iocp_port_unlock_and_free_(struct event_iocp_port *port) +event_iocp_port_unlock_and_free_(struct event_iocp_port *port) { DeleteCriticalSection(&port->lock); CloseHandle(port->port); @@ -247,7 +247,7 @@ event_iocp_notify_all(struct event_iocp_port *port) } int -event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec) +event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec) { DWORD ms = INFINITE; int n; @@ -265,7 +265,7 @@ event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec) n = port->n_live_threads; LeaveCriticalSection(&port->lock); if (n == 0) { - event_iocp_port_unlock_and_free_(port); + event_iocp_port_unlock_and_free_(port); return 0; } else { return -1; @@ -273,7 +273,7 @@ event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec) } int -event_iocp_activate_overlapped_( +event_iocp_activate_overlapped_( struct event_iocp_port *port, struct event_overlapped *o, ev_uintptr_t key, ev_uint32_t n) { @@ -284,9 +284,9 @@ event_iocp_activate_overlapped_( } struct event_iocp_port * -event_base_get_iocp_(struct event_base *base) +event_base_get_iocp_(struct event_base *base) { -#ifdef _WIN32 +#ifdef _WIN32 return base->iocp; #else return NULL; diff --git a/contrib/libs/libevent/event_openssl/ya.make b/contrib/libs/libevent/event_openssl/ya.make index fe042893c0..bc5079a9d7 100644 --- a/contrib/libs/libevent/event_openssl/ya.make +++ b/contrib/libs/libevent/event_openssl/ya.make @@ -1,7 +1,7 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() OWNER( @@ -13,29 +13,29 @@ OWNER( LICENSE(BSD-3-Clause) -PEERDIR( - contrib/libs/libc_compat - contrib/libs/openssl -) - -ADDINCL( - contrib/libs/libevent - contrib/libs/libevent/include -) - -NO_COMPILER_WARNINGS() - -NO_RUNTIME() - -CFLAGS( - -DHAVE_CONFIG_H - -DEVENT__HAVE_STRLCPY=1 -) - -SRCDIR(contrib/libs/libevent) - -SRCS( - bufferevent_openssl.c -) - -END() +PEERDIR( + contrib/libs/libc_compat + contrib/libs/openssl +) + +ADDINCL( + contrib/libs/libevent + contrib/libs/libevent/include +) + +NO_COMPILER_WARNINGS() + +NO_RUNTIME() + +CFLAGS( + -DHAVE_CONFIG_H + -DEVENT__HAVE_STRLCPY=1 +) + +SRCDIR(contrib/libs/libevent) + +SRCS( + bufferevent_openssl.c +) + +END() diff --git a/contrib/libs/libevent/event_tagging.c b/contrib/libs/libevent/event_tagging.c index b021e8c8de..32a01290dd 100644 --- a/contrib/libs/libevent/event_tagging.c +++ b/contrib/libs/libevent/event_tagging.c @@ -26,27 +26,27 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_PARAM_H +#ifdef EVENT__HAVE_SYS_PARAM_H #include <sys/param.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include <winsock2.h> #include <windows.h> #undef WIN32_LEAN_AND_MEAN -#endif - -#ifdef EVENT__HAVE_SYS_IOCTL_H +#endif + +#ifdef EVENT__HAVE_SYS_IOCTL_H #include <sys/ioctl.h> #endif #include <sys/queue.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -54,10 +54,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifndef _WIN32 +#ifndef _WIN32 #include <syslog.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif #include <limits.h> @@ -93,13 +93,13 @@ a final padding nibble with value 0 is appended. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_decode_tag(ev_uint32_t *ptag, struct evbuffer *evbuf); void @@ -217,14 +217,14 @@ decode_tag_internal(ev_uint32_t *ptag, struct evbuffer *evbuf, int dodrain) while (count++ < len) { ev_uint8_t lower = *data++; - if (shift >= 28) { - /* Make sure it fits into 32 bits */ - if (shift > 28) - return (-1); - if ((lower & 0x7f) > 15) - return (-1); - } - number |= (lower & (unsigned)0x7f) << shift; + if (shift >= 28) { + /* Make sure it fits into 32 bits */ + if (shift > 28) + return (-1); + if ((lower & 0x7f) > 15) + return (-1); + } + number |= (lower & (unsigned)0x7f) << shift; shift += 7; if (!(lower & 0x80)) { diff --git a/contrib/libs/libevent/event_thread/ya.make b/contrib/libs/libevent/event_thread/ya.make index 63579b456a..00fb32fdf9 100644 --- a/contrib/libs/libevent/event_thread/ya.make +++ b/contrib/libs/libevent/event_thread/ya.make @@ -1,7 +1,7 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + WITHOUT_LICENSE_TEXTS() OWNER( @@ -13,34 +13,34 @@ OWNER( LICENSE(BSD-3-Clause) -PEERDIR( - contrib/libs/libc_compat -) - -ADDINCL( - contrib/libs/libevent - contrib/libs/libevent/include -) - -NO_COMPILER_WARNINGS() - -NO_RUNTIME() - -CFLAGS( - -DHAVE_CONFIG_H - -DEVENT__HAVE_STRLCPY=1 -) - -SRCDIR(contrib/libs/libevent) - -IF (OS_WINDOWS) - SRCS( - evthread_win32.c - ) -ELSE() - SRCS( - evthread_pthread.c - ) -ENDIF() - -END() +PEERDIR( + contrib/libs/libc_compat +) + +ADDINCL( + contrib/libs/libevent + contrib/libs/libevent/include +) + +NO_COMPILER_WARNINGS() + +NO_RUNTIME() + +CFLAGS( + -DHAVE_CONFIG_H + -DEVENT__HAVE_STRLCPY=1 +) + +SRCDIR(contrib/libs/libevent) + +IF (OS_WINDOWS) + SRCS( + evthread_win32.c + ) +ELSE() + SRCS( + evthread_pthread.c + ) +ENDIF() + +END() diff --git a/contrib/libs/libevent/evmap-internal.h b/contrib/libs/libevent/evmap-internal.h index dfc81d5087..f1f5c08994 100644 --- a/contrib/libs/libevent/evmap-internal.h +++ b/contrib/libs/libevent/evmap-internal.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVMAP_INTERNAL_H_INCLUDED_ -#define EVMAP_INTERNAL_H_INCLUDED_ +#ifndef EVMAP_INTERNAL_H_INCLUDED_ +#define EVMAP_INTERNAL_H_INCLUDED_ /** @file evmap-internal.h * @@ -39,15 +39,15 @@ struct event; /** Initialize an event_map for use. */ -void evmap_io_initmap_(struct event_io_map* ctx); -void evmap_signal_initmap_(struct event_signal_map* ctx); +void evmap_io_initmap_(struct event_io_map* ctx); +void evmap_signal_initmap_(struct event_signal_map* ctx); /** Remove all entries from an event_map. @param ctx the map to clear. */ -void evmap_io_clear_(struct event_io_map* ctx); -void evmap_signal_clear_(struct event_signal_map* ctx); +void evmap_io_clear_(struct event_io_map* ctx); +void evmap_signal_clear_(struct event_signal_map* ctx); /** Add an IO event (some combination of EV_READ or EV_WRITE) to an event_base's list of events on a given file descriptor, and tell the @@ -59,7 +59,7 @@ void evmap_signal_clear_(struct event_signal_map* ctx); @param fd the file descriptor corresponding to ev. @param ev the event to add. */ -int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev); +int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev); /** Remove an IO event (some combination of EV_READ or EV_WRITE) to an event_base's list of events on a given file descriptor, and tell the underlying eventops about the fd if its state has changed. @@ -68,50 +68,50 @@ int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) @param fd the file descriptor corresponding to ev. @param ev the event to remove. */ -int evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev); +int evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev); /** Active the set of events waiting on an event_base for a given fd. @param base the event_base to operate on. @param fd the file descriptor that has become active. @param events a bitmask of EV_READ|EV_WRITE|EV_ET. */ -void evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events); +void evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events); /* These functions behave in the same way as evmap_io_*, except they work on * signals rather than fds. signals use a linear map everywhere; fds use * either a linear map or a hashtable. */ -int evmap_signal_add_(struct event_base *base, int signum, struct event *ev); -int evmap_signal_del_(struct event_base *base, int signum, struct event *ev); -void evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls); - -/* Return the fdinfo object associated with a given fd. If the fd has no - * events associated with it, the result may be NULL. - */ -void *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd); - -/* Helper for event_reinit(): Tell the backend to re-add every fd and signal - * for which we have a pending event. - */ -int evmap_reinit_(struct event_base *base); - -/* Helper for event_base_free(): Call event_del() on every pending fd and - * signal event. - */ -void evmap_delete_all_(struct event_base *base); - -/* Helper for event_base_assert_ok_(): Check referential integrity of the - * evmaps. - */ -void evmap_check_integrity_(struct event_base *base); - -/* Helper: Call fn on every fd or signal event, passing as its arguments the - * provided event_base, the event, and arg. If fn returns 0, process the next - * event. If it returns any other value, return that value and process no - * more events. - */ -int evmap_foreach_event_(struct event_base *base, - event_base_foreach_event_cb fn, - void *arg); - -#endif /* EVMAP_INTERNAL_H_INCLUDED_ */ +int evmap_signal_add_(struct event_base *base, int signum, struct event *ev); +int evmap_signal_del_(struct event_base *base, int signum, struct event *ev); +void evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls); + +/* Return the fdinfo object associated with a given fd. If the fd has no + * events associated with it, the result may be NULL. + */ +void *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd); + +/* Helper for event_reinit(): Tell the backend to re-add every fd and signal + * for which we have a pending event. + */ +int evmap_reinit_(struct event_base *base); + +/* Helper for event_base_free(): Call event_del() on every pending fd and + * signal event. + */ +void evmap_delete_all_(struct event_base *base); + +/* Helper for event_base_assert_ok_(): Check referential integrity of the + * evmaps. + */ +void evmap_check_integrity_(struct event_base *base); + +/* Helper: Call fn on every fd or signal event, passing as its arguments the + * provided event_base, the event, and arg. If fn returns 0, process the next + * event. If it returns any other value, return that value and process no + * more events. + */ +int evmap_foreach_event_(struct event_base *base, + event_base_foreach_event_cb fn, + void *arg); + +#endif /* EVMAP_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/evmap.c b/contrib/libs/libevent/evmap.c index e4e35c6877..11c7617f79 100644 --- a/contrib/libs/libevent/evmap.c +++ b/contrib/libs/libevent/evmap.c @@ -24,26 +24,26 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #undef WIN32_LEAN_AND_MEAN #endif #include <sys/types.h> -#if !defined(_WIN32) && defined(EVENT__HAVE_SYS_TIME_H) +#if !defined(_WIN32) && defined(EVENT__HAVE_SYS_TIME_H) #include <sys/time.h> #endif #include <sys/queue.h> #include <stdio.h> #include <stdlib.h> -#ifndef _WIN32 +#ifndef _WIN32 #include <unistd.h> #endif #include <errno.h> -#include <limits.h> +#include <limits.h> #include <signal.h> #include <string.h> #include <time.h> @@ -57,16 +57,16 @@ write on a given fd, and the number of each. */ struct evmap_io { - struct event_dlist events; + struct event_dlist events; ev_uint16_t nread; ev_uint16_t nwrite; - ev_uint16_t nclose; + ev_uint16_t nclose; }; /* An entry for an evmap_signal list: notes all the events that want to know when a signal triggers. */ struct evmap_signal { - struct event_dlist events; + struct event_dlist events; }; /* On some platforms, fds start at 0 and increment by 1 as they are @@ -113,38 +113,38 @@ HT_GENERATE(event_io_map, event_map_entry, map_node, hashsocket, eqsocket, #define GET_IO_SLOT(x, map, slot, type) \ do { \ - struct event_map_entry key_, *ent_; \ - key_.fd = slot; \ - ent_ = HT_FIND(event_io_map, map, &key_); \ - (x) = ent_ ? &ent_->ent.type : NULL; \ + struct event_map_entry key_, *ent_; \ + key_.fd = slot; \ + ent_ = HT_FIND(event_io_map, map, &key_); \ + (x) = ent_ ? &ent_->ent.type : NULL; \ } while (0); #define GET_IO_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) \ do { \ - struct event_map_entry key_, *ent_; \ - key_.fd = slot; \ - HT_FIND_OR_INSERT_(event_io_map, map_node, hashsocket, map, \ - event_map_entry, &key_, ptr, \ + struct event_map_entry key_, *ent_; \ + key_.fd = slot; \ + HT_FIND_OR_INSERT_(event_io_map, map_node, hashsocket, map, \ + event_map_entry, &key_, ptr, \ { \ - ent_ = *ptr; \ + ent_ = *ptr; \ }, \ { \ - ent_ = mm_calloc(1,sizeof(struct event_map_entry)+fdinfo_len); \ - if (EVUTIL_UNLIKELY(ent_ == NULL)) \ + ent_ = mm_calloc(1,sizeof(struct event_map_entry)+fdinfo_len); \ + if (EVUTIL_UNLIKELY(ent_ == NULL)) \ return (-1); \ - ent_->fd = slot; \ - (ctor)(&ent_->ent.type); \ - HT_FOI_INSERT_(map_node, map, &key_, ent_, ptr) \ + ent_->fd = slot; \ + (ctor)(&ent_->ent.type); \ + HT_FOI_INSERT_(map_node, map, &key_, ent_, ptr) \ }); \ - (x) = &ent_->ent.type; \ + (x) = &ent_->ent.type; \ } while (0) -void evmap_io_initmap_(struct event_io_map *ctx) +void evmap_io_initmap_(struct event_io_map *ctx) { HT_INIT(event_io_map, ctx); } -void evmap_io_clear_(struct event_io_map *ctx) +void evmap_io_clear_(struct event_io_map *ctx) { struct event_map_entry **ent, **next, *this; for (ent = HT_START(event_io_map, ctx); ent; ent = next) { @@ -186,14 +186,14 @@ void evmap_io_clear_(struct event_io_map *ctx) GET_SIGNAL_SLOT_AND_CTOR(x,map,slot,type,ctor,fdinfo_len) #define FDINFO_OFFSET sizeof(struct evmap_io) void -evmap_io_initmap_(struct event_io_map* ctx) +evmap_io_initmap_(struct event_io_map* ctx) { - evmap_signal_initmap_(ctx); + evmap_signal_initmap_(ctx); } void -evmap_io_clear_(struct event_io_map* ctx) +evmap_io_clear_(struct event_io_map* ctx) { - evmap_signal_clear_(ctx); + evmap_signal_clear_(ctx); } #endif @@ -208,15 +208,15 @@ evmap_make_space(struct event_signal_map *map, int slot, int msize) int nentries = map->nentries ? map->nentries : 32; void **tmp; - if (slot > INT_MAX / 2) - return (-1); - + if (slot > INT_MAX / 2) + return (-1); + while (nentries <= slot) nentries <<= 1; - if (nentries > INT_MAX / msize) - return (-1); - + if (nentries > INT_MAX / msize) + return (-1); + tmp = (void **)mm_realloc(map->entries, nentries * msize); if (tmp == NULL) return (-1); @@ -232,14 +232,14 @@ evmap_make_space(struct event_signal_map *map, int slot, int msize) } void -evmap_signal_initmap_(struct event_signal_map *ctx) +evmap_signal_initmap_(struct event_signal_map *ctx) { ctx->nentries = 0; ctx->entries = NULL; } void -evmap_signal_clear_(struct event_signal_map *ctx) +evmap_signal_clear_(struct event_signal_map *ctx) { if (ctx->entries != NULL) { int i; @@ -260,22 +260,22 @@ evmap_signal_clear_(struct event_signal_map *ctx) static void evmap_io_init(struct evmap_io *entry) { - LIST_INIT(&entry->events); + LIST_INIT(&entry->events); entry->nread = 0; entry->nwrite = 0; - entry->nclose = 0; + entry->nclose = 0; } /* return -1 on error, 0 on success if nothing changed in the event backend, * and 1 on success if something did. */ int -evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) +evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) { const struct eventop *evsel = base->evsel; struct event_io_map *io = &base->io; struct evmap_io *ctx = NULL; - int nread, nwrite, nclose, retval = 0; + int nread, nwrite, nclose, retval = 0; short res = 0, old = 0; struct event *old_ev; @@ -295,14 +295,14 @@ evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) nread = ctx->nread; nwrite = ctx->nwrite; - nclose = ctx->nclose; + nclose = ctx->nclose; if (nread) old |= EV_READ; if (nwrite) old |= EV_WRITE; - if (nclose) - old |= EV_CLOSED; + if (nclose) + old |= EV_CLOSED; if (ev->ev_events & EV_READ) { if (++nread == 1) @@ -312,17 +312,17 @@ evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) if (++nwrite == 1) res |= EV_WRITE; } - if (ev->ev_events & EV_CLOSED) { - if (++nclose == 1) - res |= EV_CLOSED; - } - if (EVUTIL_UNLIKELY(nread > 0xffff || nwrite > 0xffff || nclose > 0xffff)) { + if (ev->ev_events & EV_CLOSED) { + if (++nclose == 1) + res |= EV_CLOSED; + } + if (EVUTIL_UNLIKELY(nread > 0xffff || nwrite > 0xffff || nclose > 0xffff)) { event_warnx("Too many events reading or writing on fd %d", (int)fd); return -1; } if (EVENT_DEBUG_MODE_IS_ON() && - (old_ev = LIST_FIRST(&ctx->events)) && + (old_ev = LIST_FIRST(&ctx->events)) && (old_ev->ev_events&EV_ET) != (ev->ev_events&EV_ET)) { event_warnx("Tried to mix edge-triggered and non-edge-triggered" " events on fd %d", (int)fd); @@ -342,8 +342,8 @@ evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) ctx->nread = (ev_uint16_t) nread; ctx->nwrite = (ev_uint16_t) nwrite; - ctx->nclose = (ev_uint16_t) nclose; - LIST_INSERT_HEAD(&ctx->events, ev, ev_io_next); + ctx->nclose = (ev_uint16_t) nclose; + LIST_INSERT_HEAD(&ctx->events, ev, ev_io_next); return (retval); } @@ -351,12 +351,12 @@ evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev) /* return -1 on error, 0 on success if nothing changed in the event backend, * and 1 on success if something did. */ int -evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev) +evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev) { const struct eventop *evsel = base->evsel; struct event_io_map *io = &base->io; struct evmap_io *ctx; - int nread, nwrite, nclose, retval = 0; + int nread, nwrite, nclose, retval = 0; short res = 0, old = 0; if (fd < 0) @@ -373,14 +373,14 @@ evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev) nread = ctx->nread; nwrite = ctx->nwrite; - nclose = ctx->nclose; + nclose = ctx->nclose; if (nread) old |= EV_READ; if (nwrite) old |= EV_WRITE; - if (nclose) - old |= EV_CLOSED; + if (nclose) + old |= EV_CLOSED; if (ev->ev_events & EV_READ) { if (--nread == 0) @@ -392,48 +392,48 @@ evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev) res |= EV_WRITE; EVUTIL_ASSERT(nwrite >= 0); } - if (ev->ev_events & EV_CLOSED) { - if (--nclose == 0) - res |= EV_CLOSED; - EVUTIL_ASSERT(nclose >= 0); - } + if (ev->ev_events & EV_CLOSED) { + if (--nclose == 0) + res |= EV_CLOSED; + EVUTIL_ASSERT(nclose >= 0); + } if (res) { void *extra = ((char*)ctx) + sizeof(struct evmap_io); - if (evsel->del(base, ev->ev_fd, - old, (ev->ev_events & EV_ET) | res, extra) == -1) { - retval = -1; - } else { - retval = 1; - } + if (evsel->del(base, ev->ev_fd, + old, (ev->ev_events & EV_ET) | res, extra) == -1) { + retval = -1; + } else { + retval = 1; + } } ctx->nread = nread; ctx->nwrite = nwrite; - ctx->nclose = nclose; - LIST_REMOVE(ev, ev_io_next); + ctx->nclose = nclose; + LIST_REMOVE(ev, ev_io_next); return (retval); } void -evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events) +evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events) { struct event_io_map *io = &base->io; struct evmap_io *ctx; struct event *ev; #ifndef EVMAP_USE_HT - if (fd < 0 || fd >= io->nentries) - return; + if (fd < 0 || fd >= io->nentries) + return; #endif GET_IO_SLOT(ctx, io, fd, evmap_io); - if (NULL == ctx) - return; - LIST_FOREACH(ev, &ctx->events, ev_io_next) { + if (NULL == ctx) + return; + LIST_FOREACH(ev, &ctx->events, ev_io_next) { if (ev->ev_events & (events & ~EV_ET)) - event_active_nolock_(ev, ev->ev_events & events, 1); + event_active_nolock_(ev, ev->ev_events & events, 1); } } @@ -442,20 +442,20 @@ evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events) static void evmap_signal_init(struct evmap_signal *entry) { - LIST_INIT(&entry->events); + LIST_INIT(&entry->events); } int -evmap_signal_add_(struct event_base *base, int sig, struct event *ev) +evmap_signal_add_(struct event_base *base, int sig, struct event *ev) { const struct eventop *evsel = base->evsigsel; struct event_signal_map *map = &base->sigmap; struct evmap_signal *ctx = NULL; - if (sig < 0 || sig >= NSIG) - return (-1); - + if (sig < 0 || sig >= NSIG) + return (-1); + if (sig >= map->nentries) { if (evmap_make_space( map, sig, sizeof(struct evmap_signal *)) == -1) @@ -464,32 +464,32 @@ evmap_signal_add_(struct event_base *base, int sig, struct event *ev) GET_SIGNAL_SLOT_AND_CTOR(ctx, map, sig, evmap_signal, evmap_signal_init, base->evsigsel->fdinfo_len); - if (LIST_EMPTY(&ctx->events)) { + if (LIST_EMPTY(&ctx->events)) { if (evsel->add(base, ev->ev_fd, 0, EV_SIGNAL, NULL) == -1) return (-1); } - LIST_INSERT_HEAD(&ctx->events, ev, ev_signal_next); + LIST_INSERT_HEAD(&ctx->events, ev, ev_signal_next); return (1); } int -evmap_signal_del_(struct event_base *base, int sig, struct event *ev) +evmap_signal_del_(struct event_base *base, int sig, struct event *ev) { const struct eventop *evsel = base->evsigsel; struct event_signal_map *map = &base->sigmap; struct evmap_signal *ctx; - if (sig < 0 || sig >= map->nentries) + if (sig < 0 || sig >= map->nentries) return (-1); GET_SIGNAL_SLOT(ctx, map, sig, evmap_signal); - LIST_REMOVE(ev, ev_signal_next); - - if (LIST_FIRST(&ctx->events) == NULL) { + LIST_REMOVE(ev, ev_signal_next); + + if (LIST_FIRST(&ctx->events) == NULL) { if (evsel->del(base, ev->ev_fd, 0, EV_SIGNAL, NULL) == -1) return (-1); } @@ -498,24 +498,24 @@ evmap_signal_del_(struct event_base *base, int sig, struct event *ev) } void -evmap_signal_active_(struct event_base *base, evutil_socket_t sig, int ncalls) +evmap_signal_active_(struct event_base *base, evutil_socket_t sig, int ncalls) { struct event_signal_map *map = &base->sigmap; struct evmap_signal *ctx; struct event *ev; - if (sig < 0 || sig >= map->nentries) - return; + if (sig < 0 || sig >= map->nentries) + return; GET_SIGNAL_SLOT(ctx, map, sig, evmap_signal); - if (!ctx) - return; - LIST_FOREACH(ev, &ctx->events, ev_signal_next) - event_active_nolock_(ev, EV_SIGNAL, ncalls); + if (!ctx) + return; + LIST_FOREACH(ev, &ctx->events, ev_signal_next) + event_active_nolock_(ev, EV_SIGNAL, ncalls); } void * -evmap_io_get_fdinfo_(struct event_io_map *map, evutil_socket_t fd) +evmap_io_get_fdinfo_(struct event_io_map *map, evutil_socket_t fd) { struct evmap_io *ctx; GET_IO_SLOT(ctx, map, fd, evmap_io); @@ -525,177 +525,177 @@ evmap_io_get_fdinfo_(struct event_io_map *map, evutil_socket_t fd) return NULL; } -/* Callback type for evmap_io_foreach_fd */ -typedef int (*evmap_io_foreach_fd_cb)( - struct event_base *, evutil_socket_t, struct evmap_io *, void *); - -/* Multipurpose helper function: Iterate over every file descriptor event_base - * for which we could have EV_READ or EV_WRITE events. For each such fd, call - * fn(base, signum, evmap_io, arg), where fn is the user-provided - * function, base is the event_base, signum is the signal number, evmap_io - * is an evmap_io structure containing a list of events pending on the - * file descriptor, and arg is the user-supplied argument. - * - * If fn returns 0, continue on to the next signal. Otherwise, return the same - * value that fn returned. - * - * Note that there is no guarantee that the file descriptors will be processed - * in any particular order. - */ -static int -evmap_io_foreach_fd(struct event_base *base, - evmap_io_foreach_fd_cb fn, - void *arg) -{ - evutil_socket_t fd; - struct event_io_map *iomap = &base->io; - int r = 0; -#ifdef EVMAP_USE_HT - struct event_map_entry **mapent; - HT_FOREACH(mapent, event_io_map, iomap) { - struct evmap_io *ctx = &(*mapent)->ent.evmap_io; - fd = (*mapent)->fd; -#else - for (fd = 0; fd < iomap->nentries; ++fd) { - struct evmap_io *ctx = iomap->entries[fd]; - if (!ctx) - continue; -#endif - if ((r = fn(base, fd, ctx, arg))) - break; - } - return r; -} - -/* Callback type for evmap_signal_foreach_signal */ -typedef int (*evmap_signal_foreach_signal_cb)( - struct event_base *, int, struct evmap_signal *, void *); - -/* Multipurpose helper function: Iterate over every signal number in the - * event_base for which we could have signal events. For each such signal, - * call fn(base, signum, evmap_signal, arg), where fn is the user-provided - * function, base is the event_base, signum is the signal number, evmap_signal - * is an evmap_signal structure containing a list of events pending on the - * signal, and arg is the user-supplied argument. - * - * If fn returns 0, continue on to the next signal. Otherwise, return the same - * value that fn returned. - */ -static int -evmap_signal_foreach_signal(struct event_base *base, - evmap_signal_foreach_signal_cb fn, - void *arg) -{ - struct event_signal_map *sigmap = &base->sigmap; - int r = 0; - int signum; - - for (signum = 0; signum < sigmap->nentries; ++signum) { - struct evmap_signal *ctx = sigmap->entries[signum]; - if (!ctx) - continue; - if ((r = fn(base, signum, ctx, arg))) - break; - } - return r; -} - -/* Helper for evmap_reinit_: tell the backend to add every fd for which we have - * pending events, with the appropriate combination of EV_READ, EV_WRITE, and - * EV_ET. */ -static int -evmap_io_reinit_iter_fn(struct event_base *base, evutil_socket_t fd, - struct evmap_io *ctx, void *arg) -{ - const struct eventop *evsel = base->evsel; - void *extra; - int *result = arg; - short events = 0; - struct event *ev; - EVUTIL_ASSERT(ctx); - - extra = ((char*)ctx) + sizeof(struct evmap_io); - if (ctx->nread) - events |= EV_READ; - if (ctx->nwrite) - events |= EV_WRITE; - if (ctx->nclose) - events |= EV_CLOSED; - if (evsel->fdinfo_len) - memset(extra, 0, evsel->fdinfo_len); - if (events && - (ev = LIST_FIRST(&ctx->events)) && - (ev->ev_events & EV_ET)) - events |= EV_ET; - if (evsel->add(base, fd, 0, events, extra) == -1) - *result = -1; - - return 0; -} - -/* Helper for evmap_reinit_: tell the backend to add every signal for which we - * have pending events. */ -static int -evmap_signal_reinit_iter_fn(struct event_base *base, - int signum, struct evmap_signal *ctx, void *arg) -{ - const struct eventop *evsel = base->evsigsel; - int *result = arg; - - if (!LIST_EMPTY(&ctx->events)) { - if (evsel->add(base, signum, 0, EV_SIGNAL, NULL) == -1) - *result = -1; - } - return 0; -} - -int -evmap_reinit_(struct event_base *base) -{ - int result = 0; - - evmap_io_foreach_fd(base, evmap_io_reinit_iter_fn, &result); - if (result < 0) - return -1; - evmap_signal_foreach_signal(base, evmap_signal_reinit_iter_fn, &result); - if (result < 0) - return -1; - return 0; -} - -/* Helper for evmap_delete_all_: delete every event in an event_dlist. */ -static int -delete_all_in_dlist(struct event_dlist *dlist) -{ - struct event *ev; - while ((ev = LIST_FIRST(dlist))) - event_del(ev); - return 0; -} - -/* Helper for evmap_delete_all_: delete every event pending on an fd. */ -static int -evmap_io_delete_all_iter_fn(struct event_base *base, evutil_socket_t fd, - struct evmap_io *io_info, void *arg) -{ - return delete_all_in_dlist(&io_info->events); -} - -/* Helper for evmap_delete_all_: delete every event pending on a signal. */ -static int -evmap_signal_delete_all_iter_fn(struct event_base *base, int signum, - struct evmap_signal *sig_info, void *arg) -{ - return delete_all_in_dlist(&sig_info->events); -} - -void -evmap_delete_all_(struct event_base *base) -{ - evmap_signal_foreach_signal(base, evmap_signal_delete_all_iter_fn, NULL); - evmap_io_foreach_fd(base, evmap_io_delete_all_iter_fn, NULL); -} - +/* Callback type for evmap_io_foreach_fd */ +typedef int (*evmap_io_foreach_fd_cb)( + struct event_base *, evutil_socket_t, struct evmap_io *, void *); + +/* Multipurpose helper function: Iterate over every file descriptor event_base + * for which we could have EV_READ or EV_WRITE events. For each such fd, call + * fn(base, signum, evmap_io, arg), where fn is the user-provided + * function, base is the event_base, signum is the signal number, evmap_io + * is an evmap_io structure containing a list of events pending on the + * file descriptor, and arg is the user-supplied argument. + * + * If fn returns 0, continue on to the next signal. Otherwise, return the same + * value that fn returned. + * + * Note that there is no guarantee that the file descriptors will be processed + * in any particular order. + */ +static int +evmap_io_foreach_fd(struct event_base *base, + evmap_io_foreach_fd_cb fn, + void *arg) +{ + evutil_socket_t fd; + struct event_io_map *iomap = &base->io; + int r = 0; +#ifdef EVMAP_USE_HT + struct event_map_entry **mapent; + HT_FOREACH(mapent, event_io_map, iomap) { + struct evmap_io *ctx = &(*mapent)->ent.evmap_io; + fd = (*mapent)->fd; +#else + for (fd = 0; fd < iomap->nentries; ++fd) { + struct evmap_io *ctx = iomap->entries[fd]; + if (!ctx) + continue; +#endif + if ((r = fn(base, fd, ctx, arg))) + break; + } + return r; +} + +/* Callback type for evmap_signal_foreach_signal */ +typedef int (*evmap_signal_foreach_signal_cb)( + struct event_base *, int, struct evmap_signal *, void *); + +/* Multipurpose helper function: Iterate over every signal number in the + * event_base for which we could have signal events. For each such signal, + * call fn(base, signum, evmap_signal, arg), where fn is the user-provided + * function, base is the event_base, signum is the signal number, evmap_signal + * is an evmap_signal structure containing a list of events pending on the + * signal, and arg is the user-supplied argument. + * + * If fn returns 0, continue on to the next signal. Otherwise, return the same + * value that fn returned. + */ +static int +evmap_signal_foreach_signal(struct event_base *base, + evmap_signal_foreach_signal_cb fn, + void *arg) +{ + struct event_signal_map *sigmap = &base->sigmap; + int r = 0; + int signum; + + for (signum = 0; signum < sigmap->nentries; ++signum) { + struct evmap_signal *ctx = sigmap->entries[signum]; + if (!ctx) + continue; + if ((r = fn(base, signum, ctx, arg))) + break; + } + return r; +} + +/* Helper for evmap_reinit_: tell the backend to add every fd for which we have + * pending events, with the appropriate combination of EV_READ, EV_WRITE, and + * EV_ET. */ +static int +evmap_io_reinit_iter_fn(struct event_base *base, evutil_socket_t fd, + struct evmap_io *ctx, void *arg) +{ + const struct eventop *evsel = base->evsel; + void *extra; + int *result = arg; + short events = 0; + struct event *ev; + EVUTIL_ASSERT(ctx); + + extra = ((char*)ctx) + sizeof(struct evmap_io); + if (ctx->nread) + events |= EV_READ; + if (ctx->nwrite) + events |= EV_WRITE; + if (ctx->nclose) + events |= EV_CLOSED; + if (evsel->fdinfo_len) + memset(extra, 0, evsel->fdinfo_len); + if (events && + (ev = LIST_FIRST(&ctx->events)) && + (ev->ev_events & EV_ET)) + events |= EV_ET; + if (evsel->add(base, fd, 0, events, extra) == -1) + *result = -1; + + return 0; +} + +/* Helper for evmap_reinit_: tell the backend to add every signal for which we + * have pending events. */ +static int +evmap_signal_reinit_iter_fn(struct event_base *base, + int signum, struct evmap_signal *ctx, void *arg) +{ + const struct eventop *evsel = base->evsigsel; + int *result = arg; + + if (!LIST_EMPTY(&ctx->events)) { + if (evsel->add(base, signum, 0, EV_SIGNAL, NULL) == -1) + *result = -1; + } + return 0; +} + +int +evmap_reinit_(struct event_base *base) +{ + int result = 0; + + evmap_io_foreach_fd(base, evmap_io_reinit_iter_fn, &result); + if (result < 0) + return -1; + evmap_signal_foreach_signal(base, evmap_signal_reinit_iter_fn, &result); + if (result < 0) + return -1; + return 0; +} + +/* Helper for evmap_delete_all_: delete every event in an event_dlist. */ +static int +delete_all_in_dlist(struct event_dlist *dlist) +{ + struct event *ev; + while ((ev = LIST_FIRST(dlist))) + event_del(ev); + return 0; +} + +/* Helper for evmap_delete_all_: delete every event pending on an fd. */ +static int +evmap_io_delete_all_iter_fn(struct event_base *base, evutil_socket_t fd, + struct evmap_io *io_info, void *arg) +{ + return delete_all_in_dlist(&io_info->events); +} + +/* Helper for evmap_delete_all_: delete every event pending on a signal. */ +static int +evmap_signal_delete_all_iter_fn(struct event_base *base, int signum, + struct evmap_signal *sig_info, void *arg) +{ + return delete_all_in_dlist(&sig_info->events); +} + +void +evmap_delete_all_(struct event_base *base) +{ + evmap_signal_foreach_signal(base, evmap_signal_delete_all_iter_fn, NULL); + evmap_io_foreach_fd(base, evmap_io_delete_all_iter_fn, NULL); +} + /** Per-fd structure for use with changelists. It keeps track, for each fd or * signal using the changelist, of where its entry in the changelist is. */ @@ -705,7 +705,7 @@ struct event_changelist_fdinfo { }; void -event_changelist_init_(struct event_changelist *changelist) +event_changelist_init_(struct event_changelist *changelist) { changelist->changes = NULL; changelist->changes_size = 0; @@ -730,26 +730,26 @@ event_change_get_fdinfo(struct event_base *base, return (void*)ptr; } -/** Callback helper for event_changelist_assert_ok */ -static int -event_changelist_assert_ok_foreach_iter_fn( - struct event_base *base, - evutil_socket_t fd, struct evmap_io *io, void *arg) -{ - struct event_changelist *changelist = &base->changelist; - struct event_changelist_fdinfo *f; - f = (void*) - ( ((char*)io) + sizeof(struct evmap_io) ); - if (f->idxplus1) { - struct event_change *c = &changelist->changes[f->idxplus1 - 1]; - EVUTIL_ASSERT(c->fd == fd); - } - return 0; -} - +/** Callback helper for event_changelist_assert_ok */ +static int +event_changelist_assert_ok_foreach_iter_fn( + struct event_base *base, + evutil_socket_t fd, struct evmap_io *io, void *arg) +{ + struct event_changelist *changelist = &base->changelist; + struct event_changelist_fdinfo *f; + f = (void*) + ( ((char*)io) + sizeof(struct evmap_io) ); + if (f->idxplus1) { + struct event_change *c = &changelist->changes[f->idxplus1 - 1]; + EVUTIL_ASSERT(c->fd == fd); + } + return 0; +} + /** Make sure that the changelist is consistent with the evmap structures. */ static void -event_changelist_assert_ok(struct event_base *base) +event_changelist_assert_ok(struct event_base *base) { int i; struct event_changelist *changelist = &base->changelist; @@ -764,19 +764,19 @@ event_changelist_assert_ok(struct event_base *base) EVUTIL_ASSERT(f->idxplus1 == i + 1); } - evmap_io_foreach_fd(base, - event_changelist_assert_ok_foreach_iter_fn, - NULL); + evmap_io_foreach_fd(base, + event_changelist_assert_ok_foreach_iter_fn, + NULL); } - -#ifdef DEBUG_CHANGELIST -#define event_changelist_check(base) event_changelist_assert_ok((base)) + +#ifdef DEBUG_CHANGELIST +#define event_changelist_check(base) event_changelist_assert_ok((base)) #else #define event_changelist_check(base) ((void)0) #endif void -event_changelist_remove_all_(struct event_changelist *changelist, +event_changelist_remove_all_(struct event_changelist *changelist, struct event_base *base) { int i; @@ -797,11 +797,11 @@ event_changelist_remove_all_(struct event_changelist *changelist, } void -event_changelist_freemem_(struct event_changelist *changelist) +event_changelist_freemem_(struct event_changelist *changelist) { if (changelist->changes) mm_free(changelist->changes); - event_changelist_init_(changelist); /* zero it all out. */ + event_changelist_init_(changelist); /* zero it all out. */ } /** Increase the size of 'changelist' to hold more changes. */ @@ -863,13 +863,13 @@ event_changelist_get_or_construct(struct event_changelist *changelist, } int -event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events, +event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, short events, void *p) { struct event_changelist *changelist = &base->changelist; struct event_changelist_fdinfo *fdinfo = p; struct event_change *change; - ev_uint8_t evchange = EV_CHANGE_ADD | (events & (EV_ET|EV_PERSIST|EV_SIGNAL)); + ev_uint8_t evchange = EV_CHANGE_ADD | (events & (EV_ET|EV_PERSIST|EV_SIGNAL)); event_changelist_check(base); @@ -881,25 +881,25 @@ event_changelist_add_(struct event_base *base, evutil_socket_t fd, short old, sh * since the delete might fail (because the fd had been closed since * the last add, for instance. */ - if (events & (EV_READ|EV_SIGNAL)) - change->read_change = evchange; - if (events & EV_WRITE) - change->write_change = evchange; - if (events & EV_CLOSED) - change->close_change = evchange; + if (events & (EV_READ|EV_SIGNAL)) + change->read_change = evchange; + if (events & EV_WRITE) + change->write_change = evchange; + if (events & EV_CLOSED) + change->close_change = evchange; event_changelist_check(base); return (0); } int -event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events, +event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, short events, void *p) { struct event_changelist *changelist = &base->changelist; struct event_changelist_fdinfo *fdinfo = p; struct event_change *change; - ev_uint8_t del = EV_CHANGE_DEL | (events & EV_ET); + ev_uint8_t del = EV_CHANGE_DEL | (events & EV_ET); event_changelist_check(base); change = event_changelist_get_or_construct(changelist, fd, old, fdinfo); @@ -907,11 +907,11 @@ event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, sh if (!change) return -1; - /* A delete on an event set that doesn't contain the event to be - deleted produces a no-op. This effectively emoves any previous - uncommitted add, rather than replacing it: on those platforms where - "add, delete, dispatch" is not the same as "no-op, dispatch", we - want the no-op behavior. + /* A delete on an event set that doesn't contain the event to be + deleted produces a no-op. This effectively emoves any previous + uncommitted add, rather than replacing it: on those platforms where + "add, delete, dispatch" is not the same as "no-op, dispatch", we + want the no-op behavior. If we have a no-op item, we could remove it it from the list entirely, but really there's not much point: skipping the no-op @@ -923,140 +923,140 @@ event_changelist_del_(struct event_base *base, evutil_socket_t fd, short old, sh */ if (events & (EV_READ|EV_SIGNAL)) { - if (!(change->old_events & (EV_READ | EV_SIGNAL))) + if (!(change->old_events & (EV_READ | EV_SIGNAL))) change->read_change = 0; else - change->read_change = del; + change->read_change = del; } if (events & EV_WRITE) { - if (!(change->old_events & EV_WRITE)) + if (!(change->old_events & EV_WRITE)) change->write_change = 0; else - change->write_change = del; - } - if (events & EV_CLOSED) { - if (!(change->old_events & EV_CLOSED)) - change->close_change = 0; - else - change->close_change = del; + change->write_change = del; } + if (events & EV_CLOSED) { + if (!(change->old_events & EV_CLOSED)) + change->close_change = 0; + else + change->close_change = del; + } event_changelist_check(base); return (0); } -/* Helper for evmap_check_integrity_: verify that all of the events pending on - * given fd are set up correctly, and that the nread and nwrite counts on that - * fd are correct. */ -static int -evmap_io_check_integrity_fn(struct event_base *base, evutil_socket_t fd, - struct evmap_io *io_info, void *arg) +/* Helper for evmap_check_integrity_: verify that all of the events pending on + * given fd are set up correctly, and that the nread and nwrite counts on that + * fd are correct. */ +static int +evmap_io_check_integrity_fn(struct event_base *base, evutil_socket_t fd, + struct evmap_io *io_info, void *arg) { struct event *ev; - int n_read = 0, n_write = 0, n_close = 0; - - /* First, make sure the list itself isn't corrupt. Otherwise, - * running LIST_FOREACH could be an exciting adventure. */ - EVUTIL_ASSERT_LIST_OK(&io_info->events, event, ev_io_next); + int n_read = 0, n_write = 0, n_close = 0; - LIST_FOREACH(ev, &io_info->events, ev_io_next) { + /* First, make sure the list itself isn't corrupt. Otherwise, + * running LIST_FOREACH could be an exciting adventure. */ + EVUTIL_ASSERT_LIST_OK(&io_info->events, event, ev_io_next); + + LIST_FOREACH(ev, &io_info->events, ev_io_next) { EVUTIL_ASSERT(ev->ev_flags & EVLIST_INSERTED); - EVUTIL_ASSERT(ev->ev_fd == fd); - EVUTIL_ASSERT(!(ev->ev_events & EV_SIGNAL)); - EVUTIL_ASSERT((ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED))); - if (ev->ev_events & EV_READ) - ++n_read; - if (ev->ev_events & EV_WRITE) - ++n_write; - if (ev->ev_events & EV_CLOSED) - ++n_close; + EVUTIL_ASSERT(ev->ev_fd == fd); + EVUTIL_ASSERT(!(ev->ev_events & EV_SIGNAL)); + EVUTIL_ASSERT((ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED))); + if (ev->ev_events & EV_READ) + ++n_read; + if (ev->ev_events & EV_WRITE) + ++n_write; + if (ev->ev_events & EV_CLOSED) + ++n_close; } - EVUTIL_ASSERT(n_read == io_info->nread); - EVUTIL_ASSERT(n_write == io_info->nwrite); - EVUTIL_ASSERT(n_close == io_info->nclose); - - return 0; -} - -/* Helper for evmap_check_integrity_: verify that all of the events pending - * on given signal are set up correctly. */ -static int -evmap_signal_check_integrity_fn(struct event_base *base, - int signum, struct evmap_signal *sig_info, void *arg) -{ - struct event *ev; - /* First, make sure the list itself isn't corrupt. */ - EVUTIL_ASSERT_LIST_OK(&sig_info->events, event, ev_signal_next); - - LIST_FOREACH(ev, &sig_info->events, ev_io_next) { - EVUTIL_ASSERT(ev->ev_flags & EVLIST_INSERTED); - EVUTIL_ASSERT(ev->ev_fd == signum); - EVUTIL_ASSERT((ev->ev_events & EV_SIGNAL)); - EVUTIL_ASSERT(!(ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED))); + EVUTIL_ASSERT(n_read == io_info->nread); + EVUTIL_ASSERT(n_write == io_info->nwrite); + EVUTIL_ASSERT(n_close == io_info->nclose); + + return 0; +} + +/* Helper for evmap_check_integrity_: verify that all of the events pending + * on given signal are set up correctly. */ +static int +evmap_signal_check_integrity_fn(struct event_base *base, + int signum, struct evmap_signal *sig_info, void *arg) +{ + struct event *ev; + /* First, make sure the list itself isn't corrupt. */ + EVUTIL_ASSERT_LIST_OK(&sig_info->events, event, ev_signal_next); + + LIST_FOREACH(ev, &sig_info->events, ev_io_next) { + EVUTIL_ASSERT(ev->ev_flags & EVLIST_INSERTED); + EVUTIL_ASSERT(ev->ev_fd == signum); + EVUTIL_ASSERT((ev->ev_events & EV_SIGNAL)); + EVUTIL_ASSERT(!(ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED))); } - return 0; -} - -void -evmap_check_integrity_(struct event_base *base) -{ - evmap_io_foreach_fd(base, evmap_io_check_integrity_fn, NULL); - evmap_signal_foreach_signal(base, evmap_signal_check_integrity_fn, NULL); - - if (base->evsel->add == event_changelist_add_) - event_changelist_assert_ok(base); -} - -/* Helper type for evmap_foreach_event_: Bundles a function to call on every - * event, and the user-provided void* to use as its third argument. */ -struct evmap_foreach_event_helper { - event_base_foreach_event_cb fn; - void *arg; -}; - -/* Helper for evmap_foreach_event_: calls a provided function on every event - * pending on a given fd. */ -static int -evmap_io_foreach_event_fn(struct event_base *base, evutil_socket_t fd, - struct evmap_io *io_info, void *arg) -{ - struct evmap_foreach_event_helper *h = arg; - struct event *ev; - int r; - LIST_FOREACH(ev, &io_info->events, ev_io_next) { - if ((r = h->fn(base, ev, h->arg))) - return r; + return 0; +} + +void +evmap_check_integrity_(struct event_base *base) +{ + evmap_io_foreach_fd(base, evmap_io_check_integrity_fn, NULL); + evmap_signal_foreach_signal(base, evmap_signal_check_integrity_fn, NULL); + + if (base->evsel->add == event_changelist_add_) + event_changelist_assert_ok(base); +} + +/* Helper type for evmap_foreach_event_: Bundles a function to call on every + * event, and the user-provided void* to use as its third argument. */ +struct evmap_foreach_event_helper { + event_base_foreach_event_cb fn; + void *arg; +}; + +/* Helper for evmap_foreach_event_: calls a provided function on every event + * pending on a given fd. */ +static int +evmap_io_foreach_event_fn(struct event_base *base, evutil_socket_t fd, + struct evmap_io *io_info, void *arg) +{ + struct evmap_foreach_event_helper *h = arg; + struct event *ev; + int r; + LIST_FOREACH(ev, &io_info->events, ev_io_next) { + if ((r = h->fn(base, ev, h->arg))) + return r; } - return 0; -} - -/* Helper for evmap_foreach_event_: calls a provided function on every event - * pending on a given signal. */ -static int -evmap_signal_foreach_event_fn(struct event_base *base, int signum, - struct evmap_signal *sig_info, void *arg) -{ - struct event *ev; - struct evmap_foreach_event_helper *h = arg; - int r; - LIST_FOREACH(ev, &sig_info->events, ev_signal_next) { - if ((r = h->fn(base, ev, h->arg))) - return r; + return 0; +} + +/* Helper for evmap_foreach_event_: calls a provided function on every event + * pending on a given signal. */ +static int +evmap_signal_foreach_event_fn(struct event_base *base, int signum, + struct evmap_signal *sig_info, void *arg) +{ + struct event *ev; + struct evmap_foreach_event_helper *h = arg; + int r; + LIST_FOREACH(ev, &sig_info->events, ev_signal_next) { + if ((r = h->fn(base, ev, h->arg))) + return r; } - return 0; -} - -int -evmap_foreach_event_(struct event_base *base, - event_base_foreach_event_cb fn, void *arg) -{ - struct evmap_foreach_event_helper h; - int r; - h.fn = fn; - h.arg = arg; - if ((r = evmap_io_foreach_fd(base, evmap_io_foreach_event_fn, &h))) - return r; - return evmap_signal_foreach_signal(base, evmap_signal_foreach_event_fn, &h); + return 0; +} + +int +evmap_foreach_event_(struct event_base *base, + event_base_foreach_event_cb fn, void *arg) +{ + struct evmap_foreach_event_helper h; + int r; + h.fn = fn; + h.arg = arg; + if ((r = evmap_io_foreach_fd(base, evmap_io_foreach_event_fn, &h))) + return r; + return evmap_signal_foreach_signal(base, evmap_signal_foreach_event_fn, &h); } - + diff --git a/contrib/libs/libevent/evport.c b/contrib/libs/libevent/evport.c index a014386bfe..f85539bd94 100644 --- a/contrib/libs/libevent/evport.c +++ b/contrib/libs/libevent/evport.c @@ -54,10 +54,10 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_EVENT_PORTS +#include "evconfig-private.h" +#ifdef EVENT__HAVE_EVENT_PORTS + #include <sys/time.h> #include <sys/queue.h> #include <errno.h> @@ -78,8 +78,8 @@ #include "evsignal-internal.h" #include "evmap-internal.h" -#define INITIAL_EVENTS_PER_GETN 8 -#define MAX_EVENTS_PER_GETN 4096 +#define INITIAL_EVENTS_PER_GETN 8 +#define MAX_EVENTS_PER_GETN 4096 /* * Per-file-descriptor information about what events we're subscribed to. These @@ -87,12 +87,12 @@ */ struct fd_info { - /* combinations of EV_READ and EV_WRITE */ - short fdi_what; - /* Index of this fd within ed_pending, plus 1. Zero if this fd is - * not in ed_pending. (The +1 is a hack so that memset(0) will set - * it to a nil index. */ - int pending_idx_plus_1; + /* combinations of EV_READ and EV_WRITE */ + short fdi_what; + /* Index of this fd within ed_pending, plus 1. Zero if this fd is + * not in ed_pending. (The +1 is a hack so that memset(0) will set + * it to a nil index. */ + int pending_idx_plus_1; }; #define FDI_HAS_READ(fdi) ((fdi)->fdi_what & EV_READ) @@ -103,15 +103,15 @@ struct fd_info { struct evport_data { int ed_port; /* event port for system events */ - /* How many elements of ed_pending should we look at? */ - int ed_npending; - /* How many elements are allocated in ed_pending and pevtlist? */ - int ed_maxevents; + /* How many elements of ed_pending should we look at? */ + int ed_npending; + /* How many elements are allocated in ed_pending and pevtlist? */ + int ed_maxevents; /* fdi's that we need to reassoc */ - int *ed_pending; - /* storage space for incoming events. */ - port_event_t *ed_pevtlist; - + int *ed_pending; + /* storage space for incoming events. */ + port_event_t *ed_pevtlist; + }; static void* evport_init(struct event_base *); @@ -119,7 +119,7 @@ static int evport_add(struct event_base *, int fd, short old, short events, void static int evport_del(struct event_base *, int fd, short old, short events, void *); static int evport_dispatch(struct event_base *, struct timeval *); static void evport_dealloc(struct event_base *); -static int grow(struct evport_data *, int min_events); +static int grow(struct evport_data *, int min_events); const struct eventop evportops = { "evport", @@ -130,7 +130,7 @@ const struct eventop evportops = { evport_dealloc, 1, /* need reinit */ 0, /* features */ - sizeof(struct fd_info), /* fdinfo length */ + sizeof(struct fd_info), /* fdinfo length */ }; /* @@ -150,47 +150,47 @@ evport_init(struct event_base *base) return (NULL); } - if (grow(evpd, INITIAL_EVENTS_PER_GETN) < 0) { + if (grow(evpd, INITIAL_EVENTS_PER_GETN) < 0) { close(evpd->ed_port); mm_free(evpd); - return NULL; + return NULL; } - - evpd->ed_npending = 0; + + evpd->ed_npending = 0; - evsig_init_(base); + evsig_init_(base); return (evpd); } -static int -grow(struct evport_data *data, int min_events) -{ - int newsize; - int *new_pending; - port_event_t *new_pevtlist; - if (data->ed_maxevents) { - newsize = data->ed_maxevents; - do { - newsize *= 2; - } while (newsize < min_events); - } else { - newsize = min_events; - } - - new_pending = mm_realloc(data->ed_pending, sizeof(int)*newsize); - if (new_pending == NULL) - return -1; - data->ed_pending = new_pending; - new_pevtlist = mm_realloc(data->ed_pevtlist, sizeof(port_event_t)*newsize); - if (new_pevtlist == NULL) - return -1; - data->ed_pevtlist = new_pevtlist; - - data->ed_maxevents = newsize; - return 0; -} - +static int +grow(struct evport_data *data, int min_events) +{ + int newsize; + int *new_pending; + port_event_t *new_pevtlist; + if (data->ed_maxevents) { + newsize = data->ed_maxevents; + do { + newsize *= 2; + } while (newsize < min_events); + } else { + newsize = min_events; + } + + new_pending = mm_realloc(data->ed_pending, sizeof(int)*newsize); + if (new_pending == NULL) + return -1; + data->ed_pending = new_pending; + new_pevtlist = mm_realloc(data->ed_pevtlist, sizeof(port_event_t)*newsize); + if (new_pevtlist == NULL) + return -1; + data->ed_pevtlist = new_pevtlist; + + data->ed_maxevents = newsize; + return 0; +} + #ifdef CHECK_INVARIANTS /* * Checks some basic properties about the evport_data structure. Because it @@ -236,7 +236,7 @@ reassociate(struct evport_data *epdp, struct fd_info *fdip, int fd) if (sysevents != 0) { if (port_associate(epdp->ed_port, PORT_SOURCE_FD, - fd, sysevents, fdip) == -1) { + fd, sysevents, fdip) == -1) { event_warn("port_associate"); return (-1); } @@ -257,12 +257,12 @@ evport_dispatch(struct event_base *base, struct timeval *tv) { int i, res; struct evport_data *epdp = base->evbase; - port_event_t *pevtlist = epdp->ed_pevtlist; + port_event_t *pevtlist = epdp->ed_pevtlist; /* * port_getn will block until it has at least nevents events. It will * also return how many it's given us (which may be more than we asked - * for, as long as it's less than our maximum (ed_maxevents)) in + * for, as long as it's less than our maximum (ed_maxevents)) in * nevents. */ int nevents = 1; @@ -285,25 +285,25 @@ evport_dispatch(struct event_base *base, struct timeval *tv) * last time which need reassociation. See comment at the end of the * loop below. */ - for (i = 0; i < epdp->ed_npending; ++i) { + for (i = 0; i < epdp->ed_npending; ++i) { struct fd_info *fdi = NULL; - const int fd = epdp->ed_pending[i]; - if (fd != -1) { - /* We might have cleared out this event; we need - * to be sure that it's still set. */ - fdi = evmap_io_get_fdinfo_(&base->io, fd); + const int fd = epdp->ed_pending[i]; + if (fd != -1) { + /* We might have cleared out this event; we need + * to be sure that it's still set. */ + fdi = evmap_io_get_fdinfo_(&base->io, fd); } if (fdi != NULL && FDI_HAS_EVENTS(fdi)) { reassociate(epdp, fdi, fd); - /* epdp->ed_pending[i] = -1; */ - fdi->pending_idx_plus_1 = 0; + /* epdp->ed_pending[i] = -1; */ + fdi->pending_idx_plus_1 = 0; } } EVBASE_RELEASE_LOCK(base, th_base_lock); - res = port_getn(epdp->ed_port, pevtlist, epdp->ed_maxevents, + res = port_getn(epdp->ed_port, pevtlist, epdp->ed_maxevents, (unsigned int *) &nevents, ts_p); EVBASE_ACQUIRE_LOCK(base, th_base_lock); @@ -325,13 +325,13 @@ evport_dispatch(struct event_base *base, struct timeval *tv) for (i = 0; i < nevents; ++i) { port_event_t *pevt = &pevtlist[i]; int fd = (int) pevt->portev_object; - struct fd_info *fdi = pevt->portev_user; - /*EVUTIL_ASSERT(evmap_io_get_fdinfo_(&base->io, fd) == fdi);*/ + struct fd_info *fdi = pevt->portev_user; + /*EVUTIL_ASSERT(evmap_io_get_fdinfo_(&base->io, fd) == fdi);*/ check_evportop(epdp); check_event(pevt); epdp->ed_pending[i] = fd; - fdi->pending_idx_plus_1 = i + 1; + fdi->pending_idx_plus_1 = i + 1; /* * Figure out what kind of event it was @@ -353,17 +353,17 @@ evport_dispatch(struct event_base *base, struct timeval *tv) if (pevt->portev_events & (POLLERR|POLLHUP|POLLNVAL)) res |= EV_READ|EV_WRITE; - evmap_io_active_(base, fd, res); + evmap_io_active_(base, fd, res); } /* end of all events gotten */ - epdp->ed_npending = nevents; - - if (nevents == epdp->ed_maxevents && - epdp->ed_maxevents < MAX_EVENTS_PER_GETN) { - /* we used all the space this time. We should be ready - * for more events next time around. */ - grow(epdp, epdp->ed_maxevents * 2); - } - + epdp->ed_npending = nevents; + + if (nevents == epdp->ed_maxevents && + epdp->ed_maxevents < MAX_EVENTS_PER_GETN) { + /* we used all the space this time. We should be ready + * for more events next time around. */ + grow(epdp, epdp->ed_maxevents * 2); + } + check_evportop(epdp); return (0); @@ -379,7 +379,7 @@ static int evport_add(struct event_base *base, int fd, short old, short events, void *p) { struct evport_data *evpd = base->evbase; - struct fd_info *fdi = p; + struct fd_info *fdi = p; check_evportop(evpd); @@ -396,12 +396,12 @@ static int evport_del(struct event_base *base, int fd, short old, short events, void *p) { struct evport_data *evpd = base->evbase; - struct fd_info *fdi = p; - int associated = ! fdi->pending_idx_plus_1; + struct fd_info *fdi = p; + int associated = ! fdi->pending_idx_plus_1; check_evportop(evpd); - fdi->fdi_what &= ~(events &(EV_READ|EV_WRITE)); + fdi->fdi_what &= ~(events &(EV_READ|EV_WRITE)); if (associated) { if (!FDI_HAS_EVENTS(fdi) && @@ -421,10 +421,10 @@ evport_del(struct event_base *base, int fd, short old, short events, void *p) } } else { if ((fdi->fdi_what & (EV_READ|EV_WRITE)) == 0) { - const int i = fdi->pending_idx_plus_1 - 1; - EVUTIL_ASSERT(evpd->ed_pending[i] == fd); + const int i = fdi->pending_idx_plus_1 - 1; + EVUTIL_ASSERT(evpd->ed_pending[i] == fd); evpd->ed_pending[i] = -1; - fdi->pending_idx_plus_1 = 0; + fdi->pending_idx_plus_1 = 0; } } return 0; @@ -436,16 +436,16 @@ evport_dealloc(struct event_base *base) { struct evport_data *evpd = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); close(evpd->ed_port); - if (evpd->ed_pending) - mm_free(evpd->ed_pending); - if (evpd->ed_pevtlist) - mm_free(evpd->ed_pevtlist); - + if (evpd->ed_pending) + mm_free(evpd->ed_pending); + if (evpd->ed_pevtlist) + mm_free(evpd->ed_pevtlist); + mm_free(evpd); } - -#endif /* EVENT__HAVE_EVENT_PORTS */ + +#endif /* EVENT__HAVE_EVENT_PORTS */ diff --git a/contrib/libs/libevent/evrpc-internal.h b/contrib/libs/libevent/evrpc-internal.h index 9eb376386d..5af3aa6a98 100644 --- a/contrib/libs/libevent/evrpc-internal.h +++ b/contrib/libs/libevent/evrpc-internal.h @@ -24,10 +24,10 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVRPC_INTERNAL_H_INCLUDED_ -#define EVRPC_INTERNAL_H_INCLUDED_ +#ifndef EVRPC_INTERNAL_H_INCLUDED_ +#define EVRPC_INTERNAL_H_INCLUDED_ -#include "event2/http.h" +#include "event2/http.h" #include "http-internal.h" struct evrpc; @@ -57,7 +57,7 @@ TAILQ_HEAD(evrpc_hook_list, evrpc_hook); struct evrpc_hook_ctx; TAILQ_HEAD(evrpc_pause_list, evrpc_hook_ctx); -struct evrpc_hooks_ { +struct evrpc_hooks_ { /* hooks for processing outbound and inbound rpcs */ struct evrpc_hook_list in_hooks; struct evrpc_hook_list out_hooks; @@ -70,7 +70,7 @@ struct evrpc_hooks_ { #define paused_requests common.pause_requests struct evrpc_base { - struct evrpc_hooks_ common; + struct evrpc_hooks_ common; /* the HTTP server under which we register our RPC calls */ struct evhttp* http_server; @@ -80,11 +80,11 @@ struct evrpc_base { }; struct evrpc_req_generic; -void evrpc_reqstate_free_(struct evrpc_req_generic* rpc_state); +void evrpc_reqstate_free_(struct evrpc_req_generic* rpc_state); /* A pool for holding evhttp_connection objects */ struct evrpc_pool { - struct evrpc_hooks_ common; + struct evrpc_hooks_ common; struct event_base *base; @@ -118,14 +118,14 @@ struct evrpc_hook_meta { }; /* allows association of meta data with a request */ -static void evrpc_hook_associate_meta_(struct evrpc_hook_meta **pctx, +static void evrpc_hook_associate_meta_(struct evrpc_hook_meta **pctx, struct evhttp_connection *evcon); /* creates a new meta data store */ -static struct evrpc_hook_meta *evrpc_hook_meta_new_(void); +static struct evrpc_hook_meta *evrpc_hook_meta_new_(void); /* frees the meta data associated with a request */ -static void evrpc_hook_context_free_(struct evrpc_hook_meta *ctx); +static void evrpc_hook_context_free_(struct evrpc_hook_meta *ctx); /* the server side of an rpc */ @@ -202,4 +202,4 @@ struct evrpc_request_wrapper { int (*reply_unmarshal)(void *, struct evbuffer*); }; -#endif /* EVRPC_INTERNAL_H_INCLUDED_ */ +#endif /* EVRPC_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/evrpc.c b/contrib/libs/libevent/evrpc.c index 4a60ca5f07..979d3bdf32 100644 --- a/contrib/libs/libevent/evrpc.c +++ b/contrib/libs/libevent/evrpc.c @@ -25,9 +25,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include <winsock2.h> #include <windows.h> @@ -35,16 +35,16 @@ #endif #include <sys/types.h> -#ifndef _WIN32 +#ifndef _WIN32 #include <sys/socket.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> #include <stdio.h> #include <stdlib.h> -#ifndef _WIN32 +#ifndef _WIN32 #include <unistd.h> #endif #include <errno.h> @@ -122,7 +122,7 @@ evrpc_add_hook(void *vbase, int (*cb)(void *, struct evhttp_request *, struct evbuffer *, void *), void *cb_arg) { - struct evrpc_hooks_ *base = vbase; + struct evrpc_hooks_ *base = vbase; struct evrpc_hook_list *head = NULL; struct evrpc_hook *hook = NULL; switch (hook_type) { @@ -168,7 +168,7 @@ evrpc_remove_hook_internal(struct evrpc_hook_list *head, void *handle) int evrpc_remove_hook(void *vbase, enum EVRPC_HOOK_TYPE hook_type, void *handle) { - struct evrpc_hooks_ *base = vbase; + struct evrpc_hooks_ *base = vbase; struct evrpc_hook_list *head = NULL; switch (hook_type) { case EVRPC_INPUT: @@ -302,7 +302,7 @@ evrpc_request_cb(struct evhttp_request *req, void *arg) if (TAILQ_FIRST(&rpc->base->input_hooks) != NULL) { int hook_res; - evrpc_hook_associate_meta_(&rpc_state->hook_meta, req->evcon); + evrpc_hook_associate_meta_(&rpc_state->hook_meta, req->evcon); /* * allow hooks to modify the outgoing request @@ -329,8 +329,8 @@ evrpc_request_cb(struct evhttp_request *req, void *arg) return; error: - if (rpc_state) - evrpc_reqstate_free_(rpc_state); + if (rpc_state) + evrpc_reqstate_free_(rpc_state); evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL); return; } @@ -372,14 +372,14 @@ evrpc_request_cb_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res) return; error: - evrpc_reqstate_free_(rpc_state); + evrpc_reqstate_free_(rpc_state); evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL); return; } void -evrpc_reqstate_free_(struct evrpc_req_generic* rpc_state) +evrpc_reqstate_free_(struct evrpc_req_generic* rpc_state) { struct evrpc *rpc; EVUTIL_ASSERT(rpc_state != NULL); @@ -387,7 +387,7 @@ evrpc_reqstate_free_(struct evrpc_req_generic* rpc_state) /* clean up all memory */ if (rpc_state->hook_meta != NULL) - evrpc_hook_context_free_(rpc_state->hook_meta); + evrpc_hook_context_free_(rpc_state->hook_meta); if (rpc_state->request != NULL) rpc->request_free(rpc_state->request); if (rpc_state->reply != NULL) @@ -427,7 +427,7 @@ evrpc_request_done(struct evrpc_req_generic *rpc_state) if (TAILQ_FIRST(&rpc->base->output_hooks) != NULL) { int hook_res; - evrpc_hook_associate_meta_(&rpc_state->hook_meta, req->evcon); + evrpc_hook_associate_meta_(&rpc_state->hook_meta, req->evcon); /* do hook based tweaks to the request */ hook_res = evrpc_process_hooks(&rpc->base->output_hooks, @@ -453,7 +453,7 @@ evrpc_request_done(struct evrpc_req_generic *rpc_state) return; error: - evrpc_reqstate_free_(rpc_state); + evrpc_reqstate_free_(rpc_state); evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL); return; } @@ -488,12 +488,12 @@ evrpc_request_done_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res) } evhttp_send_reply(req, HTTP_OK, "OK", rpc_state->rpc_data); - evrpc_reqstate_free_(rpc_state); + evrpc_reqstate_free_(rpc_state); return; error: - evrpc_reqstate_free_(rpc_state); + evrpc_reqstate_free_(rpc_state); evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL); return; } @@ -529,7 +529,7 @@ static void evrpc_request_wrapper_free(struct evrpc_request_wrapper *request) { if (request->hook_meta != NULL) - evrpc_hook_context_free_(request->hook_meta); + evrpc_hook_context_free_(request->hook_meta); mm_free(request->name); mm_free(request); } @@ -593,8 +593,8 @@ evrpc_pool_add_connection(struct evrpc_pool *pool, * unless a timeout was specifically set for a connection, * the connection inherits the timeout from the pool. */ - if (!evutil_timerisset(&connection->timeout)) - evhttp_connection_set_timeout(connection, pool->timeout); + if (!evutil_timerisset(&connection->timeout)) + evhttp_connection_set_timeout(connection, pool->timeout); /* * if we have any requests pending, schedule them with the new @@ -621,7 +621,7 @@ evrpc_pool_set_timeout(struct evrpc_pool *pool, int timeout_in_secs) { struct evhttp_connection *evcon; TAILQ_FOREACH(evcon, &pool->connections, next) { - evhttp_connection_set_timeout(evcon, timeout_in_secs); + evhttp_connection_set_timeout(evcon, timeout_in_secs); } pool->timeout = timeout_in_secs; } @@ -678,7 +678,7 @@ evrpc_schedule_request(struct evhttp_connection *connection, if (TAILQ_FIRST(&pool->output_hooks) != NULL) { int hook_res; - evrpc_hook_associate_meta_(&ctx->hook_meta, connection); + evrpc_hook_associate_meta_(&ctx->hook_meta, connection); /* apply hooks to the outgoing request */ hook_res = evrpc_process_hooks(&pool->output_hooks, @@ -763,7 +763,7 @@ static int evrpc_pause_request(void *vbase, void *ctx, void (*cb)(void *, enum EVRPC_HOOK_RESULT)) { - struct evrpc_hooks_ *base = vbase; + struct evrpc_hooks_ *base = vbase; struct evrpc_hook_ctx *pause = mm_malloc(sizeof(*pause)); if (pause == NULL) return (-1); @@ -778,7 +778,7 @@ evrpc_pause_request(void *vbase, void *ctx, int evrpc_resume_request(void *vbase, void *ctx, enum EVRPC_HOOK_RESULT res) { - struct evrpc_hooks_ *base = vbase; + struct evrpc_hooks_ *base = vbase; struct evrpc_pause_list *head = &base->pause_requests; struct evrpc_hook_ctx *pause; @@ -875,7 +875,7 @@ evrpc_reply_done(struct evhttp_request *req, void *arg) } if (TAILQ_FIRST(&pool->input_hooks) != NULL) { - evrpc_hook_associate_meta_(&ctx->hook_meta, ctx->evcon); + evrpc_hook_associate_meta_(&ctx->hook_meta, ctx->evcon); /* apply hooks to the incoming request */ hook_res = evrpc_process_hooks(&pool->input_hooks, @@ -892,7 +892,7 @@ evrpc_reply_done(struct evhttp_request *req, void *arg) * layer is going to free it. we need to * request ownership explicitly */ - evhttp_request_own(req); + evhttp_request_own(req); evrpc_pause_request(pool, ctx, evrpc_reply_done_closure); @@ -973,7 +973,7 @@ evrpc_request_timeout(evutil_socket_t fd, short what, void *arg) struct evhttp_connection *evcon = ctx->evcon; EVUTIL_ASSERT(evcon != NULL); - evhttp_connection_fail_(evcon, EVREQ_HTTP_TIMEOUT); + evhttp_connection_fail_(evcon, EVREQ_HTTP_TIMEOUT); } /* @@ -995,7 +995,7 @@ evrpc_meta_data_free(struct evrpc_meta_list *meta_data) } static struct evrpc_hook_meta * -evrpc_hook_meta_new_(void) +evrpc_hook_meta_new_(void) { struct evrpc_hook_meta *ctx; ctx = mm_malloc(sizeof(struct evrpc_hook_meta)); @@ -1008,17 +1008,17 @@ evrpc_hook_meta_new_(void) } static void -evrpc_hook_associate_meta_(struct evrpc_hook_meta **pctx, +evrpc_hook_associate_meta_(struct evrpc_hook_meta **pctx, struct evhttp_connection *evcon) { struct evrpc_hook_meta *ctx = *pctx; if (ctx == NULL) - *pctx = ctx = evrpc_hook_meta_new_(); + *pctx = ctx = evrpc_hook_meta_new_(); ctx->evcon = evcon; } static void -evrpc_hook_context_free_(struct evrpc_hook_meta *ctx) +evrpc_hook_context_free_(struct evrpc_hook_meta *ctx) { evrpc_meta_data_free(&ctx->meta_data); mm_free(ctx); @@ -1034,7 +1034,7 @@ evrpc_hook_add_meta(void *ctx, const char *key, struct evrpc_meta *meta = NULL; if ((store = req->hook_meta) == NULL) - store = req->hook_meta = evrpc_hook_meta_new_(); + store = req->hook_meta = evrpc_hook_meta_new_(); meta = mm_malloc(sizeof(struct evrpc_meta)); EVUTIL_ASSERT(meta != NULL); diff --git a/contrib/libs/libevent/evsignal-internal.h b/contrib/libs/libevent/evsignal-internal.h index 5cff03b525..05e8e024f2 100644 --- a/contrib/libs/libevent/evsignal-internal.h +++ b/contrib/libs/libevent/evsignal-internal.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVSIGNAL_INTERNAL_H_INCLUDED_ -#define EVSIGNAL_INTERNAL_H_INCLUDED_ +#ifndef EVSIGNAL_INTERNAL_H_INCLUDED_ +#define EVSIGNAL_INTERNAL_H_INCLUDED_ #ifndef evutil_socket_t #include "event2/util.h" @@ -48,7 +48,7 @@ struct evsig_info { /* Array of previous signal handler objects before Libevent started * messing with them. Used to restore old signal handlers. */ -#ifdef EVENT__HAVE_SIGACTION +#ifdef EVENT__HAVE_SIGACTION struct sigaction **sh_old; #else ev_sighandler_t **sh_old; @@ -56,10 +56,10 @@ struct evsig_info { /* Size of sh_old. */ int sh_old_max; }; -int evsig_init_(struct event_base *); -void evsig_dealloc_(struct event_base *); +int evsig_init_(struct event_base *); +void evsig_dealloc_(struct event_base *); -void evsig_set_base_(struct event_base *base); -void evsig_free_globals_(void); +void evsig_set_base_(struct event_base *base); +void evsig_free_globals_(void); -#endif /* EVSIGNAL_INTERNAL_H_INCLUDED_ */ +#endif /* EVSIGNAL_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/evthread-internal.h b/contrib/libs/libevent/evthread-internal.h index 83e409f09b..e5c19fa928 100644 --- a/contrib/libs/libevent/evthread-internal.h +++ b/contrib/libs/libevent/evthread-internal.h @@ -23,16 +23,16 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVTHREAD_INTERNAL_H_INCLUDED_ -#define EVTHREAD_INTERNAL_H_INCLUDED_ +#ifndef EVTHREAD_INTERNAL_H_INCLUDED_ +#define EVTHREAD_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { #endif -#include "event2/event-config.h" -#include "evconfig-private.h" - +#include "event2/event-config.h" +#include "evconfig-private.h" + #include "event2/thread.h" #include "util-internal.h" @@ -46,65 +46,65 @@ struct event_base; #define EVTHREAD_EXPOSE_STRUCTS #endif -#if ! defined(EVENT__DISABLE_THREAD_SUPPORT) && defined(EVTHREAD_EXPOSE_STRUCTS) +#if ! defined(EVENT__DISABLE_THREAD_SUPPORT) && defined(EVTHREAD_EXPOSE_STRUCTS) /* Global function pointers to lock-related functions. NULL if locking isn't enabled. */ -EVENT2_EXPORT_SYMBOL -extern struct evthread_lock_callbacks evthread_lock_fns_; -EVENT2_EXPORT_SYMBOL -extern struct evthread_condition_callbacks evthread_cond_fns_; -extern unsigned long (*evthread_id_fn_)(void); -EVENT2_EXPORT_SYMBOL -extern int evthread_lock_debugging_enabled_; +EVENT2_EXPORT_SYMBOL +extern struct evthread_lock_callbacks evthread_lock_fns_; +EVENT2_EXPORT_SYMBOL +extern struct evthread_condition_callbacks evthread_cond_fns_; +extern unsigned long (*evthread_id_fn_)(void); +EVENT2_EXPORT_SYMBOL +extern int evthread_lock_debugging_enabled_; /** Return the ID of the current thread, or 1 if threading isn't enabled. */ #define EVTHREAD_GET_ID() \ - (evthread_id_fn_ ? evthread_id_fn_() : 1) + (evthread_id_fn_ ? evthread_id_fn_() : 1) /** Return true iff we're in the thread that is currently (or most recently) * running a given event_base's loop. Requires lock. */ #define EVBASE_IN_THREAD(base) \ - (evthread_id_fn_ == NULL || \ - (base)->th_owner_id == evthread_id_fn_()) + (evthread_id_fn_ == NULL || \ + (base)->th_owner_id == evthread_id_fn_()) /** Return true iff we need to notify the base's main thread about changes to * its state, because it's currently running the main loop in another * thread. Requires lock. */ #define EVBASE_NEED_NOTIFY(base) \ - (evthread_id_fn_ != NULL && \ + (evthread_id_fn_ != NULL && \ (base)->running_loop && \ - (base)->th_owner_id != evthread_id_fn_()) + (base)->th_owner_id != evthread_id_fn_()) /** Allocate a new lock, and store it in lockvar, a void*. Sets lockvar to NULL if locking is not enabled. */ #define EVTHREAD_ALLOC_LOCK(lockvar, locktype) \ - ((lockvar) = evthread_lock_fns_.alloc ? \ - evthread_lock_fns_.alloc(locktype) : NULL) + ((lockvar) = evthread_lock_fns_.alloc ? \ + evthread_lock_fns_.alloc(locktype) : NULL) /** Free a given lock, if it is present and locking is enabled. */ #define EVTHREAD_FREE_LOCK(lockvar, locktype) \ do { \ - void *lock_tmp_ = (lockvar); \ - if (lock_tmp_ && evthread_lock_fns_.free) \ - evthread_lock_fns_.free(lock_tmp_, (locktype)); \ + void *lock_tmp_ = (lockvar); \ + if (lock_tmp_ && evthread_lock_fns_.free) \ + evthread_lock_fns_.free(lock_tmp_, (locktype)); \ } while (0) /** Acquire a lock. */ #define EVLOCK_LOCK(lockvar,mode) \ do { \ if (lockvar) \ - evthread_lock_fns_.lock(mode, lockvar); \ + evthread_lock_fns_.lock(mode, lockvar); \ } while (0) /** Release a lock */ #define EVLOCK_UNLOCK(lockvar,mode) \ do { \ if (lockvar) \ - evthread_lock_fns_.unlock(mode, lockvar); \ + evthread_lock_fns_.unlock(mode, lockvar); \ } while (0) /** Helper: put lockvar1 and lockvar2 into pointerwise ascending order. */ -#define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \ +#define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \ do { \ if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \ void *tmp = lockvar1; \ @@ -128,19 +128,19 @@ extern int evthread_lock_debugging_enabled_; * locked and held by us. */ #define EVLOCK_ASSERT_LOCKED(lock) \ do { \ - if ((lock) && evthread_lock_debugging_enabled_) { \ - EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \ + if ((lock) && evthread_lock_debugging_enabled_) { \ + EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \ } \ } while (0) /** Try to grab the lock for 'lockvar' without blocking, and return 1 if we * manage to get it. */ -static inline int EVLOCK_TRY_LOCK_(void *lock); +static inline int EVLOCK_TRY_LOCK_(void *lock); static inline int -EVLOCK_TRY_LOCK_(void *lock) +EVLOCK_TRY_LOCK_(void *lock) { - if (lock && evthread_lock_fns_.lock) { - int r = evthread_lock_fns_.lock(EVTHREAD_TRY, lock); + if (lock && evthread_lock_fns_.lock) { + int r = evthread_lock_fns_.lock(EVTHREAD_TRY, lock); return !r; } else { /* Locking is disabled either globally or for this thing; @@ -152,88 +152,88 @@ EVLOCK_TRY_LOCK_(void *lock) /** Allocate a new condition variable and store it in the void *, condvar */ #define EVTHREAD_ALLOC_COND(condvar) \ do { \ - (condvar) = evthread_cond_fns_.alloc_condition ? \ - evthread_cond_fns_.alloc_condition(0) : NULL; \ + (condvar) = evthread_cond_fns_.alloc_condition ? \ + evthread_cond_fns_.alloc_condition(0) : NULL; \ } while (0) /** Deallocate and free a condition variable in condvar */ #define EVTHREAD_FREE_COND(cond) \ do { \ if (cond) \ - evthread_cond_fns_.free_condition((cond)); \ + evthread_cond_fns_.free_condition((cond)); \ } while (0) /** Signal one thread waiting on cond */ #define EVTHREAD_COND_SIGNAL(cond) \ - ( (cond) ? evthread_cond_fns_.signal_condition((cond), 0) : 0 ) + ( (cond) ? evthread_cond_fns_.signal_condition((cond), 0) : 0 ) /** Signal all threads waiting on cond */ #define EVTHREAD_COND_BROADCAST(cond) \ - ( (cond) ? evthread_cond_fns_.signal_condition((cond), 1) : 0 ) + ( (cond) ? evthread_cond_fns_.signal_condition((cond), 1) : 0 ) /** Wait until the condition 'cond' is signalled. Must be called while * holding 'lock'. The lock will be released until the condition is * signalled, at which point it will be acquired again. Returns 0 for * success, -1 for failure. */ #define EVTHREAD_COND_WAIT(cond, lock) \ - ( (cond) ? evthread_cond_fns_.wait_condition((cond), (lock), NULL) : 0 ) + ( (cond) ? evthread_cond_fns_.wait_condition((cond), (lock), NULL) : 0 ) /** As EVTHREAD_COND_WAIT, but gives up after 'tv' has elapsed. Returns 1 * on timeout. */ #define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \ - ( (cond) ? evthread_cond_fns_.wait_condition((cond), (lock), (tv)) : 0 ) + ( (cond) ? evthread_cond_fns_.wait_condition((cond), (lock), (tv)) : 0 ) /** True iff locking functions have been configured. */ #define EVTHREAD_LOCKING_ENABLED() \ - (evthread_lock_fns_.lock != NULL) - -#elif ! defined(EVENT__DISABLE_THREAD_SUPPORT) - -unsigned long evthreadimpl_get_id_(void); -EVENT2_EXPORT_SYMBOL -int evthreadimpl_is_lock_debugging_enabled_(void); -EVENT2_EXPORT_SYMBOL -void *evthreadimpl_lock_alloc_(unsigned locktype); -EVENT2_EXPORT_SYMBOL -void evthreadimpl_lock_free_(void *lock, unsigned locktype); -EVENT2_EXPORT_SYMBOL -int evthreadimpl_lock_lock_(unsigned mode, void *lock); -EVENT2_EXPORT_SYMBOL -int evthreadimpl_lock_unlock_(unsigned mode, void *lock); -EVENT2_EXPORT_SYMBOL -void *evthreadimpl_cond_alloc_(unsigned condtype); -EVENT2_EXPORT_SYMBOL -void evthreadimpl_cond_free_(void *cond); -EVENT2_EXPORT_SYMBOL -int evthreadimpl_cond_signal_(void *cond, int broadcast); -EVENT2_EXPORT_SYMBOL -int evthreadimpl_cond_wait_(void *cond, void *lock, const struct timeval *tv); -int evthreadimpl_locking_enabled_(void); - -#define EVTHREAD_GET_ID() evthreadimpl_get_id_() + (evthread_lock_fns_.lock != NULL) + +#elif ! defined(EVENT__DISABLE_THREAD_SUPPORT) + +unsigned long evthreadimpl_get_id_(void); +EVENT2_EXPORT_SYMBOL +int evthreadimpl_is_lock_debugging_enabled_(void); +EVENT2_EXPORT_SYMBOL +void *evthreadimpl_lock_alloc_(unsigned locktype); +EVENT2_EXPORT_SYMBOL +void evthreadimpl_lock_free_(void *lock, unsigned locktype); +EVENT2_EXPORT_SYMBOL +int evthreadimpl_lock_lock_(unsigned mode, void *lock); +EVENT2_EXPORT_SYMBOL +int evthreadimpl_lock_unlock_(unsigned mode, void *lock); +EVENT2_EXPORT_SYMBOL +void *evthreadimpl_cond_alloc_(unsigned condtype); +EVENT2_EXPORT_SYMBOL +void evthreadimpl_cond_free_(void *cond); +EVENT2_EXPORT_SYMBOL +int evthreadimpl_cond_signal_(void *cond, int broadcast); +EVENT2_EXPORT_SYMBOL +int evthreadimpl_cond_wait_(void *cond, void *lock, const struct timeval *tv); +int evthreadimpl_locking_enabled_(void); + +#define EVTHREAD_GET_ID() evthreadimpl_get_id_() #define EVBASE_IN_THREAD(base) \ - ((base)->th_owner_id == evthreadimpl_get_id_()) + ((base)->th_owner_id == evthreadimpl_get_id_()) #define EVBASE_NEED_NOTIFY(base) \ ((base)->running_loop && \ - ((base)->th_owner_id != evthreadimpl_get_id_())) + ((base)->th_owner_id != evthreadimpl_get_id_())) #define EVTHREAD_ALLOC_LOCK(lockvar, locktype) \ - ((lockvar) = evthreadimpl_lock_alloc_(locktype)) + ((lockvar) = evthreadimpl_lock_alloc_(locktype)) #define EVTHREAD_FREE_LOCK(lockvar, locktype) \ do { \ - void *lock_tmp_ = (lockvar); \ - if (lock_tmp_) \ - evthreadimpl_lock_free_(lock_tmp_, (locktype)); \ + void *lock_tmp_ = (lockvar); \ + if (lock_tmp_) \ + evthreadimpl_lock_free_(lock_tmp_, (locktype)); \ } while (0) /** Acquire a lock. */ #define EVLOCK_LOCK(lockvar,mode) \ do { \ if (lockvar) \ - evthreadimpl_lock_lock_(mode, lockvar); \ + evthreadimpl_lock_lock_(mode, lockvar); \ } while (0) /** Release a lock */ #define EVLOCK_UNLOCK(lockvar,mode) \ do { \ if (lockvar) \ - evthreadimpl_lock_unlock_(mode, lockvar); \ + evthreadimpl_lock_unlock_(mode, lockvar); \ } while (0) /** Lock an event_base, if it is set up for locking. Acquires the lock @@ -251,19 +251,19 @@ int evthreadimpl_locking_enabled_(void); * locked and held by us. */ #define EVLOCK_ASSERT_LOCKED(lock) \ do { \ - if ((lock) && evthreadimpl_is_lock_debugging_enabled_()) { \ - EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \ + if ((lock) && evthreadimpl_is_lock_debugging_enabled_()) { \ + EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \ } \ } while (0) /** Try to grab the lock for 'lockvar' without blocking, and return 1 if we * manage to get it. */ -static inline int EVLOCK_TRY_LOCK_(void *lock); +static inline int EVLOCK_TRY_LOCK_(void *lock); static inline int -EVLOCK_TRY_LOCK_(void *lock) +EVLOCK_TRY_LOCK_(void *lock) { if (lock) { - int r = evthreadimpl_lock_lock_(EVTHREAD_TRY, lock); + int r = evthreadimpl_lock_lock_(EVTHREAD_TRY, lock); return !r; } else { /* Locking is disabled either globally or for this thing; @@ -275,68 +275,68 @@ EVLOCK_TRY_LOCK_(void *lock) /** Allocate a new condition variable and store it in the void *, condvar */ #define EVTHREAD_ALLOC_COND(condvar) \ do { \ - (condvar) = evthreadimpl_cond_alloc_(0); \ + (condvar) = evthreadimpl_cond_alloc_(0); \ } while (0) /** Deallocate and free a condition variable in condvar */ #define EVTHREAD_FREE_COND(cond) \ do { \ if (cond) \ - evthreadimpl_cond_free_((cond)); \ + evthreadimpl_cond_free_((cond)); \ } while (0) /** Signal one thread waiting on cond */ #define EVTHREAD_COND_SIGNAL(cond) \ - ( (cond) ? evthreadimpl_cond_signal_((cond), 0) : 0 ) + ( (cond) ? evthreadimpl_cond_signal_((cond), 0) : 0 ) /** Signal all threads waiting on cond */ #define EVTHREAD_COND_BROADCAST(cond) \ - ( (cond) ? evthreadimpl_cond_signal_((cond), 1) : 0 ) + ( (cond) ? evthreadimpl_cond_signal_((cond), 1) : 0 ) /** Wait until the condition 'cond' is signalled. Must be called while * holding 'lock'. The lock will be released until the condition is * signalled, at which point it will be acquired again. Returns 0 for * success, -1 for failure. */ #define EVTHREAD_COND_WAIT(cond, lock) \ - ( (cond) ? evthreadimpl_cond_wait_((cond), (lock), NULL) : 0 ) + ( (cond) ? evthreadimpl_cond_wait_((cond), (lock), NULL) : 0 ) /** As EVTHREAD_COND_WAIT, but gives up after 'tv' has elapsed. Returns 1 * on timeout. */ #define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) \ - ( (cond) ? evthreadimpl_cond_wait_((cond), (lock), (tv)) : 0 ) + ( (cond) ? evthreadimpl_cond_wait_((cond), (lock), (tv)) : 0 ) #define EVTHREAD_LOCKING_ENABLED() \ - (evthreadimpl_locking_enabled_()) + (evthreadimpl_locking_enabled_()) -#else /* EVENT__DISABLE_THREAD_SUPPORT */ +#else /* EVENT__DISABLE_THREAD_SUPPORT */ #define EVTHREAD_GET_ID() 1 -#define EVTHREAD_ALLOC_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_ -#define EVTHREAD_FREE_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_ +#define EVTHREAD_ALLOC_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_ +#define EVTHREAD_FREE_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_ -#define EVLOCK_LOCK(lockvar, mode) EVUTIL_NIL_STMT_ -#define EVLOCK_UNLOCK(lockvar, mode) EVUTIL_NIL_STMT_ -#define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) EVUTIL_NIL_STMT_ -#define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) EVUTIL_NIL_STMT_ +#define EVLOCK_LOCK(lockvar, mode) EVUTIL_NIL_STMT_ +#define EVLOCK_UNLOCK(lockvar, mode) EVUTIL_NIL_STMT_ +#define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) EVUTIL_NIL_STMT_ +#define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) EVUTIL_NIL_STMT_ #define EVBASE_IN_THREAD(base) 1 #define EVBASE_NEED_NOTIFY(base) 0 -#define EVBASE_ACQUIRE_LOCK(base, lock) EVUTIL_NIL_STMT_ -#define EVBASE_RELEASE_LOCK(base, lock) EVUTIL_NIL_STMT_ -#define EVLOCK_ASSERT_LOCKED(lock) EVUTIL_NIL_STMT_ +#define EVBASE_ACQUIRE_LOCK(base, lock) EVUTIL_NIL_STMT_ +#define EVBASE_RELEASE_LOCK(base, lock) EVUTIL_NIL_STMT_ +#define EVLOCK_ASSERT_LOCKED(lock) EVUTIL_NIL_STMT_ -#define EVLOCK_TRY_LOCK_(lock) 1 +#define EVLOCK_TRY_LOCK_(lock) 1 -#define EVTHREAD_ALLOC_COND(condvar) EVUTIL_NIL_STMT_ -#define EVTHREAD_FREE_COND(cond) EVUTIL_NIL_STMT_ -#define EVTHREAD_COND_SIGNAL(cond) EVUTIL_NIL_STMT_ -#define EVTHREAD_COND_BROADCAST(cond) EVUTIL_NIL_STMT_ -#define EVTHREAD_COND_WAIT(cond, lock) EVUTIL_NIL_STMT_ -#define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) EVUTIL_NIL_STMT_ +#define EVTHREAD_ALLOC_COND(condvar) EVUTIL_NIL_STMT_ +#define EVTHREAD_FREE_COND(cond) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_SIGNAL(cond) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_BROADCAST(cond) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_WAIT(cond, lock) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) EVUTIL_NIL_STMT_ #define EVTHREAD_LOCKING_ENABLED() 0 #endif /* This code is shared between both lock impls */ -#if ! defined(EVENT__DISABLE_THREAD_SUPPORT) +#if ! defined(EVENT__DISABLE_THREAD_SUPPORT) /** Helper: put lockvar1 and lockvar2 into pointerwise ascending order. */ -#define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \ +#define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \ do { \ if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \ void *tmp = lockvar1; \ @@ -349,27 +349,27 @@ EVLOCK_TRY_LOCK_(void *lock) * so that two threads locking two locks with LOCK2 will not deadlock. */ #define EVLOCK_LOCK2(lock1,lock2,mode1,mode2) \ do { \ - void *lock1_tmplock_ = (lock1); \ - void *lock2_tmplock_ = (lock2); \ - EVLOCK_SORTLOCKS_(lock1_tmplock_,lock2_tmplock_); \ - EVLOCK_LOCK(lock1_tmplock_,mode1); \ - if (lock2_tmplock_ != lock1_tmplock_) \ - EVLOCK_LOCK(lock2_tmplock_,mode2); \ + void *lock1_tmplock_ = (lock1); \ + void *lock2_tmplock_ = (lock2); \ + EVLOCK_SORTLOCKS_(lock1_tmplock_,lock2_tmplock_); \ + EVLOCK_LOCK(lock1_tmplock_,mode1); \ + if (lock2_tmplock_ != lock1_tmplock_) \ + EVLOCK_LOCK(lock2_tmplock_,mode2); \ } while (0) /** Release both lock1 and lock2. */ #define EVLOCK_UNLOCK2(lock1,lock2,mode1,mode2) \ do { \ - void *lock1_tmplock_ = (lock1); \ - void *lock2_tmplock_ = (lock2); \ - EVLOCK_SORTLOCKS_(lock1_tmplock_,lock2_tmplock_); \ - if (lock2_tmplock_ != lock1_tmplock_) \ - EVLOCK_UNLOCK(lock2_tmplock_,mode2); \ - EVLOCK_UNLOCK(lock1_tmplock_,mode1); \ + void *lock1_tmplock_ = (lock1); \ + void *lock2_tmplock_ = (lock2); \ + EVLOCK_SORTLOCKS_(lock1_tmplock_,lock2_tmplock_); \ + if (lock2_tmplock_ != lock1_tmplock_) \ + EVLOCK_UNLOCK(lock2_tmplock_,mode2); \ + EVLOCK_UNLOCK(lock1_tmplock_,mode1); \ } while (0) -EVENT2_EXPORT_SYMBOL -int evthread_is_debug_lock_held_(void *lock); -void *evthread_debug_get_real_lock_(void *lock); +EVENT2_EXPORT_SYMBOL +int evthread_is_debug_lock_held_(void *lock); +void *evthread_debug_get_real_lock_(void *lock); void *evthread_setup_global_lock_(void *lock_, unsigned locktype, int enable_locks); @@ -386,21 +386,21 @@ void *evthread_setup_global_lock_(void *lock_, unsigned locktype, int event_global_setup_locks_(const int enable_locks); int evsig_global_setup_locks_(const int enable_locks); -int evutil_global_setup_locks_(const int enable_locks); +int evutil_global_setup_locks_(const int enable_locks); int evutil_secure_rng_global_setup_locks_(const int enable_locks); -/** Return current evthread_lock_callbacks */ -EVENT2_EXPORT_SYMBOL -struct evthread_lock_callbacks *evthread_get_lock_callbacks(void); -/** Return current evthread_condition_callbacks */ -struct evthread_condition_callbacks *evthread_get_condition_callbacks(void); -/** Disable locking for internal usage (like global shutdown) */ -void evthreadimpl_disable_lock_debugging_(void); - +/** Return current evthread_lock_callbacks */ +EVENT2_EXPORT_SYMBOL +struct evthread_lock_callbacks *evthread_get_lock_callbacks(void); +/** Return current evthread_condition_callbacks */ +struct evthread_condition_callbacks *evthread_get_condition_callbacks(void); +/** Disable locking for internal usage (like global shutdown) */ +void evthreadimpl_disable_lock_debugging_(void); + #endif #ifdef __cplusplus } #endif -#endif /* EVTHREAD_INTERNAL_H_INCLUDED_ */ +#endif /* EVTHREAD_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/evthread.c b/contrib/libs/libevent/evthread.c index 3eac594d64..594cf288d6 100644 --- a/contrib/libs/libevent/evthread.c +++ b/contrib/libs/libevent/evthread.c @@ -25,9 +25,9 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT #include "event2/thread.h" @@ -45,68 +45,68 @@ #define GLOBAL static #endif -#ifndef EVENT__DISABLE_DEBUG_MODE -extern int event_debug_created_threadable_ctx_; -extern int event_debug_mode_on_; -#endif - +#ifndef EVENT__DISABLE_DEBUG_MODE +extern int event_debug_created_threadable_ctx_; +extern int event_debug_mode_on_; +#endif + /* globals */ -GLOBAL int evthread_lock_debugging_enabled_ = 0; -GLOBAL struct evthread_lock_callbacks evthread_lock_fns_ = { +GLOBAL int evthread_lock_debugging_enabled_ = 0; +GLOBAL struct evthread_lock_callbacks evthread_lock_fns_ = { 0, 0, NULL, NULL, NULL, NULL }; -GLOBAL unsigned long (*evthread_id_fn_)(void) = NULL; -GLOBAL struct evthread_condition_callbacks evthread_cond_fns_ = { +GLOBAL unsigned long (*evthread_id_fn_)(void) = NULL; +GLOBAL struct evthread_condition_callbacks evthread_cond_fns_ = { 0, NULL, NULL, NULL, NULL }; /* Used for debugging */ -static struct evthread_lock_callbacks original_lock_fns_ = { +static struct evthread_lock_callbacks original_lock_fns_ = { 0, 0, NULL, NULL, NULL, NULL }; -static struct evthread_condition_callbacks original_cond_fns_ = { +static struct evthread_condition_callbacks original_cond_fns_ = { 0, NULL, NULL, NULL, NULL }; void evthread_set_id_callback(unsigned long (*id_fn)(void)) { - evthread_id_fn_ = id_fn; -} - -struct evthread_lock_callbacks *evthread_get_lock_callbacks() -{ - return evthread_lock_debugging_enabled_ - ? &original_lock_fns_ : &evthread_lock_fns_; -} -struct evthread_condition_callbacks *evthread_get_condition_callbacks() -{ - return evthread_lock_debugging_enabled_ - ? &original_cond_fns_ : &evthread_cond_fns_; -} -void evthreadimpl_disable_lock_debugging_(void) -{ - evthread_lock_debugging_enabled_ = 0; + evthread_id_fn_ = id_fn; } +struct evthread_lock_callbacks *evthread_get_lock_callbacks() +{ + return evthread_lock_debugging_enabled_ + ? &original_lock_fns_ : &evthread_lock_fns_; +} +struct evthread_condition_callbacks *evthread_get_condition_callbacks() +{ + return evthread_lock_debugging_enabled_ + ? &original_cond_fns_ : &evthread_cond_fns_; +} +void evthreadimpl_disable_lock_debugging_(void) +{ + evthread_lock_debugging_enabled_ = 0; +} + int evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs) { - struct evthread_lock_callbacks *target = evthread_get_lock_callbacks(); - -#ifndef EVENT__DISABLE_DEBUG_MODE - if (event_debug_mode_on_) { - if (event_debug_created_threadable_ctx_) { - event_errx(1, "evthread initialization must be called BEFORE anything else!"); - } - } -#endif - + struct evthread_lock_callbacks *target = evthread_get_lock_callbacks(); + +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + if (event_debug_created_threadable_ctx_) { + event_errx(1, "evthread initialization must be called BEFORE anything else!"); + } + } +#endif + if (!cbs) { if (target->alloc) event_warnx("Trying to disable lock functions after " "they have been set up will probaby not work."); - memset(target, 0, sizeof(evthread_lock_fns_)); + memset(target, 0, sizeof(evthread_lock_fns_)); return 0; } if (target->alloc) { @@ -125,7 +125,7 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs) return -1; } if (cbs->alloc && cbs->free && cbs->lock && cbs->unlock) { - memcpy(target, cbs, sizeof(evthread_lock_fns_)); + memcpy(target, cbs, sizeof(evthread_lock_fns_)); return event_global_setup_locks_(1); } else { return -1; @@ -135,22 +135,22 @@ evthread_set_lock_callbacks(const struct evthread_lock_callbacks *cbs) int evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs) { - struct evthread_condition_callbacks *target = evthread_get_condition_callbacks(); - -#ifndef EVENT__DISABLE_DEBUG_MODE - if (event_debug_mode_on_) { - if (event_debug_created_threadable_ctx_) { - event_errx(1, "evthread initialization must be called BEFORE anything else!"); - } - } -#endif - + struct evthread_condition_callbacks *target = evthread_get_condition_callbacks(); + +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + if (event_debug_created_threadable_ctx_) { + event_errx(1, "evthread initialization must be called BEFORE anything else!"); + } + } +#endif + if (!cbs) { if (target->alloc_condition) event_warnx("Trying to disable condition functions " "after they have been set up will probaby not " "work."); - memset(target, 0, sizeof(evthread_cond_fns_)); + memset(target, 0, sizeof(evthread_cond_fns_)); return 0; } if (target->alloc_condition) { @@ -169,20 +169,20 @@ evthread_set_condition_callbacks(const struct evthread_condition_callbacks *cbs) } if (cbs->alloc_condition && cbs->free_condition && cbs->signal_condition && cbs->wait_condition) { - memcpy(target, cbs, sizeof(evthread_cond_fns_)); + memcpy(target, cbs, sizeof(evthread_cond_fns_)); } - if (evthread_lock_debugging_enabled_) { - evthread_cond_fns_.alloc_condition = cbs->alloc_condition; - evthread_cond_fns_.free_condition = cbs->free_condition; - evthread_cond_fns_.signal_condition = cbs->signal_condition; + if (evthread_lock_debugging_enabled_) { + evthread_cond_fns_.alloc_condition = cbs->alloc_condition; + evthread_cond_fns_.free_condition = cbs->free_condition; + evthread_cond_fns_.signal_condition = cbs->signal_condition; } return 0; } -#define DEBUG_LOCK_SIG 0xdeb0b10c - +#define DEBUG_LOCK_SIG 0xdeb0b10c + struct debug_lock { - unsigned signature; + unsigned signature; unsigned locktype; unsigned long held_by; /* XXXX if we ever use read-write locks, we will need a separate @@ -197,8 +197,8 @@ debug_lock_alloc(unsigned locktype) struct debug_lock *result = mm_malloc(sizeof(struct debug_lock)); if (!result) return NULL; - if (original_lock_fns_.alloc) { - if (!(result->lock = original_lock_fns_.alloc( + if (original_lock_fns_.alloc) { + if (!(result->lock = original_lock_fns_.alloc( locktype|EVTHREAD_LOCKTYPE_RECURSIVE))) { mm_free(result); return NULL; @@ -206,7 +206,7 @@ debug_lock_alloc(unsigned locktype) } else { result->lock = NULL; } - result->signature = DEBUG_LOCK_SIG; + result->signature = DEBUG_LOCK_SIG; result->locktype = locktype; result->count = 0; result->held_by = 0; @@ -219,27 +219,27 @@ debug_lock_free(void *lock_, unsigned locktype) struct debug_lock *lock = lock_; EVUTIL_ASSERT(lock->count == 0); EVUTIL_ASSERT(locktype == lock->locktype); - EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); - if (original_lock_fns_.free) { - original_lock_fns_.free(lock->lock, + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + if (original_lock_fns_.free) { + original_lock_fns_.free(lock->lock, lock->locktype|EVTHREAD_LOCKTYPE_RECURSIVE); } lock->lock = NULL; lock->count = -100; - lock->signature = 0x12300fda; + lock->signature = 0x12300fda; mm_free(lock); } static void evthread_debug_lock_mark_locked(unsigned mode, struct debug_lock *lock) { - EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); ++lock->count; if (!(lock->locktype & EVTHREAD_LOCKTYPE_RECURSIVE)) EVUTIL_ASSERT(lock->count == 1); - if (evthread_id_fn_) { + if (evthread_id_fn_) { unsigned long me; - me = evthread_id_fn_(); + me = evthread_id_fn_(); if (lock->count > 1) EVUTIL_ASSERT(lock->held_by == me); lock->held_by = me; @@ -255,8 +255,8 @@ debug_lock_lock(unsigned mode, void *lock_) EVUTIL_ASSERT(mode & (EVTHREAD_READ|EVTHREAD_WRITE)); else EVUTIL_ASSERT((mode & (EVTHREAD_READ|EVTHREAD_WRITE)) == 0); - if (original_lock_fns_.lock) - res = original_lock_fns_.lock(mode, lock->lock); + if (original_lock_fns_.lock) + res = original_lock_fns_.lock(mode, lock->lock); if (!res) { evthread_debug_lock_mark_locked(mode, lock); } @@ -266,15 +266,15 @@ debug_lock_lock(unsigned mode, void *lock_) static void evthread_debug_lock_mark_unlocked(unsigned mode, struct debug_lock *lock) { - EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); if (lock->locktype & EVTHREAD_LOCKTYPE_READWRITE) EVUTIL_ASSERT(mode & (EVTHREAD_READ|EVTHREAD_WRITE)); else EVUTIL_ASSERT((mode & (EVTHREAD_READ|EVTHREAD_WRITE)) == 0); - if (evthread_id_fn_) { - unsigned long me; - me = evthread_id_fn_(); - EVUTIL_ASSERT(lock->held_by == me); + if (evthread_id_fn_) { + unsigned long me; + me = evthread_id_fn_(); + EVUTIL_ASSERT(lock->held_by == me); if (lock->count == 1) lock->held_by = 0; } @@ -288,35 +288,35 @@ debug_lock_unlock(unsigned mode, void *lock_) struct debug_lock *lock = lock_; int res = 0; evthread_debug_lock_mark_unlocked(mode, lock); - if (original_lock_fns_.unlock) - res = original_lock_fns_.unlock(mode, lock->lock); + if (original_lock_fns_.unlock) + res = original_lock_fns_.unlock(mode, lock->lock); return res; } static int -debug_cond_wait(void *cond_, void *lock_, const struct timeval *tv) +debug_cond_wait(void *cond_, void *lock_, const struct timeval *tv) { int r; - struct debug_lock *lock = lock_; + struct debug_lock *lock = lock_; EVUTIL_ASSERT(lock); - EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); - EVLOCK_ASSERT_LOCKED(lock_); + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + EVLOCK_ASSERT_LOCKED(lock_); evthread_debug_lock_mark_unlocked(0, lock); - r = original_cond_fns_.wait_condition(cond_, lock->lock, tv); + r = original_cond_fns_.wait_condition(cond_, lock->lock, tv); evthread_debug_lock_mark_locked(0, lock); return r; } -/* misspelled version for backward compatibility */ +/* misspelled version for backward compatibility */ void evthread_enable_lock_debuging(void) { - evthread_enable_lock_debugging(); -} - -void -evthread_enable_lock_debugging(void) -{ + evthread_enable_lock_debugging(); +} + +void +evthread_enable_lock_debugging(void) +{ struct evthread_lock_callbacks cbs = { EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, @@ -325,30 +325,30 @@ evthread_enable_lock_debugging(void) debug_lock_lock, debug_lock_unlock }; - if (evthread_lock_debugging_enabled_) + if (evthread_lock_debugging_enabled_) return; - memcpy(&original_lock_fns_, &evthread_lock_fns_, + memcpy(&original_lock_fns_, &evthread_lock_fns_, sizeof(struct evthread_lock_callbacks)); - memcpy(&evthread_lock_fns_, &cbs, + memcpy(&evthread_lock_fns_, &cbs, sizeof(struct evthread_lock_callbacks)); - memcpy(&original_cond_fns_, &evthread_cond_fns_, + memcpy(&original_cond_fns_, &evthread_cond_fns_, sizeof(struct evthread_condition_callbacks)); - evthread_cond_fns_.wait_condition = debug_cond_wait; - evthread_lock_debugging_enabled_ = 1; + evthread_cond_fns_.wait_condition = debug_cond_wait; + evthread_lock_debugging_enabled_ = 1; /* XXX return value should get checked. */ event_global_setup_locks_(0); } int -evthread_is_debug_lock_held_(void *lock_) +evthread_is_debug_lock_held_(void *lock_) { struct debug_lock *lock = lock_; if (! lock->count) return 0; - if (evthread_id_fn_) { - unsigned long me = evthread_id_fn_(); + if (evthread_id_fn_) { + unsigned long me = evthread_id_fn_(); if (lock->held_by != me) return 0; } @@ -356,7 +356,7 @@ evthread_is_debug_lock_held_(void *lock_) } void * -evthread_debug_get_real_lock_(void *lock_) +evthread_debug_get_real_lock_(void *lock_) { struct debug_lock *lock = lock_; return lock->lock; @@ -371,23 +371,23 @@ evthread_setup_global_lock_(void *lock_, unsigned locktype, int enable_locks) 3) we're turning on locking; debugging is not on. 4) we're turning on locking; debugging is on. */ - if (!enable_locks && original_lock_fns_.alloc == NULL) { + if (!enable_locks && original_lock_fns_.alloc == NULL) { /* Case 1: allocate a debug lock. */ EVUTIL_ASSERT(lock_ == NULL); return debug_lock_alloc(locktype); - } else if (!enable_locks && original_lock_fns_.alloc != NULL) { + } else if (!enable_locks && original_lock_fns_.alloc != NULL) { /* Case 2: wrap the lock in a debug lock. */ struct debug_lock *lock; EVUTIL_ASSERT(lock_ != NULL); if (!(locktype & EVTHREAD_LOCKTYPE_RECURSIVE)) { /* We can't wrap it: We need a recursive lock */ - original_lock_fns_.free(lock_, locktype); + original_lock_fns_.free(lock_, locktype); return debug_lock_alloc(locktype); } lock = mm_malloc(sizeof(struct debug_lock)); if (!lock) { - original_lock_fns_.free(lock_, locktype); + original_lock_fns_.free(lock_, locktype); return NULL; } lock->lock = lock_; @@ -395,24 +395,24 @@ evthread_setup_global_lock_(void *lock_, unsigned locktype, int enable_locks) lock->count = 0; lock->held_by = 0; return lock; - } else if (enable_locks && ! evthread_lock_debugging_enabled_) { + } else if (enable_locks && ! evthread_lock_debugging_enabled_) { /* Case 3: allocate a regular lock */ EVUTIL_ASSERT(lock_ == NULL); - return evthread_lock_fns_.alloc(locktype); + return evthread_lock_fns_.alloc(locktype); } else { /* Case 4: Fill in a debug lock with a real lock */ - struct debug_lock *lock = lock_ ? lock_ : debug_lock_alloc(locktype); + struct debug_lock *lock = lock_ ? lock_ : debug_lock_alloc(locktype); EVUTIL_ASSERT(enable_locks && - evthread_lock_debugging_enabled_); + evthread_lock_debugging_enabled_); EVUTIL_ASSERT(lock->locktype == locktype); if (!lock->lock) { - lock->lock = original_lock_fns_.alloc( - locktype|EVTHREAD_LOCKTYPE_RECURSIVE); - if (!lock->lock) { - lock->count = -200; - mm_free(lock); - return NULL; - } + lock->lock = original_lock_fns_.alloc( + locktype|EVTHREAD_LOCKTYPE_RECURSIVE); + if (!lock->lock) { + lock->count = -200; + mm_free(lock); + return NULL; + } } return lock; } @@ -421,88 +421,88 @@ evthread_setup_global_lock_(void *lock_, unsigned locktype, int enable_locks) #ifndef EVTHREAD_EXPOSE_STRUCTS unsigned long -evthreadimpl_get_id_() +evthreadimpl_get_id_() { - return evthread_id_fn_ ? evthread_id_fn_() : 1; + return evthread_id_fn_ ? evthread_id_fn_() : 1; } void * -evthreadimpl_lock_alloc_(unsigned locktype) +evthreadimpl_lock_alloc_(unsigned locktype) { -#ifndef EVENT__DISABLE_DEBUG_MODE - if (event_debug_mode_on_) { - event_debug_created_threadable_ctx_ = 1; - } -#endif - - return evthread_lock_fns_.alloc ? - evthread_lock_fns_.alloc(locktype) : NULL; +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + event_debug_created_threadable_ctx_ = 1; + } +#endif + + return evthread_lock_fns_.alloc ? + evthread_lock_fns_.alloc(locktype) : NULL; } void -evthreadimpl_lock_free_(void *lock, unsigned locktype) +evthreadimpl_lock_free_(void *lock, unsigned locktype) { - if (evthread_lock_fns_.free) - evthread_lock_fns_.free(lock, locktype); + if (evthread_lock_fns_.free) + evthread_lock_fns_.free(lock, locktype); } int -evthreadimpl_lock_lock_(unsigned mode, void *lock) +evthreadimpl_lock_lock_(unsigned mode, void *lock) { - if (evthread_lock_fns_.lock) - return evthread_lock_fns_.lock(mode, lock); + if (evthread_lock_fns_.lock) + return evthread_lock_fns_.lock(mode, lock); else return 0; } int -evthreadimpl_lock_unlock_(unsigned mode, void *lock) +evthreadimpl_lock_unlock_(unsigned mode, void *lock) { - if (evthread_lock_fns_.unlock) - return evthread_lock_fns_.unlock(mode, lock); + if (evthread_lock_fns_.unlock) + return evthread_lock_fns_.unlock(mode, lock); else return 0; } void * -evthreadimpl_cond_alloc_(unsigned condtype) +evthreadimpl_cond_alloc_(unsigned condtype) { -#ifndef EVENT__DISABLE_DEBUG_MODE - if (event_debug_mode_on_) { - event_debug_created_threadable_ctx_ = 1; - } -#endif - - return evthread_cond_fns_.alloc_condition ? - evthread_cond_fns_.alloc_condition(condtype) : NULL; +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + event_debug_created_threadable_ctx_ = 1; + } +#endif + + return evthread_cond_fns_.alloc_condition ? + evthread_cond_fns_.alloc_condition(condtype) : NULL; } void -evthreadimpl_cond_free_(void *cond) +evthreadimpl_cond_free_(void *cond) { - if (evthread_cond_fns_.free_condition) - evthread_cond_fns_.free_condition(cond); + if (evthread_cond_fns_.free_condition) + evthread_cond_fns_.free_condition(cond); } int -evthreadimpl_cond_signal_(void *cond, int broadcast) +evthreadimpl_cond_signal_(void *cond, int broadcast) { - if (evthread_cond_fns_.signal_condition) - return evthread_cond_fns_.signal_condition(cond, broadcast); + if (evthread_cond_fns_.signal_condition) + return evthread_cond_fns_.signal_condition(cond, broadcast); else return 0; } int -evthreadimpl_cond_wait_(void *cond, void *lock, const struct timeval *tv) +evthreadimpl_cond_wait_(void *cond, void *lock, const struct timeval *tv) { - if (evthread_cond_fns_.wait_condition) - return evthread_cond_fns_.wait_condition(cond, lock, tv); + if (evthread_cond_fns_.wait_condition) + return evthread_cond_fns_.wait_condition(cond, lock, tv); else return 0; } int -evthreadimpl_is_lock_debugging_enabled_(void) +evthreadimpl_is_lock_debugging_enabled_(void) { - return evthread_lock_debugging_enabled_; + return evthread_lock_debugging_enabled_; } int -evthreadimpl_locking_enabled_(void) +evthreadimpl_locking_enabled_(void) { - return evthread_lock_fns_.lock != NULL; + return evthread_lock_fns_.lock != NULL; } #endif diff --git a/contrib/libs/libevent/evthread_pthread.c b/contrib/libs/libevent/evthread_pthread.c index 4e11f74970..ffab3eb03e 100644 --- a/contrib/libs/libevent/evthread_pthread.c +++ b/contrib/libs/libevent/evthread_pthread.c @@ -24,11 +24,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -/* With glibc we need to define _GNU_SOURCE to get PTHREAD_MUTEX_RECURSIVE. - * This comes from evconfig-private.h - */ +/* With glibc we need to define _GNU_SOURCE to get PTHREAD_MUTEX_RECURSIVE. + * This comes from evconfig-private.h + */ #include <pthread.h> struct event_base; @@ -58,17 +58,17 @@ evthread_posix_lock_alloc(unsigned locktype) } static void -evthread_posix_lock_free(void *lock_, unsigned locktype) +evthread_posix_lock_free(void *lock_, unsigned locktype) { - pthread_mutex_t *lock = lock_; + pthread_mutex_t *lock = lock_; pthread_mutex_destroy(lock); mm_free(lock); } static int -evthread_posix_lock(unsigned mode, void *lock_) +evthread_posix_lock(unsigned mode, void *lock_) { - pthread_mutex_t *lock = lock_; + pthread_mutex_t *lock = lock_; if (mode & EVTHREAD_TRY) return pthread_mutex_trylock(lock); else @@ -76,9 +76,9 @@ evthread_posix_lock(unsigned mode, void *lock_) } static int -evthread_posix_unlock(unsigned mode, void *lock_) +evthread_posix_unlock(unsigned mode, void *lock_) { - pthread_mutex_t *lock = lock_; + pthread_mutex_t *lock = lock_; return pthread_mutex_unlock(lock); } @@ -87,13 +87,13 @@ evthread_posix_get_id(void) { union { pthread_t thr; -#if EVENT__SIZEOF_PTHREAD_T > EVENT__SIZEOF_LONG +#if EVENT__SIZEOF_PTHREAD_T > EVENT__SIZEOF_LONG ev_uint64_t id; #else unsigned long id; #endif } r; -#if EVENT__SIZEOF_PTHREAD_T < EVENT__SIZEOF_LONG +#if EVENT__SIZEOF_PTHREAD_T < EVENT__SIZEOF_LONG memset(&r, 0, sizeof(r)); #endif r.thr = pthread_self(); @@ -114,17 +114,17 @@ evthread_posix_cond_alloc(unsigned condflags) } static void -evthread_posix_cond_free(void *cond_) +evthread_posix_cond_free(void *cond_) { - pthread_cond_t *cond = cond_; + pthread_cond_t *cond = cond_; pthread_cond_destroy(cond); mm_free(cond); } static int -evthread_posix_cond_signal(void *cond_, int broadcast) +evthread_posix_cond_signal(void *cond_, int broadcast) { - pthread_cond_t *cond = cond_; + pthread_cond_t *cond = cond_; int r; if (broadcast) r = pthread_cond_broadcast(cond); @@ -134,11 +134,11 @@ evthread_posix_cond_signal(void *cond_, int broadcast) } static int -evthread_posix_cond_wait(void *cond_, void *lock_, const struct timeval *tv) +evthread_posix_cond_wait(void *cond_, void *lock_, const struct timeval *tv) { int r; - pthread_cond_t *cond = cond_; - pthread_mutex_t *lock = lock_; + pthread_cond_t *cond = cond_; + pthread_mutex_t *lock = lock_; if (tv) { struct timeval now, abstime; diff --git a/contrib/libs/libevent/evthread_win32.c b/contrib/libs/libevent/evthread_win32.c index 2ec80560a5..913eccbd95 100644 --- a/contrib/libs/libevent/evthread_win32.c +++ b/contrib/libs/libevent/evthread_win32.c @@ -24,9 +24,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #ifndef _WIN32_WINNT /* Minimum required for InitializeCriticalSectionAndSpinCount */ #define _WIN32_WINNT 0x0403 @@ -43,7 +43,7 @@ struct event_base; #include "mm-internal.h" #include "evthread-internal.h" -#include "time-internal.h" +#include "time-internal.h" #define SPIN_COUNT 2000 @@ -61,17 +61,17 @@ evthread_win32_lock_create(unsigned locktype) } static void -evthread_win32_lock_free(void *lock_, unsigned locktype) +evthread_win32_lock_free(void *lock_, unsigned locktype) { - CRITICAL_SECTION *lock = lock_; + CRITICAL_SECTION *lock = lock_; DeleteCriticalSection(lock); mm_free(lock); } static int -evthread_win32_lock(unsigned mode, void *lock_) +evthread_win32_lock(unsigned mode, void *lock_) { - CRITICAL_SECTION *lock = lock_; + CRITICAL_SECTION *lock = lock_; if ((mode & EVTHREAD_TRY)) { return ! TryEnterCriticalSection(lock); } else { @@ -81,9 +81,9 @@ evthread_win32_lock(unsigned mode, void *lock_) } static int -evthread_win32_unlock(unsigned mode, void *lock_) +evthread_win32_unlock(unsigned mode, void *lock_) { - CRITICAL_SECTION *lock = lock_; + CRITICAL_SECTION *lock = lock_; LeaveCriticalSection(lock); return 0; } @@ -135,17 +135,17 @@ evthread_win32_condvar_alloc(unsigned condflags) } static void -evthread_win32_condvar_free(void *cond_) +evthread_win32_condvar_free(void *cond_) { - CONDITION_VARIABLE *cond = cond_; + CONDITION_VARIABLE *cond = cond_; /* There doesn't _seem_ to be a cleaup fn here... */ mm_free(cond); } static int -evthread_win32_condvar_signal(void *cond, int broadcast) +evthread_win32_condvar_signal(void *cond, int broadcast) { - CONDITION_VARIABLE *cond = cond_; + CONDITION_VARIABLE *cond = cond_; if (broadcast) WakeAllConditionVariable_fn(cond); else @@ -154,15 +154,15 @@ evthread_win32_condvar_signal(void *cond, int broadcast) } static int -evthread_win32_condvar_wait(void *cond_, void *lock_, const struct timeval *tv) +evthread_win32_condvar_wait(void *cond_, void *lock_, const struct timeval *tv) { - CONDITION_VARIABLE *cond = cond_; - CRITICAL_SECTION *lock = lock_; + CONDITION_VARIABLE *cond = cond_; + CRITICAL_SECTION *lock = lock_; DWORD ms, err; BOOL result; if (tv) - ms = evutil_tv_to_msec_(tv); + ms = evutil_tv_to_msec_(tv); else ms = INFINITE; result = SleepConditionVariableCS_fn(cond, lock, ms); @@ -206,18 +206,18 @@ evthread_win32_cond_alloc(unsigned flags) } static void -evthread_win32_cond_free(void *cond_) +evthread_win32_cond_free(void *cond_) { - struct evthread_win32_cond *cond = cond_; + struct evthread_win32_cond *cond = cond_; DeleteCriticalSection(&cond->lock); CloseHandle(cond->event); mm_free(cond); } static int -evthread_win32_cond_signal(void *cond_, int broadcast) +evthread_win32_cond_signal(void *cond_, int broadcast) { - struct evthread_win32_cond *cond = cond_; + struct evthread_win32_cond *cond = cond_; EnterCriticalSection(&cond->lock); if (broadcast) cond->n_to_wake = cond->n_waiting; @@ -230,16 +230,16 @@ evthread_win32_cond_signal(void *cond_, int broadcast) } static int -evthread_win32_cond_wait(void *cond_, void *lock_, const struct timeval *tv) +evthread_win32_cond_wait(void *cond_, void *lock_, const struct timeval *tv) { - struct evthread_win32_cond *cond = cond_; - CRITICAL_SECTION *lock = lock_; + struct evthread_win32_cond *cond = cond_; + CRITICAL_SECTION *lock = lock_; int generation_at_start; int waiting = 1; int result = -1; DWORD ms = INFINITE, ms_orig = INFINITE, startTime, endTime; if (tv) - ms_orig = ms = evutil_tv_to_msec_(tv); + ms_orig = ms = evutil_tv_to_msec_(tv); EnterCriticalSection(&cond->lock); ++cond->n_waiting; diff --git a/contrib/libs/libevent/evutil.c b/contrib/libs/libevent/evutil.c index 9976e79beb..598134ec61 100644 --- a/contrib/libs/libevent/evutil.c +++ b/contrib/libs/libevent/evutil.c @@ -25,107 +25,107 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> -#include <winerror.h> +#include <winerror.h> #include <ws2tcpip.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #undef WIN32_LEAN_AND_MEAN #include <io.h> #include <tchar.h> -#include <process.h> -#undef _WIN32_WINNT -/* For structs needed by GetAdaptersAddresses */ -#define _WIN32_WINNT 0x0501 -#include <iphlpapi.h> +#include <process.h> +#undef _WIN32_WINNT +/* For structs needed by GetAdaptersAddresses */ +#define _WIN32_WINNT 0x0501 +#include <iphlpapi.h> #include <netioapi.h> #endif #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef EVENT__HAVE_FCNTL_H +#ifdef EVENT__HAVE_FCNTL_H #include <fcntl.h> #endif -#ifdef EVENT__HAVE_STDLIB_H +#ifdef EVENT__HAVE_STDLIB_H #include <stdlib.h> #endif #include <errno.h> #include <limits.h> #include <stdio.h> #include <string.h> -#ifdef EVENT__HAVE_NETINET_IN_H +#ifdef EVENT__HAVE_NETINET_IN_H #include <netinet/in.h> #endif -#ifdef EVENT__HAVE_NETINET_IN6_H -#error #include <netinet/in6.h> -#endif -#ifdef EVENT__HAVE_NETINET_TCP_H -#include <netinet/tcp.h> -#endif -#ifdef EVENT__HAVE_ARPA_INET_H +#ifdef EVENT__HAVE_NETINET_IN6_H +#error #include <netinet/in6.h> +#endif +#ifdef EVENT__HAVE_NETINET_TCP_H +#include <netinet/tcp.h> +#endif +#ifdef EVENT__HAVE_ARPA_INET_H #include <arpa/inet.h> #endif #include <time.h> -#include <sys/stat.h> +#include <sys/stat.h> #ifndef _WIN32 #include <net/if.h> #endif -#ifdef EVENT__HAVE_IFADDRS_H -#include <ifaddrs.h> +#ifdef EVENT__HAVE_IFADDRS_H +#include <ifaddrs.h> #endif #include "event2/util.h" #include "util-internal.h" #include "log-internal.h" #include "mm-internal.h" -#include "evthread-internal.h" +#include "evthread-internal.h" #include "strlcpy-internal.h" #include "ipv6-internal.h" -#ifdef _WIN32 -#define HT_NO_CACHE_HASH_VALUES -#include "ht-internal.h" +#ifdef _WIN32 +#define HT_NO_CACHE_HASH_VALUES +#include "ht-internal.h" #define open _open #define read _read #define close _close -#ifndef fstat +#ifndef fstat #define fstat _fstati64 -#endif -#ifndef stat +#endif +#ifndef stat #define stat _stati64 -#endif +#endif #define mode_t int #endif int -evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode) +evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode) { int fd; #ifdef O_CLOEXEC - fd = open(pathname, flags|O_CLOEXEC, (mode_t)mode); - if (fd >= 0 || errno == EINVAL) - return fd; - /* If we got an EINVAL, fall through and try without O_CLOEXEC */ + fd = open(pathname, flags|O_CLOEXEC, (mode_t)mode); + if (fd >= 0 || errno == EINVAL) + return fd; + /* If we got an EINVAL, fall through and try without O_CLOEXEC */ #endif - fd = open(pathname, flags, (mode_t)mode); + fd = open(pathname, flags, (mode_t)mode); if (fd < 0) return -1; -#if defined(FD_CLOEXEC) - if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { - close(fd); +#if defined(FD_CLOEXEC) + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { + close(fd); return -1; - } + } #endif return fd; @@ -142,7 +142,7 @@ evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode) Used internally only; may go away in a future version. */ int -evutil_read_file_(const char *filename, char **content_out, size_t *len_out, +evutil_read_file_(const char *filename, char **content_out, size_t *len_out, int is_binary) { int fd, r; @@ -161,7 +161,7 @@ evutil_read_file_(const char *filename, char **content_out, size_t *len_out, mode |= O_BINARY; #endif - fd = evutil_open_closeonexec_(filename, mode, 0); + fd = evutil_open_closeonexec_(filename, mode, 0); if (fd < 0) return -1; if (fstat(fd, &st) || st.st_size < 0 || @@ -175,7 +175,7 @@ evutil_read_file_(const char *filename, char **content_out, size_t *len_out, return -2; } read_so_far = 0; -#ifdef _WIN32 +#ifdef _WIN32 #define N_TO_READ(x) ((x) > INT_MAX) ? INT_MAX : ((int)(x)) #else #define N_TO_READ(x) (x) @@ -201,15 +201,15 @@ evutil_read_file_(const char *filename, char **content_out, size_t *len_out, int evutil_socketpair(int family, int type, int protocol, evutil_socket_t fd[2]) { -#ifndef _WIN32 +#ifndef _WIN32 return socketpair(family, type, protocol, fd); #else - return evutil_ersatz_socketpair_(family, type, protocol, fd); + return evutil_ersatz_socketpair_(family, type, protocol, fd); #endif } int -evutil_ersatz_socketpair_(int family, int type, int protocol, +evutil_ersatz_socketpair_(int family, int type, int protocol, evutil_socket_t fd[2]) { /* This code is originally from Tor. Used with permission. */ @@ -219,7 +219,7 @@ evutil_ersatz_socketpair_(int family, int type, int protocol, * for now, and really, when localhost is down sometimes, we * have other problems too. */ -#ifdef _WIN32 +#ifdef _WIN32 #define ERR(e) WSA##e #else #define ERR(e) e @@ -231,17 +231,17 @@ evutil_ersatz_socketpair_(int family, int type, int protocol, struct sockaddr_in connect_addr; ev_socklen_t size; int saved_errno = -1; - int family_test; - - family_test = family != AF_INET; + int family_test; + + family_test = family != AF_INET; #ifdef AF_UNIX - family_test = family_test && (family != AF_UNIX); + family_test = family_test && (family != AF_UNIX); #endif - if (protocol || family_test) { + if (protocol || family_test) { EVUTIL_SET_SOCKET_ERROR(ERR(EAFNOSUPPORT)); return -1; } - + if (!fd) { EVUTIL_SET_SOCKET_ERROR(ERR(EINVAL)); return -1; @@ -263,9 +263,9 @@ evutil_ersatz_socketpair_(int family, int type, int protocol, connector = socket(AF_INET, type, 0); if (connector < 0) goto tidy_up_and_fail; - - memset(&connect_addr, 0, sizeof(connect_addr)); - + + memset(&connect_addr, 0, sizeof(connect_addr)); + /* We want to find out the port number to connect to. */ size = sizeof(connect_addr); if (getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1) @@ -317,9 +317,9 @@ evutil_ersatz_socketpair_(int family, int type, int protocol, int evutil_make_socket_nonblocking(evutil_socket_t fd) { -#ifdef _WIN32 +#ifdef _WIN32 { - unsigned long nonblocking = 1; + unsigned long nonblocking = 1; if (ioctlsocket(fd, FIONBIO, &nonblocking) == SOCKET_ERROR) { event_sock_warn(fd, "fcntl(%d, F_GETFL)", (int)fd); return -1; @@ -332,39 +332,39 @@ evutil_make_socket_nonblocking(evutil_socket_t fd) event_warn("fcntl(%d, F_GETFL)", fd); return -1; } - if (!(flags & O_NONBLOCK)) { - if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { - event_warn("fcntl(%d, F_SETFL)", fd); - return -1; - } + if (!(flags & O_NONBLOCK)) { + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { + event_warn("fcntl(%d, F_SETFL)", fd); + return -1; + } } } #endif return 0; } -/* Faster version of evutil_make_socket_nonblocking for internal use. - * - * Requires that no F_SETFL flags were previously set on the fd. - */ -static int -evutil_fast_socket_nonblocking(evutil_socket_t fd) -{ -#ifdef _WIN32 - return evutil_make_socket_nonblocking(fd); -#else - if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { - event_warn("fcntl(%d, F_SETFL)", fd); - return -1; - } - return 0; -#endif -} - +/* Faster version of evutil_make_socket_nonblocking for internal use. + * + * Requires that no F_SETFL flags were previously set on the fd. + */ +static int +evutil_fast_socket_nonblocking(evutil_socket_t fd) +{ +#ifdef _WIN32 + return evutil_make_socket_nonblocking(fd); +#else + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + event_warn("fcntl(%d, F_SETFL)", fd); + return -1; + } + return 0; +#endif +} + int evutil_make_listen_socket_reuseable(evutil_socket_t sock) { -#if defined(SO_REUSEADDR) && !defined(_WIN32) +#if defined(SO_REUSEADDR) && !defined(_WIN32) int one = 1; /* REUSEADDR on Unix means, "don't hang on to this address after the * listener is closed." On Windows, though, it means "don't keep other @@ -377,72 +377,72 @@ evutil_make_listen_socket_reuseable(evutil_socket_t sock) } int -evutil_make_listen_socket_reuseable_port(evutil_socket_t sock) -{ -#if defined __linux__ && defined(SO_REUSEPORT) - int one = 1; - /* REUSEPORT on Linux 3.9+ means, "Multiple servers (processes or - * threads) can bind to the same port if they each set the option. */ - return setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void*) &one, - (ev_socklen_t)sizeof(one)); -#else - return 0; -#endif -} - -int -evutil_make_listen_socket_ipv6only(evutil_socket_t sock) -{ -#if defined(IPV6_V6ONLY) - int one = 1; - return setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void*) &one, - (ev_socklen_t)sizeof(one)); -#endif - return 0; -} - -int -evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock) -{ -#if defined(EVENT__HAVE_NETINET_TCP_H) && defined(TCP_DEFER_ACCEPT) - int one = 1; - - /* TCP_DEFER_ACCEPT tells the kernel to call defer accept() only after data - * has arrived and ready to read */ - return setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &one, - (ev_socklen_t)sizeof(one)); -#endif - return 0; -} - -int +evutil_make_listen_socket_reuseable_port(evutil_socket_t sock) +{ +#if defined __linux__ && defined(SO_REUSEPORT) + int one = 1; + /* REUSEPORT on Linux 3.9+ means, "Multiple servers (processes or + * threads) can bind to the same port if they each set the option. */ + return setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void*) &one, + (ev_socklen_t)sizeof(one)); +#else + return 0; +#endif +} + +int +evutil_make_listen_socket_ipv6only(evutil_socket_t sock) +{ +#if defined(IPV6_V6ONLY) + int one = 1; + return setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void*) &one, + (ev_socklen_t)sizeof(one)); +#endif + return 0; +} + +int +evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock) +{ +#if defined(EVENT__HAVE_NETINET_TCP_H) && defined(TCP_DEFER_ACCEPT) + int one = 1; + + /* TCP_DEFER_ACCEPT tells the kernel to call defer accept() only after data + * has arrived and ready to read */ + return setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &one, + (ev_socklen_t)sizeof(one)); +#endif + return 0; +} + +int evutil_make_socket_closeonexec(evutil_socket_t fd) { -#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD) +#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD) int flags; if ((flags = fcntl(fd, F_GETFD, NULL)) < 0) { event_warn("fcntl(%d, F_GETFD)", fd); return -1; } - if (!(flags & FD_CLOEXEC)) { - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) { - event_warn("fcntl(%d, F_SETFD)", fd); - return -1; - } - } -#endif - return 0; -} - -/* Faster version of evutil_make_socket_closeonexec for internal use. - * - * Requires that no F_SETFD flags were previously set on the fd. - */ -static int -evutil_fast_socket_closeonexec(evutil_socket_t fd) -{ -#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD) - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { + if (!(flags & FD_CLOEXEC)) { + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) { + event_warn("fcntl(%d, F_SETFD)", fd); + return -1; + } + } +#endif + return 0; +} + +/* Faster version of evutil_make_socket_closeonexec for internal use. + * + * Requires that no F_SETFD flags were previously set on the fd. + */ +static int +evutil_fast_socket_closeonexec(evutil_socket_t fd) +{ +#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD) + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { event_warn("fcntl(%d, F_SETFD)", fd); return -1; } @@ -453,7 +453,7 @@ evutil_fast_socket_closeonexec(evutil_socket_t fd) int evutil_closesocket(evutil_socket_t sock) { -#ifndef _WIN32 +#ifndef _WIN32 return close(sock); #else return closesocket(sock); @@ -463,11 +463,11 @@ evutil_closesocket(evutil_socket_t sock) ev_int64_t evutil_strtoll(const char *s, char **endptr, int base) { -#ifdef EVENT__HAVE_STRTOLL +#ifdef EVENT__HAVE_STRTOLL return (ev_int64_t)strtoll(s, endptr, base); -#elif EVENT__SIZEOF_LONG == 8 +#elif EVENT__SIZEOF_LONG == 8 return (ev_int64_t)strtol(s, endptr, base); -#elif defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1300 +#elif defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1300 /* XXXX on old versions of MS APIs, we only support base * 10. */ ev_int64_t r; @@ -483,9 +483,9 @@ evutil_strtoll(const char *s, char **endptr, int base) if (endptr) *endptr = (char*) s; return r; -#elif defined(_WIN32) +#elif defined(_WIN32) return (ev_int64_t) _strtoi64(s, endptr, base); -#elif defined(EVENT__SIZEOF_LONG_LONG) && EVENT__SIZEOF_LONG_LONG == 8 +#elif defined(EVENT__SIZEOF_LONG_LONG) && EVENT__SIZEOF_LONG_LONG == 8 long long r; int n; if (base != 10 && base != 16) @@ -501,15 +501,15 @@ evutil_strtoll(const char *s, char **endptr, int base) } if (n != 1) return 0; - while (EVUTIL_ISSPACE_(*s)) + while (EVUTIL_ISSPACE_(*s)) ++s; if (*s == '-') ++s; if (base == 10) { - while (EVUTIL_ISDIGIT_(*s)) + while (EVUTIL_ISDIGIT_(*s)) ++s; } else { - while (EVUTIL_ISXDIGIT_(*s)) + while (EVUTIL_ISXDIGIT_(*s)) ++s; } if (endptr) @@ -520,7 +520,7 @@ evutil_strtoll(const char *s, char **endptr, int base) #endif } -#ifdef _WIN32 +#ifdef _WIN32 int evutil_socket_geterror(evutil_socket_t sock) { @@ -540,7 +540,7 @@ evutil_socket_geterror(evutil_socket_t sock) /* XXX we should use an enum here. */ /* 2 for connection refused, 1 for connected, 0 for not yet, -1 for error. */ int -evutil_socket_connect_(evutil_socket_t *fd_ptr, const struct sockaddr *sa, int socklen) +evutil_socket_connect_(evutil_socket_t *fd_ptr, const struct sockaddr *sa, int socklen) { int made_fd = 0; @@ -577,7 +577,7 @@ err: error case, set the current socket errno to the error that happened during the connect operation. */ int -evutil_socket_finished_connecting_(evutil_socket_t fd) +evutil_socket_finished_connecting_(evutil_socket_t fd) { int e; ev_socklen_t elen = sizeof(e); @@ -611,151 +611,151 @@ evutil_socket_finished_connecting_(evutil_socket_t fd) set by evutil_check_interfaces. */ static int have_checked_interfaces, had_ipv4_address, had_ipv6_address; -/* True iff the IPv4 address 'addr', in host order, is in 127.0.0.0/8 */ -static inline int evutil_v4addr_is_localhost(ev_uint32_t addr) -{ return addr>>24 == 127; } - -/* True iff the IPv4 address 'addr', in host order, is link-local - * 169.254.0.0/16 (RFC3927) */ -static inline int evutil_v4addr_is_linklocal(ev_uint32_t addr) -{ return ((addr & 0xffff0000U) == 0xa9fe0000U); } - -/* True iff the IPv4 address 'addr', in host order, is a class D - * (multiclass) address. */ -static inline int evutil_v4addr_is_classd(ev_uint32_t addr) -{ return ((addr>>24) & 0xf0) == 0xe0; } - -int -evutil_v4addr_is_local_(const struct in_addr *in) -{ - const ev_uint32_t addr = ntohl(in->s_addr); - return addr == INADDR_ANY || - evutil_v4addr_is_localhost(addr) || - evutil_v4addr_is_linklocal(addr) || - evutil_v4addr_is_classd(addr); -} -int -evutil_v6addr_is_local_(const struct in6_addr *in) -{ - static const char ZEROES[] = - "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00"; - - const unsigned char *addr = (const unsigned char *)in->s6_addr; - return !memcmp(addr, ZEROES, 8) || - ((addr[0] & 0xfe) == 0xfc) || - (addr[0] == 0xfe && (addr[1] & 0xc0) == 0x80) || - (addr[0] == 0xfe && (addr[1] & 0xc0) == 0xc0) || - (addr[0] == 0xff); -} - -static void -evutil_found_ifaddr(const struct sockaddr *sa) -{ - if (sa->sa_family == AF_INET) { - const struct sockaddr_in *sin = (struct sockaddr_in *)sa; - if (!evutil_v4addr_is_local_(&sin->sin_addr)) { - event_debug(("Detected an IPv4 interface")); - had_ipv4_address = 1; - } - } else if (sa->sa_family == AF_INET6) { - const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; - if (!evutil_v6addr_is_local_(&sin6->sin6_addr)) { - event_debug(("Detected an IPv6 interface")); - had_ipv6_address = 1; - } - } -} - -#ifdef _WIN32 -typedef ULONG (WINAPI *GetAdaptersAddresses_fn_t)( - ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG); -#endif - -static int -evutil_check_ifaddrs(void) -{ -#if defined(EVENT__HAVE_GETIFADDRS) - /* Most free Unixy systems provide getifaddrs, which gives us a linked list - * of struct ifaddrs. */ - struct ifaddrs *ifa = NULL; - const struct ifaddrs *i; - if (getifaddrs(&ifa) < 0) { - event_warn("Unable to call getifaddrs()"); - return -1; - } - - for (i = ifa; i; i = i->ifa_next) { - if (!i->ifa_addr) - continue; - evutil_found_ifaddr(i->ifa_addr); - } - - freeifaddrs(ifa); - return 0; -#elif defined(_WIN32) - /* Windows XP began to provide GetAdaptersAddresses. Windows 2000 had a - "GetAdaptersInfo", but that's deprecated; let's just try - GetAdaptersAddresses and fall back to connect+getsockname. - */ +/* True iff the IPv4 address 'addr', in host order, is in 127.0.0.0/8 */ +static inline int evutil_v4addr_is_localhost(ev_uint32_t addr) +{ return addr>>24 == 127; } + +/* True iff the IPv4 address 'addr', in host order, is link-local + * 169.254.0.0/16 (RFC3927) */ +static inline int evutil_v4addr_is_linklocal(ev_uint32_t addr) +{ return ((addr & 0xffff0000U) == 0xa9fe0000U); } + +/* True iff the IPv4 address 'addr', in host order, is a class D + * (multiclass) address. */ +static inline int evutil_v4addr_is_classd(ev_uint32_t addr) +{ return ((addr>>24) & 0xf0) == 0xe0; } + +int +evutil_v4addr_is_local_(const struct in_addr *in) +{ + const ev_uint32_t addr = ntohl(in->s_addr); + return addr == INADDR_ANY || + evutil_v4addr_is_localhost(addr) || + evutil_v4addr_is_linklocal(addr) || + evutil_v4addr_is_classd(addr); +} +int +evutil_v6addr_is_local_(const struct in6_addr *in) +{ + static const char ZEROES[] = + "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00"; + + const unsigned char *addr = (const unsigned char *)in->s6_addr; + return !memcmp(addr, ZEROES, 8) || + ((addr[0] & 0xfe) == 0xfc) || + (addr[0] == 0xfe && (addr[1] & 0xc0) == 0x80) || + (addr[0] == 0xfe && (addr[1] & 0xc0) == 0xc0) || + (addr[0] == 0xff); +} + +static void +evutil_found_ifaddr(const struct sockaddr *sa) +{ + if (sa->sa_family == AF_INET) { + const struct sockaddr_in *sin = (struct sockaddr_in *)sa; + if (!evutil_v4addr_is_local_(&sin->sin_addr)) { + event_debug(("Detected an IPv4 interface")); + had_ipv4_address = 1; + } + } else if (sa->sa_family == AF_INET6) { + const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; + if (!evutil_v6addr_is_local_(&sin6->sin6_addr)) { + event_debug(("Detected an IPv6 interface")); + had_ipv6_address = 1; + } + } +} + +#ifdef _WIN32 +typedef ULONG (WINAPI *GetAdaptersAddresses_fn_t)( + ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG); +#endif + +static int +evutil_check_ifaddrs(void) +{ +#if defined(EVENT__HAVE_GETIFADDRS) + /* Most free Unixy systems provide getifaddrs, which gives us a linked list + * of struct ifaddrs. */ + struct ifaddrs *ifa = NULL; + const struct ifaddrs *i; + if (getifaddrs(&ifa) < 0) { + event_warn("Unable to call getifaddrs()"); + return -1; + } + + for (i = ifa; i; i = i->ifa_next) { + if (!i->ifa_addr) + continue; + evutil_found_ifaddr(i->ifa_addr); + } + + freeifaddrs(ifa); + return 0; +#elif defined(_WIN32) + /* Windows XP began to provide GetAdaptersAddresses. Windows 2000 had a + "GetAdaptersInfo", but that's deprecated; let's just try + GetAdaptersAddresses and fall back to connect+getsockname. + */ HMODULE lib = evutil_load_windows_system_library_(TEXT("iphlpapi.dll")); - GetAdaptersAddresses_fn_t fn; - ULONG size, res; - IP_ADAPTER_ADDRESSES *addresses = NULL, *address; - int result = -1; - -#define FLAGS (GAA_FLAG_SKIP_ANYCAST | \ - GAA_FLAG_SKIP_MULTICAST | \ - GAA_FLAG_SKIP_DNS_SERVER) - - if (!lib) - goto done; - - if (!(fn = (GetAdaptersAddresses_fn_t) GetProcAddress(lib, "GetAdaptersAddresses"))) - goto done; - - /* Guess how much space we need. */ - size = 15*1024; - addresses = mm_malloc(size); - if (!addresses) - goto done; - res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); - if (res == ERROR_BUFFER_OVERFLOW) { - /* we didn't guess that we needed enough space; try again */ - mm_free(addresses); - addresses = mm_malloc(size); - if (!addresses) - goto done; - res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); - } - if (res != NO_ERROR) - goto done; - - for (address = addresses; address; address = address->Next) { - IP_ADAPTER_UNICAST_ADDRESS *a; - for (a = address->FirstUnicastAddress; a; a = a->Next) { - /* Yes, it's a linked list inside a linked list */ - struct sockaddr *sa = a->Address.lpSockaddr; - evutil_found_ifaddr(sa); - } - } - - result = 0; -done: - if (lib) - FreeLibrary(lib); - if (addresses) - mm_free(addresses); - return result; -#else - return -1; -#endif -} - + GetAdaptersAddresses_fn_t fn; + ULONG size, res; + IP_ADAPTER_ADDRESSES *addresses = NULL, *address; + int result = -1; + +#define FLAGS (GAA_FLAG_SKIP_ANYCAST | \ + GAA_FLAG_SKIP_MULTICAST | \ + GAA_FLAG_SKIP_DNS_SERVER) + + if (!lib) + goto done; + + if (!(fn = (GetAdaptersAddresses_fn_t) GetProcAddress(lib, "GetAdaptersAddresses"))) + goto done; + + /* Guess how much space we need. */ + size = 15*1024; + addresses = mm_malloc(size); + if (!addresses) + goto done; + res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); + if (res == ERROR_BUFFER_OVERFLOW) { + /* we didn't guess that we needed enough space; try again */ + mm_free(addresses); + addresses = mm_malloc(size); + if (!addresses) + goto done; + res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); + } + if (res != NO_ERROR) + goto done; + + for (address = addresses; address; address = address->Next) { + IP_ADAPTER_UNICAST_ADDRESS *a; + for (a = address->FirstUnicastAddress; a; a = a->Next) { + /* Yes, it's a linked list inside a linked list */ + struct sockaddr *sa = a->Address.lpSockaddr; + evutil_found_ifaddr(sa); + } + } + + result = 0; +done: + if (lib) + FreeLibrary(lib); + if (addresses) + mm_free(addresses); + return result; +#else + return -1; +#endif +} + /* Test whether we have an ipv4 interface and an ipv6 interface. Return 0 if * the test seemed successful. */ static int -evutil_check_interfaces(void) +evutil_check_interfaces(void) { evutil_socket_t fd = -1; struct sockaddr_in sin, sin_out; @@ -763,22 +763,22 @@ evutil_check_interfaces(void) ev_socklen_t sin_out_len = sizeof(sin_out); ev_socklen_t sin6_out_len = sizeof(sin6_out); int r; - if (have_checked_interfaces) - return 0; - - /* From this point on we have done the ipv4/ipv6 interface check */ - have_checked_interfaces = 1; - - if (evutil_check_ifaddrs() == 0) { - /* Use a nice sane interface, if this system has one. */ + if (have_checked_interfaces) return 0; - } - /* Ugh. There was no nice sane interface. So to check whether we have - * an interface open for a given protocol, will try to make a UDP - * 'connection' to a remote host on the internet. We don't actually - * use it, so the address doesn't matter, but we want to pick one that - * keep us from using a host- or link-local interface. */ + /* From this point on we have done the ipv4/ipv6 interface check */ + have_checked_interfaces = 1; + + if (evutil_check_ifaddrs() == 0) { + /* Use a nice sane interface, if this system has one. */ + return 0; + } + + /* Ugh. There was no nice sane interface. So to check whether we have + * an interface open for a given protocol, will try to make a UDP + * 'connection' to a remote host on the internet. We don't actually + * use it, so the address doesn't matter, but we want to pick one that + * keep us from using a host- or link-local interface. */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(53); @@ -799,7 +799,7 @@ evutil_check_interfaces(void) connect(fd, (struct sockaddr*)&sin, sizeof(sin)) == 0 && getsockname(fd, (struct sockaddr*)&sin_out, &sin_out_len) == 0) { /* We might have an IPv4 interface. */ - evutil_found_ifaddr((struct sockaddr*) &sin_out); + evutil_found_ifaddr((struct sockaddr*) &sin_out); } if (fd >= 0) evutil_closesocket(fd); @@ -808,7 +808,7 @@ evutil_check_interfaces(void) connect(fd, (struct sockaddr*)&sin6, sizeof(sin6)) == 0 && getsockname(fd, (struct sockaddr*)&sin6_out, &sin6_out_len) == 0) { /* We might have an IPv6 interface. */ - evutil_found_ifaddr((struct sockaddr*) &sin6_out); + evutil_found_ifaddr((struct sockaddr*) &sin6_out); } if (fd >= 0) @@ -829,7 +829,7 @@ evutil_check_interfaces(void) * allocate both a TCP and a UDP addrinfo. */ struct evutil_addrinfo * -evutil_new_addrinfo_(struct sockaddr *sa, ev_socklen_t socklen, +evutil_new_addrinfo_(struct sockaddr *sa, ev_socklen_t socklen, const struct evutil_addrinfo *hints) { struct evutil_addrinfo *res; @@ -841,11 +841,11 @@ evutil_new_addrinfo_(struct sockaddr *sa, ev_socklen_t socklen, struct evutil_addrinfo tmp; memcpy(&tmp, hints, sizeof(tmp)); tmp.ai_socktype = SOCK_STREAM; tmp.ai_protocol = IPPROTO_TCP; - r1 = evutil_new_addrinfo_(sa, socklen, &tmp); + r1 = evutil_new_addrinfo_(sa, socklen, &tmp); if (!r1) return NULL; tmp.ai_socktype = SOCK_DGRAM; tmp.ai_protocol = IPPROTO_UDP; - r2 = evutil_new_addrinfo_(sa, socklen, &tmp); + r2 = evutil_new_addrinfo_(sa, socklen, &tmp); if (!r2) { evutil_freeaddrinfo(r1); return NULL; @@ -874,7 +874,7 @@ evutil_new_addrinfo_(struct sockaddr *sa, ev_socklen_t socklen, * the list. Either element can be NULL, in which case we return the element * that is not NULL. */ struct evutil_addrinfo * -evutil_addrinfo_append_(struct evutil_addrinfo *first, +evutil_addrinfo_append_(struct evutil_addrinfo *first, struct evutil_addrinfo *append) { struct evutil_addrinfo *ai = first; @@ -909,7 +909,7 @@ evutil_parse_servname(const char *servname, const char *protocol, int n = parse_numeric_servname(servname); if (n>=0) return n; -#if defined(EVENT__HAVE_GETSERVBYNAME) || defined(_WIN32) +#if defined(EVENT__HAVE_GETSERVBYNAME) || defined(_WIN32) if (!(hints->ai_flags & EVUTIL_AI_NUMERICSERV)) { struct servent *ent = getservbyname(servname, protocol); if (ent) { @@ -937,7 +937,7 @@ evutil_unparse_protoname(int proto) return "sctp"; #endif default: -#ifdef EVENT__HAVE_GETPROTOBYNUMBER +#ifdef EVENT__HAVE_GETPROTOBYNUMBER { struct protoent *ent = getprotobynumber(proto); if (ent) @@ -990,7 +990,7 @@ evutil_getaddrinfo_infer_protocols(struct evutil_addrinfo *hints) * set *res as getaddrinfo would. */ int -evutil_getaddrinfo_common_(const char *nodename, const char *servname, +evutil_getaddrinfo_common_(const char *nodename, const char *servname, struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum) { int port = 0; @@ -1033,7 +1033,7 @@ evutil_getaddrinfo_common_(const char *nodename, const char *servname, /* connect to ::1 */ sin6.sin6_addr.s6_addr[15] = 1; } - res6 = evutil_new_addrinfo_((struct sockaddr*)&sin6, + res6 = evutil_new_addrinfo_((struct sockaddr*)&sin6, sizeof(sin6), hints); if (!res6) return EVUTIL_EAI_MEMORY; @@ -1050,7 +1050,7 @@ evutil_getaddrinfo_common_(const char *nodename, const char *servname, /* connect to 127.0.0.1 */ sin.sin_addr.s_addr = htonl(0x7f000001); } - res4 = evutil_new_addrinfo_((struct sockaddr*)&sin, + res4 = evutil_new_addrinfo_((struct sockaddr*)&sin, sizeof(sin), hints); if (!res4) { if (res6) @@ -1058,7 +1058,7 @@ evutil_getaddrinfo_common_(const char *nodename, const char *servname, return EVUTIL_EAI_MEMORY; } } - *res = evutil_addrinfo_append_(res4, res6); + *res = evutil_addrinfo_append_(res4, res6); return 0; } @@ -1074,7 +1074,7 @@ evutil_getaddrinfo_common_(const char *nodename, const char *servname, sin6.sin6_family = AF_INET6; sin6.sin6_port = htons(port); sin6.sin6_scope_id = if_index; - *res = evutil_new_addrinfo_((struct sockaddr*)&sin6, + *res = evutil_new_addrinfo_((struct sockaddr*)&sin6, sizeof(sin6), hints); if (!*res) return EVUTIL_EAI_MEMORY; @@ -1087,10 +1087,10 @@ evutil_getaddrinfo_common_(const char *nodename, const char *servname, struct sockaddr_in sin; memset(&sin, 0, sizeof(sin)); if (1==evutil_inet_pton(AF_INET, nodename, &sin.sin_addr)) { - /* Got an ipv4 address. */ + /* Got an ipv4 address. */ sin.sin_family = AF_INET; sin.sin_port = htons(port); - *res = evutil_new_addrinfo_((struct sockaddr*)&sin, + *res = evutil_new_addrinfo_((struct sockaddr*)&sin, sizeof(sin), hints); if (!*res) return EVUTIL_EAI_MEMORY; @@ -1109,7 +1109,7 @@ evutil_getaddrinfo_common_(const char *nodename, const char *servname, return EVUTIL_EAI_NEED_RESOLVE; } -#ifdef EVENT__HAVE_GETADDRINFO +#ifdef EVENT__HAVE_GETADDRINFO #define USE_NATIVE_GETADDRINFO #endif @@ -1197,7 +1197,7 @@ addrinfo_from_hostent(const struct hostent *ent, sin6.sin6_family = AF_INET6; sin6.sin6_port = htons(port); sa = (struct sockaddr *)&sin6; - socklen = sizeof(struct sockaddr_in6); + socklen = sizeof(struct sockaddr_in6); addrp = &sin6.sin6_addr; if (ent->h_length != sizeof(sin6.sin6_addr)) { event_warnx("Weird h_length from gethostbyname"); @@ -1208,12 +1208,12 @@ addrinfo_from_hostent(const struct hostent *ent, for (i = 0; ent->h_addr_list[i]; ++i) { memcpy(addrp, ent->h_addr_list[i], ent->h_length); - ai = evutil_new_addrinfo_(sa, socklen, hints); + ai = evutil_new_addrinfo_(sa, socklen, hints); if (!ai) { evutil_freeaddrinfo(res); return NULL; } - res = evutil_addrinfo_append_(res, ai); + res = evutil_addrinfo_append_(res, ai); } if (res && ((hints->ai_flags & EVUTIL_AI_CANONNAME) && ent->h_name)) { @@ -1233,13 +1233,13 @@ addrinfo_from_hostent(const struct hostent *ent, * that we'll only get addresses we could maybe connect to. */ void -evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints) +evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints) { if (!(hints->ai_flags & EVUTIL_AI_ADDRCONFIG)) return; if (hints->ai_family != PF_UNSPEC) return; - evutil_check_interfaces(); + evutil_check_interfaces(); if (had_ipv4_address && !had_ipv6_address) { hints->ai_family = PF_INET; } else if (!had_ipv4_address && had_ipv6_address) { @@ -1261,7 +1261,7 @@ static int tested_for_getaddrinfo_hacks=0; turns out that the bug is present, then: - If nodename==NULL and servname is numeric, we build an answer - ourselves using evutil_getaddrinfo_common_(). + ourselves using evutil_getaddrinfo_common_(). - If nodename!=NULL and servname is numeric, then we set servname=NULL when calling getaddrinfo, and post-process the @@ -1274,20 +1274,20 @@ static int tested_for_getaddrinfo_hacks=0; field set to 0. We test for this so we can apply an appropriate workaround. */ -static struct evutil_addrinfo *ai_find_protocol(struct evutil_addrinfo *ai) -{ - while (ai) { - if (ai->ai_protocol) - return ai; - ai = ai->ai_next; - } - return NULL; -} +static struct evutil_addrinfo *ai_find_protocol(struct evutil_addrinfo *ai) +{ + while (ai) { + if (ai->ai_protocol) + return ai; + ai = ai->ai_next; + } + return NULL; +} static void test_for_getaddrinfo_hacks(void) { int r, r2; - struct evutil_addrinfo *ai=NULL, *ai2=NULL, *ai3=NULL; + struct evutil_addrinfo *ai=NULL, *ai2=NULL, *ai3=NULL; struct evutil_addrinfo hints; memset(&hints,0,sizeof(hints)); @@ -1301,13 +1301,13 @@ test_for_getaddrinfo_hacks(void) #endif 0; r = getaddrinfo("1.2.3.4", "80", &hints, &ai); - getaddrinfo("1.2.3.4", NULL, &hints, &ai3); + getaddrinfo("1.2.3.4", NULL, &hints, &ai3); hints.ai_socktype = SOCK_STREAM; r2 = getaddrinfo("1.2.3.4", "80", &hints, &ai2); if (r2 == 0 && r != 0) { need_numeric_port_hack_=1; } - if (!ai_find_protocol(ai2) || !ai_find_protocol(ai3)) { + if (!ai_find_protocol(ai2) || !ai_find_protocol(ai3)) { need_socktype_protocol_hack_=1; } @@ -1315,8 +1315,8 @@ test_for_getaddrinfo_hacks(void) freeaddrinfo(ai); if (ai2) freeaddrinfo(ai2); - if (ai3) - freeaddrinfo(ai3); + if (ai3) + freeaddrinfo(ai3); tested_for_getaddrinfo_hacks=1; } @@ -1403,7 +1403,7 @@ evutil_getaddrinfo(const char *nodename, const char *servname, /* Not every system has AI_ADDRCONFIG, so fake it. */ if (hints.ai_family == PF_UNSPEC && (hints.ai_flags & EVUTIL_AI_ADDRCONFIG)) { - evutil_adjust_hints_for_addrconfig_(&hints); + evutil_adjust_hints_for_addrconfig_(&hints); } #endif @@ -1426,10 +1426,10 @@ evutil_getaddrinfo(const char *nodename, const char *servname, * ever resolving even a literal IPv6 address when * ai_addrtype is PF_UNSPEC. */ -#ifdef _WIN32 +#ifdef _WIN32 { int tmp_port; - err = evutil_getaddrinfo_common_(nodename,servname,&hints, + err = evutil_getaddrinfo_common_(nodename,servname,&hints, res, &tmp_port); if (err == 0 || err == EVUTIL_EAI_MEMORY || @@ -1445,7 +1445,7 @@ evutil_getaddrinfo(const char *nodename, const char *servname, && ((portnum=parse_numeric_servname(servname)) >= 0); if (need_np_hack) { if (!nodename) - return evutil_getaddrinfo_common_( + return evutil_getaddrinfo_common_( NULL,servname,&hints, res, &portnum); servname = NULL; } @@ -1490,9 +1490,9 @@ evutil_getaddrinfo(const char *nodename, const char *servname, hints.ai_family = PF_UNSPEC; } - evutil_adjust_hints_for_addrconfig_(&hints); + evutil_adjust_hints_for_addrconfig_(&hints); - err = evutil_getaddrinfo_common_(nodename, servname, &hints, res, &port); + err = evutil_getaddrinfo_common_(nodename, servname, &hints, res, &port); if (err != EVUTIL_EAI_NEED_RESOLVE) { /* We either succeeded or failed. No need to continue */ return err; @@ -1501,19 +1501,19 @@ evutil_getaddrinfo(const char *nodename, const char *servname, err = 0; /* Use any of the various gethostbyname_r variants as available. */ { -#ifdef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG +#ifdef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG /* This one is what glibc provides. */ char buf[2048]; struct hostent hostent; int r; r = gethostbyname_r(nodename, &hostent, buf, sizeof(buf), &ent, &err); -#elif defined(EVENT__HAVE_GETHOSTBYNAME_R_5_ARG) +#elif defined(EVENT__HAVE_GETHOSTBYNAME_R_5_ARG) char buf[2048]; struct hostent hostent; ent = gethostbyname_r(nodename, &hostent, buf, sizeof(buf), &err); -#elif defined(EVENT__HAVE_GETHOSTBYNAME_R_3_ARG) +#elif defined(EVENT__HAVE_GETHOSTBYNAME_R_3_ARG) struct hostent_data data; struct hostent hostent; memset(&data, 0, sizeof(data)); @@ -1523,7 +1523,7 @@ evutil_getaddrinfo(const char *nodename, const char *servname, /* fall back to gethostbyname. */ /* XXXX This needs a lock everywhere but Windows. */ ent = gethostbyname(nodename); -#ifdef _WIN32 +#ifdef _WIN32 err = WSAGetLastError(); #else err = h_errno; @@ -1578,7 +1578,7 @@ evutil_getaddrinfo(const char *nodename, const char *servname, void evutil_freeaddrinfo(struct evutil_addrinfo *ai) { -#ifdef EVENT__HAVE_GETADDRINFO +#ifdef EVENT__HAVE_GETADDRINFO if (!(ai->ai_flags & EVUTIL_AI_LIBEVENT_ALLOCATED)) { freeaddrinfo(ai); return; @@ -1594,50 +1594,50 @@ evutil_freeaddrinfo(struct evutil_addrinfo *ai) } static evdns_getaddrinfo_fn evdns_getaddrinfo_impl = NULL; -static evdns_getaddrinfo_cancel_fn evdns_getaddrinfo_cancel_impl = NULL; +static evdns_getaddrinfo_cancel_fn evdns_getaddrinfo_cancel_impl = NULL; void -evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn) +evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn) { if (!evdns_getaddrinfo_impl) evdns_getaddrinfo_impl = fn; } -void -evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn) -{ - if (!evdns_getaddrinfo_cancel_impl) - evdns_getaddrinfo_cancel_impl = fn; -} +void +evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn) +{ + if (!evdns_getaddrinfo_cancel_impl) + evdns_getaddrinfo_cancel_impl = fn; +} /* Internal helper function: act like evdns_getaddrinfo if dns_base is set; * otherwise do a blocking resolve and pass the result to the callback in the * way that evdns_getaddrinfo would. */ -struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_( - struct evdns_base *dns_base, +struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_( + struct evdns_base *dns_base, const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, void (*cb)(int, struct evutil_addrinfo *, void *), void *arg) { if (dns_base && evdns_getaddrinfo_impl) { - return evdns_getaddrinfo_impl( + return evdns_getaddrinfo_impl( dns_base, nodename, servname, hints_in, cb, arg); } else { struct evutil_addrinfo *ai=NULL; int err; err = evutil_getaddrinfo(nodename, servname, hints_in, &ai); cb(err, ai, arg); - return NULL; - } -} - -void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data) -{ - if (evdns_getaddrinfo_cancel_impl && data) { - evdns_getaddrinfo_cancel_impl(data); + return NULL; } } +void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data) +{ + if (evdns_getaddrinfo_cancel_impl && data) { + evdns_getaddrinfo_cancel_impl(data); + } +} + const char * evutil_gai_strerror(int err) { @@ -1673,7 +1673,7 @@ evutil_gai_strerror(int err) case EVUTIL_EAI_SYSTEM: return "system error"; default: -#if defined(USE_NATIVE_GETADDRINFO) && defined(_WIN32) +#if defined(USE_NATIVE_GETADDRINFO) && defined(_WIN32) return gai_strerrorA(err); #elif defined(USE_NATIVE_GETADDRINFO) return gai_strerror(err); @@ -1683,181 +1683,181 @@ evutil_gai_strerror(int err) } } -#ifdef _WIN32 -/* destructively remove a trailing line terminator from s */ -static void -chomp (char *s) -{ - size_t len; - if (s && (len = strlen (s)) > 0 && s[len - 1] == '\n') { - s[--len] = 0; - if (len > 0 && s[len - 1] == '\r') - s[--len] = 0; - } -} - -/* FormatMessage returns allocated strings, but evutil_socket_error_to_string - * is supposed to return a string which is good indefinitely without having - * to be freed. To make this work without leaking memory, we cache the - * string the first time FormatMessage is called on a particular error - * code, and then return the cached string on subsequent calls with the - * same code. The strings aren't freed until libevent_global_shutdown - * (or never). We use a linked list to cache the errors, because we - * only expect there to be a few dozen, and that should be fast enough. - */ - -struct cached_sock_errs_entry { - HT_ENTRY(cached_sock_errs_entry) node; - DWORD code; - char *msg; /* allocated with LocalAlloc; free with LocalFree */ -}; - -static inline unsigned -hash_cached_sock_errs(const struct cached_sock_errs_entry *e) -{ - /* Use Murmur3's 32-bit finalizer as an integer hash function */ - DWORD h = e->code; - h ^= h >> 16; - h *= 0x85ebca6b; - h ^= h >> 13; - h *= 0xc2b2ae35; - h ^= h >> 16; - return h; -} - -static inline int -eq_cached_sock_errs(const struct cached_sock_errs_entry *a, - const struct cached_sock_errs_entry *b) -{ - return a->code == b->code; -} - -#ifndef EVENT__DISABLE_THREAD_SUPPORT -static void *windows_socket_errors_lock_ = NULL; -#endif - -static HT_HEAD(cached_sock_errs_map, cached_sock_errs_entry) - windows_socket_errors = HT_INITIALIZER(); - -HT_PROTOTYPE(cached_sock_errs_map, - cached_sock_errs_entry, - node, - hash_cached_sock_errs, - eq_cached_sock_errs); - -HT_GENERATE(cached_sock_errs_map, - cached_sock_errs_entry, - node, - hash_cached_sock_errs, - eq_cached_sock_errs, - 0.5, - mm_malloc, - mm_realloc, - mm_free); - +#ifdef _WIN32 +/* destructively remove a trailing line terminator from s */ +static void +chomp (char *s) +{ + size_t len; + if (s && (len = strlen (s)) > 0 && s[len - 1] == '\n') { + s[--len] = 0; + if (len > 0 && s[len - 1] == '\r') + s[--len] = 0; + } +} + +/* FormatMessage returns allocated strings, but evutil_socket_error_to_string + * is supposed to return a string which is good indefinitely without having + * to be freed. To make this work without leaking memory, we cache the + * string the first time FormatMessage is called on a particular error + * code, and then return the cached string on subsequent calls with the + * same code. The strings aren't freed until libevent_global_shutdown + * (or never). We use a linked list to cache the errors, because we + * only expect there to be a few dozen, and that should be fast enough. + */ + +struct cached_sock_errs_entry { + HT_ENTRY(cached_sock_errs_entry) node; + DWORD code; + char *msg; /* allocated with LocalAlloc; free with LocalFree */ +}; + +static inline unsigned +hash_cached_sock_errs(const struct cached_sock_errs_entry *e) +{ + /* Use Murmur3's 32-bit finalizer as an integer hash function */ + DWORD h = e->code; + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + return h; +} + +static inline int +eq_cached_sock_errs(const struct cached_sock_errs_entry *a, + const struct cached_sock_errs_entry *b) +{ + return a->code == b->code; +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void *windows_socket_errors_lock_ = NULL; +#endif + +static HT_HEAD(cached_sock_errs_map, cached_sock_errs_entry) + windows_socket_errors = HT_INITIALIZER(); + +HT_PROTOTYPE(cached_sock_errs_map, + cached_sock_errs_entry, + node, + hash_cached_sock_errs, + eq_cached_sock_errs); + +HT_GENERATE(cached_sock_errs_map, + cached_sock_errs_entry, + node, + hash_cached_sock_errs, + eq_cached_sock_errs, + 0.5, + mm_malloc, + mm_realloc, + mm_free); + /** Equivalent to strerror, but for windows socket errors. */ const char * evutil_socket_error_to_string(int errcode) { - struct cached_sock_errs_entry *errs, *newerr, find; - char *msg = NULL; - - EVLOCK_LOCK(windows_socket_errors_lock_, 0); - - find.code = errcode; - errs = HT_FIND(cached_sock_errs_map, &windows_socket_errors, &find); - if (errs) { - msg = errs->msg; - goto done; - } - - if (0 != FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, errcode, 0, (char *)&msg, 0, NULL)) - chomp (msg); /* because message has trailing newline */ - else { - size_t len = 50; - /* use LocalAlloc because FormatMessage does */ - msg = LocalAlloc(LMEM_FIXED, len); - if (!msg) { - msg = (char *)"LocalAlloc failed during Winsock error"; - goto done; - } - evutil_snprintf(msg, len, "winsock error 0x%08x", errcode); - } - - newerr = (struct cached_sock_errs_entry *) - mm_malloc(sizeof (struct cached_sock_errs_entry)); - - if (!newerr) { - LocalFree(msg); - msg = (char *)"malloc failed during Winsock error"; - goto done; - } - - newerr->code = errcode; - newerr->msg = msg; - HT_INSERT(cached_sock_errs_map, &windows_socket_errors, newerr); - - done: - EVLOCK_UNLOCK(windows_socket_errors_lock_, 0); - - return msg; -} - -#ifndef EVENT__DISABLE_THREAD_SUPPORT -int -evutil_global_setup_locks_(const int enable_locks) -{ - EVTHREAD_SETUP_GLOBAL_LOCK(windows_socket_errors_lock_, 0); - return 0; -} -#endif - -static void -evutil_free_sock_err_globals(void) -{ - struct cached_sock_errs_entry **errs, *tofree; - - for (errs = HT_START(cached_sock_errs_map, &windows_socket_errors) - ; errs; ) { - tofree = *errs; - errs = HT_NEXT_RMV(cached_sock_errs_map, - &windows_socket_errors, - errs); - LocalFree(tofree->msg); - mm_free(tofree); - } - - HT_CLEAR(cached_sock_errs_map, &windows_socket_errors); - -#ifndef EVENT__DISABLE_THREAD_SUPPORT - if (windows_socket_errors_lock_ != NULL) { - EVTHREAD_FREE_LOCK(windows_socket_errors_lock_, 0); - windows_socket_errors_lock_ = NULL; - } -#endif -} - -#else - -#ifndef EVENT__DISABLE_THREAD_SUPPORT -int -evutil_global_setup_locks_(const int enable_locks) -{ - return 0; -} -#endif - -static void -evutil_free_sock_err_globals(void) -{ -} - -#endif - + struct cached_sock_errs_entry *errs, *newerr, find; + char *msg = NULL; + + EVLOCK_LOCK(windows_socket_errors_lock_, 0); + + find.code = errcode; + errs = HT_FIND(cached_sock_errs_map, &windows_socket_errors, &find); + if (errs) { + msg = errs->msg; + goto done; + } + + if (0 != FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, errcode, 0, (char *)&msg, 0, NULL)) + chomp (msg); /* because message has trailing newline */ + else { + size_t len = 50; + /* use LocalAlloc because FormatMessage does */ + msg = LocalAlloc(LMEM_FIXED, len); + if (!msg) { + msg = (char *)"LocalAlloc failed during Winsock error"; + goto done; + } + evutil_snprintf(msg, len, "winsock error 0x%08x", errcode); + } + + newerr = (struct cached_sock_errs_entry *) + mm_malloc(sizeof (struct cached_sock_errs_entry)); + + if (!newerr) { + LocalFree(msg); + msg = (char *)"malloc failed during Winsock error"; + goto done; + } + + newerr->code = errcode; + newerr->msg = msg; + HT_INSERT(cached_sock_errs_map, &windows_socket_errors, newerr); + + done: + EVLOCK_UNLOCK(windows_socket_errors_lock_, 0); + + return msg; +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int +evutil_global_setup_locks_(const int enable_locks) +{ + EVTHREAD_SETUP_GLOBAL_LOCK(windows_socket_errors_lock_, 0); + return 0; +} +#endif + +static void +evutil_free_sock_err_globals(void) +{ + struct cached_sock_errs_entry **errs, *tofree; + + for (errs = HT_START(cached_sock_errs_map, &windows_socket_errors) + ; errs; ) { + tofree = *errs; + errs = HT_NEXT_RMV(cached_sock_errs_map, + &windows_socket_errors, + errs); + LocalFree(tofree->msg); + mm_free(tofree); + } + + HT_CLEAR(cached_sock_errs_map, &windows_socket_errors); + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (windows_socket_errors_lock_ != NULL) { + EVTHREAD_FREE_LOCK(windows_socket_errors_lock_, 0); + windows_socket_errors_lock_ = NULL; + } +#endif +} + +#else + +#ifndef EVENT__DISABLE_THREAD_SUPPORT int +evutil_global_setup_locks_(const int enable_locks) +{ + return 0; +} +#endif + +static void +evutil_free_sock_err_globals(void) +{ +} + +#endif + +int evutil_snprintf(char *buf, size_t buflen, const char *format, ...) { int r; @@ -1874,7 +1874,7 @@ evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap) int r; if (!buflen) return 0; -#if defined(_MSC_VER) || defined(_WIN32) +#if defined(_MSC_VER) || defined(_WIN32) r = _vsnprintf(buf, buflen, format, ap); if (r < 0) r = _vscprintf(format, ap); @@ -1898,7 +1898,7 @@ evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap) const char * evutil_inet_ntop(int af, const void *src, char *dst, size_t len) { -#if defined(EVENT__HAVE_INET_NTOP) && !defined(USE_INTERNAL_NTOP) +#if defined(EVENT__HAVE_INET_NTOP) && !defined(USE_INTERNAL_NTOP) return inet_ntop(af, src, dst, len); #else if (af == AF_INET) { @@ -2029,19 +2029,19 @@ evutil_inet_pton_scope(int af, const char *src, void *dst, unsigned *indexp) int evutil_inet_pton(int af, const char *src, void *dst) { -#if defined(EVENT__HAVE_INET_PTON) && !defined(USE_INTERNAL_PTON) +#if defined(EVENT__HAVE_INET_PTON) && !defined(USE_INTERNAL_PTON) return inet_pton(af, src, dst); #else if (af == AF_INET) { - unsigned a,b,c,d; + unsigned a,b,c,d; char more; struct in_addr *addr = dst; - if (sscanf(src, "%u.%u.%u.%u%c", &a,&b,&c,&d,&more) != 4) + if (sscanf(src, "%u.%u.%u.%u%c", &a,&b,&c,&d,&more) != 4) return 0; - if (a > 255) return 0; - if (b > 255) return 0; - if (c > 255) return 0; - if (d > 255) return 0; + if (a > 255) return 0; + if (b > 255) return 0; + if (c > 255) return 0; + if (d > 255) return 0; addr->s_addr = htonl((a<<24) | (b<<16) | (c<<8) | d); return 1; #ifdef AF_INET6 @@ -2056,22 +2056,22 @@ evutil_inet_pton(int af, const char *src, void *dst) else if (!dot) eow = src+strlen(src); else { - unsigned byte1,byte2,byte3,byte4; + unsigned byte1,byte2,byte3,byte4; char more; - for (eow = dot-1; eow >= src && EVUTIL_ISDIGIT_(*eow); --eow) + for (eow = dot-1; eow >= src && EVUTIL_ISDIGIT_(*eow); --eow) ; ++eow; /* We use "scanf" because some platform inet_aton()s are too lax * about IPv4 addresses of the form "1.2.3" */ - if (sscanf(eow, "%u.%u.%u.%u%c", + if (sscanf(eow, "%u.%u.%u.%u%c", &byte1,&byte2,&byte3,&byte4,&more) != 4) return 0; - if (byte1 > 255 || - byte2 > 255 || - byte3 > 255 || - byte4 > 255) + if (byte1 > 255 || + byte2 > 255 || + byte3 > 255 || + byte4 > 255) return 0; words[6] = (byte1<<8) | byte2; @@ -2083,7 +2083,7 @@ evutil_inet_pton(int af, const char *src, void *dst) while (src < eow) { if (i > 7) return 0; - if (EVUTIL_ISXDIGIT_(*src)) { + if (EVUTIL_ISXDIGIT_(*src)) { char *next; long r = strtol(src, &next, 16); if (next > 4+src) @@ -2156,12 +2156,12 @@ evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int * cp = strchr(ip_as_string, ':'); if (*ip_as_string == '[') { - size_t len; + size_t len; if (!(cp = strchr(ip_as_string, ']'))) { return -1; } - len = ( cp-(ip_as_string + 1) ); - if (len > sizeof(buf)-1) { + len = ( cp-(ip_as_string + 1) ); + if (len > sizeof(buf)-1) { return -1; } memcpy(buf, ip_as_string+1, len); @@ -2207,7 +2207,7 @@ evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int * { struct sockaddr_in6 sin6; memset(&sin6, 0, sizeof(sin6)); -#ifdef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN sin6.sin6_len = sizeof(sin6); #endif sin6.sin6_family = AF_INET6; @@ -2229,7 +2229,7 @@ evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int * { struct sockaddr_in sin; memset(&sin, 0, sizeof(sin)); -#ifdef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN sin.sin_len = sizeof(sin); #endif sin.sin_family = AF_INET; @@ -2246,7 +2246,7 @@ evutil_parse_sockaddr_port(const char *ip_as_string, struct sockaddr *out, int * } const char * -evutil_format_sockaddr_port_(const struct sockaddr *sa, char *out, size_t outlen) +evutil_format_sockaddr_port_(const struct sockaddr *sa, char *out, size_t outlen) { char b[128]; const char *res=NULL; @@ -2370,7 +2370,7 @@ static const unsigned char EVUTIL_TOLOWER_TABLE[256] = { }; #define IMPL_CTYPE_FN(name) \ - int EVUTIL_##name##_(char c) { \ + int EVUTIL_##name##_(char c) { \ ev_uint8_t u = c; \ return !!(EVUTIL_##name##_TABLE[(u >> 5) & 7] & (1U << (u & 31))); \ } @@ -2383,11 +2383,11 @@ IMPL_CTYPE_FN(ISPRINT) IMPL_CTYPE_FN(ISLOWER) IMPL_CTYPE_FN(ISUPPER) -char EVUTIL_TOLOWER_(char c) +char EVUTIL_TOLOWER_(char c) { return ((char)EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c]); } -char EVUTIL_TOUPPER_(char c) +char EVUTIL_TOUPPER_(char c) { return ((char)EVUTIL_TOUPPER_TABLE[(ev_uint8_t)c]); } @@ -2396,8 +2396,8 @@ evutil_ascii_strcasecmp(const char *s1, const char *s2) { char c1, c2; while (1) { - c1 = EVUTIL_TOLOWER_(*s1++); - c2 = EVUTIL_TOLOWER_(*s2++); + c1 = EVUTIL_TOLOWER_(*s1++); + c2 = EVUTIL_TOLOWER_(*s2++); if (c1 < c2) return -1; else if (c1 > c2) @@ -2410,8 +2410,8 @@ int evutil_ascii_strncasecmp(const char *s1, const char *s2, size_t n) { char c1, c2; while (n--) { - c1 = EVUTIL_TOLOWER_(*s1++); - c2 = EVUTIL_TOLOWER_(*s2++); + c1 = EVUTIL_TOLOWER_(*s1++); + c2 = EVUTIL_TOLOWER_(*s2++); if (c1 < c2) return -1; else if (c1 > c2) @@ -2422,39 +2422,39 @@ int evutil_ascii_strncasecmp(const char *s1, const char *s2, size_t n) return 0; } -void -evutil_rtrim_lws_(char *str) -{ - char *cp; - - if (str == NULL) - return; - - if ((cp = strchr(str, '\0')) == NULL || (cp == str)) - return; - - --cp; - - while (*cp == ' ' || *cp == '\t') { - *cp = '\0'; - if (cp == str) - break; - --cp; - } -} - +void +evutil_rtrim_lws_(char *str) +{ + char *cp; + + if (str == NULL) + return; + + if ((cp = strchr(str, '\0')) == NULL || (cp == str)) + return; + + --cp; + + while (*cp == ' ' || *cp == '\t') { + *cp = '\0'; + if (cp == str) + break; + --cp; + } +} + static int evutil_issetugid(void) { -#ifdef EVENT__HAVE_ISSETUGID +#ifdef EVENT__HAVE_ISSETUGID return issetugid(); #else -#ifdef EVENT__HAVE_GETEUID +#ifdef EVENT__HAVE_GETEUID if (getuid() != geteuid()) return 1; #endif -#ifdef EVENT__HAVE_GETEGID +#ifdef EVENT__HAVE_GETEGID if (getgid() != getegid()) return 1; #endif @@ -2463,7 +2463,7 @@ evutil_issetugid(void) } const char * -evutil_getenv_(const char *varname) +evutil_getenv_(const char *varname) { if (evutil_issetugid()) return NULL; @@ -2471,54 +2471,54 @@ evutil_getenv_(const char *varname) return getenv(varname); } -ev_uint32_t -evutil_weakrand_seed_(struct evutil_weakrand_state *state, ev_uint32_t seed) +ev_uint32_t +evutil_weakrand_seed_(struct evutil_weakrand_state *state, ev_uint32_t seed) { - if (seed == 0) { - struct timeval tv; - evutil_gettimeofday(&tv, NULL); - seed = (ev_uint32_t)tv.tv_sec + (ev_uint32_t)tv.tv_usec; -#ifdef _WIN32 - seed += (ev_uint32_t) _getpid(); + if (seed == 0) { + struct timeval tv; + evutil_gettimeofday(&tv, NULL); + seed = (ev_uint32_t)tv.tv_sec + (ev_uint32_t)tv.tv_usec; +#ifdef _WIN32 + seed += (ev_uint32_t) _getpid(); #else - seed += (ev_uint32_t) getpid(); -#endif - } - state->seed = seed; - return seed; -} - -ev_int32_t -evutil_weakrand_(struct evutil_weakrand_state *state) -{ - /* This RNG implementation is a linear congruential generator, with - * modulus 2^31, multiplier 1103515245, and addend 12345. It's also - * used by OpenBSD, and by Glibc's TYPE_0 RNG. - * - * The linear congruential generator is not an industrial-strength - * RNG! It's fast, but it can have higher-order patterns. Notably, - * the low bits tend to have periodicity. - */ - state->seed = ((state->seed) * 1103515245 + 12345) & 0x7fffffff; - return (ev_int32_t)(state->seed); -} - -ev_int32_t -evutil_weakrand_range_(struct evutil_weakrand_state *state, ev_int32_t top) -{ - ev_int32_t divisor, result; - - /* We can't just do weakrand() % top, since the low bits of the LCG - * are less random than the high ones. (Specifically, since the LCG - * modulus is 2^N, every 2^m for m<N will divide the modulus, and so - * therefore the low m bits of the LCG will have period 2^m.) */ - divisor = EVUTIL_WEAKRAND_MAX / top; - do { - result = evutil_weakrand_(state) / divisor; - } while (result >= top); - return result; -} - + seed += (ev_uint32_t) getpid(); +#endif + } + state->seed = seed; + return seed; +} + +ev_int32_t +evutil_weakrand_(struct evutil_weakrand_state *state) +{ + /* This RNG implementation is a linear congruential generator, with + * modulus 2^31, multiplier 1103515245, and addend 12345. It's also + * used by OpenBSD, and by Glibc's TYPE_0 RNG. + * + * The linear congruential generator is not an industrial-strength + * RNG! It's fast, but it can have higher-order patterns. Notably, + * the low bits tend to have periodicity. + */ + state->seed = ((state->seed) * 1103515245 + 12345) & 0x7fffffff; + return (ev_int32_t)(state->seed); +} + +ev_int32_t +evutil_weakrand_range_(struct evutil_weakrand_state *state, ev_int32_t top) +{ + ev_int32_t divisor, result; + + /* We can't just do weakrand() % top, since the low bits of the LCG + * are less random than the high ones. (Specifically, since the LCG + * modulus is 2^N, every 2^m for m<N will divide the modulus, and so + * therefore the low m bits of the LCG will have period 2^m.) */ + divisor = EVUTIL_WEAKRAND_MAX / top; + do { + result = evutil_weakrand_(state) / divisor; + } while (result >= top); + return result; +} + /** * Volatile pointer to memset: we use this to keep the compiler from * eliminating our call to memset. @@ -2532,7 +2532,7 @@ evutil_memclear_(void *mem, size_t len) } int -evutil_sockaddr_is_loopback_(const struct sockaddr *addr) +evutil_sockaddr_is_loopback_(const struct sockaddr *addr) { static const char LOOPBACK_S6[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"; @@ -2547,7 +2547,7 @@ evutil_sockaddr_is_loopback_(const struct sockaddr *addr) } int -evutil_hex_char_to_int_(char c) +evutil_hex_char_to_int_(char c) { switch(c) { @@ -2571,9 +2571,9 @@ evutil_hex_char_to_int_(char c) return -1; } -#ifdef _WIN32 -HMODULE -evutil_load_windows_system_library_(const TCHAR *library_name) +#ifdef _WIN32 +HMODULE +evutil_load_windows_system_library_(const TCHAR *library_name) { TCHAR path[MAX_PATH]; unsigned n; @@ -2586,183 +2586,183 @@ evutil_load_windows_system_library_(const TCHAR *library_name) } #endif -/* Internal wrapper around 'socket' to provide Linux-style support for - * syscall-saving methods where available. - * - * In addition to regular socket behavior, you can use a bitwise or to set the - * flags EVUTIL_SOCK_NONBLOCK and EVUTIL_SOCK_CLOEXEC in the 'type' argument, - * to make the socket nonblocking or close-on-exec with as few syscalls as - * possible. - */ -evutil_socket_t -evutil_socket_(int domain, int type, int protocol) -{ - evutil_socket_t r; -#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) - r = socket(domain, type, protocol); - if (r >= 0) - return r; - else if ((type & (SOCK_NONBLOCK|SOCK_CLOEXEC)) == 0) - return -1; -#endif -#define SOCKET_TYPE_MASK (~(EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC)) - r = socket(domain, type & SOCKET_TYPE_MASK, protocol); - if (r < 0) - return -1; - if (type & EVUTIL_SOCK_NONBLOCK) { - if (evutil_fast_socket_nonblocking(r) < 0) { - evutil_closesocket(r); - return -1; - } - } - if (type & EVUTIL_SOCK_CLOEXEC) { - if (evutil_fast_socket_closeonexec(r) < 0) { - evutil_closesocket(r); - return -1; - } - } - return r; -} - -/* Internal wrapper around 'accept' or 'accept4' to provide Linux-style - * support for syscall-saving methods where available. - * - * In addition to regular accept behavior, you can set one or more of flags - * EVUTIL_SOCK_NONBLOCK and EVUTIL_SOCK_CLOEXEC in the 'flags' argument, to - * make the socket nonblocking or close-on-exec with as few syscalls as - * possible. - */ -evutil_socket_t -evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr, - ev_socklen_t *addrlen, int flags) -{ - evutil_socket_t result; -#if defined(EVENT__HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) - result = accept4(sockfd, addr, addrlen, flags); - if (result >= 0 || (errno != EINVAL && errno != ENOSYS)) { - /* A nonnegative result means that we succeeded, so return. - * Failing with EINVAL means that an option wasn't supported, - * and failing with ENOSYS means that the syscall wasn't - * there: in those cases we want to fall back. Otherwise, we - * got a real error, and we should return. */ - return result; - } -#endif - result = accept(sockfd, addr, addrlen); - if (result < 0) - return result; - - if (flags & EVUTIL_SOCK_CLOEXEC) { - if (evutil_fast_socket_closeonexec(result) < 0) { - evutil_closesocket(result); - return -1; - } - } - if (flags & EVUTIL_SOCK_NONBLOCK) { - if (evutil_fast_socket_nonblocking(result) < 0) { - evutil_closesocket(result); - return -1; - } - } - return result; -} - -/* Internal function: Set fd[0] and fd[1] to a pair of fds such that writes on - * fd[1] get read from fd[0]. Make both fds nonblocking and close-on-exec. - * Return 0 on success, -1 on failure. - */ -int -evutil_make_internal_pipe_(evutil_socket_t fd[2]) -{ - /* - Making the second socket nonblocking is a bit subtle, given that we - ignore any EAGAIN returns when writing to it, and you don't usally - do that for a nonblocking socket. But if the kernel gives us EAGAIN, - then there's no need to add any more data to the buffer, since - the main thread is already either about to wake up and drain it, - or woken up and in the process of draining it. - */ - -#if defined(EVENT__HAVE_PIPE2) - if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0) - return 0; -#endif -#if defined(EVENT__HAVE_PIPE) - if (pipe(fd) == 0) { - if (evutil_fast_socket_nonblocking(fd[0]) < 0 || - evutil_fast_socket_nonblocking(fd[1]) < 0 || - evutil_fast_socket_closeonexec(fd[0]) < 0 || - evutil_fast_socket_closeonexec(fd[1]) < 0) { - close(fd[0]); - close(fd[1]); - fd[0] = fd[1] = -1; - return -1; - } - return 0; - } else { - event_warn("%s: pipe", __func__); - } -#endif - -#ifdef _WIN32 -#define LOCAL_SOCKETPAIR_AF AF_INET -#else -#define LOCAL_SOCKETPAIR_AF AF_UNIX -#endif - if (evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, fd) == 0) { - if (evutil_fast_socket_nonblocking(fd[0]) < 0 || - evutil_fast_socket_nonblocking(fd[1]) < 0 || - evutil_fast_socket_closeonexec(fd[0]) < 0 || - evutil_fast_socket_closeonexec(fd[1]) < 0) { - evutil_closesocket(fd[0]); - evutil_closesocket(fd[1]); - fd[0] = fd[1] = -1; - return -1; - } - return 0; - } - fd[0] = fd[1] = -1; - return -1; -} - -/* Wrapper around eventfd on systems that provide it. Unlike the system - * eventfd, it always supports EVUTIL_EFD_CLOEXEC and EVUTIL_EFD_NONBLOCK as - * flags. Returns -1 on error or if eventfd is not supported. - */ -evutil_socket_t -evutil_eventfd_(unsigned initval, int flags) -{ -#if defined(EVENT__HAVE_EVENTFD) && defined(EVENT__HAVE_SYS_EVENTFD_H) - int r; -#if defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK) - r = eventfd(initval, flags); - if (r >= 0 || flags == 0) - return r; -#endif - r = eventfd(initval, 0); - if (r < 0) - return r; - if (flags & EVUTIL_EFD_CLOEXEC) { - if (evutil_fast_socket_closeonexec(r) < 0) { - evutil_closesocket(r); - return -1; - } - } - if (flags & EVUTIL_EFD_NONBLOCK) { - if (evutil_fast_socket_nonblocking(r) < 0) { - evutil_closesocket(r); - return -1; - } - } - return r; -#else - return -1; -#endif -} - -void -evutil_free_globals_(void) -{ - evutil_free_secure_rng_globals_(); - evutil_free_sock_err_globals(); -} +/* Internal wrapper around 'socket' to provide Linux-style support for + * syscall-saving methods where available. + * + * In addition to regular socket behavior, you can use a bitwise or to set the + * flags EVUTIL_SOCK_NONBLOCK and EVUTIL_SOCK_CLOEXEC in the 'type' argument, + * to make the socket nonblocking or close-on-exec with as few syscalls as + * possible. + */ +evutil_socket_t +evutil_socket_(int domain, int type, int protocol) +{ + evutil_socket_t r; +#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) + r = socket(domain, type, protocol); + if (r >= 0) + return r; + else if ((type & (SOCK_NONBLOCK|SOCK_CLOEXEC)) == 0) + return -1; +#endif +#define SOCKET_TYPE_MASK (~(EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC)) + r = socket(domain, type & SOCKET_TYPE_MASK, protocol); + if (r < 0) + return -1; + if (type & EVUTIL_SOCK_NONBLOCK) { + if (evutil_fast_socket_nonblocking(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + if (type & EVUTIL_SOCK_CLOEXEC) { + if (evutil_fast_socket_closeonexec(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + return r; +} + +/* Internal wrapper around 'accept' or 'accept4' to provide Linux-style + * support for syscall-saving methods where available. + * + * In addition to regular accept behavior, you can set one or more of flags + * EVUTIL_SOCK_NONBLOCK and EVUTIL_SOCK_CLOEXEC in the 'flags' argument, to + * make the socket nonblocking or close-on-exec with as few syscalls as + * possible. + */ +evutil_socket_t +evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr, + ev_socklen_t *addrlen, int flags) +{ + evutil_socket_t result; +#if defined(EVENT__HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) + result = accept4(sockfd, addr, addrlen, flags); + if (result >= 0 || (errno != EINVAL && errno != ENOSYS)) { + /* A nonnegative result means that we succeeded, so return. + * Failing with EINVAL means that an option wasn't supported, + * and failing with ENOSYS means that the syscall wasn't + * there: in those cases we want to fall back. Otherwise, we + * got a real error, and we should return. */ + return result; + } +#endif + result = accept(sockfd, addr, addrlen); + if (result < 0) + return result; + + if (flags & EVUTIL_SOCK_CLOEXEC) { + if (evutil_fast_socket_closeonexec(result) < 0) { + evutil_closesocket(result); + return -1; + } + } + if (flags & EVUTIL_SOCK_NONBLOCK) { + if (evutil_fast_socket_nonblocking(result) < 0) { + evutil_closesocket(result); + return -1; + } + } + return result; +} + +/* Internal function: Set fd[0] and fd[1] to a pair of fds such that writes on + * fd[1] get read from fd[0]. Make both fds nonblocking and close-on-exec. + * Return 0 on success, -1 on failure. + */ +int +evutil_make_internal_pipe_(evutil_socket_t fd[2]) +{ + /* + Making the second socket nonblocking is a bit subtle, given that we + ignore any EAGAIN returns when writing to it, and you don't usally + do that for a nonblocking socket. But if the kernel gives us EAGAIN, + then there's no need to add any more data to the buffer, since + the main thread is already either about to wake up and drain it, + or woken up and in the process of draining it. + */ + +#if defined(EVENT__HAVE_PIPE2) + if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0) + return 0; +#endif +#if defined(EVENT__HAVE_PIPE) + if (pipe(fd) == 0) { + if (evutil_fast_socket_nonblocking(fd[0]) < 0 || + evutil_fast_socket_nonblocking(fd[1]) < 0 || + evutil_fast_socket_closeonexec(fd[0]) < 0 || + evutil_fast_socket_closeonexec(fd[1]) < 0) { + close(fd[0]); + close(fd[1]); + fd[0] = fd[1] = -1; + return -1; + } + return 0; + } else { + event_warn("%s: pipe", __func__); + } +#endif + +#ifdef _WIN32 +#define LOCAL_SOCKETPAIR_AF AF_INET +#else +#define LOCAL_SOCKETPAIR_AF AF_UNIX +#endif + if (evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, fd) == 0) { + if (evutil_fast_socket_nonblocking(fd[0]) < 0 || + evutil_fast_socket_nonblocking(fd[1]) < 0 || + evutil_fast_socket_closeonexec(fd[0]) < 0 || + evutil_fast_socket_closeonexec(fd[1]) < 0) { + evutil_closesocket(fd[0]); + evutil_closesocket(fd[1]); + fd[0] = fd[1] = -1; + return -1; + } + return 0; + } + fd[0] = fd[1] = -1; + return -1; +} + +/* Wrapper around eventfd on systems that provide it. Unlike the system + * eventfd, it always supports EVUTIL_EFD_CLOEXEC and EVUTIL_EFD_NONBLOCK as + * flags. Returns -1 on error or if eventfd is not supported. + */ +evutil_socket_t +evutil_eventfd_(unsigned initval, int flags) +{ +#if defined(EVENT__HAVE_EVENTFD) && defined(EVENT__HAVE_SYS_EVENTFD_H) + int r; +#if defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK) + r = eventfd(initval, flags); + if (r >= 0 || flags == 0) + return r; +#endif + r = eventfd(initval, 0); + if (r < 0) + return r; + if (flags & EVUTIL_EFD_CLOEXEC) { + if (evutil_fast_socket_closeonexec(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + if (flags & EVUTIL_EFD_NONBLOCK) { + if (evutil_fast_socket_nonblocking(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + return r; +#else + return -1; +#endif +} + +void +evutil_free_globals_(void) +{ + evutil_free_secure_rng_globals_(); + evutil_free_sock_err_globals(); +} diff --git a/contrib/libs/libevent/evutil_rand.c b/contrib/libs/libevent/evutil_rand.c index 8e9afdaa67..974e569362 100644 --- a/contrib/libs/libevent/evutil_rand.c +++ b/contrib/libs/libevent/evutil_rand.c @@ -33,14 +33,14 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" #include <limits.h> #include "util-internal.h" #include "evthread-internal.h" -#ifdef EVENT__HAVE_ARC4RANDOM +#ifdef EVENT__HAVE_ARC4RANDOM #include <stdlib.h> #include <string.h> int @@ -56,28 +56,28 @@ evutil_secure_rng_init(void) (void) arc4random(); return 0; } -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT int evutil_secure_rng_global_setup_locks_(const int enable_locks) { return 0; } -#endif -static void -evutil_free_secure_rng_globals_locks(void) -{ -} +#endif +static void +evutil_free_secure_rng_globals_locks(void) +{ +} static void ev_arc4random_buf(void *buf, size_t n) { -#if defined(EVENT__HAVE_ARC4RANDOM_BUF) && !defined(__APPLE__) - arc4random_buf(buf, n); - return; +#if defined(EVENT__HAVE_ARC4RANDOM_BUF) && !defined(__APPLE__) + arc4random_buf(buf, n); + return; #else unsigned char *b = buf; -#if defined(EVENT__HAVE_ARC4RANDOM_BUF) +#if defined(EVENT__HAVE_ARC4RANDOM_BUF) /* OSX 10.7 introducd arc4random_buf, so if you build your program * there, you'll get surprised when older versions of OSX fail to run. * To solve this, we can check whether the function pointer is set, @@ -88,8 +88,8 @@ ev_arc4random_buf(void *buf, size_t n) void (*tptr)(void *,size_t) = (void (*)(void*,size_t))arc4random_buf; if (tptr != NULL) { - arc4random_buf(buf, n); - return; + arc4random_buf(buf, n); + return; } } #endif @@ -114,15 +114,15 @@ ev_arc4random_buf(void *buf, size_t n) #endif } -#else /* !EVENT__HAVE_ARC4RANDOM { */ +#else /* !EVENT__HAVE_ARC4RANDOM { */ -#ifdef EVENT__ssize_t -#define ssize_t EVENT__ssize_t +#ifdef EVENT__ssize_t +#define ssize_t EVENT__ssize_t #endif #define ARC4RANDOM_EXPORT static -#define ARC4_LOCK_() EVLOCK_LOCK(arc4rand_lock, 0) -#define ARC4_UNLOCK_() EVLOCK_UNLOCK(arc4rand_lock, 0) -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#define ARC4_LOCK_() EVLOCK_LOCK(arc4rand_lock, 0) +#define ARC4_UNLOCK_() EVLOCK_UNLOCK(arc4rand_lock, 0) +#ifndef EVENT__DISABLE_THREAD_SUPPORT static void *arc4rand_lock; #endif @@ -133,7 +133,7 @@ static void *arc4rand_lock; #include "./arc4random.c" -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT int evutil_secure_rng_global_setup_locks_(const int enable_locks) { @@ -142,25 +142,25 @@ evutil_secure_rng_global_setup_locks_(const int enable_locks) } #endif -static void -evutil_free_secure_rng_globals_locks(void) -{ -#ifndef EVENT__DISABLE_THREAD_SUPPORT - if (arc4rand_lock != NULL) { - EVTHREAD_FREE_LOCK(arc4rand_lock, 0); - arc4rand_lock = NULL; - } -#endif - return; -} - +static void +evutil_free_secure_rng_globals_locks(void) +{ +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (arc4rand_lock != NULL) { + EVTHREAD_FREE_LOCK(arc4rand_lock, 0); + arc4rand_lock = NULL; + } +#endif + return; +} + int evutil_secure_rng_set_urandom_device_file(char *fname) { #ifdef TRY_SEED_URANDOM - ARC4_LOCK_(); + ARC4_LOCK_(); arc4random_urandom_filename = fname; - ARC4_UNLOCK_(); + ARC4_UNLOCK_(); #endif return 0; } @@ -170,9 +170,9 @@ evutil_secure_rng_init(void) { int val; - ARC4_LOCK_(); - val = (!arc4_stir()) ? 0 : -1; - ARC4_UNLOCK_(); + ARC4_LOCK_(); + val = (!arc4_stir()) ? 0 : -1; + ARC4_UNLOCK_(); return val; } @@ -182,7 +182,7 @@ ev_arc4random_buf(void *buf, size_t n) arc4random_buf(buf, n); } -#endif /* } !EVENT__HAVE_ARC4RANDOM */ +#endif /* } !EVENT__HAVE_ARC4RANDOM */ void evutil_secure_rng_get_bytes(void *buf, size_t n) @@ -190,17 +190,17 @@ evutil_secure_rng_get_bytes(void *buf, size_t n) ev_arc4random_buf(buf, n); } -#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM) +#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM) void evutil_secure_rng_add_bytes(const char *buf, size_t n) { arc4random_addrandom((unsigned char*)buf, n>(size_t)INT_MAX ? INT_MAX : (int)n); } -#endif +#endif -void -evutil_free_secure_rng_globals_(void) -{ - evutil_free_secure_rng_globals_locks(); -} +void +evutil_free_secure_rng_globals_(void) +{ + evutil_free_secure_rng_globals_locks(); +} diff --git a/contrib/libs/libevent/evutil_time.c b/contrib/libs/libevent/evutil_time.c index c327218227..90ac35e2d9 100644 --- a/contrib/libs/libevent/evutil_time.c +++ b/contrib/libs/libevent/evutil_time.c @@ -1,101 +1,101 @@ -/* - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef _WIN32 -#include <winsock2.h> -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#endif - -#include <sys/types.h> -#ifdef EVENT__HAVE_STDLIB_H -#include <stdlib.h> -#endif -#include <errno.h> -#include <limits.h> -#ifndef EVENT__HAVE_GETTIMEOFDAY -#include <sys/timeb.h> -#endif -#if !defined(EVENT__HAVE_NANOSLEEP) && !defined(EVENT__HAVE_USLEEP) && \ - !defined(_WIN32) -#include <sys/select.h> -#endif -#include <time.h> -#include <sys/stat.h> -#include <string.h> - -/** evutil_usleep_() */ -#if defined(_WIN32) -#elif defined(EVENT__HAVE_NANOSLEEP) -#elif defined(EVENT__HAVE_USLEEP) -#include <unistd.h> -#endif - -#include "event2/util.h" -#include "util-internal.h" -#include "log-internal.h" -#include "mm-internal.h" - -#ifndef EVENT__HAVE_GETTIMEOFDAY -/* No gettimeofday; this must be windows. */ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "event2/event-config.h" +#include "evconfig-private.h" + +#ifdef _WIN32 +#include <winsock2.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN +#endif + +#include <sys/types.h> +#ifdef EVENT__HAVE_STDLIB_H +#include <stdlib.h> +#endif +#include <errno.h> +#include <limits.h> +#ifndef EVENT__HAVE_GETTIMEOFDAY +#include <sys/timeb.h> +#endif +#if !defined(EVENT__HAVE_NANOSLEEP) && !defined(EVENT__HAVE_USLEEP) && \ + !defined(_WIN32) +#include <sys/select.h> +#endif +#include <time.h> +#include <sys/stat.h> +#include <string.h> + +/** evutil_usleep_() */ +#if defined(_WIN32) +#elif defined(EVENT__HAVE_NANOSLEEP) +#elif defined(EVENT__HAVE_USLEEP) +#include <unistd.h> +#endif + +#include "event2/util.h" +#include "util-internal.h" +#include "log-internal.h" +#include "mm-internal.h" + +#ifndef EVENT__HAVE_GETTIMEOFDAY +/* No gettimeofday; this must be windows. */ typedef void (WINAPI *GetSystemTimePreciseAsFileTime_fn_t) (LPFILETIME); -int -evutil_gettimeofday(struct timeval *tv, struct timezone *tz) -{ -#ifdef _MSC_VER -#define U64_LITERAL(n) n##ui64 -#else -#define U64_LITERAL(n) n##llu -#endif - - /* Conversion logic taken from Tor, which in turn took it - * from Perl. GetSystemTimeAsFileTime returns its value as - * an unaligned (!) 64-bit value containing the number of - * 100-nanosecond intervals since 1 January 1601 UTC. */ -#define EPOCH_BIAS U64_LITERAL(116444736000000000) -#define UNITS_PER_SEC U64_LITERAL(10000000) -#define USEC_PER_SEC U64_LITERAL(1000000) -#define UNITS_PER_USEC U64_LITERAL(10) - union { - FILETIME ft_ft; - ev_uint64_t ft_64; - } ft; - - if (tv == NULL) - return -1; - +int +evutil_gettimeofday(struct timeval *tv, struct timezone *tz) +{ +#ifdef _MSC_VER +#define U64_LITERAL(n) n##ui64 +#else +#define U64_LITERAL(n) n##llu +#endif + + /* Conversion logic taken from Tor, which in turn took it + * from Perl. GetSystemTimeAsFileTime returns its value as + * an unaligned (!) 64-bit value containing the number of + * 100-nanosecond intervals since 1 January 1601 UTC. */ +#define EPOCH_BIAS U64_LITERAL(116444736000000000) +#define UNITS_PER_SEC U64_LITERAL(10000000) +#define USEC_PER_SEC U64_LITERAL(1000000) +#define UNITS_PER_USEC U64_LITERAL(10) + union { + FILETIME ft_ft; + ev_uint64_t ft_64; + } ft; + + if (tv == NULL) + return -1; + static GetSystemTimePreciseAsFileTime_fn_t GetSystemTimePreciseAsFileTime_fn = NULL; static int check_precise = 1; - + if (EVUTIL_UNLIKELY(check_precise)) { HMODULE h = evutil_load_windows_system_library_(TEXT("kernel32.dll")); if (h != NULL) @@ -110,40 +110,40 @@ evutil_gettimeofday(struct timeval *tv, struct timezone *tz) else GetSystemTimeAsFileTime(&ft.ft_ft); - if (EVUTIL_UNLIKELY(ft.ft_64 < EPOCH_BIAS)) { - /* Time before the unix epoch. */ - return -1; - } - ft.ft_64 -= EPOCH_BIAS; - tv->tv_sec = (long) (ft.ft_64 / UNITS_PER_SEC); - tv->tv_usec = (long) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC); - return 0; -} -#endif - -#define MAX_SECONDS_IN_MSEC_LONG \ - (((LONG_MAX) - 999) / 1000) - -long -evutil_tv_to_msec_(const struct timeval *tv) -{ - if (tv->tv_usec > 1000000 || tv->tv_sec > MAX_SECONDS_IN_MSEC_LONG) - return -1; - - return (tv->tv_sec * 1000) + ((tv->tv_usec + 999) / 1000); -} - -/* - Replacement for usleep on platforms that don't have one. Not guaranteed to - be any more finegrained than 1 msec. - */ -void -evutil_usleep_(const struct timeval *tv) -{ - if (!tv) - return; -#if defined(_WIN32) - { + if (EVUTIL_UNLIKELY(ft.ft_64 < EPOCH_BIAS)) { + /* Time before the unix epoch. */ + return -1; + } + ft.ft_64 -= EPOCH_BIAS; + tv->tv_sec = (long) (ft.ft_64 / UNITS_PER_SEC); + tv->tv_usec = (long) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC); + return 0; +} +#endif + +#define MAX_SECONDS_IN_MSEC_LONG \ + (((LONG_MAX) - 999) / 1000) + +long +evutil_tv_to_msec_(const struct timeval *tv) +{ + if (tv->tv_usec > 1000000 || tv->tv_sec > MAX_SECONDS_IN_MSEC_LONG) + return -1; + + return (tv->tv_sec * 1000) + ((tv->tv_usec + 999) / 1000); +} + +/* + Replacement for usleep on platforms that don't have one. Not guaranteed to + be any more finegrained than 1 msec. + */ +void +evutil_usleep_(const struct timeval *tv) +{ + if (!tv) + return; +#if defined(_WIN32) + { __int64 usec; LARGE_INTEGER li; HANDLE timer; @@ -160,45 +160,45 @@ evutil_usleep_(const struct timeval *tv) SetWaitableTimer(timer, &li, 0, NULL, NULL, 0); WaitForSingleObject(timer, INFINITE); CloseHandle(timer); - } -#elif defined(EVENT__HAVE_NANOSLEEP) - { - struct timespec ts; - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec*1000; - nanosleep(&ts, NULL); - } -#elif defined(EVENT__HAVE_USLEEP) - /* Some systems don't like to usleep more than 999999 usec */ - sleep(tv->tv_sec); - usleep(tv->tv_usec); -#else - { - struct timeval tv2 = *tv; - select(0, NULL, NULL, NULL, &tv2); - } -#endif -} - -int -evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm) -{ - static const char *DAYS[] = - { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - static const char *MONTHS[] = - { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - - time_t t = time(NULL); - + } +#elif defined(EVENT__HAVE_NANOSLEEP) + { + struct timespec ts; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec*1000; + nanosleep(&ts, NULL); + } +#elif defined(EVENT__HAVE_USLEEP) + /* Some systems don't like to usleep more than 999999 usec */ + sleep(tv->tv_sec); + usleep(tv->tv_usec); +#else + { + struct timeval tv2 = *tv; + select(0, NULL, NULL, NULL, &tv2); + } +#endif +} + +int +evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm) +{ + static const char *DAYS[] = + { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + static const char *MONTHS[] = + { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + + time_t t = time(NULL); + #if defined(EVENT__HAVE__GMTIME64_S) || !defined(_WIN32) - struct tm sys; -#endif - - /* If `tm` is null, set system's current time. */ - if (tm == NULL) { + struct tm sys; +#endif + + /* If `tm` is null, set system's current time. */ + if (tm == NULL) { #if !defined(_WIN32) - gmtime_r(&t, &sys); - tm = &sys; + gmtime_r(&t, &sys); + tm = &sys; /** detect _gmtime64()/_gmtime64_s() */ #elif defined(EVENT__HAVE__GMTIME64_S) errno_t err; @@ -212,410 +212,410 @@ evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm) tm = _gmtime64(&t); #else tm = gmtime(&t); -#endif - } - - return evutil_snprintf( - date, datelen, "%s, %02d %s %4d %02d:%02d:%02d GMT", - DAYS[tm->tm_wday], tm->tm_mday, MONTHS[tm->tm_mon], - 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); -} - -/* - This function assumes it's called repeatedly with a - not-actually-so-monotonic time source whose outputs are in 'tv'. It - implements a trivial ratcheting mechanism so that the values never go - backwards. - */ -static void -adjust_monotonic_time(struct evutil_monotonic_timer *base, - struct timeval *tv) -{ - evutil_timeradd(tv, &base->adjust_monotonic_clock, tv); - - if (evutil_timercmp(tv, &base->last_time, <)) { - /* Guess it wasn't monotonic after all. */ - struct timeval adjust; - evutil_timersub(&base->last_time, tv, &adjust); - evutil_timeradd(&adjust, &base->adjust_monotonic_clock, - &base->adjust_monotonic_clock); - *tv = base->last_time; - } - base->last_time = *tv; -} - -/* - Allocate a new struct evutil_monotonic_timer - */ -struct evutil_monotonic_timer * -evutil_monotonic_timer_new(void) -{ - struct evutil_monotonic_timer *p = NULL; - - p = mm_malloc(sizeof(*p)); - if (!p) goto done; - - memset(p, 0, sizeof(*p)); - - done: - return p; -} - -/* - Free a struct evutil_monotonic_timer - */ -void -evutil_monotonic_timer_free(struct evutil_monotonic_timer *timer) -{ - if (timer) { - mm_free(timer); - } -} - -/* - Set up a struct evutil_monotonic_timer for initial use - */ -int -evutil_configure_monotonic_time(struct evutil_monotonic_timer *timer, - int flags) -{ - return evutil_configure_monotonic_time_(timer, flags); -} - -/* - Query the current monotonic time - */ -int -evutil_gettime_monotonic(struct evutil_monotonic_timer *timer, - struct timeval *tp) -{ - return evutil_gettime_monotonic_(timer, tp); -} - - -#if defined(HAVE_POSIX_MONOTONIC) -/* ===== - The POSIX clock_gettime() interface provides a few ways to get at a - monotonic clock. CLOCK_MONOTONIC is most widely supported. Linux also - provides a CLOCK_MONOTONIC_COARSE with accuracy of about 1-4 msec. - - On all platforms I'm aware of, CLOCK_MONOTONIC really is monotonic. - Platforms don't agree about whether it should jump on a sleep/resume. - */ - -int -evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, - int flags) -{ - /* CLOCK_MONOTONIC exists on FreeBSD, Linux, and Solaris. You need to - * check for it at runtime, because some older kernel versions won't - * have it working. */ -#ifdef CLOCK_MONOTONIC_COARSE - const int precise = flags & EV_MONOT_PRECISE; -#endif - const int fallback = flags & EV_MONOT_FALLBACK; - struct timespec ts; - -#ifdef CLOCK_MONOTONIC_COARSE - if (CLOCK_MONOTONIC_COARSE < 0) { - /* Technically speaking, nothing keeps CLOCK_* from being - * negative (as far as I know). This check and the one below - * make sure that it's safe for us to use -1 as an "unset" - * value. */ - event_errx(1,"I didn't expect CLOCK_MONOTONIC_COARSE to be < 0"); - } - if (! precise && ! fallback) { - if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ts) == 0) { - base->monotonic_clock = CLOCK_MONOTONIC_COARSE; - return 0; - } - } -#endif - if (!fallback && clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - base->monotonic_clock = CLOCK_MONOTONIC; - return 0; - } - - if (CLOCK_MONOTONIC < 0) { - event_errx(1,"I didn't expect CLOCK_MONOTONIC to be < 0"); - } - - base->monotonic_clock = -1; - return 0; -} - -int -evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, - struct timeval *tp) -{ - struct timespec ts; - - if (base->monotonic_clock < 0) { - if (evutil_gettimeofday(tp, NULL) < 0) - return -1; - adjust_monotonic_time(base, tp); - return 0; - } - - if (clock_gettime(base->monotonic_clock, &ts) == -1) - return -1; - tp->tv_sec = ts.tv_sec; - tp->tv_usec = ts.tv_nsec / 1000; - - return 0; -} -#endif - -#if defined(HAVE_MACH_MONOTONIC) -/* ====== - Apple is a little late to the POSIX party. And why not? Instead of - clock_gettime(), they provide mach_absolute_time(). Its units are not - fixed; we need to use mach_timebase_info() to get the right functions to - convert its units into nanoseconds. - - To all appearances, mach_absolute_time() seems to be honest-to-goodness - monotonic. Whether it stops during sleep or not is unspecified in - principle, and dependent on CPU architecture in practice. - */ - -int -evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, - int flags) -{ - const int fallback = flags & EV_MONOT_FALLBACK; - struct mach_timebase_info mi; - memset(base, 0, sizeof(*base)); - /* OSX has mach_absolute_time() */ - if (!fallback && - mach_timebase_info(&mi) == 0 && - mach_absolute_time() != 0) { - /* mach_timebase_info tells us how to convert - * mach_absolute_time() into nanoseconds, but we - * want to use microseconds instead. */ - mi.denom *= 1000; - memcpy(&base->mach_timebase_units, &mi, sizeof(mi)); - } else { - base->mach_timebase_units.numer = 0; - } - return 0; -} - -int -evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, - struct timeval *tp) -{ - ev_uint64_t abstime, usec; - if (base->mach_timebase_units.numer == 0) { - if (evutil_gettimeofday(tp, NULL) < 0) - return -1; - adjust_monotonic_time(base, tp); - return 0; - } - - abstime = mach_absolute_time(); - usec = (abstime * base->mach_timebase_units.numer) - / (base->mach_timebase_units.denom); - tp->tv_sec = usec / 1000000; - tp->tv_usec = usec % 1000000; - - return 0; -} -#endif - -#if defined(HAVE_WIN32_MONOTONIC) -/* ===== - Turn we now to Windows. Want monontonic time on Windows? - - Windows has QueryPerformanceCounter(), which gives time most high- - resolution time. It's a pity it's not so monotonic in practice; it's - also got some fun bugs, especially: with older Windowses, under - virtualizations, with funny hardware, on multiprocessor systems, and so - on. PEP418 [1] has a nice roundup of the issues here. - - There's GetTickCount64() on Vista and later, which gives a number of 1-msec - ticks since startup. The accuracy here might be as bad as 10-20 msec, I - hear. There's an undocumented function (NtSetTimerResolution) that - allegedly increases the accuracy. Good luck! - - There's also GetTickCount(), which is only 32 bits, but seems to be - supported on pre-Vista versions of Windows. Apparently, you can coax - another 14 bits out of it, giving you 2231 years before rollover. - - The less said about timeGetTime() the better. - - "We don't care. We don't have to. We're the Phone Company." - -- Lily Tomlin, SNL - - Our strategy, if precise timers are turned off, is to just use the best - GetTickCount equivalent available. If we've been asked for precise timing, - then we mostly[2] assume that GetTickCount is monotonic, and correct - GetPerformanceCounter to approximate it. - - [1] http://www.python.org/dev/peps/pep-0418 - [2] Of course, we feed the Windows stuff into adjust_monotonic_time() - anyway, just in case it isn't. - - */ -/* - Parts of our logic in the win32 timer code here are closely based on - BitTorrent's libUTP library. That code is subject to the following - license: - - Copyright (c) 2010 BitTorrent, Inc. - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -static ev_uint64_t -evutil_GetTickCount_(struct evutil_monotonic_timer *base) -{ - if (base->GetTickCount64_fn) { - /* Let's just use GetTickCount64 if we can. */ - return base->GetTickCount64_fn(); - } else if (base->GetTickCount_fn) { - /* Greg Hazel assures me that this works, that BitTorrent has - * done it for years, and this it won't turn around and - * bite us. He says they found it on some game programmers' - * forum some time around 2007. - */ - ev_uint64_t v = base->GetTickCount_fn(); - return (DWORD)v | ((v >> 18) & 0xFFFFFFFF00000000); - } else { - /* Here's the fallback implementation. We have to use - * GetTickCount() with its given signature, so we only get - * 32 bits worth of milliseconds, which will roll ove every - * 49 days or so. */ - DWORD ticks = GetTickCount(); - if (ticks < base->last_tick_count) { - base->adjust_tick_count += ((ev_uint64_t)1) << 32; - } - base->last_tick_count = ticks; - return ticks + base->adjust_tick_count; - } -} - -int -evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, - int flags) -{ - const int precise = flags & EV_MONOT_PRECISE; - const int fallback = flags & EV_MONOT_FALLBACK; - HANDLE h; - memset(base, 0, sizeof(*base)); - - h = evutil_load_windows_system_library_(TEXT("kernel32.dll")); - if (h != NULL && !fallback) { - base->GetTickCount64_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount64"); - base->GetTickCount_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount"); - } - - base->first_tick = base->last_tick_count = evutil_GetTickCount_(base); - if (precise && !fallback) { - LARGE_INTEGER freq; - if (QueryPerformanceFrequency(&freq)) { - LARGE_INTEGER counter; - QueryPerformanceCounter(&counter); - base->first_counter = counter.QuadPart; - base->usec_per_count = 1.0e6 / freq.QuadPart; - base->use_performance_counter = 1; - } - } - - return 0; -} - -static inline ev_int64_t -abs64(ev_int64_t i) -{ - return i < 0 ? -i : i; -} - - -int -evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, - struct timeval *tp) -{ - ev_uint64_t ticks = evutil_GetTickCount_(base); - if (base->use_performance_counter) { - /* Here's a trick we took from BitTorrent's libutp, at Greg - * Hazel's recommendation. We use QueryPerformanceCounter for - * our high-resolution timer, but use GetTickCount*() to keep - * it sane, and adjust_monotonic_time() to keep it monotonic. - */ - LARGE_INTEGER counter; - ev_int64_t counter_elapsed, counter_usec_elapsed, ticks_elapsed; - QueryPerformanceCounter(&counter); - counter_elapsed = (ev_int64_t) - (counter.QuadPart - base->first_counter); - ticks_elapsed = ticks - base->first_tick; - /* TODO: This may upset VC6. If you need this to work with - * VC6, please supply an appropriate patch. */ - counter_usec_elapsed = (ev_int64_t) - (counter_elapsed * base->usec_per_count); - - if (abs64(ticks_elapsed*1000 - counter_usec_elapsed) > 1000000) { - /* It appears that the QueryPerformanceCounter() - * result is more than 1 second away from - * GetTickCount() result. Let's adjust it to be as - * accurate as we can; adjust_monotnonic_time() below - * will keep it monotonic. */ - counter_usec_elapsed = ticks_elapsed * 1000; - base->first_counter = (ev_uint64_t) (counter.QuadPart - counter_usec_elapsed / base->usec_per_count); - } - tp->tv_sec = (time_t) (counter_usec_elapsed / 1000000); - tp->tv_usec = counter_usec_elapsed % 1000000; - - } else { - /* We're just using GetTickCount(). */ - tp->tv_sec = (time_t) (ticks / 1000); - tp->tv_usec = (ticks % 1000) * 1000; - } - adjust_monotonic_time(base, tp); - - return 0; -} -#endif - -#if defined(HAVE_FALLBACK_MONOTONIC) -/* ===== - And if none of the other options work, let's just use gettimeofday(), and - ratchet it forward so that it acts like a monotonic timer, whether it - wants to or not. - */ - -int -evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, - int precise) -{ - memset(base, 0, sizeof(*base)); - return 0; -} - -int -evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, - struct timeval *tp) -{ - if (evutil_gettimeofday(tp, NULL) < 0) - return -1; - adjust_monotonic_time(base, tp); - return 0; - -} -#endif +#endif + } + + return evutil_snprintf( + date, datelen, "%s, %02d %s %4d %02d:%02d:%02d GMT", + DAYS[tm->tm_wday], tm->tm_mday, MONTHS[tm->tm_mon], + 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); +} + +/* + This function assumes it's called repeatedly with a + not-actually-so-monotonic time source whose outputs are in 'tv'. It + implements a trivial ratcheting mechanism so that the values never go + backwards. + */ +static void +adjust_monotonic_time(struct evutil_monotonic_timer *base, + struct timeval *tv) +{ + evutil_timeradd(tv, &base->adjust_monotonic_clock, tv); + + if (evutil_timercmp(tv, &base->last_time, <)) { + /* Guess it wasn't monotonic after all. */ + struct timeval adjust; + evutil_timersub(&base->last_time, tv, &adjust); + evutil_timeradd(&adjust, &base->adjust_monotonic_clock, + &base->adjust_monotonic_clock); + *tv = base->last_time; + } + base->last_time = *tv; +} + +/* + Allocate a new struct evutil_monotonic_timer + */ +struct evutil_monotonic_timer * +evutil_monotonic_timer_new(void) +{ + struct evutil_monotonic_timer *p = NULL; + + p = mm_malloc(sizeof(*p)); + if (!p) goto done; + + memset(p, 0, sizeof(*p)); + + done: + return p; +} + +/* + Free a struct evutil_monotonic_timer + */ +void +evutil_monotonic_timer_free(struct evutil_monotonic_timer *timer) +{ + if (timer) { + mm_free(timer); + } +} + +/* + Set up a struct evutil_monotonic_timer for initial use + */ +int +evutil_configure_monotonic_time(struct evutil_monotonic_timer *timer, + int flags) +{ + return evutil_configure_monotonic_time_(timer, flags); +} + +/* + Query the current monotonic time + */ +int +evutil_gettime_monotonic(struct evutil_monotonic_timer *timer, + struct timeval *tp) +{ + return evutil_gettime_monotonic_(timer, tp); +} + + +#if defined(HAVE_POSIX_MONOTONIC) +/* ===== + The POSIX clock_gettime() interface provides a few ways to get at a + monotonic clock. CLOCK_MONOTONIC is most widely supported. Linux also + provides a CLOCK_MONOTONIC_COARSE with accuracy of about 1-4 msec. + + On all platforms I'm aware of, CLOCK_MONOTONIC really is monotonic. + Platforms don't agree about whether it should jump on a sleep/resume. + */ + +int +evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, + int flags) +{ + /* CLOCK_MONOTONIC exists on FreeBSD, Linux, and Solaris. You need to + * check for it at runtime, because some older kernel versions won't + * have it working. */ +#ifdef CLOCK_MONOTONIC_COARSE + const int precise = flags & EV_MONOT_PRECISE; +#endif + const int fallback = flags & EV_MONOT_FALLBACK; + struct timespec ts; + +#ifdef CLOCK_MONOTONIC_COARSE + if (CLOCK_MONOTONIC_COARSE < 0) { + /* Technically speaking, nothing keeps CLOCK_* from being + * negative (as far as I know). This check and the one below + * make sure that it's safe for us to use -1 as an "unset" + * value. */ + event_errx(1,"I didn't expect CLOCK_MONOTONIC_COARSE to be < 0"); + } + if (! precise && ! fallback) { + if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ts) == 0) { + base->monotonic_clock = CLOCK_MONOTONIC_COARSE; + return 0; + } + } +#endif + if (!fallback && clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + base->monotonic_clock = CLOCK_MONOTONIC; + return 0; + } + + if (CLOCK_MONOTONIC < 0) { + event_errx(1,"I didn't expect CLOCK_MONOTONIC to be < 0"); + } + + base->monotonic_clock = -1; + return 0; +} + +int +evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, + struct timeval *tp) +{ + struct timespec ts; + + if (base->monotonic_clock < 0) { + if (evutil_gettimeofday(tp, NULL) < 0) + return -1; + adjust_monotonic_time(base, tp); + return 0; + } + + if (clock_gettime(base->monotonic_clock, &ts) == -1) + return -1; + tp->tv_sec = ts.tv_sec; + tp->tv_usec = ts.tv_nsec / 1000; + + return 0; +} +#endif + +#if defined(HAVE_MACH_MONOTONIC) +/* ====== + Apple is a little late to the POSIX party. And why not? Instead of + clock_gettime(), they provide mach_absolute_time(). Its units are not + fixed; we need to use mach_timebase_info() to get the right functions to + convert its units into nanoseconds. + + To all appearances, mach_absolute_time() seems to be honest-to-goodness + monotonic. Whether it stops during sleep or not is unspecified in + principle, and dependent on CPU architecture in practice. + */ + +int +evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, + int flags) +{ + const int fallback = flags & EV_MONOT_FALLBACK; + struct mach_timebase_info mi; + memset(base, 0, sizeof(*base)); + /* OSX has mach_absolute_time() */ + if (!fallback && + mach_timebase_info(&mi) == 0 && + mach_absolute_time() != 0) { + /* mach_timebase_info tells us how to convert + * mach_absolute_time() into nanoseconds, but we + * want to use microseconds instead. */ + mi.denom *= 1000; + memcpy(&base->mach_timebase_units, &mi, sizeof(mi)); + } else { + base->mach_timebase_units.numer = 0; + } + return 0; +} + +int +evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, + struct timeval *tp) +{ + ev_uint64_t abstime, usec; + if (base->mach_timebase_units.numer == 0) { + if (evutil_gettimeofday(tp, NULL) < 0) + return -1; + adjust_monotonic_time(base, tp); + return 0; + } + + abstime = mach_absolute_time(); + usec = (abstime * base->mach_timebase_units.numer) + / (base->mach_timebase_units.denom); + tp->tv_sec = usec / 1000000; + tp->tv_usec = usec % 1000000; + + return 0; +} +#endif + +#if defined(HAVE_WIN32_MONOTONIC) +/* ===== + Turn we now to Windows. Want monontonic time on Windows? + + Windows has QueryPerformanceCounter(), which gives time most high- + resolution time. It's a pity it's not so monotonic in practice; it's + also got some fun bugs, especially: with older Windowses, under + virtualizations, with funny hardware, on multiprocessor systems, and so + on. PEP418 [1] has a nice roundup of the issues here. + + There's GetTickCount64() on Vista and later, which gives a number of 1-msec + ticks since startup. The accuracy here might be as bad as 10-20 msec, I + hear. There's an undocumented function (NtSetTimerResolution) that + allegedly increases the accuracy. Good luck! + + There's also GetTickCount(), which is only 32 bits, but seems to be + supported on pre-Vista versions of Windows. Apparently, you can coax + another 14 bits out of it, giving you 2231 years before rollover. + + The less said about timeGetTime() the better. + + "We don't care. We don't have to. We're the Phone Company." + -- Lily Tomlin, SNL + + Our strategy, if precise timers are turned off, is to just use the best + GetTickCount equivalent available. If we've been asked for precise timing, + then we mostly[2] assume that GetTickCount is monotonic, and correct + GetPerformanceCounter to approximate it. + + [1] http://www.python.org/dev/peps/pep-0418 + [2] Of course, we feed the Windows stuff into adjust_monotonic_time() + anyway, just in case it isn't. + + */ +/* + Parts of our logic in the win32 timer code here are closely based on + BitTorrent's libUTP library. That code is subject to the following + license: + + Copyright (c) 2010 BitTorrent, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +static ev_uint64_t +evutil_GetTickCount_(struct evutil_monotonic_timer *base) +{ + if (base->GetTickCount64_fn) { + /* Let's just use GetTickCount64 if we can. */ + return base->GetTickCount64_fn(); + } else if (base->GetTickCount_fn) { + /* Greg Hazel assures me that this works, that BitTorrent has + * done it for years, and this it won't turn around and + * bite us. He says they found it on some game programmers' + * forum some time around 2007. + */ + ev_uint64_t v = base->GetTickCount_fn(); + return (DWORD)v | ((v >> 18) & 0xFFFFFFFF00000000); + } else { + /* Here's the fallback implementation. We have to use + * GetTickCount() with its given signature, so we only get + * 32 bits worth of milliseconds, which will roll ove every + * 49 days or so. */ + DWORD ticks = GetTickCount(); + if (ticks < base->last_tick_count) { + base->adjust_tick_count += ((ev_uint64_t)1) << 32; + } + base->last_tick_count = ticks; + return ticks + base->adjust_tick_count; + } +} + +int +evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, + int flags) +{ + const int precise = flags & EV_MONOT_PRECISE; + const int fallback = flags & EV_MONOT_FALLBACK; + HANDLE h; + memset(base, 0, sizeof(*base)); + + h = evutil_load_windows_system_library_(TEXT("kernel32.dll")); + if (h != NULL && !fallback) { + base->GetTickCount64_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount64"); + base->GetTickCount_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount"); + } + + base->first_tick = base->last_tick_count = evutil_GetTickCount_(base); + if (precise && !fallback) { + LARGE_INTEGER freq; + if (QueryPerformanceFrequency(&freq)) { + LARGE_INTEGER counter; + QueryPerformanceCounter(&counter); + base->first_counter = counter.QuadPart; + base->usec_per_count = 1.0e6 / freq.QuadPart; + base->use_performance_counter = 1; + } + } + + return 0; +} + +static inline ev_int64_t +abs64(ev_int64_t i) +{ + return i < 0 ? -i : i; +} + + +int +evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, + struct timeval *tp) +{ + ev_uint64_t ticks = evutil_GetTickCount_(base); + if (base->use_performance_counter) { + /* Here's a trick we took from BitTorrent's libutp, at Greg + * Hazel's recommendation. We use QueryPerformanceCounter for + * our high-resolution timer, but use GetTickCount*() to keep + * it sane, and adjust_monotonic_time() to keep it monotonic. + */ + LARGE_INTEGER counter; + ev_int64_t counter_elapsed, counter_usec_elapsed, ticks_elapsed; + QueryPerformanceCounter(&counter); + counter_elapsed = (ev_int64_t) + (counter.QuadPart - base->first_counter); + ticks_elapsed = ticks - base->first_tick; + /* TODO: This may upset VC6. If you need this to work with + * VC6, please supply an appropriate patch. */ + counter_usec_elapsed = (ev_int64_t) + (counter_elapsed * base->usec_per_count); + + if (abs64(ticks_elapsed*1000 - counter_usec_elapsed) > 1000000) { + /* It appears that the QueryPerformanceCounter() + * result is more than 1 second away from + * GetTickCount() result. Let's adjust it to be as + * accurate as we can; adjust_monotnonic_time() below + * will keep it monotonic. */ + counter_usec_elapsed = ticks_elapsed * 1000; + base->first_counter = (ev_uint64_t) (counter.QuadPart - counter_usec_elapsed / base->usec_per_count); + } + tp->tv_sec = (time_t) (counter_usec_elapsed / 1000000); + tp->tv_usec = counter_usec_elapsed % 1000000; + + } else { + /* We're just using GetTickCount(). */ + tp->tv_sec = (time_t) (ticks / 1000); + tp->tv_usec = (ticks % 1000) * 1000; + } + adjust_monotonic_time(base, tp); + + return 0; +} +#endif + +#if defined(HAVE_FALLBACK_MONOTONIC) +/* ===== + And if none of the other options work, let's just use gettimeofday(), and + ratchet it forward so that it acts like a monotonic timer, whether it + wants to or not. + */ + +int +evutil_configure_monotonic_time_(struct evutil_monotonic_timer *base, + int precise) +{ + memset(base, 0, sizeof(*base)); + return 0; +} + +int +evutil_gettime_monotonic_(struct evutil_monotonic_timer *base, + struct timeval *tp) +{ + if (evutil_gettimeofday(tp, NULL) < 0) + return -1; + adjust_monotonic_time(base, tp); + return 0; + +} +#endif diff --git a/contrib/libs/libevent/ht-internal.h b/contrib/libs/libevent/ht-internal.h index 50375bbaa9..b96d857600 100644 --- a/contrib/libs/libevent/ht-internal.h +++ b/contrib/libs/libevent/ht-internal.h @@ -1,12 +1,12 @@ -/* Copyright 2002 Christopher Clark */ +/* Copyright 2002 Christopher Clark */ /* Copyright 2005-2012 Nick Mathewson */ /* Copyright 2009-2012 Niels Provos and Nick Mathewson */ /* See license at end. */ /* Based on ideas by Christopher Clark and interfaces from Niels Provos. */ -#ifndef HT_INTERNAL_H_INCLUDED_ -#define HT_INTERNAL_H_INCLUDED_ +#ifndef HT_INTERNAL_H_INCLUDED_ +#define HT_INTERNAL_H_INCLUDED_ #define HT_HEAD(name, type) \ struct name { \ @@ -25,7 +25,7 @@ #define HT_INITIALIZER() \ { NULL, 0, 0, 0, -1 } -#ifdef HT_NO_CACHE_HASH_VALUES +#ifdef HT_NO_CACHE_HASH_VALUES #define HT_ENTRY(type) \ struct { \ struct type *hte_next; \ @@ -34,7 +34,7 @@ #define HT_ENTRY(type) \ struct { \ struct type *hte_next; \ - unsigned hte_hash; \ + unsigned hte_hash; \ } #endif @@ -45,10 +45,10 @@ #define HT_SIZE(head) \ ((head)->hth_n_entries) -/* Return memory usage for a hashtable (not counting the entries themselves) */ -#define HT_MEM_USAGE(head) \ - (sizeof(*head) + (head)->hth_table_length * sizeof(void*)) - +/* Return memory usage for a hashtable (not counting the entries themselves) */ +#define HT_MEM_USAGE(head) \ + (sizeof(*head) + (head)->hth_table_length * sizeof(void*)) + #define HT_FIND(name, head, elm) name##_HT_FIND((head), (elm)) #define HT_INSERT(name, head, elm) name##_HT_INSERT((head), (elm)) #define HT_REPLACE(name, head, elm) name##_HT_REPLACE((head), (elm)) @@ -60,7 +60,7 @@ #define HT_INIT(name, head) name##_HT_INIT(head) /* Helper: */ static inline unsigned -ht_improve_hash_(unsigned h) +ht_improve_hash_(unsigned h) { /* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */ @@ -74,7 +74,7 @@ ht_improve_hash_(unsigned h) #if 0 /** Basic string hash function, from Java standard String.hashCode(). */ static inline unsigned -ht_string_hash_(const char *s) +ht_string_hash_(const char *s) { unsigned h = 0; int m = 1; @@ -88,7 +88,7 @@ ht_string_hash_(const char *s) /** Basic string hash function, from Python's str.__hash__() */ static inline unsigned -ht_string_hash_(const char *s) +ht_string_hash_(const char *s) { unsigned h; const unsigned char *cp = (const unsigned char *)s; @@ -101,25 +101,25 @@ ht_string_hash_(const char *s) return h; } -#ifndef HT_NO_CACHE_HASH_VALUES -#define HT_SET_HASH_(elm, field, hashfn) \ +#ifndef HT_NO_CACHE_HASH_VALUES +#define HT_SET_HASH_(elm, field, hashfn) \ do { (elm)->field.hte_hash = hashfn(elm); } while (0) -#define HT_SET_HASHVAL_(elm, field, val) \ +#define HT_SET_HASHVAL_(elm, field, val) \ do { (elm)->field.hte_hash = (val); } while (0) -#define HT_ELT_HASH_(elm, field, hashfn) \ +#define HT_ELT_HASH_(elm, field, hashfn) \ ((elm)->field.hte_hash) #else -#define HT_SET_HASH_(elm, field, hashfn) \ +#define HT_SET_HASH_(elm, field, hashfn) \ ((void)0) -#define HT_ELT_HASH_(elm, field, hashfn) \ +#define HT_ELT_HASH_(elm, field, hashfn) \ (hashfn(elm)) -#define HT_SET_HASHVAL_(elm, field, val) \ +#define HT_SET_HASHVAL_(elm, field, val) \ ((void)0) #endif /* Helper: alias for the bucket containing 'elm'. */ -#define HT_BUCKET_(head, field, elm, hashfn) \ - ((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn) % head->hth_table_length]) +#define HT_BUCKET_(head, field, elm, hashfn) \ + ((head)->hth_table[HT_ELT_HASH_(elm,field,hashfn) % head->hth_table_length]) #define HT_FOREACH(x, name, head) \ for ((x) = HT_START(name, head); \ @@ -129,7 +129,7 @@ ht_string_hash_(const char *s) #define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \ int name##_HT_GROW(struct name *ht, unsigned min_capacity); \ void name##_HT_CLEAR(struct name *ht); \ - int name##_HT_REP_IS_BAD_(const struct name *ht); \ + int name##_HT_REP_IS_BAD_(const struct name *ht); \ static inline void \ name##_HT_INIT(struct name *head) { \ head->hth_table_length = 0; \ @@ -141,12 +141,12 @@ ht_string_hash_(const char *s) /* Helper: returns a pointer to the right location in the table \ * 'head' to find or insert the element 'elm'. */ \ static inline struct type ** \ - name##_HT_FIND_P_(struct name *head, struct type *elm) \ + name##_HT_FIND_P_(struct name *head, struct type *elm) \ { \ struct type **p; \ if (!head->hth_table) \ return NULL; \ - p = &HT_BUCKET_(head, field, elm, hashfn); \ + p = &HT_BUCKET_(head, field, elm, hashfn); \ while (*p) { \ if (eqfn(*p, elm)) \ return p; \ @@ -161,8 +161,8 @@ ht_string_hash_(const char *s) { \ struct type **p; \ struct name *h = (struct name *) head; \ - HT_SET_HASH_(elm, field, hashfn); \ - p = name##_HT_FIND_P_(h, elm); \ + HT_SET_HASH_(elm, field, hashfn); \ + p = name##_HT_FIND_P_(h, elm); \ return p ? *p : NULL; \ } \ /* Insert the element 'elm' into the table 'head'. Do not call this \ @@ -174,8 +174,8 @@ ht_string_hash_(const char *s) if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \ name##_HT_GROW(head, head->hth_n_entries+1); \ ++head->hth_n_entries; \ - HT_SET_HASH_(elm, field, hashfn); \ - p = &HT_BUCKET_(head, field, elm, hashfn); \ + HT_SET_HASH_(elm, field, hashfn); \ + p = &HT_BUCKET_(head, field, elm, hashfn); \ elm->field.hte_next = *p; \ *p = elm; \ } \ @@ -188,8 +188,8 @@ ht_string_hash_(const char *s) struct type **p, *r; \ if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \ name##_HT_GROW(head, head->hth_n_entries+1); \ - HT_SET_HASH_(elm, field, hashfn); \ - p = name##_HT_FIND_P_(head, elm); \ + HT_SET_HASH_(elm, field, hashfn); \ + p = name##_HT_FIND_P_(head, elm); \ r = *p; \ *p = elm; \ if (r && (r!=elm)) { \ @@ -207,8 +207,8 @@ ht_string_hash_(const char *s) name##_HT_REMOVE(struct name *head, struct type *elm) \ { \ struct type **p, *r; \ - HT_SET_HASH_(elm, field, hashfn); \ - p = name##_HT_FIND_P_(head,elm); \ + HT_SET_HASH_(elm, field, hashfn); \ + p = name##_HT_FIND_P_(head,elm); \ if (!p || !*p) \ return NULL; \ r = *p; \ @@ -269,7 +269,7 @@ ht_string_hash_(const char *s) if ((*elm)->field.hte_next) { \ return &(*elm)->field.hte_next; \ } else { \ - unsigned b = (HT_ELT_HASH_(*elm, field, hashfn) % head->hth_table_length)+1; \ + unsigned b = (HT_ELT_HASH_(*elm, field, hashfn) % head->hth_table_length)+1; \ while (b < head->hth_table_length) { \ if (head->hth_table[b]) \ return &head->hth_table[b]; \ @@ -281,7 +281,7 @@ ht_string_hash_(const char *s) static inline struct type ** \ name##_HT_NEXT_RMV(struct name *head, struct type **elm) \ { \ - unsigned h = HT_ELT_HASH_(*elm, field, hashfn); \ + unsigned h = HT_ELT_HASH_(*elm, field, hashfn); \ *elm = (*elm)->field.hte_next; \ --head->hth_n_entries; \ if (*elm) { \ @@ -338,7 +338,7 @@ ht_string_hash_(const char *s) elm = head->hth_table[b]; \ while (elm) { \ next = elm->field.hte_next; \ - b2 = HT_ELT_HASH_(elm, field, hashfn) % new_len; \ + b2 = HT_ELT_HASH_(elm, field, hashfn) % new_len; \ elm->field.hte_next = new_table[b2]; \ new_table[b2] = elm; \ elm = next; \ @@ -356,7 +356,7 @@ ht_string_hash_(const char *s) for (b=0; b < head->hth_table_length; ++b) { \ struct type *e, **pE; \ for (pE = &new_table[b], e = *pE; e != NULL; e = *pE) { \ - b2 = HT_ELT_HASH_(e, field, hashfn) % new_len; \ + b2 = HT_ELT_HASH_(e, field, hashfn) % new_len; \ if (b2 == b) { \ pE = &e->field.hte_next; \ } else { \ @@ -385,7 +385,7 @@ ht_string_hash_(const char *s) /* Debugging helper: return false iff the representation of 'head' is \ * internally consistent. */ \ int \ - name##_HT_REP_IS_BAD_(const struct name *head) \ + name##_HT_REP_IS_BAD_(const struct name *head) \ { \ unsigned n, i; \ struct type *elm; \ @@ -407,9 +407,9 @@ ht_string_hash_(const char *s) return 5; \ for (n = i = 0; i < head->hth_table_length; ++i) { \ for (elm = head->hth_table[i]; elm; elm = elm->field.hte_next) { \ - if (HT_ELT_HASH_(elm, field, hashfn) != hashfn(elm)) \ + if (HT_ELT_HASH_(elm, field, hashfn) != hashfn(elm)) \ return 1000 + i; \ - if ((HT_ELT_HASH_(elm, field, hashfn) % head->hth_table_length) != i) \ + if ((HT_ELT_HASH_(elm, field, hashfn) % head->hth_table_length) != i) \ return 10000 + i; \ ++n; \ } \ @@ -422,24 +422,24 @@ ht_string_hash_(const char *s) /** Implements an over-optimized "find and insert if absent" block; * not meant for direct usage by typical code, or usage outside the critical * path.*/ -#define HT_FIND_OR_INSERT_(name, field, hashfn, head, eltype, elm, var, y, n) \ +#define HT_FIND_OR_INSERT_(name, field, hashfn, head, eltype, elm, var, y, n) \ { \ - struct name *var##_head_ = head; \ - struct eltype **var; \ - if (!var##_head_->hth_table || \ - var##_head_->hth_n_entries >= var##_head_->hth_load_limit) \ - name##_HT_GROW(var##_head_, var##_head_->hth_n_entries+1); \ - HT_SET_HASH_((elm), field, hashfn); \ - var = name##_HT_FIND_P_(var##_head_, (elm)); \ + struct name *var##_head_ = head; \ + struct eltype **var; \ + if (!var##_head_->hth_table || \ + var##_head_->hth_n_entries >= var##_head_->hth_load_limit) \ + name##_HT_GROW(var##_head_, var##_head_->hth_n_entries+1); \ + HT_SET_HASH_((elm), field, hashfn); \ + var = name##_HT_FIND_P_(var##_head_, (elm)); \ if (*var) { \ y; \ } else { \ n; \ } \ } -#define HT_FOI_INSERT_(field, head, elm, newent, var) \ +#define HT_FOI_INSERT_(field, head, elm, newent, var) \ { \ - HT_SET_HASHVAL_(newent, field, (elm)->field.hte_hash); \ + HT_SET_HASHVAL_(newent, field, (elm)->field.hte_hash); \ newent->field.hte_next = NULL; \ *var = newent; \ ++((head)->hth_n_entries); \ @@ -447,7 +447,7 @@ ht_string_hash_(const char *s) /* * Copyright 2005, Nick Mathewson. Implementation logic is adapted from code - * by Christopher Clark, retrofit to allow drop-in memory management, and to + * by Christopher Clark, retrofit to allow drop-in memory management, and to * use the same interface as Niels Provos's tree.h. This is probably still * a derived work, so the original license below still applies. * diff --git a/contrib/libs/libevent/http-internal.h b/contrib/libs/libevent/http-internal.h index 85760eafc2..9f199eced7 100644 --- a/contrib/libs/libevent/http-internal.h +++ b/contrib/libs/libevent/http-internal.h @@ -7,8 +7,8 @@ * need to know about these. */ -#ifndef HTTP_INTERNAL_H_INCLUDED_ -#define HTTP_INTERNAL_H_INCLUDED_ +#ifndef HTTP_INTERNAL_H_INCLUDED_ +#define HTTP_INTERNAL_H_INCLUDED_ #include "event2/event_struct.h" #include "util-internal.h" @@ -32,7 +32,7 @@ struct addrinfo; struct evhttp_request; /* Indicates an unknown request method. */ -#define EVHTTP_REQ_UNKNOWN_ (1<<15) +#define EVHTTP_REQ_UNKNOWN_ (1<<15) enum evhttp_connection_state { EVCON_DISCONNECTED, /**< not currently connected not trying either*/ @@ -62,30 +62,30 @@ struct evhttp_connection { struct event retry_ev; /* for retrying connects */ char *bind_address; /* address to use for binding the src */ - ev_uint16_t bind_port; /* local port for binding the src */ + ev_uint16_t bind_port; /* local port for binding the src */ char *address; /* address to connect to */ - ev_uint16_t port; + ev_uint16_t port; size_t max_headers_size; ev_uint64_t max_body_size; int flags; -#define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */ -#define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */ -#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */ -/* set when we want to auto free the connection */ -#define EVHTTP_CON_AUTOFREE EVHTTP_CON_PUBLIC_FLAGS_END -/* Installed when attempt to read HTTP error after write failed, see - * EVHTTP_CON_READ_ON_WRITE_ERROR */ -#define EVHTTP_CON_READING_ERROR (EVHTTP_CON_AUTOFREE << 1) - - struct timeval timeout; /* timeout for events */ +#define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */ +#define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */ +#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */ +/* set when we want to auto free the connection */ +#define EVHTTP_CON_AUTOFREE EVHTTP_CON_PUBLIC_FLAGS_END +/* Installed when attempt to read HTTP error after write failed, see + * EVHTTP_CON_READ_ON_WRITE_ERROR */ +#define EVHTTP_CON_READING_ERROR (EVHTTP_CON_AUTOFREE << 1) + + struct timeval timeout; /* timeout for events */ int retry_cnt; /* retry count */ int retry_max; /* maximum number of retries */ - struct timeval initial_retry_timeout; /* Timeout for low long to wait - * after first failing attempt - * before retry */ + struct timeval initial_retry_timeout; /* Timeout for low long to wait + * after first failing attempt + * before retry */ enum evhttp_connection_state state; @@ -100,11 +100,11 @@ struct evhttp_connection { void (*closecb)(struct evhttp_connection *, void *); void *closecb_arg; - struct event_callback read_more_deferred_cb; + struct event_callback read_more_deferred_cb; struct event_base *base; struct evdns_base *dns_base; - int ai_family; + int ai_family; }; /* A callback for an http server */ @@ -142,7 +142,7 @@ struct evhttp { /* All listeners for this host */ TAILQ_HEAD(boundq, evhttp_bound_socket) sockets; - TAILQ_HEAD(httpcbq, evhttp_cb) callbacks; + TAILQ_HEAD(httpcbq, evhttp_cb) callbacks; /* All live connections on this host. */ struct evconq connections; @@ -154,12 +154,12 @@ struct evhttp { /* NULL if this server is not a vhost */ char *vhost_pattern; - struct timeval timeout; + struct timeval timeout; size_t default_max_headers_size; ev_uint64_t default_max_body_size; - int flags; - const char *default_content_type; + int flags; + const char *default_content_type; /* Bitmask of all HTTP methods that we accept and pass to user * callbacks. */ @@ -178,33 +178,33 @@ struct evhttp { /* XXX most of these functions could be static. */ /* resets the connection; can be reused for more requests */ -void evhttp_connection_reset_(struct evhttp_connection *); +void evhttp_connection_reset_(struct evhttp_connection *); /* connects if necessary */ -int evhttp_connection_connect_(struct evhttp_connection *); +int evhttp_connection_connect_(struct evhttp_connection *); -enum evhttp_request_error; +enum evhttp_request_error; /* notifies the current request that it failed; resets connection */ -EVENT2_EXPORT_SYMBOL -void evhttp_connection_fail_(struct evhttp_connection *, - enum evhttp_request_error error); +EVENT2_EXPORT_SYMBOL +void evhttp_connection_fail_(struct evhttp_connection *, + enum evhttp_request_error error); enum message_read_status; -EVENT2_EXPORT_SYMBOL -enum message_read_status evhttp_parse_firstline_(struct evhttp_request *, struct evbuffer*); -EVENT2_EXPORT_SYMBOL -enum message_read_status evhttp_parse_headers_(struct evhttp_request *, struct evbuffer*); +EVENT2_EXPORT_SYMBOL +enum message_read_status evhttp_parse_firstline_(struct evhttp_request *, struct evbuffer*); +EVENT2_EXPORT_SYMBOL +enum message_read_status evhttp_parse_headers_(struct evhttp_request *, struct evbuffer*); -void evhttp_start_read_(struct evhttp_connection *); -void evhttp_start_write_(struct evhttp_connection *); +void evhttp_start_read_(struct evhttp_connection *); +void evhttp_start_write_(struct evhttp_connection *); /* response sending HTML the data in the buffer */ -void evhttp_response_code_(struct evhttp_request *, int, const char *); -void evhttp_send_page_(struct evhttp_request *, struct evbuffer *); - -EVENT2_EXPORT_SYMBOL -int evhttp_decode_uri_internal(const char *uri, size_t length, - char *ret, int decode_plus); - -#endif /* HTTP_INTERNAL_H_INCLUDED_ */ +void evhttp_response_code_(struct evhttp_request *, int, const char *); +void evhttp_send_page_(struct evhttp_request *, struct evbuffer *); + +EVENT2_EXPORT_SYMBOL +int evhttp_decode_uri_internal(const char *uri, size_t length, + char *ret, int decode_plus); + +#endif /* HTTP_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/http.c b/contrib/libs/libevent/http.c index b750d491c9..63dd84e5e9 100644 --- a/contrib/libs/libevent/http.c +++ b/contrib/libs/libevent/http.c @@ -26,56 +26,56 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef EVENT__HAVE_SYS_PARAM_H +#ifdef EVENT__HAVE_SYS_PARAM_H #include <sys/param.h> #endif -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif #ifdef HAVE_SYS_IOCCOM_H #include <sys/ioccom.h> #endif -#ifdef EVENT__HAVE_SYS_RESOURCE_H -#include <sys/resource.h> -#endif -#ifdef EVENT__HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#ifdef EVENT__HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif - -#ifndef _WIN32 +#ifdef EVENT__HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#ifdef EVENT__HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif + +#ifndef _WIN32 #include <sys/socket.h> #include <sys/stat.h> -#else /* _WIN32 */ +#else /* _WIN32 */ #include <winsock2.h> #include <ws2tcpip.h> -#endif /* _WIN32 */ - -#ifdef EVENT__HAVE_SYS_UN_H -#include <sys/un.h> -#endif -#ifdef EVENT__HAVE_AFUNIX_H -#error #include <afunix.h> +#endif /* _WIN32 */ + +#ifdef EVENT__HAVE_SYS_UN_H +#include <sys/un.h> #endif +#ifdef EVENT__HAVE_AFUNIX_H +#error #include <afunix.h> +#endif #include <sys/queue.h> -#ifdef EVENT__HAVE_NETINET_IN_H +#ifdef EVENT__HAVE_NETINET_IN_H #include <netinet/in.h> #endif -#ifdef EVENT__HAVE_ARPA_INET_H +#ifdef EVENT__HAVE_ARPA_INET_H #include <arpa/inet.h> #endif -#ifdef EVENT__HAVE_NETDB_H +#ifdef EVENT__HAVE_NETDB_H #include <netdb.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #endif @@ -83,14 +83,14 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifndef _WIN32 +#ifndef _WIN32 #include <syslog.h> -#endif /* !_WIN32 */ +#endif /* !_WIN32 */ #include <signal.h> -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef EVENT__HAVE_FCNTL_H +#ifdef EVENT__HAVE_FCNTL_H #include <fcntl.h> #endif @@ -112,7 +112,7 @@ #include "mm-internal.h" #include "bufferevent-internal.h" -#ifndef EVENT__HAVE_GETNAMEINFO +#ifndef EVENT__HAVE_GETNAMEINFO #define NI_MAXSERV 32 #define NI_MAXHOST 1025 @@ -180,7 +180,7 @@ extern int debug; static evutil_socket_t create_bind_socket_nonblock(struct evutil_addrinfo *, int reuse); static evutil_socket_t bind_socket(const char *, ev_uint16_t, int reuse); static void name_from_addr(struct sockaddr *, ev_socklen_t, char **, char **); -static struct evhttp_uri *evhttp_uri_parse_authority(char *source_uri); +static struct evhttp_uri *evhttp_uri_parse_authority(char *source_uri); static int evhttp_associate_new_request_with_connection( struct evhttp_connection *evcon); static void evhttp_connection_start_detectclose( @@ -210,7 +210,7 @@ static void evhttp_error_cb(struct bufferevent *bufev, short what, void *arg); static int evhttp_find_vhost(struct evhttp *http, struct evhttp **outhttp, const char *hostname); -#ifndef EVENT__HAVE_STRSEP +#ifndef EVENT__HAVE_STRSEP /* strsep replacement for platforms that lack it. Only works if * del is one character long. */ static char * @@ -380,15 +380,15 @@ evhttp_write_buffer(struct evhttp_connection *evcon, evcon->cb_arg = arg; /* Disable the read callback: we don't actually care about data; - * we only care about close detection. (We don't disable reading -- - * EV_READ, since we *do* want to learn about any close events.) */ + * we only care about close detection. (We don't disable reading -- + * EV_READ, since we *do* want to learn about any close events.) */ bufferevent_setcb(evcon->bufev, NULL, /*read*/ evhttp_write_cb, evhttp_error_cb, evcon); - bufferevent_enable(evcon->bufev, EV_READ|EV_WRITE); + bufferevent_enable(evcon->bufev, EV_READ|EV_WRITE); } static void @@ -446,10 +446,10 @@ evhttp_make_header_request(struct evhttp_connection *evcon, evhttp_remove_header(req->output_headers, "Proxy-Connection"); /* Generate request line */ - if (!(method = evhttp_method(req->type))) { - method = "NULL"; - } - + if (!(method = evhttp_method(req->type))) { + method = "NULL"; + } + evbuffer_add_printf(bufferevent_get_output(evcon->bufev), "%s %s HTTP/%d.%d\r\n", method, req->uri, req->major, req->minor); @@ -479,16 +479,16 @@ evhttp_is_connection_close(int flags, struct evkeyvalq* headers) return (connection != NULL && evutil_ascii_strcasecmp(connection, "close") == 0); } } -static int -evhttp_is_request_connection_close(struct evhttp_request *req) -{ +static int +evhttp_is_request_connection_close(struct evhttp_request *req) +{ if (req->type == EVHTTP_REQ_CONNECT) return 0; - return - evhttp_is_connection_close(req->flags, req->input_headers) || - evhttp_is_connection_close(req->flags, req->output_headers); -} + return + evhttp_is_connection_close(req->flags, req->input_headers) || + evhttp_is_connection_close(req->flags, req->output_headers); +} /* Return true iff 'headers' contains 'Connection: keep-alive' */ static int @@ -505,7 +505,7 @@ evhttp_maybe_add_date_header(struct evkeyvalq *headers) { if (evhttp_find_header(headers, "Date") == NULL) { char date[50]; - if (sizeof(date) - evutil_date_rfc1123(date, sizeof(date), NULL) > 0) { + if (sizeof(date) - evutil_date_rfc1123(date, sizeof(date), NULL) > 0) { evhttp_add_header(headers, "Date", date); } } @@ -568,11 +568,11 @@ evhttp_make_header_response(struct evhttp_connection *evcon, /* Potentially add headers for unidentified content. */ if (evhttp_response_needs_body(req)) { if (evhttp_find_header(req->output_headers, - "Content-Type") == NULL - && evcon->http_server->default_content_type) { + "Content-Type") == NULL + && evcon->http_server->default_content_type) { evhttp_add_header(req->output_headers, - "Content-Type", - evcon->http_server->default_content_type); + "Content-Type", + evcon->http_server->default_content_type); } } @@ -585,23 +585,23 @@ evhttp_make_header_response(struct evhttp_connection *evcon, } } -enum expect { NO, CONTINUE, OTHER }; -static enum expect evhttp_have_expect(struct evhttp_request *req, int input) -{ - const char *expect; - struct evkeyvalq *h = input ? req->input_headers : req->output_headers; - - if (!(req->kind == EVHTTP_REQUEST) || !REQ_VERSION_ATLEAST(req, 1, 1)) - return NO; - - expect = evhttp_find_header(h, "Expect"); - if (!expect) - return NO; - - return !evutil_ascii_strcasecmp(expect, "100-continue") ? CONTINUE : OTHER; -} - - +enum expect { NO, CONTINUE, OTHER }; +static enum expect evhttp_have_expect(struct evhttp_request *req, int input) +{ + const char *expect; + struct evkeyvalq *h = input ? req->input_headers : req->output_headers; + + if (!(req->kind == EVHTTP_REQUEST) || !REQ_VERSION_ATLEAST(req, 1, 1)) + return NO; + + expect = evhttp_find_header(h, "Expect"); + if (!expect) + return NO; + + return !evutil_ascii_strcasecmp(expect, "100-continue") ? CONTINUE : OTHER; +} + + /** Generate all headers appropriate for sending the http request in req (or * the response, if we're sending a response), and write them to evcon's * bufferevent. Also writes all data from req->output_buffer */ @@ -627,8 +627,8 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) } evbuffer_add(output, "\r\n", 2); - if (evhttp_have_expect(req, 0) != CONTINUE && - evbuffer_get_length(req->output_buffer)) { + if (evhttp_have_expect(req, 0) != CONTINUE && + evbuffer_get_length(req->output_buffer)) { /* * For a request, we add the POST data, for a reply, this * is the regular data. @@ -658,19 +658,19 @@ evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, static int evhttp_connection_incoming_fail(struct evhttp_request *req, - enum evhttp_request_error error) + enum evhttp_request_error error) { switch (error) { - case EVREQ_HTTP_DATA_TOO_LONG: - req->response_code = HTTP_ENTITYTOOLARGE; - break; - default: - req->response_code = HTTP_BADREQUEST; - } - - switch (error) { - case EVREQ_HTTP_TIMEOUT: - case EVREQ_HTTP_EOF: + case EVREQ_HTTP_DATA_TOO_LONG: + req->response_code = HTTP_ENTITYTOOLARGE; + break; + default: + req->response_code = HTTP_BADREQUEST; + } + + switch (error) { + case EVREQ_HTTP_TIMEOUT: + case EVREQ_HTTP_EOF: /* * these are cases in which we probably should just * close the connection and not send a reply. this @@ -688,10 +688,10 @@ evhttp_connection_incoming_fail(struct evhttp_request *req, req->evcon = NULL; } return (-1); - case EVREQ_HTTP_INVALID_HEADER: - case EVREQ_HTTP_BUFFER_ERROR: - case EVREQ_HTTP_REQUEST_CANCEL: - case EVREQ_HTTP_DATA_TOO_LONG: + case EVREQ_HTTP_INVALID_HEADER: + case EVREQ_HTTP_BUFFER_ERROR: + case EVREQ_HTTP_REQUEST_CANCEL: + case EVREQ_HTTP_DATA_TOO_LONG: default: /* xxx: probably should just error on default */ /* the callback looks at the uri to determine errors */ if (req->uri) { @@ -713,36 +713,36 @@ evhttp_connection_incoming_fail(struct evhttp_request *req, return (0); } -/* Free connection ownership of which can be acquired by user using - * evhttp_request_own(). */ -static inline void -evhttp_request_free_auto(struct evhttp_request *req) -{ - if (!(req->flags & EVHTTP_USER_OWNED)) - evhttp_request_free(req); -} - -static void -evhttp_request_free_(struct evhttp_connection *evcon, struct evhttp_request *req) -{ - TAILQ_REMOVE(&evcon->requests, req, next); - evhttp_request_free_auto(req); -} - +/* Free connection ownership of which can be acquired by user using + * evhttp_request_own(). */ +static inline void +evhttp_request_free_auto(struct evhttp_request *req) +{ + if (!(req->flags & EVHTTP_USER_OWNED)) + evhttp_request_free(req); +} + +static void +evhttp_request_free_(struct evhttp_connection *evcon, struct evhttp_request *req) +{ + TAILQ_REMOVE(&evcon->requests, req, next); + evhttp_request_free_auto(req); +} + /* Called when evcon has experienced a (non-recoverable? -NM) error, as * given in error. If it's an outgoing connection, reset the connection, * retry any pending requests, and inform the user. If it's incoming, * delegates to evhttp_connection_incoming_fail(). */ void -evhttp_connection_fail_(struct evhttp_connection *evcon, - enum evhttp_request_error error) +evhttp_connection_fail_(struct evhttp_connection *evcon, + enum evhttp_request_error error) { - const int errsave = EVUTIL_SOCKET_ERROR(); + const int errsave = EVUTIL_SOCKET_ERROR(); struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); void (*cb)(struct evhttp_request *, void *); void *cb_arg; - void (*error_cb)(enum evhttp_request_error, void *); - void *error_cb_arg; + void (*error_cb)(enum evhttp_request_error, void *); + void *error_cb_arg; EVUTIL_ASSERT(req != NULL); bufferevent_disable(evcon->bufev, EV_READ|EV_WRITE); @@ -761,10 +761,10 @@ evhttp_connection_fail_(struct evhttp_connection *evcon, return; } - error_cb = req->error_cb; - error_cb_arg = req->cb_arg; + error_cb = req->error_cb; + error_cb_arg = req->cb_arg; /* when the request was canceled, the callback is not executed */ - if (error != EVREQ_HTTP_REQUEST_CANCEL) { + if (error != EVREQ_HTTP_REQUEST_CANCEL) { /* save the callback for later; the cb might free our object */ cb = req->cb; cb_arg = req->cb_arg; @@ -777,29 +777,29 @@ evhttp_connection_fail_(struct evhttp_connection *evcon, * send over a new connection. when a user cancels a request, * all other pending requests should be processed as normal */ - evhttp_request_free_(evcon, req); + evhttp_request_free_(evcon, req); /* reset the connection */ - evhttp_connection_reset_(evcon); + evhttp_connection_reset_(evcon); /* We are trying the next request that was queued on us */ if (TAILQ_FIRST(&evcon->requests) != NULL) - evhttp_connection_connect_(evcon); + evhttp_connection_connect_(evcon); else if ((evcon->flags & EVHTTP_CON_OUTGOING) && (evcon->flags & EVHTTP_CON_AUTOFREE)) { evhttp_connection_free(evcon); } - /* The call to evhttp_connection_reset_ overwrote errno. - * Let's restore the original errno, so that the user's - * callback can have a better idea of what the error was. - */ - EVUTIL_SET_SOCKET_ERROR(errsave); - + /* The call to evhttp_connection_reset_ overwrote errno. + * Let's restore the original errno, so that the user's + * callback can have a better idea of what the error was. + */ + EVUTIL_SET_SOCKET_ERROR(errsave); + /* inform the user */ - if (error_cb != NULL) - error_cb(error, error_cb_arg); + if (error_cb != NULL) + error_cb(error, error_cb_arg); if (cb != NULL) (*cb)(NULL, cb_arg); } @@ -828,11 +828,11 @@ evhttp_connection_done(struct evhttp_connection *evcon) { struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); int con_outgoing = evcon->flags & EVHTTP_CON_OUTGOING; - int free_evcon = 0; + int free_evcon = 0; if (con_outgoing) { /* idle or close the connection */ - int need_close = evhttp_is_request_connection_close(req); + int need_close = evhttp_is_request_connection_close(req); TAILQ_REMOVE(&evcon->requests, req, next); req->evcon = NULL; @@ -840,7 +840,7 @@ evhttp_connection_done(struct evhttp_connection *evcon) /* check if we got asked to close the connection */ if (need_close) - evhttp_connection_reset_(evcon); + evhttp_connection_reset_(evcon); if (TAILQ_FIRST(&evcon->requests) != NULL) { /* @@ -848,7 +848,7 @@ evhttp_connection_done(struct evhttp_connection *evcon) * and deal with the next request. */ if (!evhttp_connected(evcon)) - evhttp_connection_connect_(evcon); + evhttp_connection_connect_(evcon); else evhttp_request_dispatch(evcon); } else if (!need_close) { @@ -857,12 +857,12 @@ evhttp_connection_done(struct evhttp_connection *evcon) * need to detect if the other side closes it. */ evhttp_connection_start_detectclose(evcon); - } else if ((evcon->flags & EVHTTP_CON_AUTOFREE)) { - /* - * If we have no more requests that need completion - * and we're not waiting for the connection to close - */ - free_evcon = 1; + } else if ((evcon->flags & EVHTTP_CON_AUTOFREE)) { + /* + * If we have no more requests that need completion + * and we're not waiting for the connection to close + */ + free_evcon = 1; } } else { /* @@ -875,19 +875,19 @@ evhttp_connection_done(struct evhttp_connection *evcon) /* notify the user of the request */ (*req->cb)(req, req->cb_arg); - /* if this was an outgoing request, we own and it's done. so free it. */ - if (con_outgoing) { - evhttp_request_free_auto(req); - } - - /* If this was the last request of an outgoing connection and we're - * not waiting to receive a connection close event and we want to - * automatically free the connection. We check to ensure our request - * list is empty one last time just in case our callback added a - * new request. + /* if this was an outgoing request, we own and it's done. so free it. */ + if (con_outgoing) { + evhttp_request_free_auto(req); + } + + /* If this was the last request of an outgoing connection and we're + * not waiting to receive a connection close event and we want to + * automatically free the connection. We check to ensure our request + * list is empty one last time just in case our callback added a + * new request. */ - if (free_evcon && TAILQ_FIRST(&evcon->requests) == NULL) { - evhttp_connection_free(evcon); + if (free_evcon && TAILQ_FIRST(&evcon->requests) == NULL) { + evhttp_connection_free(evcon); } } @@ -1007,10 +1007,10 @@ evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req) { struct evbuffer *buf = bufferevent_get_input(evcon->bufev); - switch (evhttp_parse_headers_(req, buf)) { + switch (evhttp_parse_headers_(req, buf)) { case DATA_CORRUPTED: case DATA_TOO_LONG: - evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); + evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); break; case ALL_DATA_READ: bufferevent_disable(evcon->bufev, EV_READ); @@ -1024,35 +1024,35 @@ evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req) } static void -evhttp_lingering_close(struct evhttp_connection *evcon, - struct evhttp_request *req) -{ - struct evbuffer *buf = bufferevent_get_input(evcon->bufev); - - size_t n = evbuffer_get_length(buf); - if (n > (size_t) req->ntoread) - n = (size_t) req->ntoread; - req->ntoread -= n; - req->body_size += n; - - event_debug(("Request body is too long, left " EV_I64_FMT, - EV_I64_ARG(req->ntoread))); - - evbuffer_drain(buf, n); - if (!req->ntoread) - evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); -} -static void -evhttp_lingering_fail(struct evhttp_connection *evcon, - struct evhttp_request *req) -{ - if (evcon->flags & EVHTTP_CON_LINGERING_CLOSE) - evhttp_lingering_close(evcon, req); - else - evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); -} - -static void +evhttp_lingering_close(struct evhttp_connection *evcon, + struct evhttp_request *req) +{ + struct evbuffer *buf = bufferevent_get_input(evcon->bufev); + + size_t n = evbuffer_get_length(buf); + if (n > (size_t) req->ntoread) + n = (size_t) req->ntoread; + req->ntoread -= n; + req->body_size += n; + + event_debug(("Request body is too long, left " EV_I64_FMT, + EV_I64_ARG(req->ntoread))); + + evbuffer_drain(buf, n); + if (!req->ntoread) + evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); +} +static void +evhttp_lingering_fail(struct evhttp_connection *evcon, + struct evhttp_request *req) +{ + if (evcon->flags & EVHTTP_CON_LINGERING_CLOSE) + evhttp_lingering_close(evcon, req); + else + evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); +} + +static void evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) { struct evbuffer *buf = bufferevent_get_input(evcon->bufev); @@ -1065,14 +1065,14 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) evhttp_read_trailer(evcon, req); return; case DATA_CORRUPTED: - case DATA_TOO_LONG: + case DATA_TOO_LONG: /* corrupted data */ - evhttp_connection_fail_(evcon, - EVREQ_HTTP_DATA_TOO_LONG); + evhttp_connection_fail_(evcon, + EVREQ_HTTP_DATA_TOO_LONG); return; case REQUEST_CANCELED: /* request canceled */ - evhttp_request_free_auto(req); + evhttp_request_free_auto(req); return; case MORE_DATA_EXPECTED: default: @@ -1081,7 +1081,7 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) } else if (req->ntoread < 0) { /* Read until connection close. */ if ((size_t)(req->body_size + evbuffer_get_length(buf)) < req->body_size) { - evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); + evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); return; } @@ -1105,8 +1105,8 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) (size_t)req->ntoread > req->evcon->max_body_size)) { /* XXX: The above casted comparison must checked for overflow */ /* failed body length test */ - - evhttp_lingering_fail(evcon, req); + + evhttp_lingering_fail(evcon, req); return; } @@ -1117,12 +1117,12 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) evbuffer_drain(req->input_buffer, evbuffer_get_length(req->input_buffer)); if ((req->flags & EVHTTP_REQ_NEEDS_FREE) != 0) { - evhttp_request_free_auto(req); + evhttp_request_free_auto(req); return; } } - if (!req->ntoread) { + if (!req->ntoread) { bufferevent_disable(evcon->bufev, EV_READ); /* Completed content length */ evhttp_connection_done(evcon); @@ -1131,7 +1131,7 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) } #define get_deferred_queue(evcon) \ - ((evcon)->base) + ((evcon)->base) /* * Gets called when more data becomes available @@ -1144,7 +1144,7 @@ evhttp_read_cb(struct bufferevent *bufev, void *arg) struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); /* Cancel if it's pending. */ - event_deferred_cb_cancel_(get_deferred_queue(evcon), + event_deferred_cb_cancel_(get_deferred_queue(evcon), &evcon->read_more_deferred_cb); switch (evcon->state) { @@ -1180,7 +1180,7 @@ evhttp_read_cb(struct bufferevent *bufev, void *arg) __func__, EV_SIZE_ARG(total_len))); #endif - evhttp_connection_reset_(evcon); + evhttp_connection_reset_(evcon); } break; case EVCON_DISCONNECTED: @@ -1193,12 +1193,12 @@ evhttp_read_cb(struct bufferevent *bufev, void *arg) } static void -evhttp_deferred_read_cb(struct event_callback *cb, void *data) +evhttp_deferred_read_cb(struct event_callback *cb, void *data) { struct evhttp_connection *evcon = data; - struct bufferevent *bev = evcon->bufev; - if (bev->readcb) - (bev->readcb)(evcon->bufev, evcon); + struct bufferevent *bev = evcon->bufev; + if (bev->readcb) + (bev->readcb)(evcon->bufev, evcon); } static void @@ -1206,20 +1206,20 @@ evhttp_write_connectioncb(struct evhttp_connection *evcon, void *arg) { /* This is after writing the request to the server */ struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); - struct evbuffer *output = bufferevent_get_output(evcon->bufev); + struct evbuffer *output = bufferevent_get_output(evcon->bufev); EVUTIL_ASSERT(req != NULL); EVUTIL_ASSERT(evcon->state == EVCON_WRITING); - /* We need to wait until we've written all of our output data before we can - * continue */ - if (evbuffer_get_length(output) > 0) - return; - + /* We need to wait until we've written all of our output data before we can + * continue */ + if (evbuffer_get_length(output) > 0) + return; + /* We are done writing our header and are now expecting the response */ req->kind = EVHTTP_RESPONSE; - evhttp_start_read_(evcon); + evhttp_start_read_(evcon); } /* @@ -1230,7 +1230,7 @@ void evhttp_connection_free(struct evhttp_connection *evcon) { struct evhttp_request *req; - int need_close = 0; + int need_close = 0; /* notify interested parties that this connection is going down */ if (evcon->fd != -1) { @@ -1241,10 +1241,10 @@ evhttp_connection_free(struct evhttp_connection *evcon) /* remove all requests that might be queued on this * connection. for server connections, this should be empty. * because it gets dequeued either in evhttp_connection_done or - * evhttp_connection_fail_. + * evhttp_connection_fail_. */ while ((req = TAILQ_FIRST(&evcon->requests)) != NULL) { - evhttp_request_free_(evcon, req); + evhttp_request_free_(evcon, req); } if (evcon->http_server != NULL) { @@ -1257,22 +1257,22 @@ evhttp_connection_free(struct evhttp_connection *evcon) event_debug_unassign(&evcon->retry_ev); } - event_deferred_cb_cancel_(get_deferred_queue(evcon), - &evcon->read_more_deferred_cb); - - if (evcon->bufev != NULL) { - need_close = - !(bufferevent_get_options_(evcon->bufev) & BEV_OPT_CLOSE_ON_FREE); - if (evcon->fd == -1) - evcon->fd = bufferevent_getfd(evcon->bufev); - + event_deferred_cb_cancel_(get_deferred_queue(evcon), + &evcon->read_more_deferred_cb); + + if (evcon->bufev != NULL) { + need_close = + !(bufferevent_get_options_(evcon->bufev) & BEV_OPT_CLOSE_ON_FREE); + if (evcon->fd == -1) + evcon->fd = bufferevent_getfd(evcon->bufev); + bufferevent_free(evcon->bufev); - } + } if (evcon->fd != -1) { shutdown(evcon->fd, EVUTIL_SHUT_WR); - if (need_close) - evutil_closesocket(evcon->fd); + if (need_close) + evutil_closesocket(evcon->fd); } if (evcon->bind_address != NULL) @@ -1285,11 +1285,11 @@ evhttp_connection_free(struct evhttp_connection *evcon) } void -evhttp_connection_free_on_completion(struct evhttp_connection *evcon) { - evcon->flags |= EVHTTP_CON_AUTOFREE; -} - -void +evhttp_connection_free_on_completion(struct evhttp_connection *evcon) { + evcon->flags |= EVHTTP_CON_AUTOFREE; +} + +void evhttp_connection_set_local_address(struct evhttp_connection *evcon, const char *address) { @@ -1317,8 +1317,8 @@ evhttp_request_dispatch(struct evhttp_connection* evcon) if (req == NULL) return; - EVUTIL_ASSERT(req->kind == EVHTTP_REQUEST); - + EVUTIL_ASSERT(req->kind == EVHTTP_REQUEST); + /* delete possible close detection events */ evhttp_connection_stop_detectclose(evcon); @@ -1336,13 +1336,13 @@ evhttp_request_dispatch(struct evhttp_connection* evcon) /* Reset our connection state: disables reading/writing, closes our fd (if * any), clears out buffers, and puts us in state DISCONNECTED. */ void -evhttp_connection_reset_(struct evhttp_connection *evcon) +evhttp_connection_reset_(struct evhttp_connection *evcon) { struct evbuffer *tmp; - int err; - - bufferevent_setcb(evcon->bufev, NULL, NULL, NULL, NULL); + int err; + bufferevent_setcb(evcon->bufev, NULL, NULL, NULL, NULL); + /* XXXX This is not actually an optimal fix. Instead we ought to have an API for "stop connecting", or use bufferevent_setfd to turn off connecting. But for Libevent 2.0, this seems like a minimal change @@ -1352,13 +1352,13 @@ evhttp_connection_reset_(struct evhttp_connection *evcon) bufferevent is connecting, then you can't actually stop the bufferevent from trying to connect with bufferevent_disable(). The connect will never trigger, since we close the fd, but the timeout - might. That caused an assertion failure in evhttp_connection_fail_. + might. That caused an assertion failure in evhttp_connection_fail_. */ - bufferevent_disable_hard_(evcon->bufev, EV_READ|EV_WRITE); - - if (evcon->fd == -1) - evcon->fd = bufferevent_getfd(evcon->bufev); + bufferevent_disable_hard_(evcon->bufev, EV_READ|EV_WRITE); + if (evcon->fd == -1) + evcon->fd = bufferevent_getfd(evcon->bufev); + if (evcon->fd != -1) { /* inform interested parties about connection close */ if (evhttp_connected(evcon) && evcon->closecb != NULL) @@ -1385,19 +1385,19 @@ evhttp_connection_reset_(struct evhttp_connection *evcon) evutil_closesocket(evcon->fd); evcon->fd = -1; } - err = bufferevent_setfd(evcon->bufev, -1); - EVUTIL_ASSERT(!err && "setfd"); + err = bufferevent_setfd(evcon->bufev, -1); + EVUTIL_ASSERT(!err && "setfd"); /* we need to clean up any buffered data */ tmp = bufferevent_get_output(evcon->bufev); - err = evbuffer_drain(tmp, -1); - EVUTIL_ASSERT(!err && "drain output"); + err = evbuffer_drain(tmp, -1); + EVUTIL_ASSERT(!err && "drain output"); tmp = bufferevent_get_input(evcon->bufev); - err = evbuffer_drain(tmp, -1); - EVUTIL_ASSERT(!err && "drain input"); - - evcon->flags &= ~EVHTTP_CON_READING_ERROR; + err = evbuffer_drain(tmp, -1); + EVUTIL_ASSERT(!err && "drain input"); + evcon->flags &= ~EVHTTP_CON_READING_ERROR; + evcon->state = EVCON_DISCONNECTED; } @@ -1421,7 +1421,7 @@ evhttp_connection_retry(evutil_socket_t fd, short what, void *arg) struct evhttp_connection *evcon = arg; evcon->state = EVCON_DISCONNECTED; - evhttp_connection_connect_(evcon); + evhttp_connection_connect_(evcon); } static void @@ -1429,25 +1429,25 @@ evhttp_connection_cb_cleanup(struct evhttp_connection *evcon) { struct evcon_requestq requests; - evhttp_connection_reset_(evcon); + evhttp_connection_reset_(evcon); if (evcon->retry_max < 0 || evcon->retry_cnt < evcon->retry_max) { - struct timeval tv_retry = evcon->initial_retry_timeout; - int i; + struct timeval tv_retry = evcon->initial_retry_timeout; + int i; evtimer_assign(&evcon->retry_ev, evcon->base, evhttp_connection_retry, evcon); /* XXXX handle failure from evhttp_add_event */ - for (i=0; i < evcon->retry_cnt; ++i) { - tv_retry.tv_usec *= 2; - if (tv_retry.tv_usec > 1000000) { - tv_retry.tv_usec -= 1000000; - tv_retry.tv_sec += 1; - } - tv_retry.tv_sec *= 2; - if (tv_retry.tv_sec > 3600) { - tv_retry.tv_sec = 3600; - tv_retry.tv_usec = 0; - } - } - event_add(&evcon->retry_ev, &tv_retry); + for (i=0; i < evcon->retry_cnt; ++i) { + tv_retry.tv_usec *= 2; + if (tv_retry.tv_usec > 1000000) { + tv_retry.tv_usec -= 1000000; + tv_retry.tv_sec += 1; + } + tv_retry.tv_sec *= 2; + if (tv_retry.tv_sec > 3600) { + tv_retry.tv_sec = 3600; + tv_retry.tv_usec = 0; + } + } + event_add(&evcon->retry_ev, &tv_retry); evcon->retry_cnt++; return; } @@ -1473,43 +1473,43 @@ evhttp_connection_cb_cleanup(struct evhttp_connection *evcon) /* we might want to set an error here */ request->cb(request, request->cb_arg); - evhttp_request_free_auto(request); + evhttp_request_free_auto(request); } } static void -evhttp_connection_read_on_write_error(struct evhttp_connection *evcon, - struct evhttp_request *req) -{ - struct evbuffer *buf; - - /** Second time, we can't read anything */ - if (evcon->flags & EVHTTP_CON_READING_ERROR) { - evcon->flags &= ~EVHTTP_CON_READING_ERROR; - evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); - return; - } - - req->kind = EVHTTP_RESPONSE; - - buf = bufferevent_get_output(evcon->bufev); - evbuffer_unfreeze(buf, 1); - evbuffer_drain(buf, evbuffer_get_length(buf)); - evbuffer_freeze(buf, 1); - - evhttp_start_read_(evcon); - evcon->flags |= EVHTTP_CON_READING_ERROR; -} - -static void +evhttp_connection_read_on_write_error(struct evhttp_connection *evcon, + struct evhttp_request *req) +{ + struct evbuffer *buf; + + /** Second time, we can't read anything */ + if (evcon->flags & EVHTTP_CON_READING_ERROR) { + evcon->flags &= ~EVHTTP_CON_READING_ERROR; + evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); + return; + } + + req->kind = EVHTTP_RESPONSE; + + buf = bufferevent_get_output(evcon->bufev); + evbuffer_unfreeze(buf, 1); + evbuffer_drain(buf, evbuffer_get_length(buf)); + evbuffer_freeze(buf, 1); + + evhttp_start_read_(evcon); + evcon->flags |= EVHTTP_CON_READING_ERROR; +} + +static void evhttp_error_cb(struct bufferevent *bufev, short what, void *arg) { struct evhttp_connection *evcon = arg; struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); - if (evcon->fd == -1) - evcon->fd = bufferevent_getfd(bufev); - + if (evcon->fd == -1) + evcon->fd = bufferevent_getfd(bufev); + switch (evcon->state) { case EVCON_CONNECTING: if (what & BEV_EVENT_TIMEOUT) { @@ -1552,42 +1552,42 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg) * disconnected. */ EVUTIL_ASSERT(evcon->state == EVCON_IDLE); - evhttp_connection_reset_(evcon); - - /* - * If we have no more requests that need completion - * and we want to auto-free the connection when all - * requests have been completed. - */ - if (TAILQ_FIRST(&evcon->requests) == NULL - && (evcon->flags & EVHTTP_CON_OUTGOING) - && (evcon->flags & EVHTTP_CON_AUTOFREE)) { - evhttp_connection_free(evcon); - } + evhttp_connection_reset_(evcon); + + /* + * If we have no more requests that need completion + * and we want to auto-free the connection when all + * requests have been completed. + */ + if (TAILQ_FIRST(&evcon->requests) == NULL + && (evcon->flags & EVHTTP_CON_OUTGOING) + && (evcon->flags & EVHTTP_CON_AUTOFREE)) { + evhttp_connection_free(evcon); + } return; } if (what & BEV_EVENT_TIMEOUT) { - evhttp_connection_fail_(evcon, EVREQ_HTTP_TIMEOUT); + evhttp_connection_fail_(evcon, EVREQ_HTTP_TIMEOUT); } else if (what & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) { - if (what & BEV_EVENT_WRITING && - evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR) { - evhttp_connection_read_on_write_error(evcon, req); - return; - } - - if (what & BEV_EVENT_READING && - evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR && - evbuffer_get_length(bufferevent_get_input(bufev))) { - event_deferred_cb_schedule_(get_deferred_queue(evcon), - &evcon->read_more_deferred_cb); - return; - } - - evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); + if (what & BEV_EVENT_WRITING && + evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR) { + evhttp_connection_read_on_write_error(evcon, req); + return; + } + + if (what & BEV_EVENT_READING && + evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR && + evbuffer_get_length(bufferevent_get_input(bufev))) { + event_deferred_cb_schedule_(get_deferred_queue(evcon), + &evcon->read_more_deferred_cb); + return; + } + + evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); } else if (what == BEV_EVENT_CONNECTED) { } else { - evhttp_connection_fail_(evcon, EVREQ_HTTP_BUFFER_ERROR); + evhttp_connection_fail_(evcon, EVREQ_HTTP_BUFFER_ERROR); } } @@ -1609,7 +1609,7 @@ evhttp_connection_cb(struct bufferevent *bufev, short what, void *arg) * when connecting to a local address. the cleanup is going * to reschedule this function call. */ -#ifndef _WIN32 +#ifndef _WIN32 if (errno == ECONNREFUSED) goto cleanup; #endif @@ -1617,12 +1617,12 @@ evhttp_connection_cb(struct bufferevent *bufev, short what, void *arg) return; } - if (evcon->fd == -1) { - event_debug(("%s: bufferevent_getfd returned -1", - __func__)); - goto cleanup; - } - + if (evcon->fd == -1) { + event_debug(("%s: bufferevent_getfd returned -1", + __func__)); + goto cleanup; + } + /* Check if the connection completed */ if (getsockopt(evcon->fd, SOL_SOCKET, SO_ERROR, (void*)&error, &errsz) == -1) { @@ -1657,12 +1657,12 @@ evhttp_connection_cb(struct bufferevent *bufev, short what, void *arg) evhttp_error_cb, evcon); - if (!evutil_timerisset(&evcon->timeout)) { - const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 }; - const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 }; - bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); - } else { - bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); + if (!evutil_timerisset(&evcon->timeout)) { + const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 }; + const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 }; + bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); + } else { + bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); } /* try to start requests that have queued up on this connection */ @@ -1728,8 +1728,8 @@ evhttp_parse_response_line(struct evhttp_request *req, char *line) return (-1); } - if (req->response_code_line != NULL) - mm_free(req->response_code_line); + if (req->response_code_line != NULL) + mm_free(req->response_code_line); if ((req->response_code_line = mm_strdup(readable)) == NULL) { event_warn("%s: strdup", __func__); return (-1); @@ -1741,170 +1741,170 @@ evhttp_parse_response_line(struct evhttp_request *req, char *line) /* Parse the first line of a HTTP request */ static int -evhttp_parse_request_line(struct evhttp_request *req, char *line, size_t len) +evhttp_parse_request_line(struct evhttp_request *req, char *line, size_t len) { - char *eos = line + len; + char *eos = line + len; char *method; char *uri; char *version; const char *hostname; const char *scheme; - size_t method_len; - enum evhttp_cmd_type type; - - while (eos > line && *(eos-1) == ' ') { - *(eos-1) = '\0'; - --eos; - --len; - } - if (len < strlen("GET / HTTP/1.0")) - return -1; - + size_t method_len; + enum evhttp_cmd_type type; + + while (eos > line && *(eos-1) == ' ') { + *(eos-1) = '\0'; + --eos; + --len; + } + if (len < strlen("GET / HTTP/1.0")) + return -1; + /* Parse the request line */ method = strsep(&line, " "); - if (!line) - return -1; - uri = line; - version = strrchr(uri, ' '); - if (!version || uri == version) - return -1; - *version = '\0'; - version++; - - method_len = (uri - method) - 1; - type = EVHTTP_REQ_UNKNOWN_; - + if (!line) + return -1; + uri = line; + version = strrchr(uri, ' '); + if (!version || uri == version) + return -1; + *version = '\0'; + version++; + + method_len = (uri - method) - 1; + type = EVHTTP_REQ_UNKNOWN_; + /* First line */ - switch (method_len) { - case 3: - /* The length of the method string is 3, meaning it can only be one of two methods: GET or PUT */ - - /* Since both GET and PUT share the same character 'T' at the end, - * if the string doesn't have 'T', we can immediately determine this - * is an invalid HTTP method */ - - if (method[2] != 'T') { - break; - } - - switch (*method) { - case 'G': - /* This first byte is 'G', so make sure the next byte is - * 'E', if it isn't then this isn't a valid method */ - - if (method[1] == 'E') { - type = EVHTTP_REQ_GET; - } - - break; - case 'P': - /* First byte is P, check second byte for 'U', if not, - * we know it's an invalid method */ - if (method[1] == 'U') { - type = EVHTTP_REQ_PUT; - } - break; - default: - break; - } - break; - case 4: - /* The method length is 4 bytes, leaving only the methods "POST" and "HEAD" */ - switch (*method) { - case 'P': - if (method[3] == 'T' && method[2] == 'S' && method[1] == 'O') { - type = EVHTTP_REQ_POST; - } - break; - case 'H': - if (method[3] == 'D' && method[2] == 'A' && method[1] == 'E') { - type = EVHTTP_REQ_HEAD; - } - break; - default: - break; - } - break; - case 5: - /* Method length is 5 bytes, which can only encompass PATCH and TRACE */ - switch (*method) { - case 'P': - if (method[4] == 'H' && method[3] == 'C' && method[2] == 'T' && method[1] == 'A') { - type = EVHTTP_REQ_PATCH; - } - break; - case 'T': - if (method[4] == 'E' && method[3] == 'C' && method[2] == 'A' && method[1] == 'R') { - type = EVHTTP_REQ_TRACE; - } + switch (method_len) { + case 3: + /* The length of the method string is 3, meaning it can only be one of two methods: GET or PUT */ + + /* Since both GET and PUT share the same character 'T' at the end, + * if the string doesn't have 'T', we can immediately determine this + * is an invalid HTTP method */ + + if (method[2] != 'T') { + break; + } + + switch (*method) { + case 'G': + /* This first byte is 'G', so make sure the next byte is + * 'E', if it isn't then this isn't a valid method */ + + if (method[1] == 'E') { + type = EVHTTP_REQ_GET; + } + + break; + case 'P': + /* First byte is P, check second byte for 'U', if not, + * we know it's an invalid method */ + if (method[1] == 'U') { + type = EVHTTP_REQ_PUT; + } + break; + default: + break; + } + break; + case 4: + /* The method length is 4 bytes, leaving only the methods "POST" and "HEAD" */ + switch (*method) { + case 'P': + if (method[3] == 'T' && method[2] == 'S' && method[1] == 'O') { + type = EVHTTP_REQ_POST; + } + break; + case 'H': + if (method[3] == 'D' && method[2] == 'A' && method[1] == 'E') { + type = EVHTTP_REQ_HEAD; + } + break; + default: + break; + } + break; + case 5: + /* Method length is 5 bytes, which can only encompass PATCH and TRACE */ + switch (*method) { + case 'P': + if (method[4] == 'H' && method[3] == 'C' && method[2] == 'T' && method[1] == 'A') { + type = EVHTTP_REQ_PATCH; + } + break; + case 'T': + if (method[4] == 'E' && method[3] == 'C' && method[2] == 'A' && method[1] == 'R') { + type = EVHTTP_REQ_TRACE; + } + + break; + default: + break; + } + break; + case 6: + /* Method length is 6, only valid method 6 bytes in length is DELEte */ + + /* If the first byte isn't 'D' then it's invalid */ + if (*method != 'D') { + break; + } + + if (method[5] == 'E' && method[4] == 'T' && method[3] == 'E' && method[2] == 'L' && method[1] == 'E') { + type = EVHTTP_REQ_DELETE; + } + + break; + case 7: + /* Method length is 7, only valid methods are "OPTIONS" and "CONNECT" */ + switch (*method) { + case 'O': + if (method[6] == 'S' && method[5] == 'N' && method[4] == 'O' && + method[3] == 'I' && method[2] == 'T' && method[1] == 'P') { + type = EVHTTP_REQ_OPTIONS; + } - break; - default: - break; - } - break; - case 6: - /* Method length is 6, only valid method 6 bytes in length is DELEte */ - - /* If the first byte isn't 'D' then it's invalid */ - if (*method != 'D') { - break; - } - - if (method[5] == 'E' && method[4] == 'T' && method[3] == 'E' && method[2] == 'L' && method[1] == 'E') { - type = EVHTTP_REQ_DELETE; - } - - break; - case 7: - /* Method length is 7, only valid methods are "OPTIONS" and "CONNECT" */ - switch (*method) { - case 'O': - if (method[6] == 'S' && method[5] == 'N' && method[4] == 'O' && - method[3] == 'I' && method[2] == 'T' && method[1] == 'P') { - type = EVHTTP_REQ_OPTIONS; - } - - break; - case 'C': - if (method[6] == 'T' && method[5] == 'C' && method[4] == 'E' && - method[3] == 'N' && method[2] == 'N' && method[1] == 'O') { - type = EVHTTP_REQ_CONNECT; - } - - break; - default: - break; - } - break; - } /* switch */ - - if ((int)type == EVHTTP_REQ_UNKNOWN_) { - event_debug(("%s: bad method %s on request %p from %s", + break; + case 'C': + if (method[6] == 'T' && method[5] == 'C' && method[4] == 'E' && + method[3] == 'N' && method[2] == 'N' && method[1] == 'O') { + type = EVHTTP_REQ_CONNECT; + } + + break; + default: + break; + } + break; + } /* switch */ + + if ((int)type == EVHTTP_REQ_UNKNOWN_) { + event_debug(("%s: bad method %s on request %p from %s", __func__, method, req, req->remote_host)); - /* No error yet; we'll give a better error later when - * we see that req->type is unsupported. */ + /* No error yet; we'll give a better error later when + * we see that req->type is unsupported. */ } - - req->type = type; + + req->type = type; if (evhttp_parse_http_version(version, req) < 0) - return -1; + return -1; if ((req->uri = mm_strdup(uri)) == NULL) { event_debug(("%s: mm_strdup", __func__)); - return -1; + return -1; } - if (type == EVHTTP_REQ_CONNECT) { - if ((req->uri_elems = evhttp_uri_parse_authority(req->uri)) == NULL) { - return -1; - } - } else { - if ((req->uri_elems = evhttp_uri_parse_with_flags(req->uri, - EVHTTP_URI_NONCONFORMANT)) == NULL) { - return -1; - } + if (type == EVHTTP_REQ_CONNECT) { + if ((req->uri_elems = evhttp_uri_parse_authority(req->uri)) == NULL) { + return -1; + } + } else { + if ((req->uri_elems = evhttp_uri_parse_with_flags(req->uri, + EVHTTP_URI_NONCONFORMANT)) == NULL) { + return -1; + } } /* If we have an absolute-URI, check to see if it is an http request @@ -1925,8 +1925,8 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line, size_t len) req->chunk_cb_arg = chunkcb->cbarg; } } - - return 0; + + return 0; } const char * @@ -2056,14 +2056,14 @@ evhttp_add_header_internal(struct evkeyvalq *headers, */ enum message_read_status -evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer) +evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer) { char *line; enum message_read_status status = ALL_DATA_READ; - size_t len; + size_t len; /* XXX try */ - line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF); + line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF); if (line == NULL) { if (req->evcon != NULL && evbuffer_get_length(buffer) > req->evcon->max_headers_size) @@ -2072,16 +2072,16 @@ evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer) return (MORE_DATA_EXPECTED); } - if (req->evcon != NULL && len > req->evcon->max_headers_size) { + if (req->evcon != NULL && len > req->evcon->max_headers_size) { mm_free(line); return (DATA_TOO_LONG); } - req->headers_size = len; + req->headers_size = len; switch (req->kind) { case EVHTTP_REQUEST: - if (evhttp_parse_request_line(req, line, len) == -1) + if (evhttp_parse_request_line(req, line, len) == -1) status = DATA_CORRUPTED; break; case EVHTTP_RESPONSE: @@ -2097,7 +2097,7 @@ evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer) } static int -evhttp_append_to_last_header(struct evkeyvalq *headers, char *line) +evhttp_append_to_last_header(struct evkeyvalq *headers, char *line) { struct evkeyval *header = TAILQ_LAST(headers, evkeyvalq); char *newval; @@ -2107,39 +2107,39 @@ evhttp_append_to_last_header(struct evkeyvalq *headers, char *line) return (-1); old_len = strlen(header->value); - - /* Strip space from start and end of line. */ - while (*line == ' ' || *line == '\t') - ++line; - evutil_rtrim_lws_(line); - + + /* Strip space from start and end of line. */ + while (*line == ' ' || *line == '\t') + ++line; + evutil_rtrim_lws_(line); + line_len = strlen(line); - newval = mm_realloc(header->value, old_len + line_len + 2); + newval = mm_realloc(header->value, old_len + line_len + 2); if (newval == NULL) return (-1); - newval[old_len] = ' '; - memcpy(newval + old_len + 1, line, line_len + 1); + newval[old_len] = ' '; + memcpy(newval + old_len + 1, line, line_len + 1); header->value = newval; return (0); } enum message_read_status -evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer) +evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer) { enum message_read_status errcode = DATA_CORRUPTED; char *line; enum message_read_status status = MORE_DATA_EXPECTED; struct evkeyvalq* headers = req->input_headers; - size_t len; - while ((line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF)) + size_t len; + while ((line = evbuffer_readln(buffer, &len, EVBUFFER_EOL_CRLF)) != NULL) { char *skey, *svalue; - req->headers_size += len; + req->headers_size += len; if (req->evcon != NULL && req->headers_size > req->evcon->max_headers_size) { @@ -2168,7 +2168,7 @@ evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer) goto error; svalue += strspn(svalue, " "); - evutil_rtrim_lws_(svalue); + evutil_rtrim_lws_(svalue); if (evhttp_add_header(headers, skey, svalue) == -1) goto error; @@ -2203,7 +2203,7 @@ evhttp_get_body_length(struct evhttp_request *req) req->ntoread = -1; else if (content_length == NULL && evutil_ascii_strcasecmp(connection, "Close") != 0) { - req->ntoread = 0; + req->ntoread = 0; } else if (content_length == NULL) { req->ntoread = -1; } else { @@ -2231,15 +2231,15 @@ evhttp_method_may_have_body(enum evhttp_cmd_type type) case EVHTTP_REQ_POST: case EVHTTP_REQ_PUT: case EVHTTP_REQ_PATCH: - + case EVHTTP_REQ_GET: case EVHTTP_REQ_DELETE: case EVHTTP_REQ_OPTIONS: case EVHTTP_REQ_CONNECT: - return 1; - - case EVHTTP_REQ_TRACE: - case EVHTTP_REQ_HEAD: + return 1; + + case EVHTTP_REQ_TRACE: + case EVHTTP_REQ_HEAD: default: return 0; } @@ -2263,7 +2263,7 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) req->ntoread = -1; } else { if (evhttp_get_body_length(req) == -1) { - evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); + evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); return; } if (req->kind == EVHTTP_REQUEST && req->ntoread < 1) { @@ -2275,8 +2275,8 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) } /* Should we send a 100 Continue status line? */ - switch (evhttp_have_expect(req, 1)) { - case CONTINUE: + switch (evhttp_have_expect(req, 1)) { + case CONTINUE: /* XXX It would be nice to do some sanity checking here. Does the resource exist? Should the resource accept post requests? If @@ -2284,20 +2284,20 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) now, just optimistically tell the client to send their message body. */ if (req->ntoread > 0) { - /* ntoread is ev_int64_t, max_body_size is ev_uint64_t */ - if ((req->evcon->max_body_size <= EV_INT64_MAX) && - (ev_uint64_t)req->ntoread > req->evcon->max_body_size) { - evhttp_lingering_fail(evcon, req); + /* ntoread is ev_int64_t, max_body_size is ev_uint64_t */ + if ((req->evcon->max_body_size <= EV_INT64_MAX) && + (ev_uint64_t)req->ntoread > req->evcon->max_body_size) { + evhttp_lingering_fail(evcon, req); return; } } if (!evbuffer_get_length(bufferevent_get_input(evcon->bufev))) evhttp_send_continue(evcon, req); - break; - case OTHER: - evhttp_send_error(req, HTTP_EXPECTATIONFAILED, NULL); - return; - case NO: break; + break; + case OTHER: + evhttp_send_error(req, HTTP_EXPECTATIONFAILED, NULL); + return; + case NO: break; } evhttp_read_body(evcon, req); @@ -2310,12 +2310,12 @@ evhttp_read_firstline(struct evhttp_connection *evcon, { enum message_read_status res; - res = evhttp_parse_firstline_(req, bufferevent_get_input(evcon->bufev)); + res = evhttp_parse_firstline_(req, bufferevent_get_input(evcon->bufev)); if (res == DATA_CORRUPTED || res == DATA_TOO_LONG) { /* Error while reading, terminate */ event_debug(("%s: bad header lines on "EV_SOCK_FMT"\n", __func__, EV_SOCK_ARG(evcon->fd))); - evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); + evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); return; } else if (res == MORE_DATA_EXPECTED) { /* Need more header lines */ @@ -2333,25 +2333,25 @@ evhttp_read_header(struct evhttp_connection *evcon, enum message_read_status res; evutil_socket_t fd = evcon->fd; - res = evhttp_parse_headers_(req, bufferevent_get_input(evcon->bufev)); + res = evhttp_parse_headers_(req, bufferevent_get_input(evcon->bufev)); if (res == DATA_CORRUPTED || res == DATA_TOO_LONG) { /* Error while reading, terminate */ event_debug(("%s: bad header lines on "EV_SOCK_FMT"\n", __func__, EV_SOCK_ARG(fd))); - evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); + evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); return; } else if (res == MORE_DATA_EXPECTED) { /* Need more header lines */ return; } - /* Callback can shut down connection with negative return value */ - if (req->header_cb != NULL) { - if ((*req->header_cb)(req, req->cb_arg) < 0) { - evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); - return; - } - } + /* Callback can shut down connection with negative return value */ + if (req->header_cb != NULL) { + if ((*req->header_cb)(req, req->cb_arg) < 0) { + evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); + return; + } + } /* Done reading headers, do the real work */ switch (req->kind) { @@ -2365,9 +2365,9 @@ evhttp_read_header(struct evhttp_connection *evcon, case EVHTTP_RESPONSE: /* Start over if we got a 100 Continue response. */ if (req->response_code == 100) { - struct evbuffer *output = bufferevent_get_output(evcon->bufev); - evbuffer_add_buffer(output, req->output_buffer); - evhttp_start_write_(evcon); + struct evbuffer *output = bufferevent_get_output(evcon->bufev); + evbuffer_add_buffer(output, req->output_buffer); + evhttp_start_write_(evcon); return; } if (!evhttp_response_needs_body(req)) { @@ -2387,7 +2387,7 @@ evhttp_read_header(struct evhttp_connection *evcon, default: event_warnx("%s: bad header on "EV_SOCK_FMT, __func__, EV_SOCK_ARG(fd)); - evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); + evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); break; } /* request may have been freed above */ @@ -2428,14 +2428,14 @@ struct evhttp_connection *evhttp_connection_base_bufferevent_factory_new( } struct evhttp_connection * -evhttp_connection_new(const char *address, ev_uint16_t port) +evhttp_connection_new(const char *address, ev_uint16_t port) { return (evhttp_connection_base_new(NULL, NULL, address, port)); } struct evhttp_connection * evhttp_connection_base_bufferevent_new(struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, - const char *address, ev_uint16_t port) + const char *address, ev_uint16_t port) { struct evhttp_connection *evcon = NULL; @@ -2452,43 +2452,43 @@ evhttp_connection_base_bufferevent_new(struct event_base *base, struct evdns_bas evcon->max_headers_size = EV_SIZE_MAX; evcon->max_body_size = EV_SIZE_MAX; - evutil_timerclear(&evcon->timeout); + evutil_timerclear(&evcon->timeout); evcon->retry_cnt = evcon->retry_max = 0; if ((evcon->address = mm_strdup(address)) == NULL) { event_warn("%s: strdup failed", __func__); goto error; } - + if (bev == NULL) { - if (!(bev = bufferevent_socket_new(base, -1, 0))) { - event_warn("%s: bufferevent_socket_new failed", __func__); + if (!(bev = bufferevent_socket_new(base, -1, 0))) { + event_warn("%s: bufferevent_socket_new failed", __func__); goto error; } } - bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon); - evcon->bufev = bev; - + bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon); + evcon->bufev = bev; + evcon->state = EVCON_DISCONNECTED; TAILQ_INIT(&evcon->requests); - evcon->initial_retry_timeout.tv_sec = 2; - evcon->initial_retry_timeout.tv_usec = 0; - + evcon->initial_retry_timeout.tv_sec = 2; + evcon->initial_retry_timeout.tv_usec = 0; + if (base != NULL) { evcon->base = base; - if (bufferevent_get_base(bev) != base) - bufferevent_base_set(base, evcon->bufev); + if (bufferevent_get_base(bev) != base) + bufferevent_base_set(base, evcon->bufev); } - event_deferred_cb_init_( - &evcon->read_more_deferred_cb, - bufferevent_get_priority(bev), + event_deferred_cb_init_( + &evcon->read_more_deferred_cb, + bufferevent_get_priority(bev), evhttp_deferred_read_cb, evcon); evcon->dns_base = dnsbase; - evcon->ai_family = AF_UNSPEC; + evcon->ai_family = AF_UNSPEC; return (evcon); @@ -2498,46 +2498,46 @@ evhttp_connection_base_bufferevent_new(struct event_base *base, struct evdns_bas return (NULL); } -struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon) +struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon) { return evcon->bufev; } -struct evhttp * -evhttp_connection_get_server(struct evhttp_connection *evcon) +struct evhttp * +evhttp_connection_get_server(struct evhttp_connection *evcon) { - return evcon->http_server; -} + return evcon->http_server; +} struct evhttp_connection * evhttp_connection_base_new(struct event_base *base, struct evdns_base *dnsbase, - const char *address, ev_uint16_t port) + const char *address, ev_uint16_t port) { return evhttp_connection_base_bufferevent_new(base, dnsbase, NULL, address, port); } -void evhttp_connection_set_family(struct evhttp_connection *evcon, - int family) -{ - evcon->ai_family = family; -} - -int evhttp_connection_set_flags(struct evhttp_connection *evcon, - int flags) -{ - int avail_flags = 0; - avail_flags |= EVHTTP_CON_REUSE_CONNECTED_ADDR; - avail_flags |= EVHTTP_CON_READ_ON_WRITE_ERROR; - - if (flags & ~avail_flags || flags > EVHTTP_CON_PUBLIC_FLAGS_END) - return 1; - evcon->flags &= ~avail_flags; - - evcon->flags |= flags; - - return 0; -} - +void evhttp_connection_set_family(struct evhttp_connection *evcon, + int family) +{ + evcon->ai_family = family; +} + +int evhttp_connection_set_flags(struct evhttp_connection *evcon, + int flags) +{ + int avail_flags = 0; + avail_flags |= EVHTTP_CON_REUSE_CONNECTED_ADDR; + avail_flags |= EVHTTP_CON_READ_ON_WRITE_ERROR; + + if (flags & ~avail_flags || flags > EVHTTP_CON_PUBLIC_FLAGS_END) + return 1; + evcon->flags &= ~avail_flags; + + evcon->flags |= flags; + + return 0; +} + void evhttp_connection_set_base(struct evhttp_connection *evcon, struct event_base *base) @@ -2552,44 +2552,44 @@ void evhttp_connection_set_timeout(struct evhttp_connection *evcon, int timeout_in_secs) { - if (timeout_in_secs == -1) - evhttp_connection_set_timeout_tv(evcon, NULL); - else { - struct timeval tv; - tv.tv_sec = timeout_in_secs; - tv.tv_usec = 0; - evhttp_connection_set_timeout_tv(evcon, &tv); - } -} - -void -evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, - const struct timeval* tv) -{ - if (tv) { - evcon->timeout = *tv; - bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); - } else { - const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 }; - const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 }; - evutil_timerclear(&evcon->timeout); - bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); - } -} - -void -evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, - const struct timeval *tv) -{ - if (tv) { - evcon->initial_retry_timeout = *tv; - } else { - evutil_timerclear(&evcon->initial_retry_timeout); - evcon->initial_retry_timeout.tv_sec = 2; - } + if (timeout_in_secs == -1) + evhttp_connection_set_timeout_tv(evcon, NULL); + else { + struct timeval tv; + tv.tv_sec = timeout_in_secs; + tv.tv_usec = 0; + evhttp_connection_set_timeout_tv(evcon, &tv); + } +} + +void +evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, + const struct timeval* tv) +{ + if (tv) { + evcon->timeout = *tv; + bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); + } else { + const struct timeval read_tv = { HTTP_READ_TIMEOUT, 0 }; + const struct timeval write_tv = { HTTP_WRITE_TIMEOUT, 0 }; + evutil_timerclear(&evcon->timeout); + bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); + } } void +evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, + const struct timeval *tv) +{ + if (tv) { + evcon->initial_retry_timeout = *tv; + } else { + evutil_timerclear(&evcon->initial_retry_timeout); + evcon->initial_retry_timeout.tv_sec = 2; + } +} + +void evhttp_connection_set_retries(struct evhttp_connection *evcon, int retry_max) { @@ -2612,24 +2612,24 @@ evhttp_connection_get_peer(struct evhttp_connection *evcon, *port = evcon->port; } -const struct sockaddr* -evhttp_connection_get_addr(struct evhttp_connection *evcon) -{ - return bufferevent_socket_get_conn_address_(evcon->bufev); -} - +const struct sockaddr* +evhttp_connection_get_addr(struct evhttp_connection *evcon) +{ + return bufferevent_socket_get_conn_address_(evcon->bufev); +} + int -evhttp_connection_connect_(struct evhttp_connection *evcon) +evhttp_connection_connect_(struct evhttp_connection *evcon) { int old_state = evcon->state; - const char *address = evcon->address; - const struct sockaddr *sa = evhttp_connection_get_addr(evcon); - int ret; + const char *address = evcon->address; + const struct sockaddr *sa = evhttp_connection_get_addr(evcon); + int ret; if (evcon->state == EVCON_CONNECTING) return (0); - evhttp_connection_reset_(evcon); + evhttp_connection_reset_(evcon); EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING)); evcon->flags |= EVHTTP_CON_OUTGOING; @@ -2643,11 +2643,11 @@ evhttp_connection_connect_(struct evhttp_connection *evcon) return (-1); } - if (bufferevent_setfd(evcon->bufev, evcon->fd)) - return (-1); + if (bufferevent_setfd(evcon->bufev, evcon->fd)) + return (-1); } else { - if (bufferevent_setfd(evcon->bufev, -1)) - return (-1); + if (bufferevent_setfd(evcon->bufev, -1)) + return (-1); } /* Set up a callback for successful connection setup */ @@ -2656,32 +2656,32 @@ evhttp_connection_connect_(struct evhttp_connection *evcon) NULL /* evhttp_write_cb */, evhttp_connection_cb, evcon); - if (!evutil_timerisset(&evcon->timeout)) { - const struct timeval conn_tv = { HTTP_CONNECT_TIMEOUT, 0 }; - bufferevent_set_timeouts(evcon->bufev, &conn_tv, &conn_tv); - } else { - bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); - } + if (!evutil_timerisset(&evcon->timeout)) { + const struct timeval conn_tv = { HTTP_CONNECT_TIMEOUT, 0 }; + bufferevent_set_timeouts(evcon->bufev, &conn_tv, &conn_tv); + } else { + bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); + } /* make sure that we get a write callback */ - if (bufferevent_enable(evcon->bufev, EV_WRITE)) - return (-1); + if (bufferevent_enable(evcon->bufev, EV_WRITE)) + return (-1); evcon->state = EVCON_CONNECTING; - if (evcon->flags & EVHTTP_CON_REUSE_CONNECTED_ADDR && - sa && - (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)) { - int socklen = sizeof(struct sockaddr_in); - if (sa->sa_family == AF_INET6) { - socklen = sizeof(struct sockaddr_in6); - } - ret = bufferevent_socket_connect(evcon->bufev, sa, socklen); - } else { - ret = bufferevent_socket_connect_hostname(evcon->bufev, - evcon->dns_base, evcon->ai_family, address, evcon->port); - } - - if (ret < 0) { + if (evcon->flags & EVHTTP_CON_REUSE_CONNECTED_ADDR && + sa && + (sa->sa_family == AF_INET || sa->sa_family == AF_INET6)) { + int socklen = sizeof(struct sockaddr_in); + if (sa->sa_family == AF_INET6) { + socklen = sizeof(struct sockaddr_in6); + } + ret = bufferevent_socket_connect(evcon->bufev, sa, socklen); + } else { + ret = bufferevent_socket_connect_hostname(evcon->bufev, + evcon->dns_base, evcon->ai_family, address, evcon->port); + } + + if (ret < 0) { evcon->state = old_state; event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed", __func__, evcon->address); @@ -2714,7 +2714,7 @@ evhttp_make_request(struct evhttp_connection *evcon, mm_free(req->uri); if ((req->uri = mm_strdup(uri)) == NULL) { event_warn("%s: strdup", __func__); - evhttp_request_free_auto(req); + evhttp_request_free_auto(req); return (-1); } @@ -2728,23 +2728,23 @@ evhttp_make_request(struct evhttp_connection *evcon, req->evcon = evcon; EVUTIL_ASSERT(!(req->flags & EVHTTP_REQ_OWN_CONNECTION)); - TAILQ_INSERT_TAIL(&evcon->requests, req, next); - - /* We do not want to conflict with retry_ev */ - if (evcon->retry_cnt) - return (0); + TAILQ_INSERT_TAIL(&evcon->requests, req, next); + /* We do not want to conflict with retry_ev */ + if (evcon->retry_cnt) + return (0); + /* If the connection object is not connected; make it so */ if (!evhttp_connected(evcon)) { - int res = evhttp_connection_connect_(evcon); - /* evhttp_connection_fail_(), which is called through - * evhttp_connection_connect_(), assumes that req lies in - * evcon->requests. Thus, enqueue the request in advance and - * remove it in the error case. */ - if (res != 0) - TAILQ_REMOVE(&evcon->requests, req, next); + int res = evhttp_connection_connect_(evcon); + /* evhttp_connection_fail_(), which is called through + * evhttp_connection_connect_(), assumes that req lies in + * evcon->requests. Thus, enqueue the request in advance and + * remove it in the error case. */ + if (res != 0) + TAILQ_REMOVE(&evcon->requests, req, next); - return (res); + return (res); } /* @@ -2768,8 +2768,8 @@ evhttp_cancel_request(struct evhttp_request *req) /* it's currently being worked on, so reset * the connection. */ - evhttp_connection_fail_(evcon, - EVREQ_HTTP_REQUEST_CANCEL); + evhttp_connection_fail_(evcon, + EVREQ_HTTP_REQUEST_CANCEL); /* connection fail freed the request */ return; @@ -2781,7 +2781,7 @@ evhttp_cancel_request(struct evhttp_request *req) } } - evhttp_request_free_auto(req); + evhttp_request_free_auto(req); } /* @@ -2790,11 +2790,11 @@ evhttp_cancel_request(struct evhttp_request *req) */ void -evhttp_start_read_(struct evhttp_connection *evcon) +evhttp_start_read_(struct evhttp_connection *evcon) { bufferevent_disable(evcon->bufev, EV_WRITE); bufferevent_enable(evcon->bufev, EV_READ); - + evcon->state = EVCON_READING_FIRSTLINE; /* Reset the bufferevent callbacks */ bufferevent_setcb(evcon->bufev, @@ -2806,21 +2806,21 @@ evhttp_start_read_(struct evhttp_connection *evcon) /* If there's still data pending, process it next time through the * loop. Don't do it now; that could get recusive. */ if (evbuffer_get_length(bufferevent_get_input(evcon->bufev))) { - event_deferred_cb_schedule_(get_deferred_queue(evcon), + event_deferred_cb_schedule_(get_deferred_queue(evcon), &evcon->read_more_deferred_cb); } } -void -evhttp_start_write_(struct evhttp_connection *evcon) -{ - bufferevent_disable(evcon->bufev, EV_WRITE); - bufferevent_enable(evcon->bufev, EV_READ); - - evcon->state = EVCON_WRITING; - evhttp_write_buffer(evcon, evhttp_write_connectioncb, NULL); -} - +void +evhttp_start_write_(struct evhttp_connection *evcon) +{ + bufferevent_disable(evcon->bufev, EV_WRITE); + bufferevent_enable(evcon->bufev, EV_READ); + + evcon->state = EVCON_WRITING; + evhttp_write_buffer(evcon, evhttp_write_connectioncb, NULL); +} + static void evhttp_send_done(struct evhttp_connection *evcon, void *arg) { @@ -2828,14 +2828,14 @@ evhttp_send_done(struct evhttp_connection *evcon, void *arg) struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); TAILQ_REMOVE(&evcon->requests, req, next); - if (req->on_complete_cb != NULL) { - req->on_complete_cb(req, req->on_complete_cb_arg); - } - + if (req->on_complete_cb != NULL) { + req->on_complete_cb(req, req->on_complete_cb_arg); + } + need_close = (REQ_VERSION_BEFORE(req, 1, 1) && - !evhttp_is_connection_keepalive(req->input_headers)) || - evhttp_is_request_connection_close(req); + !evhttp_is_connection_keepalive(req->input_headers)) || + evhttp_is_request_connection_close(req); EVUTIL_ASSERT(req->flags & EVHTTP_REQ_OWN_CONNECTION); evhttp_request_free(req); @@ -2875,11 +2875,11 @@ evhttp_send_error(struct evhttp_request *req, int error, const char *reason) reason = evhttp_response_phrase_internal(error); } - evhttp_response_code_(req, error, reason); + evhttp_response_code_(req, error, reason); evbuffer_add_printf(buf, ERR_FORMAT, error, reason, reason); - evhttp_send_page_(req, buf); + evhttp_send_page_(req, buf); evbuffer_free(buf); #undef ERR_FORMAT @@ -2916,7 +2916,7 @@ void evhttp_send_reply(struct evhttp_request *req, int code, const char *reason, struct evbuffer *databuf) { - evhttp_response_code_(req, code, reason); + evhttp_response_code_(req, code, reason); evhttp_send(req, databuf); } @@ -2925,11 +2925,11 @@ void evhttp_send_reply_start(struct evhttp_request *req, int code, const char *reason) { - evhttp_response_code_(req, code, reason); - - if (req->evcon == NULL) - return; - + evhttp_response_code_(req, code, reason); + + if (req->evcon == NULL) + return; + if (evhttp_find_header(req->output_headers, "Content-Length") == NULL && REQ_VERSION_ATLEAST(req, 1, 1) && evhttp_response_needs_body(req)) { @@ -2949,8 +2949,8 @@ evhttp_send_reply_start(struct evhttp_request *req, int code, } void -evhttp_send_reply_chunk_with_cb(struct evhttp_request *req, struct evbuffer *databuf, - void (*cb)(struct evhttp_connection *, void *), void *arg) +evhttp_send_reply_chunk_with_cb(struct evhttp_request *req, struct evbuffer *databuf, + void (*cb)(struct evhttp_connection *, void *), void *arg) { struct evhttp_connection *evcon = req->evcon; struct evbuffer *output; @@ -2972,15 +2972,15 @@ evhttp_send_reply_chunk_with_cb(struct evhttp_request *req, struct evbuffer *dat if (req->chunked) { evbuffer_add(output, "\r\n", 2); } - evhttp_write_buffer(evcon, cb, arg); + evhttp_write_buffer(evcon, cb, arg); } void -evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf) -{ - evhttp_send_reply_chunk_with_cb(req, databuf, NULL, NULL); -} -void +evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf) +{ + evhttp_send_reply_chunk_with_cb(req, databuf, NULL, NULL); +} +void evhttp_send_reply_end(struct evhttp_request *req) { struct evhttp_connection *evcon = req->evcon; @@ -3101,7 +3101,7 @@ evhttp_response_phrase_internal(int code) } void -evhttp_response_code_(struct evhttp_request *req, int code, const char *reason) +evhttp_response_code_(struct evhttp_request *req, int code, const char *reason) { req->kind = EVHTTP_RESPONSE; req->response_code = code; @@ -3117,7 +3117,7 @@ evhttp_response_code_(struct evhttp_request *req, int code, const char *reason) } void -evhttp_send_page_(struct evhttp_request *req, struct evbuffer *databuf) +evhttp_send_page_(struct evhttp_request *req, struct evbuffer *databuf) { if (!req->major || !req->minor) { req->major = 1; @@ -3125,7 +3125,7 @@ evhttp_send_page_(struct evhttp_request *req, struct evbuffer *databuf) } if (req->kind != EVHTTP_RESPONSE) - evhttp_response_code_(req, 200, "OK"); + evhttp_response_code_(req, 200, "OK"); evhttp_clear_headers(req->output_headers); evhttp_add_header(req->output_headers, "Content-Type", "text/html"); @@ -3169,33 +3169,33 @@ evhttp_uriencode(const char *uri, ev_ssize_t len, int space_as_plus) { struct evbuffer *buf = evbuffer_new(); const char *p, *end; - char *result = NULL; - - if (!buf) { - goto out; - } - - if (len >= 0) { - if (uri + len < uri) { - goto out; - } - - end = uri + len; - } else { - size_t slen = strlen(uri); - - if (slen >= EV_SSIZE_MAX) { - /* we don't want to mix signed and unsigned */ - goto out; - } - - if (uri + slen < uri) { - goto out; - } - - end = uri + slen; - } - + char *result = NULL; + + if (!buf) { + goto out; + } + + if (len >= 0) { + if (uri + len < uri) { + goto out; + } + + end = uri + len; + } else { + size_t slen = strlen(uri); + + if (slen >= EV_SSIZE_MAX) { + /* we don't want to mix signed and unsigned */ + goto out; + } + + if (uri + slen < uri) { + goto out; + } + + end = uri + slen; + } + for (p = uri; p < end; p++) { if (CHAR_IS_UNRESERVED(*p)) { evbuffer_add(buf, p, 1); @@ -3205,17 +3205,17 @@ evhttp_uriencode(const char *uri, ev_ssize_t len, int space_as_plus) evbuffer_add_printf(buf, "%%%02X", (unsigned char)(*p)); } } - + evbuffer_add(buf, "", 1); /* NUL-terminator. */ result = mm_malloc(evbuffer_get_length(buf)); - + if (result) evbuffer_remove(buf, result, evbuffer_get_length(buf)); -out: - if (buf) - evbuffer_free(buf); - return result; +out: + if (buf) + evbuffer_free(buf); + return result; } char * @@ -3230,7 +3230,7 @@ evhttp_encode_uri(const char *str) * a ?. -1 is deprecated. * @return the number of bytes written to 'ret'. */ -int +int evhttp_decode_uri_internal( const char *uri, size_t length, char *ret, int decode_plus_ctl) { @@ -3246,8 +3246,8 @@ evhttp_decode_uri_internal( decode_plus = 1; } else if (c == '+' && decode_plus) { c = ' '; - } else if ((i + 2) < length && c == '%' && - EVUTIL_ISXDIGIT_(uri[i+1]) && EVUTIL_ISXDIGIT_(uri[i+2])) { + } else if ((i + 2) < length && c == '%' && + EVUTIL_ISXDIGIT_(uri[i+1]) && EVUTIL_ISXDIGIT_(uri[i+2])) { char tmp[3]; tmp[0] = uri[i+1]; tmp[1] = uri[i+2]; @@ -3443,7 +3443,7 @@ prefix_suffix_match(const char *pattern, const char *name, int ignorecase) default: if (c != *name) { if (!ignorecase || - EVUTIL_TOLOWER_(c) != EVUTIL_TOLOWER_(*name)) + EVUTIL_TOLOWER_(c) != EVUTIL_TOLOWER_(*name)) return (0); } ++name; @@ -3534,10 +3534,10 @@ evhttp_handle_request(struct evhttp_request *req, void *arg) /* we have a new request on which the user needs to take action */ req->userdone = 0; - bufferevent_disable(req->evcon->bufev, EV_READ); - + bufferevent_disable(req->evcon->bufev, EV_READ); + if (req->type == 0 || req->uri == NULL) { - evhttp_send_error(req, req->response_code, NULL); + evhttp_send_error(req, req->response_code, NULL); return; } @@ -3586,13 +3586,13 @@ evhttp_handle_request(struct evhttp_request *req, void *arg) return; } - evhttp_response_code_(req, HTTP_NOTFOUND, "Not Found"); + evhttp_response_code_(req, HTTP_NOTFOUND, "Not Found"); evbuffer_add_printf(buf, ERR_FORMAT, escaped_html); mm_free(escaped_html); - evhttp_send_page_(req, buf); + evhttp_send_page_(req, buf); evbuffer_free(buf); #undef ERR_FORMAT @@ -3623,16 +3623,16 @@ evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint { evutil_socket_t fd; struct evhttp_bound_socket *bound; - int serrno; + int serrno; if ((fd = bind_socket(address, port, 1 /*reuse*/)) == -1) return (NULL); if (listen(fd, 128) == -1) { - serrno = EVUTIL_SOCKET_ERROR(); + serrno = EVUTIL_SOCKET_ERROR(); event_sock_warn(fd, "%s: listen", __func__); evutil_closesocket(fd); - EVUTIL_SET_SOCKET_ERROR(serrno); + EVUTIL_SET_SOCKET_ERROR(serrno); return (NULL); } @@ -3657,17 +3657,17 @@ evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd) return (0); } -void -evhttp_foreach_bound_socket(struct evhttp *http, - evhttp_bound_socket_foreach_fn *function, - void *argument) -{ - struct evhttp_bound_socket *bound; - - TAILQ_FOREACH(bound, &http->sockets, next) - function(bound, argument); -} +void +evhttp_foreach_bound_socket(struct evhttp *http, + evhttp_bound_socket_foreach_fn *function, + void *argument) +{ + struct evhttp_bound_socket *bound; + TAILQ_FOREACH(bound, &http->sockets, next) + function(bound, argument); +} + struct evhttp_bound_socket * evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd) { @@ -3737,10 +3737,10 @@ evhttp_new_object(void) return (NULL); } - evutil_timerclear(&http->timeout); + evutil_timerclear(&http->timeout); evhttp_set_max_headers_size(http, EV_SIZE_MAX); evhttp_set_max_body_size(http, EV_SIZE_MAX); - evhttp_set_default_content_type(http, "text/html; charset=ISO-8859-1"); + evhttp_set_default_content_type(http, "text/html; charset=ISO-8859-1"); evhttp_set_allowed_methods(http, EVHTTP_REQ_GET | EVHTTP_REQ_POST | @@ -3775,7 +3775,7 @@ evhttp_new(struct event_base *base) */ struct evhttp * -evhttp_start(const char *address, ev_uint16_t port) +evhttp_start(const char *address, ev_uint16_t port) { struct evhttp *http = NULL; @@ -3909,41 +3909,41 @@ evhttp_remove_server_alias(struct evhttp *http, const char *alias) void evhttp_set_timeout(struct evhttp* http, int timeout_in_secs) { - if (timeout_in_secs == -1) { - evhttp_set_timeout_tv(http, NULL); - } else { - struct timeval tv; - tv.tv_sec = timeout_in_secs; - tv.tv_usec = 0; - evhttp_set_timeout_tv(http, &tv); - } -} - -void -evhttp_set_timeout_tv(struct evhttp* http, const struct timeval* tv) -{ - if (tv) { - http->timeout = *tv; - } else { - evutil_timerclear(&http->timeout); - } -} - -int evhttp_set_flags(struct evhttp *http, int flags) -{ - int avail_flags = 0; - avail_flags |= EVHTTP_SERVER_LINGERING_CLOSE; - - if (flags & ~avail_flags) - return 1; - http->flags &= ~avail_flags; - - http->flags |= flags; - - return 0; + if (timeout_in_secs == -1) { + evhttp_set_timeout_tv(http, NULL); + } else { + struct timeval tv; + tv.tv_sec = timeout_in_secs; + tv.tv_usec = 0; + evhttp_set_timeout_tv(http, &tv); + } } void +evhttp_set_timeout_tv(struct evhttp* http, const struct timeval* tv) +{ + if (tv) { + http->timeout = *tv; + } else { + evutil_timerclear(&http->timeout); + } +} + +int evhttp_set_flags(struct evhttp *http, int flags) +{ + int avail_flags = 0; + avail_flags |= EVHTTP_SERVER_LINGERING_CLOSE; + + if (flags & ~avail_flags) + return 1; + http->flags &= ~avail_flags; + + http->flags |= flags; + + return 0; +} + +void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size) { if (max_headers_size < 0) @@ -3962,18 +3962,18 @@ evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size) } void -evhttp_set_default_content_type(struct evhttp *http, - const char *content_type) { - http->default_content_type = content_type; -} - -void +evhttp_set_default_content_type(struct evhttp *http, + const char *content_type) { + http->default_content_type = content_type; +} + +void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods) { http->allowed_methods = methods; } -int +int evhttp_set_cb_internal(struct evhttp *http, const char *uri, void (*cb)(struct evhttp_request *, void *), void *cbarg, int chunked) { @@ -3995,8 +3995,8 @@ evhttp_set_cb_internal(struct evhttp *http, const char *uri, mm_free(http_cb); return (-3); } - http_cb->cb = cb; - http_cb->cbarg = cbarg; + http_cb->cb = cb; + http_cb->cbarg = cbarg; http_cb->chunked = chunked; TAILQ_INSERT_TAIL(&http->callbacks, http_cb, next); @@ -4172,28 +4172,28 @@ evhttp_request_set_chunked_cb(struct evhttp_request *req, req->chunk_cb_arg = arg; } -void -evhttp_request_set_header_cb(struct evhttp_request *req, - int (*cb)(struct evhttp_request *, void *)) -{ - req->header_cb = cb; -} - -void -evhttp_request_set_error_cb(struct evhttp_request *req, - void (*cb)(enum evhttp_request_error, void *)) -{ - req->error_cb = cb; -} - -void -evhttp_request_set_on_complete_cb(struct evhttp_request *req, - void (*cb)(struct evhttp_request *, void *), void *cb_arg) -{ - req->on_complete_cb = cb; - req->on_complete_cb_arg = cb_arg; -} - +void +evhttp_request_set_header_cb(struct evhttp_request *req, + int (*cb)(struct evhttp_request *, void *)) +{ + req->header_cb = cb; +} + +void +evhttp_request_set_error_cb(struct evhttp_request *req, + void (*cb)(enum evhttp_request_error, void *)) +{ + req->error_cb = cb; +} + +void +evhttp_request_set_on_complete_cb(struct evhttp_request *req, + void (*cb)(struct evhttp_request *, void *), void *cb_arg) +{ + req->on_complete_cb = cb; + req->on_complete_cb_arg = cb_arg; +} + /* * Allows for inspection of the request URI */ @@ -4232,7 +4232,7 @@ evhttp_request_get_host(struct evhttp_request *req) to be consistent with uri_elems case above. */ if (host) { p = host + strlen(host) - 1; - while (p > host && EVUTIL_ISDIGIT_(*p)) + while (p > host && EVUTIL_ISDIGIT_(*p)) --p; if (p > host && *p == ':') { len = p - host; @@ -4262,12 +4262,12 @@ evhttp_request_get_response_code(const struct evhttp_request *req) return req->response_code; } -const char * -evhttp_request_get_response_code_line(const struct evhttp_request *req) -{ - return req->response_code_line; -} - +const char * +evhttp_request_get_response_code_line(const struct evhttp_request *req) +{ + return req->response_code_line; +} + /** Returns the input headers */ struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req) { @@ -4307,13 +4307,13 @@ evhttp_get_request_connection( char *hostname = NULL, *portname = NULL; struct bufferevent* bev = NULL; -#ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN - if (sa->sa_family == AF_UNIX) { - struct sockaddr_un *sa_un = (struct sockaddr_un *)sa; - sa_un->sun_path[0] = '\0'; - } -#endif - +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_UN + if (sa->sa_family == AF_UNIX) { + struct sockaddr_un *sa_un = (struct sockaddr_un *)sa; + sa_un->sun_path[0] = '\0'; + } +#endif + name_from_addr(sa, salen, &hostname, &portname); if (hostname == NULL || portname == NULL) { if (hostname) mm_free(hostname); @@ -4337,27 +4337,27 @@ evhttp_get_request_connection( evcon->max_headers_size = http->default_max_headers_size; evcon->max_body_size = http->default_max_body_size; - if (http->flags & EVHTTP_SERVER_LINGERING_CLOSE) - evcon->flags |= EVHTTP_CON_LINGERING_CLOSE; + if (http->flags & EVHTTP_SERVER_LINGERING_CLOSE) + evcon->flags |= EVHTTP_CON_LINGERING_CLOSE; evcon->flags |= EVHTTP_CON_INCOMING; evcon->state = EVCON_READING_FIRSTLINE; evcon->fd = fd; - if (bufferevent_setfd(evcon->bufev, fd)) - goto err; - if (bufferevent_enable(evcon->bufev, EV_READ)) - goto err; - if (bufferevent_disable(evcon->bufev, EV_WRITE)) - goto err; - bufferevent_socket_set_conn_address_(evcon->bufev, sa, salen); + if (bufferevent_setfd(evcon->bufev, fd)) + goto err; + if (bufferevent_enable(evcon->bufev, EV_READ)) + goto err; + if (bufferevent_disable(evcon->bufev, EV_WRITE)) + goto err; + bufferevent_socket_set_conn_address_(evcon->bufev, sa, salen); return (evcon); - -err: - evhttp_connection_free(evcon); - return (NULL); + +err: + evhttp_connection_free(evcon); + return (NULL); } static int @@ -4390,7 +4390,7 @@ evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon) req->kind = EVHTTP_REQUEST; - evhttp_start_read_(evcon); + evhttp_start_read_(evcon); return (0); } @@ -4410,8 +4410,8 @@ evhttp_get_request(struct evhttp *http, evutil_socket_t fd, } /* the timeout can be used by the server to close idle connections */ - if (evutil_timerisset(&http->timeout)) - evhttp_connection_set_timeout_tv(evcon, &http->timeout); + if (evutil_timerisset(&http->timeout)) + evhttp_connection_set_timeout_tv(evcon, &http->timeout); /* * if we want to accept more than one request on a connection, @@ -4438,7 +4438,7 @@ name_from_addr(struct sockaddr *sa, ev_socklen_t salen, char strport[NI_MAXSERV]; int ni_result; -#ifdef EVENT__HAVE_GETNAMEINFO +#ifdef EVENT__HAVE_GETNAMEINFO ni_result = getnameinfo(sa, salen, ntop, sizeof(ntop), strport, sizeof(strport), NI_NUMERICHOST|NI_NUMERICSERV); @@ -4475,15 +4475,15 @@ create_bind_socket_nonblock(struct evutil_addrinfo *ai, int reuse) int serrno; /* Create listen socket */ - fd = evutil_socket_(ai ? ai->ai_family : AF_INET, - SOCK_STREAM|EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC, 0); + fd = evutil_socket_(ai ? ai->ai_family : AF_INET, + SOCK_STREAM|EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC, 0); if (fd == -1) { event_sock_warn(-1, "socket"); return (-1); } #if defined IPV6_V6ONLY - int v6opt = 1; + int v6opt = 1; if (ai->ai_family == AF_INET6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6opt, sizeof(v6opt)) < 0) goto out; #endif @@ -4620,10 +4620,10 @@ scheme_ok(const char *s, const char *eos) EVUTIL_ASSERT(eos >= s); if (s == eos) return 0; - if (!EVUTIL_ISALPHA_(*s)) + if (!EVUTIL_ISALPHA_(*s)) return 0; while (++s < eos) { - if (! EVUTIL_ISALNUM_(*s) && + if (! EVUTIL_ISALNUM_(*s) && *s != '+' && *s != '-' && *s != '.') return 0; } @@ -4642,8 +4642,8 @@ userinfo_ok(const char *s, const char *eos) *s == ':') ++s; else if (*s == '%' && s+2 < eos && - EVUTIL_ISXDIGIT_(s[1]) && - EVUTIL_ISXDIGIT_(s[2])) + EVUTIL_ISXDIGIT_(s[1]) && + EVUTIL_ISXDIGIT_(s[2])) s += 3; else return 0; @@ -4659,8 +4659,8 @@ regname_ok(const char *s, const char *eos) strchr(SUBDELIMS, *s)) ++s; else if (*s == '%' && - EVUTIL_ISXDIGIT_(s[1]) && - EVUTIL_ISXDIGIT_(s[2])) + EVUTIL_ISXDIGIT_(s[1]) && + EVUTIL_ISXDIGIT_(s[2])) s += 3; else return 0; @@ -4673,13 +4673,13 @@ parse_port(const char *s, const char *eos) { int portnum = 0; while (s < eos) { - if (! EVUTIL_ISDIGIT_(*s)) + if (! EVUTIL_ISDIGIT_(*s)) return -1; portnum = (portnum * 10) + (*s - '0'); if (portnum < 0) return -1; - if (portnum > 65535) - return -1; + if (portnum > 65535) + return -1; ++s; } return portnum; @@ -4697,10 +4697,10 @@ bracket_addr_ok(const char *s, const char *eos) */ s += 2; /* skip [v */ --eos; - if (!EVUTIL_ISXDIGIT_(*s)) /*require at least one*/ + if (!EVUTIL_ISXDIGIT_(*s)) /*require at least one*/ return 0; while (s < eos && *s != '.') { - if (EVUTIL_ISXDIGIT_(*s)) + if (EVUTIL_ISXDIGIT_(*s)) ++s; else return 0; @@ -4760,7 +4760,7 @@ parse_authority(struct evhttp_uri *uri, char *s, char *eos) cp = s; } /* Optionally, we end with ":port" */ - for (port=eos-1; port >= cp && EVUTIL_ISDIGIT_(*port); --port) + for (port=eos-1; port >= cp && EVUTIL_ISDIGIT_(*port); --port) ; if (port >= cp && *port == ':') { if (port+1 == eos) /* Leave port unspecified; the RFC allows a @@ -4844,8 +4844,8 @@ end_of_path(char *cp, enum uri_part part, unsigned flags) strchr(SUBDELIMS, *cp) || *cp == ':' || *cp == '@' || *cp == '/') ++cp; - else if (*cp == '%' && EVUTIL_ISXDIGIT_(cp[1]) && - EVUTIL_ISXDIGIT_(cp[2])) + else if (*cp == '%' && EVUTIL_ISXDIGIT_(cp[1]) && + EVUTIL_ISXDIGIT_(cp[2])) cp += 3; else if (*cp == '?' && part != PART_PATH) ++cp; @@ -5002,53 +5002,53 @@ err: return NULL; } -static struct evhttp_uri * -evhttp_uri_parse_authority(char *source_uri) -{ - struct evhttp_uri *uri = mm_calloc(1, sizeof(struct evhttp_uri)); - char *end; - - if (uri == NULL) { - event_warn("%s: calloc", __func__); - goto err; - } - uri->port = -1; - uri->flags = 0; - - end = end_of_authority(source_uri); - if (parse_authority(uri, source_uri, end) < 0) - goto err; - - uri->path = mm_strdup(""); - if (uri->path == NULL) { - event_warn("%s: strdup", __func__); - goto err; - } - - return uri; -err: - if (uri) - evhttp_uri_free(uri); - return NULL; -} - +static struct evhttp_uri * +evhttp_uri_parse_authority(char *source_uri) +{ + struct evhttp_uri *uri = mm_calloc(1, sizeof(struct evhttp_uri)); + char *end; + + if (uri == NULL) { + event_warn("%s: calloc", __func__); + goto err; + } + uri->port = -1; + uri->flags = 0; + + end = end_of_authority(source_uri); + if (parse_authority(uri, source_uri, end) < 0) + goto err; + + uri->path = mm_strdup(""); + if (uri->path == NULL) { + event_warn("%s: strdup", __func__); + goto err; + } + + return uri; +err: + if (uri) + evhttp_uri_free(uri); + return NULL; +} + void evhttp_uri_free(struct evhttp_uri *uri) { -#define URI_FREE_STR_(f) \ +#define URI_FREE_STR_(f) \ if (uri->f) { \ mm_free(uri->f); \ } - URI_FREE_STR_(scheme); - URI_FREE_STR_(userinfo); - URI_FREE_STR_(host); - URI_FREE_STR_(path); - URI_FREE_STR_(query); - URI_FREE_STR_(fragment); + URI_FREE_STR_(scheme); + URI_FREE_STR_(userinfo); + URI_FREE_STR_(host); + URI_FREE_STR_(path); + URI_FREE_STR_(query); + URI_FREE_STR_(fragment); mm_free(uri); -#undef URI_FREE_STR_ +#undef URI_FREE_STR_ } char * @@ -5058,7 +5058,7 @@ evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit) size_t joined_size = 0; char *output = NULL; -#define URI_ADD_(f) evbuffer_add(tmp, uri->f, strlen(uri->f)) +#define URI_ADD_(f) evbuffer_add(tmp, uri->f, strlen(uri->f)) if (!uri || !buf || !limit) return NULL; @@ -5068,14 +5068,14 @@ evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit) return NULL; if (uri->scheme) { - URI_ADD_(scheme); + URI_ADD_(scheme); evbuffer_add(tmp, ":", 1); } if (uri->host) { evbuffer_add(tmp, "//", 2); if (uri->userinfo) evbuffer_add_printf(tmp,"%s@", uri->userinfo); - URI_ADD_(host); + URI_ADD_(host); if (uri->port >= 0) evbuffer_add_printf(tmp,":%d", uri->port); @@ -5084,16 +5084,16 @@ evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit) } if (uri->path) - URI_ADD_(path); + URI_ADD_(path); if (uri->query) { evbuffer_add(tmp, "?", 1); - URI_ADD_(query); + URI_ADD_(query); } if (uri->fragment) { evbuffer_add(tmp, "#", 1); - URI_ADD_(fragment); + URI_ADD_(fragment); } evbuffer_add(tmp, "\0", 1); /* NUL */ @@ -5112,7 +5112,7 @@ err: evbuffer_free(tmp); return output; -#undef URI_ADD_ +#undef URI_ADD_ } const char * @@ -5151,7 +5151,7 @@ evhttp_uri_get_fragment(const struct evhttp_uri *uri) return uri->fragment; } -#define URI_SET_STR_(f) do { \ +#define URI_SET_STR_(f) do { \ if (uri->f) \ mm_free(uri->f); \ if (f) { \ @@ -5170,7 +5170,7 @@ evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme) if (scheme && !scheme_ok(scheme, scheme+strlen(scheme))) return -1; - URI_SET_STR_(scheme); + URI_SET_STR_(scheme); return 0; } int @@ -5178,7 +5178,7 @@ evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo) { if (userinfo && !userinfo_ok(userinfo, userinfo+strlen(userinfo))) return -1; - URI_SET_STR_(userinfo); + URI_SET_STR_(userinfo); return 0; } int @@ -5194,7 +5194,7 @@ evhttp_uri_set_host(struct evhttp_uri *uri, const char *host) } } - URI_SET_STR_(host); + URI_SET_STR_(host); return 0; } int @@ -5214,7 +5214,7 @@ evhttp_uri_set_path(struct evhttp_uri *uri, const char *path) if (path && end_of_cpath(path, PART_PATH, uri->flags) != path+strlen(path)) return -1; - URI_SET_STR_(path); + URI_SET_STR_(path); return 0; } int @@ -5222,7 +5222,7 @@ evhttp_uri_set_query(struct evhttp_uri *uri, const char *query) { if (query && end_of_cpath(query, PART_QUERY, uri->flags) != query+strlen(query)) return -1; - URI_SET_STR_(query); + URI_SET_STR_(query); return 0; } int @@ -5230,6 +5230,6 @@ evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment) { if (fragment && end_of_cpath(fragment, PART_FRAGMENT, uri->flags) != fragment+strlen(fragment)) return -1; - URI_SET_STR_(fragment); + URI_SET_STR_(fragment); return 0; } diff --git a/contrib/libs/libevent/include/evdns.h b/contrib/libs/libevent/include/evdns.h index 8672db0369..45c36c8cb3 100644 --- a/contrib/libs/libevent/include/evdns.h +++ b/contrib/libs/libevent/include/evdns.h @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EVENT1_EVDNS_H_INCLUDED_ -#define EVENT1_EVDNS_H_INCLUDED_ - -/** @file evdns.h - - A dns subsystem for Libevent. - - The <evdns.h> header is deprecated in Libevent 2.0 and later; please - use <event2/evdns.h> instead. Depending on what functionality you - need, you may also want to include more of the other <event2/...> - headers. - */ - -#include <event.h> -#include <event2/dns.h> -#include <event2/dns_compat.h> -#include <event2/dns_struct.h> - -#endif /* EVENT1_EVDNS_H_INCLUDED_ */ +/* + * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT1_EVDNS_H_INCLUDED_ +#define EVENT1_EVDNS_H_INCLUDED_ + +/** @file evdns.h + + A dns subsystem for Libevent. + + The <evdns.h> header is deprecated in Libevent 2.0 and later; please + use <event2/evdns.h> instead. Depending on what functionality you + need, you may also want to include more of the other <event2/...> + headers. + */ + +#include <event.h> +#include <event2/dns.h> +#include <event2/dns_compat.h> +#include <event2/dns_struct.h> + +#endif /* EVENT1_EVDNS_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event.h b/contrib/libs/libevent/include/event.h index ba5186713b..dcf8af7a16 100644 --- a/contrib/libs/libevent/include/event.h +++ b/contrib/libs/libevent/include/event.h @@ -1,83 +1,83 @@ -/* - * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EVENT1_EVENT_H_INCLUDED_ -#define EVENT1_EVENT_H_INCLUDED_ - -/** @file event.h - - A library for writing event-driven network servers. - - The <event.h> header is deprecated in Libevent 2.0 and later; please - use <event2/event.h> instead. Depending on what functionality you - need, you may also want to include more of the other event2/ - headers. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef EVENT__HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#ifdef EVENT__HAVE_STDINT_H -#include <stdint.h> -#endif -#include <stdarg.h> - -/* For int types. */ -#include <evutil.h> - -#ifdef _WIN32 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include <winsock2.h> -#include <windows.h> -#undef WIN32_LEAN_AND_MEAN -#endif - -#include <event2/event_struct.h> -#include <event2/event.h> -#include <event2/event_compat.h> -#include <event2/buffer.h> -#include <event2/buffer_compat.h> -#include <event2/bufferevent.h> -#include <event2/bufferevent_struct.h> -#include <event2/bufferevent_compat.h> -#include <event2/tag.h> -#include <event2/tag_compat.h> - -#ifdef __cplusplus -} -#endif - -#endif /* EVENT1_EVENT_H_INCLUDED_ */ +/* + * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT1_EVENT_H_INCLUDED_ +#define EVENT1_EVENT_H_INCLUDED_ + +/** @file event.h + + A library for writing event-driven network servers. + + The <event.h> header is deprecated in Libevent 2.0 and later; please + use <event2/event.h> instead. Depending on what functionality you + need, you may also want to include more of the other event2/ + headers. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <event2/event-config.h> +#ifdef EVENT__HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#ifdef EVENT__HAVE_STDINT_H +#include <stdint.h> +#endif +#include <stdarg.h> + +/* For int types. */ +#include <evutil.h> + +#ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include <winsock2.h> +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN +#endif + +#include <event2/event_struct.h> +#include <event2/event.h> +#include <event2/event_compat.h> +#include <event2/buffer.h> +#include <event2/buffer_compat.h> +#include <event2/bufferevent.h> +#include <event2/bufferevent_struct.h> +#include <event2/bufferevent_compat.h> +#include <event2/tag.h> +#include <event2/tag_compat.h> + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT1_EVENT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/buffer.h b/contrib/libs/libevent/include/event2/buffer.h index 88af3ae141..fb776f5480 100644 --- a/contrib/libs/libevent/include/event2/buffer.h +++ b/contrib/libs/libevent/include/event2/buffer.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_BUFFER_H_INCLUDED_ -#define EVENT2_BUFFER_H_INCLUDED_ +#ifndef EVENT2_BUFFER_H_INCLUDED_ +#define EVENT2_BUFFER_H_INCLUDED_ /** @file event2/buffer.h @@ -72,18 +72,18 @@ evbuffer_peek() if you don't require that the memory to be contiguous. */ -#include <event2/visibility.h> - +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif #include <event2/event-config.h> #include <stdarg.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_UIO_H +#ifdef EVENT__HAVE_SYS_UIO_H #include <sys/uio.h> #endif #include <event2/util.h> @@ -95,7 +95,7 @@ extern "C" { @see event2/event.h for more information */ struct evbuffer -#ifdef EVENT_IN_DOXYGEN_ +#ifdef EVENT_IN_DOXYGEN_ {} #endif ; @@ -105,23 +105,23 @@ struct evbuffer Used when repeatedly searching through a buffer. Calling any function that modifies or re-packs the buffer contents may invalidate all - evbuffer_ptrs for that buffer. Do not modify or contruct these values - except with evbuffer_ptr_set. - - An evbuffer_ptr can represent any position from the start of a buffer up - to a position immediately after the end of a buffer. - - @see evbuffer_ptr_set() + evbuffer_ptrs for that buffer. Do not modify or contruct these values + except with evbuffer_ptr_set. + + An evbuffer_ptr can represent any position from the start of a buffer up + to a position immediately after the end of a buffer. + + @see evbuffer_ptr_set() */ struct evbuffer_ptr { ev_ssize_t pos; - /* Do not alter or rely on the values of fields: they are for internal - * use */ + /* Do not alter or rely on the values of fields: they are for internal + * use */ struct { void *chain; size_t pos_in_chain; - } internal_; + } internal_; }; /** Describes a single extent of memory inside an evbuffer. Used for @@ -129,10 +129,10 @@ struct evbuffer_ptr { @see evbuffer_reserve_space, evbuffer_commit_space, evbuffer_peek */ -#ifdef EVENT__HAVE_SYS_UIO_H +#ifdef EVENT__HAVE_SYS_UIO_H #define evbuffer_iovec iovec /* Internal use -- defined only if we are using the native struct iovec */ -#define EVBUFFER_IOVEC_IS_NATIVE_ +#define EVBUFFER_IOVEC_IS_NATIVE_ #else struct evbuffer_iovec { /** The start of the extent of memory. */ @@ -148,14 +148,14 @@ struct evbuffer_iovec { @return a pointer to a newly allocated evbuffer struct, or NULL if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer *evbuffer_new(void); /** Deallocate storage for an evbuffer. @param buf pointer to the evbuffer to be freed */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evbuffer_free(struct evbuffer *buf); /** @@ -170,21 +170,21 @@ void evbuffer_free(struct evbuffer *buf); @param lock A lock object, or NULL if we should allocate our own. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_enable_locking(struct evbuffer *buf, void *lock); /** Acquire the lock on an evbuffer. Has no effect if locking was not enabled with evbuffer_enable_locking. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evbuffer_lock(struct evbuffer *buf); /** Release the lock on an evbuffer. Has no effect if locking was not enabled with evbuffer_enable_locking. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evbuffer_unlock(struct evbuffer *buf); @@ -212,7 +212,7 @@ void evbuffer_unlock(struct evbuffer *buf); * @param flags One or more EVBUFFER_FLAG_* options * @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_set_flags(struct evbuffer *buf, ev_uint64_t flags); /** Change the flags that are set for an evbuffer by removing some. * @@ -221,7 +221,7 @@ int evbuffer_set_flags(struct evbuffer *buf, ev_uint64_t flags); * @param flags One or more EVBUFFER_FLAG_* options * @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_clear_flags(struct evbuffer *buf, ev_uint64_t flags); /** @@ -230,7 +230,7 @@ int evbuffer_clear_flags(struct evbuffer *buf, ev_uint64_t flags); @param buf pointer to the evbuffer @return the number of bytes stored in the evbuffer */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL size_t evbuffer_get_length(const struct evbuffer *buf); /** @@ -245,7 +245,7 @@ size_t evbuffer_get_length(const struct evbuffer *buf); @return 0 if no data is available, otherwise the number of available bytes in the first buffer chain. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL size_t evbuffer_get_contiguous_space(const struct evbuffer *buf); /** @@ -258,7 +258,7 @@ size_t evbuffer_get_contiguous_space(const struct evbuffer *buf); @param datlen the new minimum length requirement @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_expand(struct evbuffer *buf, size_t datlen); /** @@ -294,7 +294,7 @@ int evbuffer_expand(struct evbuffer *buf, size_t datlen); @return the number of provided extents, or -1 on error. @see evbuffer_commit_space() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size, struct evbuffer_iovec *vec, int n_vec); @@ -320,7 +320,7 @@ evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size, @return 0 on success, -1 on error @see evbuffer_reserve_space() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_commit_space(struct evbuffer *buf, struct evbuffer_iovec *vec, int n_vecs); @@ -332,7 +332,7 @@ int evbuffer_commit_space(struct evbuffer *buf, @param datlen the number of bytes to be copied from the data buffer @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen); @@ -347,7 +347,7 @@ int evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen); @param datlen the maximum size of the destination buffer @return the number of bytes read, or -1 if we can't drain the buffer. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_remove(struct evbuffer *buf, void *data, size_t datlen); /** @@ -361,25 +361,25 @@ int evbuffer_remove(struct evbuffer *buf, void *data, size_t datlen); @param datlen the maximum size of the destination buffer @return the number of bytes read, or -1 if we can't drain the buffer. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t evbuffer_copyout(struct evbuffer *buf, void *data_out, size_t datlen); /** - Read data from the middle of an evbuffer, and leave the buffer unchanged. - - If more bytes are requested than are available in the evbuffer, we - only extract as many bytes as were available. - - @param buf the evbuffer to be read from - @param pos the position to start reading from - @param data_out the destination buffer to store the result - @param datlen the maximum size of the destination buffer - @return the number of bytes read, or -1 if we can't drain the buffer. - */ -EVENT2_EXPORT_SYMBOL -ev_ssize_t evbuffer_copyout_from(struct evbuffer *buf, const struct evbuffer_ptr *pos, void *data_out, size_t datlen); - -/** + Read data from the middle of an evbuffer, and leave the buffer unchanged. + + If more bytes are requested than are available in the evbuffer, we + only extract as many bytes as were available. + + @param buf the evbuffer to be read from + @param pos the position to start reading from + @param data_out the destination buffer to store the result + @param datlen the maximum size of the destination buffer + @return the number of bytes read, or -1 if we can't drain the buffer. + */ +EVENT2_EXPORT_SYMBOL +ev_ssize_t evbuffer_copyout_from(struct evbuffer *buf, const struct evbuffer_ptr *pos, void *data_out, size_t datlen); + +/** Read data from an evbuffer into another evbuffer, draining the bytes from the source buffer. This function avoids copy operations to the extent possible. @@ -392,7 +392,7 @@ ev_ssize_t evbuffer_copyout_from(struct evbuffer *buf, const struct evbuffer_ptr @param datlen the maximum numbers of bytes to transfer @return the number of bytes read */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst, size_t datlen); @@ -415,9 +415,9 @@ enum evbuffer_eol_style { /** An EOL is a CR followed by an LF. */ EVBUFFER_EOL_CRLF_STRICT, /** An EOL is a LF. */ - EVBUFFER_EOL_LF, - /** An EOL is a NUL character (that is, a single byte with value 0) */ - EVBUFFER_EOL_NUL + EVBUFFER_EOL_LF, + /** An EOL is a NUL character (that is, a single byte with value 0) */ + EVBUFFER_EOL_NUL }; /** @@ -434,7 +434,7 @@ enum evbuffer_eol_style { * @param eol_style the style of line-ending to use. * @return pointer to a single line, or NULL if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out, enum evbuffer_eol_style eol_style); @@ -450,27 +450,27 @@ char *evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out, @see evbuffer_remove_buffer() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf); /** - Copy data from one evbuffer into another evbuffer. - - This is a non-destructive add. The data from one buffer is copied - into the other buffer. However, no unnecessary memory copies occur. - - Note that buffers already containing buffer references can't be added - to other buffers. - - @param outbuf the output buffer - @param inbuf the input buffer - @return 0 if successful, or -1 if an error occurred - */ -EVENT2_EXPORT_SYMBOL -int evbuffer_add_buffer_reference(struct evbuffer *outbuf, - struct evbuffer *inbuf); - -/** + Copy data from one evbuffer into another evbuffer. + + This is a non-destructive add. The data from one buffer is copied + into the other buffer. However, no unnecessary memory copies occur. + + Note that buffers already containing buffer references can't be added + to other buffers. + + @param outbuf the output buffer + @param inbuf the input buffer + @return 0 if successful, or -1 if an error occurred + */ +EVENT2_EXPORT_SYMBOL +int evbuffer_add_buffer_reference(struct evbuffer *outbuf, + struct evbuffer *inbuf); + +/** A cleanup function for a piece of memory added to an evbuffer by reference. @@ -494,7 +494,7 @@ typedef void (*evbuffer_ref_cleanup_cb)(const void *data, @param cleanupfn_arg optional argument to the cleanup callback @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_add_reference(struct evbuffer *outbuf, const void *data, size_t datlen, evbuffer_ref_cleanup_cb cleanupfn, void *cleanupfn_arg); @@ -513,140 +513,140 @@ int evbuffer_add_reference(struct evbuffer *outbuf, The results of using evbuffer_remove() or evbuffer_pullup() on evbuffers whose data was added using this function are undefined. - For more fine-grained control, use evbuffer_add_file_segment. - + For more fine-grained control, use evbuffer_add_file_segment. + @param outbuf the output buffer @param fd the file descriptor @param offset the offset from which to read data - @param length how much data to read, or -1 to read as much as possible. - (-1 requires that 'fd' support fstat.) + @param length how much data to read, or -1 to read as much as possible. + (-1 requires that 'fd' support fstat.) @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_add_file(struct evbuffer *outbuf, int fd, ev_off_t offset, ev_off_t length); /** - An evbuffer_file_segment holds a reference to a range of a file -- - possibly the whole file! -- for use in writing from an evbuffer to a - socket. It could be implemented with mmap, sendfile, splice, or (if all - else fails) by just pulling all the data into RAM. A single - evbuffer_file_segment can be added more than once, and to more than one - evbuffer. - */ -struct evbuffer_file_segment; - -/** - Flag for creating evbuffer_file_segment: If this flag is set, then when - the evbuffer_file_segment is freed and no longer in use by any - evbuffer, the underlying fd is closed. - */ -#define EVBUF_FS_CLOSE_ON_FREE 0x01 -/** - Flag for creating evbuffer_file_segment: Disable memory-map based - implementations. - */ -#define EVBUF_FS_DISABLE_MMAP 0x02 -/** - Flag for creating evbuffer_file_segment: Disable direct fd-to-fd - implementations (including sendfile and splice). - - You might want to use this option if data needs to be taken from the - evbuffer by any means other than writing it to the network: the sendfile - backend is fast, but it only works for sending files directly to the - network. - */ -#define EVBUF_FS_DISABLE_SENDFILE 0x04 -/** - Flag for creating evbuffer_file_segment: Do not allocate a lock for this - segment. If this option is set, then neither the segment nor any - evbuffer it is added to may ever be accessed from more than one thread - at a time. - */ -#define EVBUF_FS_DISABLE_LOCKING 0x08 - -/** - A cleanup function for a evbuffer_file_segment added to an evbuffer - for reference. - */ -typedef void (*evbuffer_file_segment_cleanup_cb)( - struct evbuffer_file_segment const* seg, int flags, void* arg); - -/** - Create and return a new evbuffer_file_segment for reading data from a - file and sending it out via an evbuffer. - - This function avoids unnecessary data copies between userland and - kernel. Where available, it uses sendfile or splice. - - The file descriptor must not be closed so long as any evbuffer is using - this segment. - - The results of using evbuffer_remove() or evbuffer_pullup() or any other - function that reads bytes from an evbuffer on any evbuffer containing - the newly returned segment are undefined, unless you pass the - EVBUF_FS_DISABLE_SENDFILE flag to this function. - - @param fd an open file to read from. - @param offset an index within the file at which to start reading - @param length how much data to read, or -1 to read as much as possible. - (-1 requires that 'fd' support fstat.) - @param flags any number of the EVBUF_FS_* flags - @return a new evbuffer_file_segment, or NULL on failure. - **/ -EVENT2_EXPORT_SYMBOL -struct evbuffer_file_segment *evbuffer_file_segment_new( - int fd, ev_off_t offset, ev_off_t length, unsigned flags); - -/** - Free an evbuffer_file_segment - - It is safe to call this function even if the segment has been added to - one or more evbuffers. The evbuffer_file_segment will not be freed - until no more references to it exist. - */ -EVENT2_EXPORT_SYMBOL -void evbuffer_file_segment_free(struct evbuffer_file_segment *seg); - -/** - Add cleanup callback and argument for the callback to an - evbuffer_file_segment. - - The cleanup callback will be invoked when no more references to the - evbuffer_file_segment exist. - **/ -EVENT2_EXPORT_SYMBOL -void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment *seg, - evbuffer_file_segment_cleanup_cb cb, void* arg); - -/** - Insert some or all of an evbuffer_file_segment at the end of an evbuffer - - Note that the offset and length parameters of this function have a - different meaning from those provided to evbuffer_file_segment_new: When - you create the segment, the offset is the offset _within the file_, and - the length is the length _of the segment_, whereas when you add a - segment to an evbuffer, the offset is _within the segment_ and the - length is the length of the _part of the segment you want to use. - - In other words, if you have a 10 KiB file, and you create an - evbuffer_file_segment for it with offset 20 and length 1000, it will - refer to bytes 20..1019 inclusive. If you then pass this segment to - evbuffer_add_file_segment and specify an offset of 20 and a length of - 50, you will be adding bytes 40..99 inclusive. - - @param buf the evbuffer to append to - @param seg the segment to add - @param offset the offset within the segment to start from - @param length the amount of data to add, or -1 to add it all. - @return 0 on success, -1 on failure. - */ -EVENT2_EXPORT_SYMBOL -int evbuffer_add_file_segment(struct evbuffer *buf, - struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length); - -/** + An evbuffer_file_segment holds a reference to a range of a file -- + possibly the whole file! -- for use in writing from an evbuffer to a + socket. It could be implemented with mmap, sendfile, splice, or (if all + else fails) by just pulling all the data into RAM. A single + evbuffer_file_segment can be added more than once, and to more than one + evbuffer. + */ +struct evbuffer_file_segment; + +/** + Flag for creating evbuffer_file_segment: If this flag is set, then when + the evbuffer_file_segment is freed and no longer in use by any + evbuffer, the underlying fd is closed. + */ +#define EVBUF_FS_CLOSE_ON_FREE 0x01 +/** + Flag for creating evbuffer_file_segment: Disable memory-map based + implementations. + */ +#define EVBUF_FS_DISABLE_MMAP 0x02 +/** + Flag for creating evbuffer_file_segment: Disable direct fd-to-fd + implementations (including sendfile and splice). + + You might want to use this option if data needs to be taken from the + evbuffer by any means other than writing it to the network: the sendfile + backend is fast, but it only works for sending files directly to the + network. + */ +#define EVBUF_FS_DISABLE_SENDFILE 0x04 +/** + Flag for creating evbuffer_file_segment: Do not allocate a lock for this + segment. If this option is set, then neither the segment nor any + evbuffer it is added to may ever be accessed from more than one thread + at a time. + */ +#define EVBUF_FS_DISABLE_LOCKING 0x08 + +/** + A cleanup function for a evbuffer_file_segment added to an evbuffer + for reference. + */ +typedef void (*evbuffer_file_segment_cleanup_cb)( + struct evbuffer_file_segment const* seg, int flags, void* arg); + +/** + Create and return a new evbuffer_file_segment for reading data from a + file and sending it out via an evbuffer. + + This function avoids unnecessary data copies between userland and + kernel. Where available, it uses sendfile or splice. + + The file descriptor must not be closed so long as any evbuffer is using + this segment. + + The results of using evbuffer_remove() or evbuffer_pullup() or any other + function that reads bytes from an evbuffer on any evbuffer containing + the newly returned segment are undefined, unless you pass the + EVBUF_FS_DISABLE_SENDFILE flag to this function. + + @param fd an open file to read from. + @param offset an index within the file at which to start reading + @param length how much data to read, or -1 to read as much as possible. + (-1 requires that 'fd' support fstat.) + @param flags any number of the EVBUF_FS_* flags + @return a new evbuffer_file_segment, or NULL on failure. + **/ +EVENT2_EXPORT_SYMBOL +struct evbuffer_file_segment *evbuffer_file_segment_new( + int fd, ev_off_t offset, ev_off_t length, unsigned flags); + +/** + Free an evbuffer_file_segment + + It is safe to call this function even if the segment has been added to + one or more evbuffers. The evbuffer_file_segment will not be freed + until no more references to it exist. + */ +EVENT2_EXPORT_SYMBOL +void evbuffer_file_segment_free(struct evbuffer_file_segment *seg); + +/** + Add cleanup callback and argument for the callback to an + evbuffer_file_segment. + + The cleanup callback will be invoked when no more references to the + evbuffer_file_segment exist. + **/ +EVENT2_EXPORT_SYMBOL +void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment *seg, + evbuffer_file_segment_cleanup_cb cb, void* arg); + +/** + Insert some or all of an evbuffer_file_segment at the end of an evbuffer + + Note that the offset and length parameters of this function have a + different meaning from those provided to evbuffer_file_segment_new: When + you create the segment, the offset is the offset _within the file_, and + the length is the length _of the segment_, whereas when you add a + segment to an evbuffer, the offset is _within the segment_ and the + length is the length of the _part of the segment you want to use. + + In other words, if you have a 10 KiB file, and you create an + evbuffer_file_segment for it with offset 20 and length 1000, it will + refer to bytes 20..1019 inclusive. If you then pass this segment to + evbuffer_add_file_segment and specify an offset of 20 and a length of + 50, you will be adding bytes 40..99 inclusive. + + @param buf the evbuffer to append to + @param seg the segment to add + @param offset the offset within the segment to start from + @param length the amount of data to add, or -1 to add it all. + @return 0 on success, -1 on failure. + */ +EVENT2_EXPORT_SYMBOL +int evbuffer_add_file_segment(struct evbuffer *buf, + struct evbuffer_file_segment *seg, ev_off_t offset, ev_off_t length); + +/** Append a formatted string to the end of an evbuffer. The string is formated as printf. @@ -658,7 +658,7 @@ int evbuffer_add_file_segment(struct evbuffer *buf, @see evutil_printf(), evbuffer_add_vprintf() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...) #ifdef __GNUC__ __attribute__((format(printf, 2, 3))) @@ -673,7 +673,7 @@ int evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...) @param ap a varargs va_list argument array that will be passed to vprintf(3) @return The number of bytes added if successful, or -1 if an error occurred. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap) #ifdef __GNUC__ __attribute__((format(printf, 2, 0))) @@ -688,7 +688,7 @@ int evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap) @param len the number of bytes to drain from the beginning of the buffer @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_drain(struct evbuffer *buf, size_t len); @@ -702,7 +702,7 @@ int evbuffer_drain(struct evbuffer *buf, size_t len); @return the number of bytes written, or -1 if an error occurred @see evbuffer_read() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_write(struct evbuffer *buffer, evutil_socket_t fd); /** @@ -717,7 +717,7 @@ int evbuffer_write(struct evbuffer *buffer, evutil_socket_t fd); @return the number of bytes written, or -1 if an error occurred @see evbuffer_read() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd, ev_ssize_t howmuch); @@ -731,7 +731,7 @@ int evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd, @return the number of bytes read, or -1 if an error occurred @see evbuffer_write() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_read(struct evbuffer *buffer, evutil_socket_t fd, int howmuch); /** @@ -745,7 +745,7 @@ int evbuffer_read(struct evbuffer *buffer, evutil_socket_t fd, int howmuch); first occurrence of the string in the buffer after 'start'. The 'pos' field of the result is -1 if the string was not found. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer_ptr evbuffer_search(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start); /** @@ -762,7 +762,7 @@ struct evbuffer_ptr evbuffer_search(struct evbuffer *buffer, const char *what, s first occurrence of the string in the buffer after 'start'. The 'pos' field of the result is -1 if the string was not found. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer_ptr evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start, const struct evbuffer_ptr *end); /** @@ -780,25 +780,25 @@ enum evbuffer_ptr_how { /** Sets the search pointer in the buffer to position. - There are two ways to use this function: you can call - evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_SET) - to move 'pos' to a position 'N' bytes after the start of the buffer, or - evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_ADD) - to move 'pos' forward by 'N' bytes. - - If evbuffer_ptr is not initialized, this function can only be called + There are two ways to use this function: you can call + evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_SET) + to move 'pos' to a position 'N' bytes after the start of the buffer, or + evbuffer_ptr_set(buf, &pos, N, EVBUFFER_PTR_ADD) + to move 'pos' forward by 'N' bytes. + + If evbuffer_ptr is not initialized, this function can only be called with EVBUFFER_PTR_SET. - An evbuffer_ptr can represent any position from the start of the buffer to - a position immediately after the end of the buffer. - + An evbuffer_ptr can represent any position from the start of the buffer to + a position immediately after the end of the buffer. + @param buffer the evbuffer to be search @param ptr a pointer to a struct evbuffer_ptr @param position the position at which to start the next search @param how determines how the pointer should be manipulated. @returns 0 on success or -1 otherwise */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_ptr_set(struct evbuffer *buffer, struct evbuffer_ptr *ptr, size_t position, enum evbuffer_ptr_how how); @@ -817,7 +817,7 @@ evbuffer_ptr_set(struct evbuffer *buffer, struct evbuffer_ptr *ptr, first occurrence EOL in the buffer after 'start'. The 'pos' field of the result is -1 if the string was not found. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer_ptr evbuffer_search_eol(struct evbuffer *buffer, struct evbuffer_ptr *start, size_t *eol_len_out, enum evbuffer_eol_style eol_style); @@ -850,7 +850,7 @@ struct evbuffer_ptr evbuffer_search_eol(struct evbuffer *buffer, than n_vec if we would need more to return all the data that was requested. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len, struct evbuffer_ptr *start_at, struct evbuffer_iovec *vec_out, int n_vec); @@ -903,7 +903,7 @@ struct evbuffer_cb_entry; @param cbarg an argument to be provided to the callback function @return a handle to the callback on success, or NULL on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer_cb_entry *evbuffer_add_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg); /** Remove a callback from an evbuffer, given a handle returned from @@ -914,7 +914,7 @@ struct evbuffer_cb_entry *evbuffer_add_cb(struct evbuffer *buffer, evbuffer_cb_f @return 0 if a callback was removed, or -1 if no matching callback was found. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_remove_cb_entry(struct evbuffer *buffer, struct evbuffer_cb_entry *ent); @@ -924,7 +924,7 @@ int evbuffer_remove_cb_entry(struct evbuffer *buffer, @return 0 if a callback was removed, or -1 if no matching callback was found. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg); /** If this flag is not set, then a callback is temporarily disabled, and @@ -941,7 +941,7 @@ int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg @param flags EVBUFFER_CB_ENABLED to re-enable the callback. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_cb_set_flags(struct evbuffer *buffer, struct evbuffer_cb_entry *cb, ev_uint32_t flags); @@ -952,7 +952,7 @@ int evbuffer_cb_set_flags(struct evbuffer *buffer, @param flags EVBUFFER_CB_ENABLED to disable the callback. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_cb_clear_flags(struct evbuffer *buffer, struct evbuffer_cb_entry *cb, ev_uint32_t flags); @@ -966,7 +966,7 @@ int evbuffer_cb_clear_flags(struct evbuffer *buffer, @param the buffer that the callback is watching. @param cb the callback we want to suspend. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb); /** Stop postponing a callback that we postponed with evbuffer_cb_suspend. @@ -976,7 +976,7 @@ void evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb); @param the buffer that the callback is watching. @param cb the callback we want to stop suspending. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb); #endif @@ -986,11 +986,11 @@ void evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb @param buf the evbuffer to make contiguous @param size the number of bytes to make contiguous, or -1 to make the entire buffer contiguous. - @return a pointer to the contiguous memory array, or NULL if param size - requested more data than is present in the buffer. + @return a pointer to the contiguous memory array, or NULL if param size + requested more data than is present in the buffer. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL unsigned char *evbuffer_pullup(struct evbuffer *buf, ev_ssize_t size); /** @@ -1002,7 +1002,7 @@ unsigned char *evbuffer_pullup(struct evbuffer *buf, ev_ssize_t size); @return 0 if successful, or -1 otherwise */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_prepend(struct evbuffer *buf, const void *data, size_t size); /** @@ -1013,7 +1013,7 @@ int evbuffer_prepend(struct evbuffer *buf, const void *data, size_t size); @param src the evbuffer to prepend; it will be emptied as a result @return 0 if successful, or -1 otherwise */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_prepend_buffer(struct evbuffer *dst, struct evbuffer* src); /** @@ -1030,7 +1030,7 @@ int evbuffer_prepend_buffer(struct evbuffer *dst, struct evbuffer* src); we freeze the back. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_freeze(struct evbuffer *buf, int at_front); /** Re-enable calls that modify an evbuffer. @@ -1040,7 +1040,7 @@ int evbuffer_freeze(struct evbuffer *buf, int at_front); we unfreeze the back. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_unfreeze(struct evbuffer *buf, int at_front); struct event_base; @@ -1051,27 +1051,27 @@ struct event_base; This can be used to serialize all the callbacks to a single thread of execution. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evbuffer_defer_callbacks(struct evbuffer *buffer, struct event_base *base); -/** - Append data from 1 or more iovec's to an evbuffer - - Calculates the number of bytes needed for an iovec structure and guarantees - all data will fit into a single chain. Can be used in lieu of functionality - which calls evbuffer_add() constantly before being used to increase - performance. - - @param buffer the destination buffer - @param vec the source iovec - @param n_vec the number of iovec structures. - @return the number of bytes successfully written to the output buffer. -*/ -EVENT2_EXPORT_SYMBOL -size_t evbuffer_add_iovec(struct evbuffer * buffer, struct evbuffer_iovec * vec, int n_vec); - +/** + Append data from 1 or more iovec's to an evbuffer + + Calculates the number of bytes needed for an iovec structure and guarantees + all data will fit into a single chain. Can be used in lieu of functionality + which calls evbuffer_add() constantly before being used to increase + performance. + + @param buffer the destination buffer + @param vec the source iovec + @param n_vec the number of iovec structures. + @return the number of bytes successfully written to the output buffer. +*/ +EVENT2_EXPORT_SYMBOL +size_t evbuffer_add_iovec(struct evbuffer * buffer, struct evbuffer_iovec * vec, int n_vec); + #ifdef __cplusplus } #endif -#endif /* EVENT2_BUFFER_H_INCLUDED_ */ +#endif /* EVENT2_BUFFER_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/buffer_compat.h b/contrib/libs/libevent/include/event2/buffer_compat.h index 0ce1025448..8b55bc6fe6 100644 --- a/contrib/libs/libevent/include/event2/buffer_compat.h +++ b/contrib/libs/libevent/include/event2/buffer_compat.h @@ -24,11 +24,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_BUFFER_COMPAT_H_INCLUDED_ -#define EVENT2_BUFFER_COMPAT_H_INCLUDED_ - -#include <event2/visibility.h> +#ifndef EVENT2_BUFFER_COMPAT_H_INCLUDED_ +#define EVENT2_BUFFER_COMPAT_H_INCLUDED_ +#include <event2/visibility.h> + /** @file event2/buffer_compat.h Obsolete and deprecated versions of the functions in buffer.h: provided @@ -37,7 +37,7 @@ /** - Obsolete alias for evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY). + Obsolete alias for evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY). @deprecated This function is deprecated because its behavior is not correct for almost any protocol, and also because it's wholly subsumed by @@ -47,7 +47,7 @@ @return pointer to a single line, or NULL if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evbuffer_readline(struct evbuffer *buffer); /** Type definition for a callback that is invoked whenever data is added or @@ -90,10 +90,10 @@ typedef void (*evbuffer_cb)(struct evbuffer *buffer, size_t old_len, size_t new_ @param cb the callback function to invoke when the evbuffer is modified, or NULL to remove all callbacks. @param cbarg an argument to be provided to the callback function - @return 0 if successful, or -1 on error + @return 0 if successful, or -1 on error */ -EVENT2_EXPORT_SYMBOL -int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); +EVENT2_EXPORT_SYMBOL +int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); /** @@ -104,7 +104,7 @@ int evbuffer_setcb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg); @param len the length of the search string @return a pointer to the beginning of the search string, or NULL if the search failed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL unsigned char *evbuffer_find(struct evbuffer *buffer, const unsigned char *what, size_t len); /** deprecated in favor of calling the functions directly */ diff --git a/contrib/libs/libevent/include/event2/bufferevent.h b/contrib/libs/libevent/include/event2/bufferevent.h index 48cd153563..87876effec 100644 --- a/contrib/libs/libevent/include/event2/bufferevent.h +++ b/contrib/libs/libevent/include/event2/bufferevent.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_BUFFEREVENT_H_INCLUDED_ -#define EVENT2_BUFFEREVENT_H_INCLUDED_ +#ifndef EVENT2_BUFFEREVENT_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_H_INCLUDED_ /** @file event2/bufferevent.h @@ -74,17 +74,17 @@ </dl> */ -#include <event2/visibility.h> - +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -111,7 +111,7 @@ extern "C" { @see event2/bufferevent.h */ struct bufferevent -#ifdef EVENT_IN_DOXYGEN_ +#ifdef EVENT_IN_DOXYGEN_ {} #endif ; @@ -140,9 +140,9 @@ typedef void (*bufferevent_data_cb)(struct bufferevent *bev, void *ctx); The event callback is triggered if either an EOF condition or another unrecoverable error was encountered. - For bufferevents with deferred callbacks, this is a bitwise OR of all errors - that have happened on the bufferevent since the last callback invocation. - + For bufferevents with deferred callbacks, this is a bitwise OR of all errors + that have happened on the bufferevent since the last callback invocation. + @param bev the bufferevent for which the error condition was reached @param what a conjunction of flags: BEV_EVENT_READING or BEV_EVENT_WRITING to indicate if the error was encountered on the read or write path, @@ -186,7 +186,7 @@ enum bufferevent_options { error occurred @see bufferevent_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, int options); /** @@ -208,8 +208,8 @@ struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socke @param socklen The length of the address @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL -int bufferevent_socket_connect(struct bufferevent *, const struct sockaddr *, int); +EVENT2_EXPORT_SYMBOL +int bufferevent_socket_connect(struct bufferevent *, const struct sockaddr *, int); struct evdns_base; /** @@ -238,7 +238,7 @@ struct evdns_base; may block while it waits for a DNS response. This is probably not what you want. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_socket_connect_hostname(struct bufferevent *, struct evdns_base *, int, const char *, int); @@ -250,7 +250,7 @@ int bufferevent_socket_connect_hostname(struct bufferevent *, @return DNS error code. @see evutil_gai_strerror() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_socket_get_dns_error(struct bufferevent *bev); /** @@ -264,13 +264,13 @@ int bufferevent_socket_get_dns_error(struct bufferevent *bev); @return 0 if successful, or -1 if an error occurred @see bufferevent_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev); /** Return the event_base used by a bufferevent */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *bufferevent_get_base(struct bufferevent *bev); /** @@ -282,26 +282,26 @@ struct event_base *bufferevent_get_base(struct bufferevent *bev); @param pri the priority to be assigned @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_priority_set(struct bufferevent *bufev, int pri); -/** - Return the priority of a bufferevent. - - Only supported for socket bufferevents - */ -EVENT2_EXPORT_SYMBOL -int bufferevent_get_priority(const struct bufferevent *bufev); +/** + Return the priority of a bufferevent. + Only supported for socket bufferevents + */ +EVENT2_EXPORT_SYMBOL +int bufferevent_get_priority(const struct bufferevent *bufev); + /** Deallocate the storage associated with a bufferevent structure. - If there is pending data to write on the bufferevent, it probably won't be - flushed before the bufferevent is freed. - + If there is pending data to write on the bufferevent, it probably won't be + flushed before the bufferevent is freed. + @param bufev the bufferevent structure to be freed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_free(struct bufferevent *bufev); @@ -319,54 +319,54 @@ void bufferevent_free(struct bufferevent *bufev); (readcb, writecb, and errorcb) @see bufferevent_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_setcb(struct bufferevent *bufev, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void *cbarg); /** - Retrieves the callbacks for a bufferevent. - - @param bufev the bufferevent to examine. - @param readcb_ptr if readcb_ptr is nonnull, *readcb_ptr is set to the current - read callback for the bufferevent. - @param writecb_ptr if writecb_ptr is nonnull, *writecb_ptr is set to the - current write callback for the bufferevent. - @param eventcb_ptr if eventcb_ptr is nonnull, *eventcb_ptr is set to the - current event callback for the bufferevent. - @param cbarg_ptr if cbarg_ptr is nonnull, *cbarg_ptr is set to the current - callback argument for the bufferevent. - @see buffervent_setcb() -*/ -EVENT2_EXPORT_SYMBOL -void bufferevent_getcb(struct bufferevent *bufev, - bufferevent_data_cb *readcb_ptr, - bufferevent_data_cb *writecb_ptr, - bufferevent_event_cb *eventcb_ptr, - void **cbarg_ptr); - -/** + Retrieves the callbacks for a bufferevent. + + @param bufev the bufferevent to examine. + @param readcb_ptr if readcb_ptr is nonnull, *readcb_ptr is set to the current + read callback for the bufferevent. + @param writecb_ptr if writecb_ptr is nonnull, *writecb_ptr is set to the + current write callback for the bufferevent. + @param eventcb_ptr if eventcb_ptr is nonnull, *eventcb_ptr is set to the + current event callback for the bufferevent. + @param cbarg_ptr if cbarg_ptr is nonnull, *cbarg_ptr is set to the current + callback argument for the bufferevent. + @see buffervent_setcb() +*/ +EVENT2_EXPORT_SYMBOL +void bufferevent_getcb(struct bufferevent *bufev, + bufferevent_data_cb *readcb_ptr, + bufferevent_data_cb *writecb_ptr, + bufferevent_event_cb *eventcb_ptr, + void **cbarg_ptr); + +/** Changes the file descriptor on which the bufferevent operates. Not supported for all bufferevent types. @param bufev the bufferevent object for which to change the file descriptor @param fd the file descriptor to operate on */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_setfd(struct bufferevent *bufev, evutil_socket_t fd); /** Returns the file descriptor associated with a bufferevent, or -1 if no file descriptor is associated with the bufferevent. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL evutil_socket_t bufferevent_getfd(struct bufferevent *bufev); /** Returns the underlying bufferevent associated with a bufferevent (if the bufferevent is a wrapper), or NULL if there is no underlying bufferevent. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent *bufferevent_get_underlying(struct bufferevent *bufev); /** @@ -382,7 +382,7 @@ struct bufferevent *bufferevent_get_underlying(struct bufferevent *bufev); @return 0 if successful, or -1 if an error occurred @see bufferevent_write_buffer() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_write(struct bufferevent *bufev, const void *data, size_t size); @@ -396,7 +396,7 @@ int bufferevent_write(struct bufferevent *bufev, @return 0 if successful, or -1 if an error occurred @see bufferevent_write() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf); @@ -410,7 +410,7 @@ int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf); @param size the size of the data buffer, in bytes @return the amount of data read, in bytes. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size); /** @@ -421,7 +421,7 @@ size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size); @param buf the evbuffer to which to add data @return 0 if successful, or -1 if an error occurred. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_read_buffer(struct bufferevent *bufev, struct evbuffer *buf); /** @@ -433,7 +433,7 @@ int bufferevent_read_buffer(struct bufferevent *bufev, struct evbuffer *buf); @return the evbuffer object for the input buffer */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer *bufferevent_get_input(struct bufferevent *bufev); /** @@ -448,7 +448,7 @@ struct evbuffer *bufferevent_get_input(struct bufferevent *bufev); @return the evbuffer object for the output buffer */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer *bufferevent_get_output(struct bufferevent *bufev); /** @@ -459,7 +459,7 @@ struct evbuffer *bufferevent_get_output(struct bufferevent *bufev); @return 0 if successful, or -1 if an error occurred @see bufferevent_disable() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_enable(struct bufferevent *bufev, short event); /** @@ -470,7 +470,7 @@ int bufferevent_enable(struct bufferevent *bufev, short event); @return 0 if successful, or -1 if an error occurred @see bufferevent_enable() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_disable(struct bufferevent *bufev, short event); /** @@ -479,7 +479,7 @@ int bufferevent_disable(struct bufferevent *bufev, short event); @param bufev the bufferevent to inspect @return A combination of EV_READ | EV_WRITE */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL short bufferevent_get_enabled(struct bufferevent *bufev); /** @@ -491,7 +491,7 @@ short bufferevent_get_enabled(struct bufferevent *bufev); (In other words, if reading or writing is disabled, or if the bufferevent's read or write operation has been suspended because - there's no data to write, or not enough bandwidth, or so on, the + there's no data to write, or not enough bandwidth, or so on, the timeout isn't active. The timeout only becomes active when we we're willing to actually read or write.) @@ -508,7 +508,7 @@ short bufferevent_get_enabled(struct bufferevent *bufev); @param timeout_read the read timeout, or NULL @param timeout_write the write timeout, or NULL */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_set_timeouts(struct bufferevent *bufev, const struct timeval *timeout_read, const struct timeval *timeout_write); @@ -518,9 +518,9 @@ int bufferevent_set_timeouts(struct bufferevent *bufev, On input, a bufferevent does not invoke the user read callback unless there is at least low watermark data in the buffer. If the read buffer is beyond the high watermark, the bufferevent stops reading from the network. - But be aware that bufferevent input/read buffer can overrun high watermark - limit (typical example is openssl bufferevent), so you should not relay in - this. + But be aware that bufferevent input/read buffer can overrun high watermark + limit (typical example is openssl bufferevent), so you should not relay in + this. On output, the user write callback is invoked whenever the buffered data falls below the low watermark. Filters that write to this bufev will try @@ -533,65 +533,65 @@ int bufferevent_set_timeouts(struct bufferevent *bufev, @param highmark the high watermark to set */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_setwatermark(struct bufferevent *bufev, short events, size_t lowmark, size_t highmark); /** - Retrieves the watermarks for read or write events. - Returns non-zero if events contains not only EV_READ or EV_WRITE. - Returns zero if events equal EV_READ or EV_WRITE - - @param bufev the bufferevent to be examined - @param events EV_READ or EV_WRITE - @param lowmark receives the lower watermark if not NULL - @param highmark receives the high watermark if not NULL -*/ -EVENT2_EXPORT_SYMBOL -int bufferevent_getwatermark(struct bufferevent *bufev, short events, - size_t *lowmark, size_t *highmark); - -/** + Retrieves the watermarks for read or write events. + Returns non-zero if events contains not only EV_READ or EV_WRITE. + Returns zero if events equal EV_READ or EV_WRITE + + @param bufev the bufferevent to be examined + @param events EV_READ or EV_WRITE + @param lowmark receives the lower watermark if not NULL + @param highmark receives the high watermark if not NULL +*/ +EVENT2_EXPORT_SYMBOL +int bufferevent_getwatermark(struct bufferevent *bufev, short events, + size_t *lowmark, size_t *highmark); + +/** Acquire the lock on a bufferevent. Has no effect if locking was not enabled with BEV_OPT_THREADSAFE. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_lock(struct bufferevent *bufev); /** Release the lock on a bufferevent. Has no effect if locking was not enabled with BEV_OPT_THREADSAFE. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_unlock(struct bufferevent *bufev); - -/** - * Public interface to manually increase the reference count of a bufferevent - * this is useful in situations where a user may reference the bufferevent - * somewhere else (unknown to libevent) - * - * @param bufev the bufferevent to increase the refcount on - * - */ -EVENT2_EXPORT_SYMBOL -void bufferevent_incref(struct bufferevent *bufev); - -/** - * Public interface to manually decrement the reference count of a bufferevent - * - * Warning: make sure you know what you're doing. This is mainly used in - * conjunction with bufferevent_incref(). This will free up all data associated - * with a bufferevent if the reference count hits 0. - * - * @param bufev the bufferevent to decrement the refcount on - * - * @return 1 if the bufferevent was freed, otherwise 0 (still referenced) - */ -EVENT2_EXPORT_SYMBOL -int bufferevent_decref(struct bufferevent *bufev); - + /** + * Public interface to manually increase the reference count of a bufferevent + * this is useful in situations where a user may reference the bufferevent + * somewhere else (unknown to libevent) + * + * @param bufev the bufferevent to increase the refcount on + * + */ +EVENT2_EXPORT_SYMBOL +void bufferevent_incref(struct bufferevent *bufev); + +/** + * Public interface to manually decrement the reference count of a bufferevent + * + * Warning: make sure you know what you're doing. This is mainly used in + * conjunction with bufferevent_incref(). This will free up all data associated + * with a bufferevent if the reference count hits 0. + * + * @param bufev the bufferevent to decrement the refcount on + * + * @return 1 if the bufferevent was freed, otherwise 0 (still referenced) + */ +EVENT2_EXPORT_SYMBOL +int bufferevent_decref(struct bufferevent *bufev); + +/** Flags that can be passed into filters to let them know how to deal with the incoming data. */ @@ -614,55 +614,55 @@ enum bufferevent_flush_mode { @param mode either BEV_NORMAL or BEV_FLUSH or BEV_FINISHED @return -1 on failure, 0 if no data was produces, 1 if data was produced */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_flush(struct bufferevent *bufev, short iotype, enum bufferevent_flush_mode mode); /** - Flags for bufferevent_trigger(_event) that modify when and how to trigger - the callback. -*/ -enum bufferevent_trigger_options { - /** trigger the callback regardless of the watermarks */ - BEV_TRIG_IGNORE_WATERMARKS = (1<<16), - - /** defer even if the callbacks are not */ - BEV_TRIG_DEFER_CALLBACKS = BEV_OPT_DEFER_CALLBACKS - - /* (Note: for internal reasons, these need to be disjoint from - * bufferevent_options, except when they mean the same thing. */ -}; - -/** - Triggers bufferevent data callbacks. - - The function will honor watermarks unless options contain - BEV_TRIG_IGNORE_WATERMARKS. If the options contain BEV_OPT_DEFER_CALLBACKS, - the callbacks are deferred. - - @param bufev the bufferevent object - @param iotype either EV_READ or EV_WRITE or both. - @param options - */ -EVENT2_EXPORT_SYMBOL -void bufferevent_trigger(struct bufferevent *bufev, short iotype, - int options); - -/** - Triggers the bufferevent event callback. - - If the options contain BEV_OPT_DEFER_CALLBACKS, the callbacks are deferred. - - @param bufev the bufferevent object - @param what the flags to pass onto the event callback - @param options - */ -EVENT2_EXPORT_SYMBOL -void bufferevent_trigger_event(struct bufferevent *bufev, short what, - int options); - -/** + Flags for bufferevent_trigger(_event) that modify when and how to trigger + the callback. +*/ +enum bufferevent_trigger_options { + /** trigger the callback regardless of the watermarks */ + BEV_TRIG_IGNORE_WATERMARKS = (1<<16), + + /** defer even if the callbacks are not */ + BEV_TRIG_DEFER_CALLBACKS = BEV_OPT_DEFER_CALLBACKS + + /* (Note: for internal reasons, these need to be disjoint from + * bufferevent_options, except when they mean the same thing. */ +}; + +/** + Triggers bufferevent data callbacks. + + The function will honor watermarks unless options contain + BEV_TRIG_IGNORE_WATERMARKS. If the options contain BEV_OPT_DEFER_CALLBACKS, + the callbacks are deferred. + + @param bufev the bufferevent object + @param iotype either EV_READ or EV_WRITE or both. + @param options + */ +EVENT2_EXPORT_SYMBOL +void bufferevent_trigger(struct bufferevent *bufev, short iotype, + int options); + +/** + Triggers the bufferevent event callback. + + If the options contain BEV_OPT_DEFER_CALLBACKS, the callbacks are deferred. + + @param bufev the bufferevent object + @param what the flags to pass onto the event callback + @param options + */ +EVENT2_EXPORT_SYMBOL +void bufferevent_trigger_event(struct bufferevent *bufev, short what, + int options); + +/** @name Filtering support @{ @@ -717,7 +717,7 @@ typedef enum bufferevent_filter_result (*bufferevent_filter_cb)( this bufferevent is freed. @param ctx A context pointer to pass to the filter functions. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_filter_new(struct bufferevent *underlying, bufferevent_filter_cb input_filter, @@ -737,7 +737,7 @@ bufferevent_filter_new(struct bufferevent *underlying, @param pair A pointer to an array to hold the two new bufferevent objects. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_pair_new(struct event_base *base, int options, struct bufferevent *pair[2]); @@ -745,7 +745,7 @@ int bufferevent_pair_new(struct event_base *base, int options, Given one bufferevent returned by bufferevent_pair_new(), returns the other one if it still exists. Otherwise returns NULL. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent *bufferevent_pair_get_partner(struct bufferevent *bev); /** @@ -779,7 +779,7 @@ struct bufferevent_rate_limit_group; Note that all rate-limits hare are currently best-effort: future versions of Libevent may implement them more tightly. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct ev_token_bucket_cfg *ev_token_bucket_cfg_new( size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, @@ -790,7 +790,7 @@ struct ev_token_bucket_cfg *ev_token_bucket_cfg_new( Note: 'cfg' is not currently reference-counted; it is not safe to free it until no bufferevent is using it. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg *cfg); /** @@ -802,9 +802,9 @@ void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg *cfg); They are: socket-based bufferevents (normal and IOCP-based), and SSL-based bufferevents. - Return 0 on success, -1 on failure. + Return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_set_rate_limit(struct bufferevent *bev, struct ev_token_bucket_cfg *cfg); @@ -825,7 +825,7 @@ int bufferevent_set_rate_limit(struct bufferevent *bev, They are: socket-based bufferevents (normal and IOCP-based), and SSL-based bufferevents. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent_rate_limit_group *bufferevent_rate_limit_group_new( struct event_base *base, const struct ev_token_bucket_cfg *cfg); @@ -834,7 +834,7 @@ struct bufferevent_rate_limit_group *bufferevent_rate_limit_group_new( Return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_cfg( struct bufferevent_rate_limit_group *, const struct ev_token_bucket_cfg *); @@ -853,9 +853,9 @@ int bufferevent_rate_limit_group_set_cfg( The default min-share is currently 64 bytes. - Returns 0 on success, -1 on failure. + Returns 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_set_min_share( struct bufferevent_rate_limit_group *, size_t); @@ -863,7 +863,7 @@ int bufferevent_rate_limit_group_set_min_share( Free a rate-limiting group. The group must have no members when this function is called. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_free(struct bufferevent_rate_limit_group *); /** @@ -876,43 +876,43 @@ void bufferevent_rate_limit_group_free(struct bufferevent_rate_limit_group *); Return 0 on success and -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_add_to_rate_limit_group(struct bufferevent *bev, struct bufferevent_rate_limit_group *g); /** Remove 'bev' from its current rate-limit group (if any). */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_remove_from_rate_limit_group(struct bufferevent *bev); /** - Set the size limit for single read operation. - - Set to 0 for a reasonable default. - - Return 0 on success and -1 on failure. - */ -EVENT2_EXPORT_SYMBOL -int bufferevent_set_max_single_read(struct bufferevent *bev, size_t size); - -/** - Set the size limit for single write operation. - - Set to 0 for a reasonable default. - - Return 0 on success and -1 on failure. - */ -EVENT2_EXPORT_SYMBOL -int bufferevent_set_max_single_write(struct bufferevent *bev, size_t size); - -/** Get the current size limit for single read operation. */ -EVENT2_EXPORT_SYMBOL -ev_ssize_t bufferevent_get_max_single_read(struct bufferevent *bev); - -/** Get the current size limit for single write operation. */ -EVENT2_EXPORT_SYMBOL -ev_ssize_t bufferevent_get_max_single_write(struct bufferevent *bev); - -/** + Set the size limit for single read operation. + + Set to 0 for a reasonable default. + + Return 0 on success and -1 on failure. + */ +EVENT2_EXPORT_SYMBOL +int bufferevent_set_max_single_read(struct bufferevent *bev, size_t size); + +/** + Set the size limit for single write operation. + + Set to 0 for a reasonable default. + + Return 0 on success and -1 on failure. + */ +EVENT2_EXPORT_SYMBOL +int bufferevent_set_max_single_write(struct bufferevent *bev, size_t size); + +/** Get the current size limit for single read operation. */ +EVENT2_EXPORT_SYMBOL +ev_ssize_t bufferevent_get_max_single_read(struct bufferevent *bev); + +/** Get the current size limit for single write operation. */ +EVENT2_EXPORT_SYMBOL +ev_ssize_t bufferevent_get_max_single_write(struct bufferevent *bev); + +/** @name Rate limit inspection Return the current read or write bucket size for a bufferevent. @@ -923,20 +923,20 @@ ev_ssize_t bufferevent_get_max_single_write(struct bufferevent *bev); @{ */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_get_read_limit(struct bufferevent *bev); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_get_write_limit(struct bufferevent *bev); /*@}*/ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_get_max_to_read(struct bufferevent *bev); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_get_max_to_write(struct bufferevent *bev); -EVENT2_EXPORT_SYMBOL -const struct ev_token_bucket_cfg *bufferevent_get_token_bucket_cfg(const struct bufferevent * bev); - +EVENT2_EXPORT_SYMBOL +const struct ev_token_bucket_cfg *bufferevent_get_token_bucket_cfg(const struct bufferevent * bev); + /** @name Group Rate limit inspection @@ -946,10 +946,10 @@ const struct ev_token_bucket_cfg *bufferevent_get_token_bucket_cfg(const struct @{ */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_rate_limit_group_get_read_limit( struct bufferevent_rate_limit_group *); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_ssize_t bufferevent_rate_limit_group_get_write_limit( struct bufferevent_rate_limit_group *); /*@}*/ @@ -968,9 +968,9 @@ ev_ssize_t bufferevent_rate_limit_group_get_write_limit( @{ */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_decrement_read_limit(struct bufferevent *bev, ev_ssize_t decr); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_decrement_write_limit(struct bufferevent *bev, ev_ssize_t decr); /*@}*/ @@ -987,10 +987,10 @@ int bufferevent_decrement_write_limit(struct bufferevent *bev, ev_ssize_t decr); @{ */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_decrement_read( struct bufferevent_rate_limit_group *, ev_ssize_t); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_rate_limit_group_decrement_write( struct bufferevent_rate_limit_group *, ev_ssize_t); /*@}*/ @@ -1002,7 +1002,7 @@ int bufferevent_rate_limit_group_decrement_write( * Set the variable pointed to by total_read_out to the total number of bytes * ever read on grp, and the variable pointed to by total_written_out to the * total number of bytes ever written on grp. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_get_totals( struct bufferevent_rate_limit_group *grp, ev_uint64_t *total_read_out, ev_uint64_t *total_written_out); @@ -1012,7 +1012,7 @@ void bufferevent_rate_limit_group_get_totals( * * Reset the number of bytes read or written on grp as given by * bufferevent_rate_limit_group_reset_totals(). */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_rate_limit_group_reset_totals( struct bufferevent_rate_limit_group *grp); @@ -1021,4 +1021,4 @@ bufferevent_rate_limit_group_reset_totals( } #endif -#endif /* EVENT2_BUFFEREVENT_H_INCLUDED_ */ +#endif /* EVENT2_BUFFEREVENT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/bufferevent_compat.h b/contrib/libs/libevent/include/event2/bufferevent_compat.h index a5a3c7207d..22aefba4b8 100644 --- a/contrib/libs/libevent/include/event2/bufferevent_compat.h +++ b/contrib/libs/libevent/include/event2/bufferevent_compat.h @@ -25,11 +25,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ -#define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ - -#include <event2/visibility.h> +#ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ +#include <event2/visibility.h> + #define evbuffercb bufferevent_data_cb #define everrorcb bufferevent_event_cb @@ -74,7 +74,7 @@ error occurred @see bufferevent_base_set(), bufferevent_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent *bufferevent_new(evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); @@ -86,7 +86,7 @@ struct bufferevent *bufferevent_new(evutil_socket_t fd, @param timeout_read the read timeout @param timeout_write the write timeout */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void bufferevent_settimeout(struct bufferevent *bufev, int timeout_read, int timeout_write); diff --git a/contrib/libs/libevent/include/event2/bufferevent_ssl.h b/contrib/libs/libevent/include/event2/bufferevent_ssl.h index bf39b844a9..39b4768562 100644 --- a/contrib/libs/libevent/include/event2/bufferevent_ssl.h +++ b/contrib/libs/libevent/include/event2/bufferevent_ssl.h @@ -23,14 +23,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ -#define EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ +#ifndef EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ /** @file event2/bufferevent_ssl.h OpenSSL support for bufferevents. */ -#include <event2/visibility.h> +#include <event2/visibility.h> #include <event2/event-config.h> #include <event2/bufferevent.h> #include <event2/util.h> @@ -52,7 +52,7 @@ enum bufferevent_ssl_state { BUFFEREVENT_SSL_ACCEPTING = 2 }; -#if defined(EVENT__HAVE_OPENSSL) || defined(EVENT_IN_DOXYGEN_) +#if defined(EVENT__HAVE_OPENSSL) || defined(EVENT_IN_DOXYGEN_) /** Create a new SSL bufferevent to send its data over another bufferevent. @@ -64,7 +64,7 @@ enum bufferevent_ssl_state { @param options One or more bufferevent_options @return A new bufferevent on success, or NULL on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_openssl_filter_new(struct event_base *base, struct bufferevent *underlying, @@ -82,7 +82,7 @@ bufferevent_openssl_filter_new(struct event_base *base, @param options One or more bufferevent_options @return A new bufferevent on success, or NULL on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct bufferevent * bufferevent_openssl_socket_new(struct event_base *base, evutil_socket_t fd, @@ -90,39 +90,39 @@ bufferevent_openssl_socket_new(struct event_base *base, enum bufferevent_ssl_state state, int options); -/** Control how to report dirty SSL shutdowns. - - If the peer (or the network, or an attacker) closes the TCP - connection before closing the SSL channel, and the protocol is SSL >= v3, - this is a "dirty" shutdown. If allow_dirty_shutdown is 0 (default), - this is reported as BEV_EVENT_ERROR. - - If instead allow_dirty_shutdown=1, a dirty shutdown is reported as - BEV_EVENT_EOF. - - (Note that if the protocol is < SSLv3, you will always receive - BEV_EVENT_EOF, since SSL 2 and earlier cannot distinguish a secure - connection close from a dirty one. This is one reason (among many) - not to use SSL 2.) -*/ - -EVENT2_EXPORT_SYMBOL -int bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev); -EVENT2_EXPORT_SYMBOL -void bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev, - int allow_dirty_shutdown); - +/** Control how to report dirty SSL shutdowns. + + If the peer (or the network, or an attacker) closes the TCP + connection before closing the SSL channel, and the protocol is SSL >= v3, + this is a "dirty" shutdown. If allow_dirty_shutdown is 0 (default), + this is reported as BEV_EVENT_ERROR. + + If instead allow_dirty_shutdown=1, a dirty shutdown is reported as + BEV_EVENT_EOF. + + (Note that if the protocol is < SSLv3, you will always receive + BEV_EVENT_EOF, since SSL 2 and earlier cannot distinguish a secure + connection close from a dirty one. This is one reason (among many) + not to use SSL 2.) +*/ + +EVENT2_EXPORT_SYMBOL +int bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev); +EVENT2_EXPORT_SYMBOL +void bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev, + int allow_dirty_shutdown); + /** Return the underlying openssl SSL * object for an SSL bufferevent. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct ssl_st * bufferevent_openssl_get_ssl(struct bufferevent *bufev); /** Tells a bufferevent to begin SSL renegotiation. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int bufferevent_ssl_renegotiate(struct bufferevent *bev); /** Return the most recent OpenSSL error reported on an SSL bufferevent. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL unsigned long bufferevent_get_openssl_error(struct bufferevent *bev); #endif @@ -131,4 +131,4 @@ unsigned long bufferevent_get_openssl_error(struct bufferevent *bev); } #endif -#endif /* EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ */ +#endif /* EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/bufferevent_struct.h b/contrib/libs/libevent/include/event2/bufferevent_struct.h index e84c082c30..862f1d75f3 100644 --- a/contrib/libs/libevent/include/event2/bufferevent_struct.h +++ b/contrib/libs/libevent/include/event2/bufferevent_struct.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ -#define EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ +#ifndef EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ /** @file event2/bufferevent_struct.h @@ -42,10 +42,10 @@ extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -113,4 +113,4 @@ struct bufferevent { } #endif -#endif /* EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ */ +#endif /* EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/dns.h b/contrib/libs/libevent/include/event2/dns.h index 13ce027e4a..1a59fad056 100644 --- a/contrib/libs/libevent/include/event2/dns.h +++ b/contrib/libs/libevent/include/event2/dns.h @@ -132,11 +132,11 @@ * with the next probe. */ -#ifndef EVENT2_DNS_H_INCLUDED_ -#define EVENT2_DNS_H_INCLUDED_ - -#include <event2/visibility.h> +#ifndef EVENT2_DNS_H_INCLUDED_ +#define EVENT2_DNS_H_INCLUDED_ +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif @@ -179,39 +179,39 @@ extern "C" { #define DNS_QUERY_NO_SEARCH 1 -/* Allow searching */ +/* Allow searching */ #define DNS_OPTION_SEARCH 1 -/* Parse "nameserver" and add default if no such section */ +/* Parse "nameserver" and add default if no such section */ #define DNS_OPTION_NAMESERVERS 2 -/* Parse additional options like: - * - timeout: - * - getaddrinfo-allow-skew: - * - max-timeouts: - * - max-inflight: - * - attempts: - * - randomize-case: - * - initial-probe-timeout: - */ +/* Parse additional options like: + * - timeout: + * - getaddrinfo-allow-skew: + * - max-timeouts: + * - max-inflight: + * - attempts: + * - randomize-case: + * - initial-probe-timeout: + */ #define DNS_OPTION_MISC 4 -/* Load hosts file (i.e. "/etc/hosts") */ +/* Load hosts file (i.e. "/etc/hosts") */ #define DNS_OPTION_HOSTSFILE 8 -/** - * All above: - * - DNS_OPTION_SEARCH - * - DNS_OPTION_NAMESERVERS - * - DNS_OPTION_MISC - * - DNS_OPTION_HOSTSFILE - */ -#define DNS_OPTIONS_ALL ( \ - DNS_OPTION_SEARCH | \ - DNS_OPTION_NAMESERVERS | \ - DNS_OPTION_MISC | \ - DNS_OPTION_HOSTSFILE | \ - 0 \ -) -/* 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) */ -#define DNS_OPTION_NAMESERVERS_NO_DEFAULT 16 +/** + * All above: + * - DNS_OPTION_SEARCH + * - DNS_OPTION_NAMESERVERS + * - DNS_OPTION_MISC + * - DNS_OPTION_HOSTSFILE + */ +#define DNS_OPTIONS_ALL ( \ + DNS_OPTION_SEARCH | \ + DNS_OPTION_NAMESERVERS | \ + DNS_OPTION_MISC | \ + DNS_OPTION_HOSTSFILE | \ + 0 \ +) +/* 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) */ +#define DNS_OPTION_NAMESERVERS_NO_DEFAULT 16 /* Obsolete name for DNS_QUERY_NO_SEARCH */ #define DNS_NO_SEARCH DNS_QUERY_NO_SEARCH @@ -231,16 +231,16 @@ typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, struct evdns_base; struct event_base; -/** Flag for evdns_base_new: process resolv.conf. */ -#define EVDNS_BASE_INITIALIZE_NAMESERVERS 1 -/** Flag for evdns_base_new: Do not prevent the libevent event loop from - * exiting when we have no active dns requests. */ -#define EVDNS_BASE_DISABLE_WHEN_INACTIVE 0x8000 -/** Flag for evdns_base_new: If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not - * add default nameserver if there are no nameservers in resolv.conf - * @see DNS_OPTION_NAMESERVERS_NO_DEFAULT */ -#define EVDNS_BASE_NAMESERVERS_NO_DEFAULT 0x10000 - +/** Flag for evdns_base_new: process resolv.conf. */ +#define EVDNS_BASE_INITIALIZE_NAMESERVERS 1 +/** Flag for evdns_base_new: Do not prevent the libevent event loop from + * exiting when we have no active dns requests. */ +#define EVDNS_BASE_DISABLE_WHEN_INACTIVE 0x8000 +/** Flag for evdns_base_new: If EVDNS_BASE_INITIALIZE_NAMESERVERS isset, do not + * add default nameserver if there are no nameservers in resolv.conf + * @see DNS_OPTION_NAMESERVERS_NO_DEFAULT */ +#define EVDNS_BASE_NAMESERVERS_NO_DEFAULT 0x10000 + /** Initialize the asynchronous DNS library. @@ -249,12 +249,12 @@ struct event_base; evdns_config_windows_nameservers() on Windows. @param event_base the event base to associate the dns client with - @param flags any of EVDNS_BASE_INITIALIZE_NAMESERVERS| - EVDNS_BASE_DISABLE_WHEN_INACTIVE|EVDNS_BASE_NAMESERVERS_NO_DEFAULT + @param flags any of EVDNS_BASE_INITIALIZE_NAMESERVERS| + EVDNS_BASE_DISABLE_WHEN_INACTIVE|EVDNS_BASE_NAMESERVERS_NO_DEFAULT @return evdns_base object if successful, or NULL if an error occurred. @see evdns_base_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize_nameservers); @@ -270,25 +270,25 @@ struct evdns_base * evdns_base_new(struct event_base *event_base, int initialize active requests will return DNS_ERR_SHUTDOWN. @see evdns_base_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_base_free(struct evdns_base *base, int fail_requests); /** - Remove all hosts entries that have been loaded into the event_base via - evdns_base_load_hosts or via event_base_resolv_conf_parse. - - @param evdns_base the evdns base to remove outdated host addresses from - */ -EVENT2_EXPORT_SYMBOL -void evdns_base_clear_host_addresses(struct evdns_base *base); - -/** + Remove all hosts entries that have been loaded into the event_base via + evdns_base_load_hosts or via event_base_resolv_conf_parse. + + @param evdns_base the evdns base to remove outdated host addresses from + */ +EVENT2_EXPORT_SYMBOL +void evdns_base_clear_host_addresses(struct evdns_base *base); + +/** Convert a DNS error code to a string. @param err the DNS error code @return a string containing an explanation of the error code */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evdns_err_to_string(int err); @@ -303,7 +303,7 @@ const char *evdns_err_to_string(int err); @return 0 if successful, or -1 if an error occurred @see evdns_base_nameserver_ip_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_nameserver_add(struct evdns_base *base, unsigned long int address); @@ -319,7 +319,7 @@ int evdns_base_nameserver_add(struct evdns_base *base, @return the number of configured nameservers @see evdns_base_nameserver_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_count_nameservers(struct evdns_base *base); /** @@ -331,7 +331,7 @@ int evdns_base_count_nameservers(struct evdns_base *base); @return 0 if successful, or -1 if an error occurred @see evdns_base_resume() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_clear_nameservers_and_suspend(struct evdns_base *base); @@ -345,7 +345,7 @@ int evdns_base_clear_nameservers_and_suspend(struct evdns_base *base); @return 0 if successful, or -1 if an error occurred @see evdns_base_clear_nameservers_and_suspend() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_resume(struct evdns_base *base); /** @@ -365,14 +365,14 @@ int evdns_base_resume(struct evdns_base *base); @return 0 if successful, or -1 if an error occurred @see evdns_base_nameserver_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_nameserver_ip_add(struct evdns_base *base, const char *ip_as_string); /** Add a nameserver by sockaddr. **/ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_nameserver_sockaddr_add(struct evdns_base *base, const struct sockaddr *sa, ev_socklen_t len, unsigned flags); @@ -390,7 +390,7 @@ struct evdns_request; @return an evdns_request object if successful, or NULL if an error occurred. @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_request *evdns_base_resolve_ipv4(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr); /** @@ -404,7 +404,7 @@ struct evdns_request *evdns_base_resolve_ipv4(struct evdns_base *base, const cha @return an evdns_request object if successful, or NULL if an error occurred. @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6(), evdns_cancel_request() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_request *evdns_base_resolve_ipv6(struct evdns_base *base, const char *name, int flags, evdns_callback_type callback, void *ptr); struct in_addr; @@ -421,7 +421,7 @@ struct in6_addr; @return an evdns_request object if successful, or NULL if an error occurred. @see evdns_resolve_reverse_ipv6(), evdns_cancel_request() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_request *evdns_base_resolve_reverse(struct evdns_base *base, const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); @@ -436,7 +436,7 @@ struct evdns_request *evdns_base_resolve_reverse(struct evdns_base *base, const @return an evdns_request object if successful, or NULL if an error occurred. @see evdns_resolve_reverse_ipv6(), evdns_cancel_request() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_request *evdns_base_resolve_reverse_ipv6(struct evdns_base *base, const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); /** @@ -446,7 +446,7 @@ struct evdns_request *evdns_base_resolve_reverse_ipv6(struct evdns_base *base, c @param req the evdns_request that was returned by calling a resolve function @see evdns_base_resolve_ipv4(), evdns_base_resolve_ipv6, evdns_base_resolve_reverse */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req); /** @@ -455,8 +455,8 @@ void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req); The currently available configuration options are: ndots, timeout, max-timeouts, max-inflight, attempts, randomize-case, - bind-to, initial-probe-timeout, getaddrinfo-allow-skew, - so-rcvbuf, so-sndbuf. + bind-to, initial-probe-timeout, getaddrinfo-allow-skew, + so-rcvbuf, so-sndbuf. In versions before Libevent 2.0.3-alpha, the option name needed to end with a colon. @@ -466,7 +466,7 @@ void evdns_cancel_request(struct evdns_base *base, struct evdns_request *req); @param val the value to be set @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_set_option(struct evdns_base *base, const char *option, const char *val); @@ -486,13 +486,13 @@ int evdns_base_set_option(struct evdns_base *base, const char *option, const cha @param base the evdns_base to which to apply this operation @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH|DNS_OPTION_MISC| - DNS_OPTION_HOSTSFILE|DNS_OPTIONS_ALL|DNS_OPTION_NAMESERVERS_NO_DEFAULT + DNS_OPTION_HOSTSFILE|DNS_OPTIONS_ALL|DNS_OPTION_NAMESERVERS_NO_DEFAULT @param filename the path to the resolv.conf file @return 0 if successful, or various positive error codes if an error occurred (see above) @see resolv.conf(3), evdns_config_windows_nameservers() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char *const filename); /** @@ -503,15 +503,15 @@ int evdns_base_resolv_conf_parse(struct evdns_base *base, int flags, const char Note that only evdns_getaddrinfo uses the /etc/hosts entries. - This function does not replace previously loaded hosts entries; to do that, - call evdns_base_clear_host_addresses first. - + This function does not replace previously loaded hosts entries; to do that, + call evdns_base_clear_host_addresses first. + Return 0 on success, negative on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname); -#if defined(EVENT_IN_DOXYGEN_) || defined(_WIN32) +#if defined(EVENT_IN_DOXYGEN_) || defined(_WIN32) /** Obtain nameserver information using the Windows API. @@ -522,7 +522,7 @@ int evdns_base_load_hosts(struct evdns_base *base, const char *hosts_fname); @return 0 if successful, or -1 if an error occurred @see evdns_resolv_conf_parse() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_base_config_windows_nameservers(struct evdns_base *); #define EVDNS_BASE_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED #endif @@ -531,7 +531,7 @@ int evdns_base_config_windows_nameservers(struct evdns_base *); /** Clear the list of search domains. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_base_search_clear(struct evdns_base *base); @@ -540,7 +540,7 @@ void evdns_base_search_clear(struct evdns_base *base); @param domain the domain to be added to the search list */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_base_search_add(struct evdns_base *base, const char *domain); @@ -552,7 +552,7 @@ void evdns_base_search_add(struct evdns_base *base, const char *domain); @param ndots the new ndots parameter */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_base_search_ndots_set(struct evdns_base *base, const int ndots); /** @@ -571,7 +571,7 @@ typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg); @param fn the callback to be invoked when a log message is generated */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_set_log_fn(evdns_debug_log_fn_type fn); /** @@ -584,7 +584,7 @@ void evdns_set_log_fn(evdns_debug_log_fn_type fn); NOTE: This function has no effect in Libevent 2.0.4-alpha and later, since Libevent now provides its own secure RNG. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_set_transaction_id_fn(ev_uint16_t (*fn)(void)); /** @@ -596,7 +596,7 @@ void evdns_set_transaction_id_fn(ev_uint16_t (*fn)(void)); NOTE: This function has no effect in Libevent 2.0.4-alpha and later, since Libevent now provides its own secure RNG. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_set_random_bytes_fn(void (*fn)(char *, size_t)); /* @@ -648,50 +648,50 @@ typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, vo @param callback A function to invoke whenever we get a DNS request on the socket. @param user_data Data to pass to the callback. - @return an evdns_server_port structure for this server port or NULL if - an error occurred. + @return an evdns_server_port structure for this server port or NULL if + an error occurred. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_server_port *evdns_add_server_port_with_base(struct event_base *base, evutil_socket_t socket, int flags, evdns_request_callback_fn_type callback, void *user_data); /** Close down a DNS server port, and free associated structures. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_close_server_port(struct evdns_server_port *port); /** Sets some flags in a reply we're building. Allows setting of the AA or RD flags */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_server_request_set_flags(struct evdns_server_request *req, int flags); /* Functions to add an answer to an in-progress DNS reply. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int dns_class, int ttl, int datalen, int is_name, const char *data); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl); /** Send back a response to a DNS request, and free the request structure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_respond(struct evdns_server_request *req, int err); /** Free a DNS request without sending back a reply. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_server_request_drop(struct evdns_server_request *req); struct sockaddr; /** Get the address that made a DNS request. */ -EVENT2_EXPORT_SYMBOL -int evdns_server_request_get_requesting_addr(struct evdns_server_request *req, struct sockaddr *sa, int addr_len); +EVENT2_EXPORT_SYMBOL +int evdns_server_request_get_requesting_addr(struct evdns_server_request *req, struct sockaddr *sa, int addr_len); /** Callback for evdns_getaddrinfo. */ typedef void (*evdns_getaddrinfo_cb)(int result, struct evutil_addrinfo *res, void *arg); @@ -715,7 +715,7 @@ struct evdns_getaddrinfo_request; * - For ai_socktype, we only handle SOCKTYPE_STREAM, SOCKTYPE_UDP, and 0. * - For ai_protocol, we only handle IPPROTO_TCP, IPPROTO_UDP, and 0. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_getaddrinfo_request *evdns_getaddrinfo( struct evdns_base *dns_base, const char *nodename, const char *servname, @@ -725,27 +725,27 @@ struct evdns_getaddrinfo_request *evdns_getaddrinfo( /* Cancel an in-progress evdns_getaddrinfo. This MUST NOT be called after the * getaddrinfo's callback has been invoked. The resolves will be canceled, * and the callback will be invoked with the error EVUTIL_EAI_CANCEL. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_getaddrinfo_cancel(struct evdns_getaddrinfo_request *req); -/** - Retrieve the address of the 'idx'th configured nameserver. - - @param base The evdns_base to examine. - @param idx The index of the nameserver to get the address of. - @param sa A location to receive the server's address. - @param len The number of bytes available at sa. - - @return the number of bytes written into sa on success. On failure, returns - -1 if idx is greater than the number of configured nameservers, or a - value greater than 'len' if len was not high enough. - */ -EVENT2_EXPORT_SYMBOL -int evdns_base_get_nameserver_addr(struct evdns_base *base, int idx, - struct sockaddr *sa, ev_socklen_t len); - +/** + Retrieve the address of the 'idx'th configured nameserver. + + @param base The evdns_base to examine. + @param idx The index of the nameserver to get the address of. + @param sa A location to receive the server's address. + @param len The number of bytes available at sa. + + @return the number of bytes written into sa on success. On failure, returns + -1 if idx is greater than the number of configured nameservers, or a + value greater than 'len' if len was not high enough. + */ +EVENT2_EXPORT_SYMBOL +int evdns_base_get_nameserver_addr(struct evdns_base *base, int idx, + struct sockaddr *sa, ev_socklen_t len); + #ifdef __cplusplus } #endif -#endif /* !EVENT2_DNS_H_INCLUDED_ */ +#endif /* !EVENT2_DNS_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/dns_compat.h b/contrib/libs/libevent/include/event2/dns_compat.h index a58c4b2937..433607220d 100644 --- a/contrib/libs/libevent/include/event2/dns_compat.h +++ b/contrib/libs/libevent/include/event2/dns_compat.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_DNS_COMPAT_H_INCLUDED_ -#define EVENT2_DNS_COMPAT_H_INCLUDED_ +#ifndef EVENT2_DNS_COMPAT_H_INCLUDED_ +#define EVENT2_DNS_COMPAT_H_INCLUDED_ /** @file event2/dns_compat.h @@ -40,16 +40,16 @@ extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif /* For int types. */ #include <event2/util.h> -#include <event2/visibility.h> +#include <event2/visibility.h> /** Initialize the asynchronous DNS library. @@ -67,7 +67,7 @@ extern "C" { @return 0 if successful, or -1 if an error occurred @see evdns_shutdown() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_init(void); struct evdns_base; @@ -78,7 +78,7 @@ struct evdns_base; @deprecated This function is deprecated because use of the global evdns_base is error-prone. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evdns_base *evdns_get_global_base(void); /** @@ -96,7 +96,7 @@ struct evdns_base *evdns_get_global_base(void); active requests will return DNS_ERR_SHUTDOWN. @see evdns_init() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_shutdown(int fail_requests); /** @@ -113,7 +113,7 @@ void evdns_shutdown(int fail_requests); @return 0 if successful, or -1 if an error occurred @see evdns_nameserver_ip_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_nameserver_add(unsigned long int address); /** @@ -131,7 +131,7 @@ int evdns_nameserver_add(unsigned long int address); @return the number of configured nameservers @see evdns_nameserver_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_count_nameservers(void); /** @@ -146,7 +146,7 @@ int evdns_count_nameservers(void); @return 0 if successful, or -1 if an error occurred @see evdns_resume() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_clear_nameservers_and_suspend(void); /** @@ -162,7 +162,7 @@ int evdns_clear_nameservers_and_suspend(void); @return 0 if successful, or -1 if an error occurred @see evdns_clear_nameservers_and_suspend() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_resume(void); /** @@ -178,7 +178,7 @@ int evdns_resume(void); @return 0 if successful, or -1 if an error occurred @see evdns_nameserver_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_nameserver_ip_add(const char *ip_as_string); /** @@ -195,7 +195,7 @@ int evdns_nameserver_ip_add(const char *ip_as_string); @return 0 if successful, or -1 if an error occurred @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr); /** @@ -208,7 +208,7 @@ int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback @return 0 if successful, or -1 if an error occurred @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr); struct in_addr; @@ -228,7 +228,7 @@ struct in6_addr; @return 0 if successful, or -1 if an error occurred @see evdns_resolve_reverse_ipv6() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); /** @@ -245,7 +245,7 @@ int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_ty @return 0 if successful, or -1 if an error occurred @see evdns_resolve_reverse_ipv6() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); /** @@ -264,7 +264,7 @@ int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callb @param flags Ignored. @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_set_option(const char *option, const char *val, int flags); /** @@ -292,7 +292,7 @@ int evdns_set_option(const char *option, const char *val, int flags); occurred (see above) @see resolv.conf(3), evdns_config_windows_nameservers() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evdns_resolv_conf_parse(int flags, const char *const filename); /** @@ -302,7 +302,7 @@ int evdns_resolv_conf_parse(int flags, const char *const filename); caller to specify which evdns_base it applies to. The recommended function is evdns_base_search_clear(). */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_search_clear(void); /** @@ -314,7 +314,7 @@ void evdns_search_clear(void); @param domain the domain to be added to the search list */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_search_add(const char *domain); /** @@ -329,7 +329,7 @@ void evdns_search_add(const char *domain); @param ndots the new ndots parameter */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evdns_search_ndots_set(const int ndots); /** @@ -340,13 +340,13 @@ void evdns_search_ndots_set(const int ndots); function is evdns_add_server_port_with_base(). */ -EVENT2_EXPORT_SYMBOL -struct evdns_server_port * -evdns_add_server_port(evutil_socket_t socket, int flags, - evdns_request_callback_fn_type callback, void *user_data); +EVENT2_EXPORT_SYMBOL +struct evdns_server_port * +evdns_add_server_port(evutil_socket_t socket, int flags, + evdns_request_callback_fn_type callback, void *user_data); -#ifdef _WIN32 -EVENT2_EXPORT_SYMBOL +#ifdef _WIN32 +EVENT2_EXPORT_SYMBOL int evdns_config_windows_nameservers(void); #define EVDNS_CONFIG_WINDOWS_NAMESERVERS_IMPLEMENTED #endif @@ -355,4 +355,4 @@ int evdns_config_windows_nameservers(void); } #endif -#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ +#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/dns_struct.h b/contrib/libs/libevent/include/event2/dns_struct.h index 593a8a70b6..18d7196d2f 100644 --- a/contrib/libs/libevent/include/event2/dns_struct.h +++ b/contrib/libs/libevent/include/event2/dns_struct.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_DNS_STRUCT_H_INCLUDED_ -#define EVENT2_DNS_STRUCT_H_INCLUDED_ +#ifndef EVENT2_DNS_STRUCT_H_INCLUDED_ +#define EVENT2_DNS_STRUCT_H_INCLUDED_ /** @file event2/dns_struct.h @@ -39,10 +39,10 @@ extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -76,5 +76,5 @@ struct evdns_server_question { } #endif -#endif /* EVENT2_DNS_STRUCT_H_INCLUDED_ */ +#endif /* EVENT2_DNS_STRUCT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/event-config-linux.h b/contrib/libs/libevent/include/event2/event-config-linux.h index f8fbfe5c8b..775a2d2171 100644 --- a/contrib/libs/libevent/include/event2/event-config-linux.h +++ b/contrib/libs/libevent/include/event2/event-config-linux.h @@ -8,41 +8,41 @@ * Do not rely on macros in this file existing in later versions. */ -#ifndef EVENT2_EVENT_CONFIG_H_INCLUDED_ -#define EVENT2_EVENT_CONFIG_H_INCLUDED_ +#ifndef EVENT2_EVENT_CONFIG_H_INCLUDED_ +#define EVENT2_EVENT_CONFIG_H_INCLUDED_ /* config.h. Generated from config.h.in by configure. */ /* config.h.in. Generated from configure.ac by autoheader. */ /* Define if libevent should build without support for a debug mode */ -/* #undef EVENT__DISABLE_DEBUG_MODE */ +/* #undef EVENT__DISABLE_DEBUG_MODE */ /* Define if libevent should not allow replacing the mm functions */ -/* #undef EVENT__DISABLE_MM_REPLACEMENT */ +/* #undef EVENT__DISABLE_MM_REPLACEMENT */ /* Define if libevent should not be compiled with thread support */ -/* #undef EVENT__DISABLE_THREAD_SUPPORT */ - -/* Define to 1 if you have the `accept4' function. */ -#define EVENT__HAVE_ACCEPT4 1 +/* #undef EVENT__DISABLE_THREAD_SUPPORT */ +/* Define to 1 if you have the `accept4' function. */ +#define EVENT__HAVE_ACCEPT4 1 + /* Define to 1 if you have the <afunix.h> header file. */ /* #undef EVENT__HAVE_AFUNIX_H */ /* Define to 1 if you have the `arc4random' function. */ -/* #undef EVENT__HAVE_ARC4RANDOM */ - -/* Define to 1 if you have the `arc4random_addrandom' function. */ -/* #undef EVENT__HAVE_ARC4RANDOM_ADDRANDOM */ +/* #undef EVENT__HAVE_ARC4RANDOM */ +/* Define to 1 if you have the `arc4random_addrandom' function. */ +/* #undef EVENT__HAVE_ARC4RANDOM_ADDRANDOM */ + /* Define to 1 if you have the `arc4random_buf' function. */ -/* #undef EVENT__HAVE_ARC4RANDOM_BUF */ +/* #undef EVENT__HAVE_ARC4RANDOM_BUF */ /* Define to 1 if you have the <arpa/inet.h> header file. */ -#define EVENT__HAVE_ARPA_INET_H 1 +#define EVENT__HAVE_ARPA_INET_H 1 /* Define to 1 if you have the `clock_gettime' function. */ -#define EVENT__HAVE_CLOCK_GETTIME 1 +#define EVENT__HAVE_CLOCK_GETTIME 1 /* Define to 1 if you have the declaration of `CTL_KERN', and to 0 if you don't. */ @@ -53,376 +53,376 @@ /* #undef EVENT__HAVE_DECL_KERN_ARND */ /* Define if /dev/poll is available */ -/* #undef EVENT__HAVE_DEVPOLL */ +/* #undef EVENT__HAVE_DEVPOLL */ /* Define to 1 if you have the <dlfcn.h> header file. */ -#define EVENT__HAVE_DLFCN_H 1 +#define EVENT__HAVE_DLFCN_H 1 /* Define if your system supports the epoll system calls */ -#define EVENT__HAVE_EPOLL 1 - -/* Define to 1 if you have the `epoll_create1' function. */ -#define EVENT__HAVE_EPOLL_CREATE1 1 +#define EVENT__HAVE_EPOLL 1 +/* Define to 1 if you have the `epoll_create1' function. */ +#define EVENT__HAVE_EPOLL_CREATE1 1 + /* Define to 1 if you have the `epoll_ctl' function. */ -#define EVENT__HAVE_EPOLL_CTL 1 - -/* Define to 1 if you have the <errno.h> header file. */ -#define EVENT__HAVE_ERRNO_H 1 +#define EVENT__HAVE_EPOLL_CTL 1 +/* Define to 1 if you have the <errno.h> header file. */ +#define EVENT__HAVE_ERRNO_H 1 + /* Define to 1 if you have the `eventfd' function. */ -#define EVENT__HAVE_EVENTFD 1 +#define EVENT__HAVE_EVENTFD 1 /* Define if your system supports event ports */ -/* #undef EVENT__HAVE_EVENT_PORTS */ +/* #undef EVENT__HAVE_EVENT_PORTS */ /* Define to 1 if you have the `fcntl' function. */ -#define EVENT__HAVE_FCNTL 1 +#define EVENT__HAVE_FCNTL 1 /* Define to 1 if you have the <fcntl.h> header file. */ -#define EVENT__HAVE_FCNTL_H 1 +#define EVENT__HAVE_FCNTL_H 1 /* Define to 1 if the system has the type `fd_mask'. */ -#define EVENT__HAVE_FD_MASK 1 +#define EVENT__HAVE_FD_MASK 1 /* Do we have getaddrinfo()? */ -#define EVENT__HAVE_GETADDRINFO 1 +#define EVENT__HAVE_GETADDRINFO 1 /* Define to 1 if you have the `getegid' function. */ -#define EVENT__HAVE_GETEGID 1 +#define EVENT__HAVE_GETEGID 1 /* Define to 1 if you have the `geteuid' function. */ -#define EVENT__HAVE_GETEUID 1 +#define EVENT__HAVE_GETEUID 1 /* Define this if you have any gethostbyname_r() */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R */ /* Define this if gethostbyname_r takes 3 arguments */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R_3_ARG */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_3_ARG */ /* Define this if gethostbyname_r takes 5 arguments */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R_5_ARG */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_5_ARG */ /* Define this if gethostbyname_r takes 6 arguments */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG */ - -/* Define to 1 if you have the `getifaddrs' function. */ -#define EVENT__HAVE_GETIFADDRS 1 +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG */ +/* Define to 1 if you have the `getifaddrs' function. */ +#define EVENT__HAVE_GETIFADDRS 1 + /* Define to 1 if you have the `getnameinfo' function. */ -#define EVENT__HAVE_GETNAMEINFO 1 +#define EVENT__HAVE_GETNAMEINFO 1 /* Define to 1 if you have the `getprotobynumber' function. */ -#define EVENT__HAVE_GETPROTOBYNUMBER 1 +#define EVENT__HAVE_GETPROTOBYNUMBER 1 /* Define to 1 if you have the `getrandom' function. */ #define EVENT__HAVE_GETRANDOM 1 /* Define to 1 if you have the `getservbyname' function. */ -#define EVENT__HAVE_GETSERVBYNAME 1 +#define EVENT__HAVE_GETSERVBYNAME 1 /* Define to 1 if you have the `gettimeofday' function. */ -#define EVENT__HAVE_GETTIMEOFDAY 1 +#define EVENT__HAVE_GETTIMEOFDAY 1 -/* Define to 1 if you have the <ifaddrs.h> header file. */ -#define EVENT__HAVE_IFADDRS_H 1 +/* Define to 1 if you have the <ifaddrs.h> header file. */ +#define EVENT__HAVE_IFADDRS_H 1 /* Define to 1 if you have the `inet_ntop' function. */ -#define EVENT__HAVE_INET_NTOP 1 +#define EVENT__HAVE_INET_NTOP 1 /* Define to 1 if you have the `inet_pton' function. */ -#define EVENT__HAVE_INET_PTON 1 +#define EVENT__HAVE_INET_PTON 1 /* Define to 1 if you have the <inttypes.h> header file. */ -#define EVENT__HAVE_INTTYPES_H 1 +#define EVENT__HAVE_INTTYPES_H 1 /* Define to 1 if you have the `issetugid' function. */ -/* #undef EVENT__HAVE_ISSETUGID */ +/* #undef EVENT__HAVE_ISSETUGID */ /* Define to 1 if you have the `kqueue' function. */ -/* #undef EVENT__HAVE_KQUEUE */ +/* #undef EVENT__HAVE_KQUEUE */ /* Define to 1 if you have the `ws2_32' library (-lws2_32). */ /* #undef EVENT__HAVE_LIBWS2_32 */ /* Define if the system has zlib */ -#define EVENT__HAVE_LIBZ 1 - -/* Define to 1 if you have the `mach_absolute_time' function. */ -/* #undef EVENT__HAVE_MACH_ABSOLUTE_TIME */ +#define EVENT__HAVE_LIBZ 1 +/* Define to 1 if you have the `mach_absolute_time' function. */ +/* #undef EVENT__HAVE_MACH_ABSOLUTE_TIME */ + /* Define to 1 if you have the <mach/mach.h> header file. */ /* #undef EVENT__HAVE_MACH_MACH_H */ -/* Define to 1 if you have the <mach/mach_time.h> header file. */ -/* #undef EVENT__HAVE_MACH_MACH_TIME_H */ - +/* Define to 1 if you have the <mach/mach_time.h> header file. */ +/* #undef EVENT__HAVE_MACH_MACH_TIME_H */ + /* Define to 1 if you have the <memory.h> header file. */ -#define EVENT__HAVE_MEMORY_H 1 +#define EVENT__HAVE_MEMORY_H 1 /* Define to 1 if you have the `mmap' function. */ -#define EVENT__HAVE_MMAP 1 - -/* Define to 1 if you have the `nanosleep' function. */ -#define EVENT__HAVE_NANOSLEEP 1 +#define EVENT__HAVE_MMAP 1 +/* Define to 1 if you have the `nanosleep' function. */ +#define EVENT__HAVE_NANOSLEEP 1 + /* Define to 1 if you have the <netdb.h> header file. */ -#define EVENT__HAVE_NETDB_H 1 +#define EVENT__HAVE_NETDB_H 1 /* Define to 1 if you have the <netinet/in6.h> header file. */ -/* #undef EVENT__HAVE_NETINET_IN6_H */ +/* #undef EVENT__HAVE_NETINET_IN6_H */ /* Define to 1 if you have the <netinet/in.h> header file. */ -#define EVENT__HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the <netinet/tcp.h> header file. */ -#define EVENT__HAVE_NETINET_TCP_H 1 +#define EVENT__HAVE_NETINET_IN_H 1 +/* Define to 1 if you have the <netinet/tcp.h> header file. */ +#define EVENT__HAVE_NETINET_TCP_H 1 + /* Define if the system has openssl */ -#define EVENT__HAVE_OPENSSL 1 +#define EVENT__HAVE_OPENSSL 1 -/* Define to 1 if you have the <openssl/ssl.h> header file. */ -#define EVENT__HAVE_OPENSSL_SSL_H 1 +/* Define to 1 if you have the <openssl/ssl.h> header file. */ +#define EVENT__HAVE_OPENSSL_SSL_H 1 /* Define to 1 if you have the `pipe' function. */ -#define EVENT__HAVE_PIPE 1 - -/* Define to 1 if you have the `pipe2' function. */ -#define EVENT__HAVE_PIPE2 1 +#define EVENT__HAVE_PIPE 1 +/* Define to 1 if you have the `pipe2' function. */ +#define EVENT__HAVE_PIPE2 1 + /* Define to 1 if you have the `poll' function. */ -#define EVENT__HAVE_POLL 1 +#define EVENT__HAVE_POLL 1 /* Define to 1 if you have the <poll.h> header file. */ -#define EVENT__HAVE_POLL_H 1 +#define EVENT__HAVE_POLL_H 1 /* Define to 1 if you have the `port_create' function. */ -/* #undef EVENT__HAVE_PORT_CREATE */ +/* #undef EVENT__HAVE_PORT_CREATE */ /* Define to 1 if you have the <port.h> header file. */ -/* #undef EVENT__HAVE_PORT_H */ +/* #undef EVENT__HAVE_PORT_H */ /* Define if you have POSIX threads libraries and header files. */ -/* #undef EVENT__HAVE_PTHREAD */ +/* #undef EVENT__HAVE_PTHREAD */ /* Define if we have pthreads on this system */ -#define EVENT__HAVE_PTHREADS 1 +#define EVENT__HAVE_PTHREADS 1 /* Define to 1 if you have the `putenv' function. */ -#define EVENT__HAVE_PUTENV 1 +#define EVENT__HAVE_PUTENV 1 /* Define to 1 if the system has the type `sa_family_t'. */ -#define EVENT__HAVE_SA_FAMILY_T 1 +#define EVENT__HAVE_SA_FAMILY_T 1 /* Define to 1 if you have the `select' function. */ -#define EVENT__HAVE_SELECT 1 +#define EVENT__HAVE_SELECT 1 /* Define to 1 if you have the `sendfile' function. */ -#define EVENT__HAVE_SENDFILE 1 +#define EVENT__HAVE_SENDFILE 1 /* Define to 1 if you have the `setenv' function. */ -#define EVENT__HAVE_SETENV 1 +#define EVENT__HAVE_SETENV 1 /* Define if F_SETFD is defined in <fcntl.h> */ -#define EVENT__HAVE_SETFD 1 - -/* Define to 1 if you have the `setrlimit' function. */ -#define EVENT__HAVE_SETRLIMIT 1 +#define EVENT__HAVE_SETFD 1 +/* Define to 1 if you have the `setrlimit' function. */ +#define EVENT__HAVE_SETRLIMIT 1 + /* Define to 1 if you have the `sigaction' function. */ -#define EVENT__HAVE_SIGACTION 1 +#define EVENT__HAVE_SIGACTION 1 /* Define to 1 if you have the `signal' function. */ -#define EVENT__HAVE_SIGNAL 1 +#define EVENT__HAVE_SIGNAL 1 /* Define to 1 if you have the `splice' function. */ -#define EVENT__HAVE_SPLICE 1 +#define EVENT__HAVE_SPLICE 1 /* Define to 1 if you have the <stdarg.h> header file. */ -#define EVENT__HAVE_STDARG_H 1 +#define EVENT__HAVE_STDARG_H 1 /* Define to 1 if you have the <stddef.h> header file. */ -#define EVENT__HAVE_STDDEF_H 1 +#define EVENT__HAVE_STDDEF_H 1 /* Define to 1 if you have the <stdint.h> header file. */ -#define EVENT__HAVE_STDINT_H 1 +#define EVENT__HAVE_STDINT_H 1 /* Define to 1 if you have the <stdlib.h> header file. */ -#define EVENT__HAVE_STDLIB_H 1 +#define EVENT__HAVE_STDLIB_H 1 /* Define to 1 if you have the <strings.h> header file. */ -#define EVENT__HAVE_STRINGS_H 1 +#define EVENT__HAVE_STRINGS_H 1 /* Define to 1 if you have the <string.h> header file. */ -#define EVENT__HAVE_STRING_H 1 +#define EVENT__HAVE_STRING_H 1 /* Define to 1 if you have the `strlcpy' function. */ -/* #undef EVENT__HAVE_STRLCPY */ +/* #undef EVENT__HAVE_STRLCPY */ /* Define to 1 if you have the `strsep' function. */ -#define EVENT__HAVE_STRSEP 1 +#define EVENT__HAVE_STRSEP 1 /* Define to 1 if you have the `strtok_r' function. */ -#define EVENT__HAVE_STRTOK_R 1 +#define EVENT__HAVE_STRTOK_R 1 /* Define to 1 if you have the `strtoll' function. */ -#define EVENT__HAVE_STRTOLL 1 +#define EVENT__HAVE_STRTOLL 1 /* Define to 1 if the system has the type `struct addrinfo'. */ -#define EVENT__HAVE_STRUCT_ADDRINFO 1 +#define EVENT__HAVE_STRUCT_ADDRINFO 1 /* Define to 1 if the system has the type `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR 1 /* Define to 1 if `s6_addr16' is a member of `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 /* Define to 1 if `s6_addr32' is a member of `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 - -/* Define to 1 if the system has the type `struct linger'. */ -#define EVENT__HAVE_STRUCT_LINGER 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 +/* Define to 1 if the system has the type `struct linger'. */ +#define EVENT__HAVE_STRUCT_LINGER 1 + /* Define to 1 if the system has the type `struct sockaddr_in6'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 1 /* Define to 1 if `sin6_len' is a member of `struct sockaddr_in6'. */ -/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */ /* Define to 1 if `sin_len' is a member of `struct sockaddr_in'. */ -/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ /* Define to 1 if the system has the type `struct sockaddr_storage'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE 1 /* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 /* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */ -/* #undef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ - -/* Define to 1 if the system has the type `struct sockaddr_un'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_UN 1 +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ +/* Define to 1 if the system has the type `struct sockaddr_un'. */ +#define EVENT__HAVE_STRUCT_SOCKADDR_UN 1 + /* Define to 1 if you have the `sysctl' function. */ /* #undef EVENT__HAVE_SYSCTL */ /* Define to 1 if you have the <sys/devpoll.h> header file. */ -/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ +/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ /* Define to 1 if you have the <sys/epoll.h> header file. */ -#define EVENT__HAVE_SYS_EPOLL_H 1 +#define EVENT__HAVE_SYS_EPOLL_H 1 /* Define to 1 if you have the <sys/eventfd.h> header file. */ -#define EVENT__HAVE_SYS_EVENTFD_H 1 +#define EVENT__HAVE_SYS_EVENTFD_H 1 /* Define to 1 if you have the <sys/event.h> header file. */ -/* #undef EVENT__HAVE_SYS_EVENT_H */ +/* #undef EVENT__HAVE_SYS_EVENT_H */ /* Define to 1 if you have the <sys/ioctl.h> header file. */ -#define EVENT__HAVE_SYS_IOCTL_H 1 +#define EVENT__HAVE_SYS_IOCTL_H 1 /* Define to 1 if you have the <sys/mman.h> header file. */ -#define EVENT__HAVE_SYS_MMAN_H 1 +#define EVENT__HAVE_SYS_MMAN_H 1 /* Define to 1 if you have the <sys/param.h> header file. */ -#define EVENT__HAVE_SYS_PARAM_H 1 +#define EVENT__HAVE_SYS_PARAM_H 1 /* Define to 1 if you have the <sys/queue.h> header file. */ -#define EVENT__HAVE_SYS_QUEUE_H 1 +#define EVENT__HAVE_SYS_QUEUE_H 1 /* Define to 1 if you have the <sys/random.h> header file. */ #define EVENT__HAVE_SYS_RANDOM_H 1 -/* Define to 1 if you have the <sys/resource.h> header file. */ -#define EVENT__HAVE_SYS_RESOURCE_H 1 - +/* Define to 1 if you have the <sys/resource.h> header file. */ +#define EVENT__HAVE_SYS_RESOURCE_H 1 + /* Define to 1 if you have the <sys/select.h> header file. */ -#define EVENT__HAVE_SYS_SELECT_H 1 +#define EVENT__HAVE_SYS_SELECT_H 1 /* Define to 1 if you have the <sys/sendfile.h> header file. */ -#define EVENT__HAVE_SYS_SENDFILE_H 1 +#define EVENT__HAVE_SYS_SENDFILE_H 1 /* Define to 1 if you have the <sys/socket.h> header file. */ -#define EVENT__HAVE_SYS_SOCKET_H 1 +#define EVENT__HAVE_SYS_SOCKET_H 1 /* Define to 1 if you have the <sys/stat.h> header file. */ -#define EVENT__HAVE_SYS_STAT_H 1 +#define EVENT__HAVE_SYS_STAT_H 1 /* Define to 1 if you have the <sys/sysctl.h> header file. */ /* #undef EVENT__HAVE_SYS_SYSCTL_H */ -/* Define to 1 if you have the <sys/timerfd.h> header file. */ -#define EVENT__HAVE_SYS_TIMERFD_H 1 - +/* Define to 1 if you have the <sys/timerfd.h> header file. */ +#define EVENT__HAVE_SYS_TIMERFD_H 1 + /* Define to 1 if you have the <sys/time.h> header file. */ -#define EVENT__HAVE_SYS_TIME_H 1 +#define EVENT__HAVE_SYS_TIME_H 1 /* Define to 1 if you have the <sys/types.h> header file. */ -#define EVENT__HAVE_SYS_TYPES_H 1 +#define EVENT__HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the <sys/uio.h> header file. */ -#define EVENT__HAVE_SYS_UIO_H 1 - -/* Define to 1 if you have the <sys/un.h> header file. */ -#define EVENT__HAVE_SYS_UN_H 1 +#define EVENT__HAVE_SYS_UIO_H 1 +/* Define to 1 if you have the <sys/un.h> header file. */ +#define EVENT__HAVE_SYS_UN_H 1 + /* Define to 1 if you have the <sys/wait.h> header file. */ -#define EVENT__HAVE_SYS_WAIT_H 1 +#define EVENT__HAVE_SYS_WAIT_H 1 /* Define if TAILQ_FOREACH is defined in <sys/queue.h> */ -#define EVENT__HAVE_TAILQFOREACH 1 +#define EVENT__HAVE_TAILQFOREACH 1 /* Define if timeradd is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERADD 1 +#define EVENT__HAVE_TIMERADD 1 /* Define if timerclear is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERCLEAR 1 +#define EVENT__HAVE_TIMERCLEAR 1 /* Define if timercmp is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERCMP 1 - -/* Define to 1 if you have the `timerfd_create' function. */ -#define EVENT__HAVE_TIMERFD_CREATE 1 +#define EVENT__HAVE_TIMERCMP 1 +/* Define to 1 if you have the `timerfd_create' function. */ +#define EVENT__HAVE_TIMERFD_CREATE 1 + /* Define if timerisset is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERISSET 1 +#define EVENT__HAVE_TIMERISSET 1 /* Define to 1 if the system has the type `uint16_t'. */ -#define EVENT__HAVE_UINT16_T 1 +#define EVENT__HAVE_UINT16_T 1 /* Define to 1 if the system has the type `uint32_t'. */ -#define EVENT__HAVE_UINT32_T 1 +#define EVENT__HAVE_UINT32_T 1 /* Define to 1 if the system has the type `uint64_t'. */ -#define EVENT__HAVE_UINT64_T 1 +#define EVENT__HAVE_UINT64_T 1 /* Define to 1 if the system has the type `uint8_t'. */ -#define EVENT__HAVE_UINT8_T 1 +#define EVENT__HAVE_UINT8_T 1 /* Define to 1 if the system has the type `uintptr_t'. */ -#define EVENT__HAVE_UINTPTR_T 1 +#define EVENT__HAVE_UINTPTR_T 1 /* Define to 1 if you have the `umask' function. */ -#define EVENT__HAVE_UMASK 1 +#define EVENT__HAVE_UMASK 1 /* Define to 1 if you have the <unistd.h> header file. */ -#define EVENT__HAVE_UNISTD_H 1 +#define EVENT__HAVE_UNISTD_H 1 /* Define to 1 if you have the `unsetenv' function. */ -#define EVENT__HAVE_UNSETENV 1 - -/* Define to 1 if you have the `usleep' function. */ -#define EVENT__HAVE_USLEEP 1 +#define EVENT__HAVE_UNSETENV 1 +/* Define to 1 if you have the `usleep' function. */ +#define EVENT__HAVE_USLEEP 1 + /* Define to 1 if you have the `vasprintf' function. */ -#define EVENT__HAVE_VASPRINTF 1 +#define EVENT__HAVE_VASPRINTF 1 /* Define if kqueue works correctly with pipes */ -/* #undef EVENT__HAVE_WORKING_KQUEUE */ +/* #undef EVENT__HAVE_WORKING_KQUEUE */ /* Define to 1 if you have the <zlib.h> header file. */ -#define EVENT__HAVE_ZLIB_H 1 +#define EVENT__HAVE_ZLIB_H 1 /* Define to 1 if you have the `_gmtime64' function. */ /* #undef EVENT__HAVE__GMTIME64 */ @@ -430,141 +430,141 @@ /* Define to 1 if you have the `_gmtime64_s' function. */ /* #undef EVENT__HAVE__GMTIME64_S */ -/* Define to 1 if compiler have __FUNCTION__ */ -#define EVENT__HAVE___FUNCTION__ 1 +/* Define to 1 if compiler have __FUNCTION__ */ +#define EVENT__HAVE___FUNCTION__ 1 -/* Define to 1 if compiler have __func__ */ -#define EVENT__HAVE___func__ 1 - -/* Define to the sub-directory where libtool stores uninstalled libraries. */ -#define EVENT__LT_OBJDIR ".libs/" +/* Define to 1 if compiler have __func__ */ +#define EVENT__HAVE___func__ 1 +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#define EVENT__LT_OBJDIR ".libs/" + /* Numeric representation of the version */ #define EVENT__NUMERIC_VERSION 0x02010c00 /* Name of package */ -#define EVENT__PACKAGE "libevent" +#define EVENT__PACKAGE "libevent" /* Define to the address where bug reports for this package should be sent. */ -#define EVENT__PACKAGE_BUGREPORT "" +#define EVENT__PACKAGE_BUGREPORT "" /* Define to the full name of this package. */ -#define EVENT__PACKAGE_NAME "libevent" +#define EVENT__PACKAGE_NAME "libevent" /* Define to the full name and version of this package. */ #define EVENT__PACKAGE_STRING "libevent 2.1.12-stable" /* Define to the one symbol short name of this package. */ -#define EVENT__PACKAGE_TARNAME "libevent" +#define EVENT__PACKAGE_TARNAME "libevent" /* Define to the home page for this package. */ -#define EVENT__PACKAGE_URL "" +#define EVENT__PACKAGE_URL "" /* Define to the version of this package. */ #define EVENT__PACKAGE_VERSION "2.1.12-stable" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ -/* #undef EVENT__PTHREAD_CREATE_JOINABLE */ +/* #undef EVENT__PTHREAD_CREATE_JOINABLE */ /* The size of `int', as computed by sizeof. */ -#define EVENT__SIZEOF_INT 4 +#define EVENT__SIZEOF_INT 4 /* The size of `long', as computed by sizeof. */ -#define EVENT__SIZEOF_LONG 8 +#define EVENT__SIZEOF_LONG 8 /* The size of `long long', as computed by sizeof. */ -#define EVENT__SIZEOF_LONG_LONG 8 +#define EVENT__SIZEOF_LONG_LONG 8 /* The size of `off_t', as computed by sizeof. */ -#define EVENT__SIZEOF_OFF_T 8 +#define EVENT__SIZEOF_OFF_T 8 /* The size of `pthread_t', as computed by sizeof. */ -#define EVENT__SIZEOF_PTHREAD_T 8 +#define EVENT__SIZEOF_PTHREAD_T 8 /* The size of `short', as computed by sizeof. */ -#define EVENT__SIZEOF_SHORT 2 +#define EVENT__SIZEOF_SHORT 2 /* The size of `size_t', as computed by sizeof. */ -#define EVENT__SIZEOF_SIZE_T 8 - -/* The size of `time_t', as computed by sizeof. */ -#define EVENT__SIZEOF_TIME_T 8 +#define EVENT__SIZEOF_SIZE_T 8 +/* The size of `time_t', as computed by sizeof. */ +#define EVENT__SIZEOF_TIME_T 8 + /* The size of `void *', as computed by sizeof. */ -#define EVENT__SIZEOF_VOID_P 8 +#define EVENT__SIZEOF_VOID_P 8 /* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 +#define STDC_HEADERS 1 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ -#define EVENT__TIME_WITH_SYS_TIME 1 - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - - +#define EVENT__TIME_WITH_SYS_TIME 1 + +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif + + /* Version number of package */ #define EVENT__VERSION "2.1.12-stable" -/* Enable large inode numbers on Mac OS X 10.5. */ -#ifndef _DARWIN_USE_64_BIT_INODE -# define _DARWIN_USE_64_BIT_INODE 1 -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -/* #undef _FILE_OFFSET_BITS */ - -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - +/* Enable large inode numbers on Mac OS X 10.5. */ +#ifndef _DARWIN_USE_64_BIT_INODE +# define _DARWIN_USE_64_BIT_INODE 1 +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ + +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + /* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ +/* #undef const */ /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ +#ifndef __cplusplus +/* #undef inline */ #endif /* Define to `int' if <sys/types.h> does not define. */ -/* #undef pid_t */ +/* #undef pid_t */ /* Define to `unsigned int' if <sys/types.h> does not define. */ -/* #undef size_t */ +/* #undef size_t */ /* Define to unsigned int if you dont have it */ -/* #undef socklen_t */ +/* #undef socklen_t */ /* Define to `int' if <sys/types.h> does not define. */ -/* #undef ssize_t */ +/* #undef ssize_t */ #endif /* event2/event-config.h */ diff --git a/contrib/libs/libevent/include/event2/event-config-musl.h b/contrib/libs/libevent/include/event2/event-config-musl.h index 7b4fabd32d..de6930948e 100644 --- a/contrib/libs/libevent/include/event2/event-config-musl.h +++ b/contrib/libs/libevent/include/event2/event-config-musl.h @@ -2,6 +2,6 @@ #include "event-config-linux.h" -#undef EVENT__HAVE_DECL_CTL_KERN -#undef EVENT__HAVE_DECL_KERN_RANDOM -#undef EVENT__HAVE_DECL_RANDOM_UUID +#undef EVENT__HAVE_DECL_CTL_KERN +#undef EVENT__HAVE_DECL_KERN_RANDOM +#undef EVENT__HAVE_DECL_RANDOM_UUID diff --git a/contrib/libs/libevent/include/event2/event-config-osx.h b/contrib/libs/libevent/include/event2/event-config-osx.h index 8e6c4f7ea0..1798ec2d5b 100644 --- a/contrib/libs/libevent/include/event2/event-config-osx.h +++ b/contrib/libs/libevent/include/event2/event-config-osx.h @@ -8,446 +8,446 @@ * Do not rely on macros in this file existing in later versions. */ -#ifndef _EVENT2EVENT__CONFIG_H_ -#define _EVENT2EVENT__CONFIG_H_ +#ifndef _EVENT2EVENT__CONFIG_H_ +#define _EVENT2EVENT__CONFIG_H_ /* config.h. Generated from config.h.in by configure. */ /* config.h.in. Generated from configure.ac by autoheader. */ /* Define if libevent should build without support for a debug mode */ -/* #undef EVENT__DISABLE_DEBUG_MODE */ +/* #undef EVENT__DISABLE_DEBUG_MODE */ /* Define if libevent should not allow replacing the mm functions */ -/* #undef EVENT__DISABLE_MM_REPLACEMENT */ +/* #undef EVENT__DISABLE_MM_REPLACEMENT */ /* Define if libevent should not be compiled with thread support */ -/* #undef EVENT__DISABLE_THREAD_SUPPORT */ +/* #undef EVENT__DISABLE_THREAD_SUPPORT */ /* Define to 1 if you have the `arc4random' function. */ -#define EVENT__HAVE_ARC4RANDOM 1 +#define EVENT__HAVE_ARC4RANDOM 1 /* Define to 1 if you have the `arc4random_buf' function. */ -#define EVENT__HAVE_ARC4RANDOM_BUF 1 +#define EVENT__HAVE_ARC4RANDOM_BUF 1 /* Define to 1 if you have the <arpa/inet.h> header file. */ -#define EVENT__HAVE_ARPA_INET_H 1 +#define EVENT__HAVE_ARPA_INET_H 1 /* Define to 1 if you have the `clock_gettime' function. */ -/* #undef EVENT__HAVE_CLOCK_GETTIME */ +/* #undef EVENT__HAVE_CLOCK_GETTIME */ /* Define to 1 if you have the declaration of `CTL_KERN', and to 0 if you don't. */ -#define EVENT__HAVE_DECL_CTL_KERN 1 +#define EVENT__HAVE_DECL_CTL_KERN 1 /* Define to 1 if you have the declaration of `KERN_ARND', and to 0 if you don't. */ -#define EVENT__HAVE_DECL_KERN_ARND 0 +#define EVENT__HAVE_DECL_KERN_ARND 0 /* Define to 1 if you have the declaration of `KERN_RANDOM', and to 0 if you don't. */ -#define EVENT__HAVE_DECL_KERN_RANDOM 0 +#define EVENT__HAVE_DECL_KERN_RANDOM 0 /* Define to 1 if you have the declaration of `RANDOM_UUID', and to 0 if you don't. */ -#define EVENT__HAVE_DECL_RANDOM_UUID 0 +#define EVENT__HAVE_DECL_RANDOM_UUID 0 /* Define if /dev/poll is available */ -/* #undef EVENT__HAVE_DEVPOLL */ +/* #undef EVENT__HAVE_DEVPOLL */ /* Define to 1 if you have the <dlfcn.h> header file. */ -#define EVENT__HAVE_DLFCN_H 1 +#define EVENT__HAVE_DLFCN_H 1 /* Define if your system supports the epoll system calls */ -/* #undef EVENT__HAVE_EPOLL */ +/* #undef EVENT__HAVE_EPOLL */ /* Define to 1 if you have the `epoll_ctl' function. */ -/* #undef EVENT__HAVE_EPOLL_CTL */ +/* #undef EVENT__HAVE_EPOLL_CTL */ /* Define to 1 if you have the `eventfd' function. */ -/* #undef EVENT__HAVE_EVENTFD */ +/* #undef EVENT__HAVE_EVENTFD */ /* Define if your system supports event ports */ -/* #undef EVENT__HAVE_EVENT_PORTS */ +/* #undef EVENT__HAVE_EVENT_PORTS */ /* Define to 1 if you have the `fcntl' function. */ -#define EVENT__HAVE_FCNTL 1 +#define EVENT__HAVE_FCNTL 1 /* Define to 1 if you have the <fcntl.h> header file. */ -#define EVENT__HAVE_FCNTL_H 1 +#define EVENT__HAVE_FCNTL_H 1 /* Define to 1 if the system has the type `fd_mask'. */ -#define EVENT__HAVE_FD_MASK 1 +#define EVENT__HAVE_FD_MASK 1 /* Do we have getaddrinfo()? */ -#define EVENT__HAVE_GETADDRINFO 1 +#define EVENT__HAVE_GETADDRINFO 1 /* Define to 1 if you have the `getegid' function. */ -#define EVENT__HAVE_GETEGID 1 +#define EVENT__HAVE_GETEGID 1 /* Define to 1 if you have the `geteuid' function. */ -#define EVENT__HAVE_GETEUID 1 +#define EVENT__HAVE_GETEUID 1 /* Define this if you have any gethostbyname_r() */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R */ /* Define this if gethostbyname_r takes 3 arguments */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R_3_ARG */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_3_ARG */ /* Define this if gethostbyname_r takes 5 arguments */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R_5_ARG */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_5_ARG */ /* Define this if gethostbyname_r takes 6 arguments */ -/* #undef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG */ /* Define to 1 if you have the `getnameinfo' function. */ -#define EVENT__HAVE_GETNAMEINFO 1 +#define EVENT__HAVE_GETNAMEINFO 1 /* Define to 1 if you have the `getprotobynumber' function. */ -#define EVENT__HAVE_GETPROTOBYNUMBER 1 +#define EVENT__HAVE_GETPROTOBYNUMBER 1 /* Define to 1 if you have the `getservbyname' function. */ -/* #undef EVENT__HAVE_GETSERVBYNAME */ +/* #undef EVENT__HAVE_GETSERVBYNAME */ /* Define to 1 if you have the `gettimeofday' function. */ -#define EVENT__HAVE_GETTIMEOFDAY 1 +#define EVENT__HAVE_GETTIMEOFDAY 1 /* Define to 1 if you have the `inet_aton' function. */ -#define EVENT__HAVE_INET_ATON 1 +#define EVENT__HAVE_INET_ATON 1 /* Define to 1 if you have the `inet_ntop' function. */ -#define EVENT__HAVE_INET_NTOP 1 +#define EVENT__HAVE_INET_NTOP 1 /* Define to 1 if you have the `inet_pton' function. */ -#define EVENT__HAVE_INET_PTON 1 +#define EVENT__HAVE_INET_PTON 1 /* Define to 1 if you have the <inttypes.h> header file. */ -#define EVENT__HAVE_INTTYPES_H 1 +#define EVENT__HAVE_INTTYPES_H 1 /* Define to 1 if you have the `issetugid' function. */ -#define EVENT__HAVE_ISSETUGID 1 +#define EVENT__HAVE_ISSETUGID 1 /* Define to 1 if you have the `kqueue' function. */ -#define EVENT__HAVE_KQUEUE 1 +#define EVENT__HAVE_KQUEUE 1 /* Define if the system has zlib */ -#define EVENT__HAVE_LIBZ 1 +#define EVENT__HAVE_LIBZ 1 /* Define to 1 if you have the <memory.h> header file. */ -#define EVENT__HAVE_MEMORY_H 1 +#define EVENT__HAVE_MEMORY_H 1 /* Define to 1 if you have the `mmap' function. */ -#define EVENT__HAVE_MMAP 1 +#define EVENT__HAVE_MMAP 1 /* Define to 1 if you have the <netdb.h> header file. */ -#define EVENT__HAVE_NETDB_H 1 +#define EVENT__HAVE_NETDB_H 1 /* Define to 1 if you have the <netinet/in6.h> header file. */ -/* #undef EVENT__HAVE_NETINET_IN6_H */ +/* #undef EVENT__HAVE_NETINET_IN6_H */ /* Define to 1 if you have the <netinet/in.h> header file. */ -#define EVENT__HAVE_NETINET_IN_H 1 +#define EVENT__HAVE_NETINET_IN_H 1 /* Define if the system has openssl */ -#define EVENT__HAVE_OPENSSL 1 +#define EVENT__HAVE_OPENSSL 1 /* Define to 1 if you have the <openssl/bio.h> header file. */ -#define EVENT__HAVE_OPENSSL_BIO_H 1 +#define EVENT__HAVE_OPENSSL_BIO_H 1 /* Define to 1 if you have the `pipe' function. */ -#define EVENT__HAVE_PIPE 1 +#define EVENT__HAVE_PIPE 1 /* Define to 1 if you have the `poll' function. */ -#define EVENT__HAVE_POLL 1 +#define EVENT__HAVE_POLL 1 /* Define to 1 if you have the <poll.h> header file. */ -#define EVENT__HAVE_POLL_H 1 +#define EVENT__HAVE_POLL_H 1 /* Define to 1 if you have the `port_create' function. */ -/* #undef EVENT__HAVE_PORT_CREATE */ +/* #undef EVENT__HAVE_PORT_CREATE */ /* Define to 1 if you have the <port.h> header file. */ -/* #undef EVENT__HAVE_PORT_H */ +/* #undef EVENT__HAVE_PORT_H */ /* Define if you have POSIX threads libraries and header files. */ -/* #undef EVENT__HAVE_PTHREAD */ +/* #undef EVENT__HAVE_PTHREAD */ /* Define if we have pthreads on this system */ -#define EVENT__HAVE_PTHREADS 1 +#define EVENT__HAVE_PTHREADS 1 /* Define to 1 if you have the `putenv' function. */ -#define EVENT__HAVE_PUTENV 1 +#define EVENT__HAVE_PUTENV 1 /* Define to 1 if the system has the type `sa_family_t'. */ -#define EVENT__HAVE_SA_FAMILY_T 1 +#define EVENT__HAVE_SA_FAMILY_T 1 /* Define to 1 if you have the `select' function. */ -#define EVENT__HAVE_SELECT 1 +#define EVENT__HAVE_SELECT 1 /* Define to 1 if you have the `sendfile' function. */ -#define EVENT__HAVE_SENDFILE 1 +#define EVENT__HAVE_SENDFILE 1 /* Define to 1 if you have the `setenv' function. */ -#define EVENT__HAVE_SETENV 1 +#define EVENT__HAVE_SETENV 1 /* Define if F_SETFD is defined in <fcntl.h> */ -#define EVENT__HAVE_SETFD 1 +#define EVENT__HAVE_SETFD 1 /* Define to 1 if you have the `sigaction' function. */ -#define EVENT__HAVE_SIGACTION 1 +#define EVENT__HAVE_SIGACTION 1 /* Define to 1 if you have the `signal' function. */ -#define EVENT__HAVE_SIGNAL 1 +#define EVENT__HAVE_SIGNAL 1 /* Define to 1 if you have the `splice' function. */ -/* #undef EVENT__HAVE_SPLICE */ +/* #undef EVENT__HAVE_SPLICE */ /* Define to 1 if you have the <stdarg.h> header file. */ -#define EVENT__HAVE_STDARG_H 1 +#define EVENT__HAVE_STDARG_H 1 /* Define to 1 if you have the <stddef.h> header file. */ -#define EVENT__HAVE_STDDEF_H 1 +#define EVENT__HAVE_STDDEF_H 1 /* Define to 1 if you have the <stdint.h> header file. */ -#define EVENT__HAVE_STDINT_H 1 +#define EVENT__HAVE_STDINT_H 1 /* Define to 1 if you have the <stdlib.h> header file. */ -#define EVENT__HAVE_STDLIB_H 1 +#define EVENT__HAVE_STDLIB_H 1 /* Define to 1 if you have the <strings.h> header file. */ -#define EVENT__HAVE_STRINGS_H 1 +#define EVENT__HAVE_STRINGS_H 1 /* Define to 1 if you have the <string.h> header file. */ -#define EVENT__HAVE_STRING_H 1 +#define EVENT__HAVE_STRING_H 1 /* Define to 1 if you have the `strlcpy' function. */ -#define EVENT__HAVE_STRLCPY 1 +#define EVENT__HAVE_STRLCPY 1 /* Define to 1 if you have the `strsep' function. */ -#define EVENT__HAVE_STRSEP 1 +#define EVENT__HAVE_STRSEP 1 /* Define to 1 if you have the `strtok_r' function. */ -#define EVENT__HAVE_STRTOK_R 1 +#define EVENT__HAVE_STRTOK_R 1 /* Define to 1 if you have the `strtoll' function. */ -#define EVENT__HAVE_STRTOLL 1 +#define EVENT__HAVE_STRTOLL 1 /* Define to 1 if the system has the type `struct addrinfo'. */ -#define EVENT__HAVE_STRUCT_ADDRINFO 1 +#define EVENT__HAVE_STRUCT_ADDRINFO 1 /* Define to 1 if the system has the type `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR 1 /* Define to 1 if `s6_addr16' is a member of `struct in6_addr'. */ -/* #undef EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 */ +/* #undef EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 */ /* Define to 1 if `s6_addr32' is a member of `struct in6_addr'. */ -/* #undef EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 */ +/* #undef EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 */ /* Define to 1 if the system has the type `struct sockaddr_in6'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 1 /* Define to 1 if `sin6_len' is a member of `struct sockaddr_in6'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN 1 /* Define to 1 if `sin_len' is a member of `struct sockaddr_in'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 1 /* Define to 1 if the system has the type `struct sockaddr_storage'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE 1 /* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1 /* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */ -/* #undef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ /* Define to 1 if you have the `sysctl' function. */ -#define EVENT__HAVE_SYSCTL 1 +#define EVENT__HAVE_SYSCTL 1 /* Define to 1 if you have the <sys/devpoll.h> header file. */ -/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ +/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ /* Define to 1 if you have the <sys/epoll.h> header file. */ -/* #undef EVENT__HAVE_SYS_EPOLL_H */ +/* #undef EVENT__HAVE_SYS_EPOLL_H */ /* Define to 1 if you have the <sys/eventfd.h> header file. */ -/* #undef EVENT__HAVE_SYS_EVENTFD_H */ +/* #undef EVENT__HAVE_SYS_EVENTFD_H */ /* Define to 1 if you have the <sys/event.h> header file. */ -#define EVENT__HAVE_SYS_EVENT_H 1 +#define EVENT__HAVE_SYS_EVENT_H 1 /* Define to 1 if you have the <sys/ioctl.h> header file. */ -#define EVENT__HAVE_SYS_IOCTL_H 1 +#define EVENT__HAVE_SYS_IOCTL_H 1 /* Define to 1 if you have the <sys/mman.h> header file. */ -#define EVENT__HAVE_SYS_MMAN_H 1 +#define EVENT__HAVE_SYS_MMAN_H 1 /* Define to 1 if you have the <sys/param.h> header file. */ -#define EVENT__HAVE_SYS_PARAM_H 1 +#define EVENT__HAVE_SYS_PARAM_H 1 /* Define to 1 if you have the <sys/queue.h> header file. */ -#define EVENT__HAVE_SYS_QUEUE_H 1 +#define EVENT__HAVE_SYS_QUEUE_H 1 /* Define to 1 if you have the <sys/select.h> header file. */ -#define EVENT__HAVE_SYS_SELECT_H 1 +#define EVENT__HAVE_SYS_SELECT_H 1 /* Define to 1 if you have the <sys/sendfile.h> header file. */ -/* #undef EVENT__HAVE_SYS_SENDFILE_H */ +/* #undef EVENT__HAVE_SYS_SENDFILE_H */ /* Define to 1 if you have the <sys/socket.h> header file. */ -#define EVENT__HAVE_SYS_SOCKET_H 1 +#define EVENT__HAVE_SYS_SOCKET_H 1 /* Define to 1 if you have the <sys/stat.h> header file. */ -#define EVENT__HAVE_SYS_STAT_H 1 +#define EVENT__HAVE_SYS_STAT_H 1 /* Define to 1 if you have the <sys/sysctl.h> header file. */ -#define EVENT__HAVE_SYS_SYSCTL_H 1 +#define EVENT__HAVE_SYS_SYSCTL_H 1 /* Define to 1 if you have the <sys/time.h> header file. */ -#define EVENT__HAVE_SYS_TIME_H 1 +#define EVENT__HAVE_SYS_TIME_H 1 /* Define to 1 if you have the <sys/types.h> header file. */ -#define EVENT__HAVE_SYS_TYPES_H 1 +#define EVENT__HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the <sys/uio.h> header file. */ -#define EVENT__HAVE_SYS_UIO_H 1 +#define EVENT__HAVE_SYS_UIO_H 1 /* Define to 1 if you have the <sys/wait.h> header file. */ -#define EVENT__HAVE_SYS_WAIT_H 1 +#define EVENT__HAVE_SYS_WAIT_H 1 /* Define if TAILQ_FOREACH is defined in <sys/queue.h> */ -#define EVENT__HAVE_TAILQFOREACH 1 +#define EVENT__HAVE_TAILQFOREACH 1 /* Define if timeradd is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERADD 1 +#define EVENT__HAVE_TIMERADD 1 /* Define if timerclear is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERCLEAR 1 +#define EVENT__HAVE_TIMERCLEAR 1 /* Define if timercmp is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERCMP 1 +#define EVENT__HAVE_TIMERCMP 1 /* Define if timerisset is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERISSET 1 +#define EVENT__HAVE_TIMERISSET 1 /* Define to 1 if the system has the type `uint16_t'. */ -#define EVENT__HAVE_UINT16_T 1 +#define EVENT__HAVE_UINT16_T 1 /* Define to 1 if the system has the type `uint32_t'. */ -#define EVENT__HAVE_UINT32_T 1 +#define EVENT__HAVE_UINT32_T 1 /* Define to 1 if the system has the type `uint64_t'. */ -#define EVENT__HAVE_UINT64_T 1 +#define EVENT__HAVE_UINT64_T 1 /* Define to 1 if the system has the type `uint8_t'. */ -#define EVENT__HAVE_UINT8_T 1 +#define EVENT__HAVE_UINT8_T 1 /* Define to 1 if the system has the type `uintptr_t'. */ -#define EVENT__HAVE_UINTPTR_T 1 +#define EVENT__HAVE_UINTPTR_T 1 /* Define to 1 if you have the `umask' function. */ -#define EVENT__HAVE_UMASK 1 +#define EVENT__HAVE_UMASK 1 /* Define to 1 if you have the <unistd.h> header file. */ -#define EVENT__HAVE_UNISTD_H 1 +#define EVENT__HAVE_UNISTD_H 1 /* Define to 1 if you have the `unsetenv' function. */ -#define EVENT__HAVE_UNSETENV 1 +#define EVENT__HAVE_UNSETENV 1 /* Define to 1 if you have the `vasprintf' function. */ -#define EVENT__HAVE_VASPRINTF 1 +#define EVENT__HAVE_VASPRINTF 1 /* Define if kqueue works correctly with pipes */ -#define EVENT__HAVE_WORKING_KQUEUE 1 +#define EVENT__HAVE_WORKING_KQUEUE 1 /* Define to 1 if you have the <zlib.h> header file. */ -#define EVENT__HAVE_ZLIB_H 1 +#define EVENT__HAVE_ZLIB_H 1 /* Define to the sub-directory where libtool stores uninstalled libraries. */ -#define EVENT__LT_OBJDIR ".libs/" +#define EVENT__LT_OBJDIR ".libs/" /* Numeric representation of the version */ #define EVENT__NUMERIC_VERSION 0x02010c00 /* Name of package */ -#define EVENT__PACKAGE "libevent" +#define EVENT__PACKAGE "libevent" /* Define to the address where bug reports for this package should be sent. */ -#define EVENT__PACKAGE_BUGREPORT "" +#define EVENT__PACKAGE_BUGREPORT "" /* Define to the full name of this package. */ -#define EVENT__PACKAGE_NAME "" +#define EVENT__PACKAGE_NAME "" /* Define to the full name and version of this package. */ #define EVENT__PACKAGE_STRING "libevent 2.1.12-stable" /* Define to the one symbol short name of this package. */ -#define EVENT__PACKAGE_TARNAME "" +#define EVENT__PACKAGE_TARNAME "" /* Define to the home page for this package. */ -#define EVENT__PACKAGE_URL "" +#define EVENT__PACKAGE_URL "" /* Define to the version of this package. */ #define EVENT__PACKAGE_VERSION "2.1.12-stable" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ -/* #undef EVENT__PTHREAD_CREATE_JOINABLE */ +/* #undef EVENT__PTHREAD_CREATE_JOINABLE */ /* The size of `int', as computed by sizeof. */ -#define EVENT__SIZEOF_INT 4 +#define EVENT__SIZEOF_INT 4 /* The size of `long', as computed by sizeof. */ -#define EVENT__SIZEOF_LONG 8 +#define EVENT__SIZEOF_LONG 8 /* The size of `long long', as computed by sizeof. */ -#define EVENT__SIZEOF_LONG_LONG 8 +#define EVENT__SIZEOF_LONG_LONG 8 /* The size of `off_t', as computed by sizeof. */ -#define EVENT__SIZEOF_OFF_T 8 +#define EVENT__SIZEOF_OFF_T 8 /* The size of `pthread_t', as computed by sizeof. */ -#define EVENT__SIZEOF_PTHREAD_T 8 +#define EVENT__SIZEOF_PTHREAD_T 8 /* The size of `short', as computed by sizeof. */ -#define EVENT__SIZEOF_SHORT 2 +#define EVENT__SIZEOF_SHORT 2 /* The size of `size_t', as computed by sizeof. */ -#define EVENT__SIZEOF_SIZE_T 8 +#define EVENT__SIZEOF_SIZE_T 8 /* The size of `void *', as computed by sizeof. */ -#define EVENT__SIZEOF_VOID_P 8 +#define EVENT__SIZEOF_VOID_P 8 /* Define to 1 if you have the ANSI C header files. */ -#define EVENT__STDC_HEADERS 1 +#define EVENT__STDC_HEADERS 1 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ -#define EVENT__TIME_WITH_SYS_TIME 1 +#define EVENT__TIME_WITH_SYS_TIME 1 /* Version number of package */ #define EVENT__VERSION "2.1.12-stable" /* Define to appropriate substitue if compiler doesnt have __func__ */ -/* #undef EVENT____func__ */ +/* #undef EVENT____func__ */ /* Define to empty if `const' does not conform to ANSI C. */ -/* #undef EVENT__const */ +/* #undef EVENT__const */ /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef EVENT____cplusplus -/* #undef EVENT__inline */ +#ifndef EVENT____cplusplus +/* #undef EVENT__inline */ #endif /* Define to `int' if <sys/types.h> does not define. */ -/* #undef EVENT__pid_t */ +/* #undef EVENT__pid_t */ /* Define to `unsigned int' if <sys/types.h> does not define. */ -/* #undef EVENT__size_t */ +/* #undef EVENT__size_t */ /* Define to unsigned int if you dont have it */ -/* #undef EVENT__socklen_t */ +/* #undef EVENT__socklen_t */ /* Define to `int' if <sys/types.h> does not define. */ -/* #undef EVENT__ssize_t */ +/* #undef EVENT__ssize_t */ #endif /* event2/event-config.h */ diff --git a/contrib/libs/libevent/include/event2/event-config-win.h b/contrib/libs/libevent/include/event2/event-config-win.h index ef4141a720..5175bb0ad6 100644 --- a/contrib/libs/libevent/include/event2/event-config-win.h +++ b/contrib/libs/libevent/include/event2/event-config-win.h @@ -7,357 +7,357 @@ * * Do not rely on macros in this file existing in later versions. */ -#ifndef EVENT__CONFIG_H_ -#define EVENT__CONFIG_H_ +#ifndef EVENT__CONFIG_H_ +#define EVENT__CONFIG_H_ /* config.h. Generated by configure. */ /* config.h.in. Generated from configure.in by autoheader. */ /* Define if libevent should not allow replacing the mm functions */ -/* #undef EVENT__DISABLE_MM_REPLACEMENT */ +/* #undef EVENT__DISABLE_MM_REPLACEMENT */ /* Define if libevent should not be compiled with thread support */ -/* #undef EVENT__DISABLE_THREAD_SUPPORT */ +/* #undef EVENT__DISABLE_THREAD_SUPPORT */ /* Define if clock_gettime is available in libc */ -/* #undef EVENT__DNS_USE_CPU_CLOCK_FOR_ID */ +/* #undef EVENT__DNS_USE_CPU_CLOCK_FOR_ID */ /* Define is no secure id variant is available */ -/* #define EVENT__DNS_USE_GETTIMEOFDAY_FOR_ID 1 */ -#define EVENT__DNS_USE_FTIME_FOR_ID 1 +/* #define EVENT__DNS_USE_GETTIMEOFDAY_FOR_ID 1 */ +#define EVENT__DNS_USE_FTIME_FOR_ID 1 /* Define to 1 if you have the <arpa/inet.h> header file. */ -/* #undef EVENT__HAVE_ARPA_INET_H */ +/* #undef EVENT__HAVE_ARPA_INET_H */ /* Define to 1 if you have the `clock_gettime' function. */ -/* #undef EVENT__HAVE_CLOCK_GETTIME */ +/* #undef EVENT__HAVE_CLOCK_GETTIME */ /* Define if /dev/poll is available */ -/* #undef EVENT__HAVE_DEVPOLL */ +/* #undef EVENT__HAVE_DEVPOLL */ /* Define to 1 if you have the <dlfcn.h> header file. */ -/* #undef EVENT__HAVE_DLFCN_H */ +/* #undef EVENT__HAVE_DLFCN_H */ /* Define if your system supports the epoll system calls */ -/* #undef EVENT__HAVE_EPOLL */ +/* #undef EVENT__HAVE_EPOLL */ /* Define to 1 if you have the `epoll_ctl' function. */ -/* #undef EVENT__HAVE_EPOLL_CTL */ +/* #undef EVENT__HAVE_EPOLL_CTL */ /* Define to 1 if you have the `eventfd' function. */ -/* #undef EVENT__HAVE_EVENTFD */ +/* #undef EVENT__HAVE_EVENTFD */ /* Define if your system supports event ports */ -/* #undef EVENT__HAVE_EVENT_PORTS */ +/* #undef EVENT__HAVE_EVENT_PORTS */ /* Define to 1 if you have the `fcntl' function. */ -/* #undef EVENT__HAVE_FCNTL */ +/* #undef EVENT__HAVE_FCNTL */ /* Define to 1 if you have the <fcntl.h> header file. */ -#define EVENT__HAVE_FCNTL_H 1 +#define EVENT__HAVE_FCNTL_H 1 /* Define to 1 if you have the `getaddrinfo' function. */ -#define EVENT__HAVE_GETADDRINFO 1 +#define EVENT__HAVE_GETADDRINFO 1 /* Define to 1 if you have the `getnameinfo' function. */ -#define EVENT__HAVE_GETNAMEINFO 1 +#define EVENT__HAVE_GETNAMEINFO 1 /* Define to 1 if you have the `getprotobynumber' function. */ -#define EVENT__HAVE_GETPROTOBYNUMBER 1 +#define EVENT__HAVE_GETPROTOBYNUMBER 1 /* Define to 1 if you have the `getservbyname' function. */ -#define EVENT__HAVE_GETSERVBYNAME 1 +#define EVENT__HAVE_GETSERVBYNAME 1 /* Define to 1 if you have the `gettimeofday' function. */ -/* #define EVENT__HAVE_GETTIMEOFDAY 1 */ +/* #define EVENT__HAVE_GETTIMEOFDAY 1 */ /* Define to 1 if you have the `inet_aton' function. */ -/* #undef EVENT__HAVE_INET_ATON */ +/* #undef EVENT__HAVE_INET_ATON */ /* Define to 1 if you have the `inet_ntop' function. */ -/* #undef EVENT__HAVE_INET_NTOP */ +/* #undef EVENT__HAVE_INET_NTOP */ /* Define to 1 if you have the `inet_pton' function. */ -/* #undef EVENT__HAVE_INET_PTON */ +/* #undef EVENT__HAVE_INET_PTON */ /* Define to 1 if you have the <inttypes.h> header file. */ -/* #define EVENT__HAVE_INTTYPES_H 1 */ +/* #define EVENT__HAVE_INTTYPES_H 1 */ /* Define to 1 if you have the `kqueue' function. */ -/* #undef EVENT__HAVE_KQUEUE */ +/* #undef EVENT__HAVE_KQUEUE */ /* Define if the system has zlib */ -/* #undef EVENT__HAVE_LIBZ */ +/* #undef EVENT__HAVE_LIBZ */ /* Define to 1 if you have the <memory.h> header file. */ -#define EVENT__HAVE_MEMORY_H 1 +#define EVENT__HAVE_MEMORY_H 1 /* Define to 1 if you have the `mmap' function. */ -/* #undef EVENT__HAVE_MMAP */ +/* #undef EVENT__HAVE_MMAP */ /* Define to 1 if you have the <netinet/in6.h> header file. */ -/* #undef EVENT__HAVE_NETINET_IN6_H */ +/* #undef EVENT__HAVE_NETINET_IN6_H */ /* Define to 1 if you have the <netinet/in.h> header file. */ -/* #undef EVENT__HAVE_NETINET_IN_H */ +/* #undef EVENT__HAVE_NETINET_IN_H */ /* Define to 1 if you have the `pipe' function. */ -/* #undef EVENT__HAVE_PIPE */ +/* #undef EVENT__HAVE_PIPE */ /* Define to 1 if you have the `poll' function. */ -/* #undef EVENT__HAVE_POLL */ +/* #undef EVENT__HAVE_POLL */ /* Define to 1 if you have the <poll.h> header file. */ -/* #undef EVENT__HAVE_POLL_H */ +/* #undef EVENT__HAVE_POLL_H */ /* Define to 1 if you have the `port_create' function. */ -/* #undef EVENT__HAVE_PORT_CREATE */ +/* #undef EVENT__HAVE_PORT_CREATE */ /* Define to 1 if you have the <port.h> header file. */ -/* #undef EVENT__HAVE_PORT_H */ +/* #undef EVENT__HAVE_PORT_H */ /* Define if you have POSIX threads libraries and header files. */ -/* #undef EVENT__HAVE_PTHREAD */ +/* #undef EVENT__HAVE_PTHREAD */ /* Define if we have pthreads on this system */ -/* #undef EVENT__HAVE_PTHREADS */ +/* #undef EVENT__HAVE_PTHREADS */ /* Define to 1 if the system has the type `sa_family_t'. */ -/* #undef EVENT__HAVE_SA_FAMILY_T */ +/* #undef EVENT__HAVE_SA_FAMILY_T */ /* Define to 1 if you have the `select' function. */ -/* #undef EVENT__HAVE_SELECT */ +/* #undef EVENT__HAVE_SELECT */ /* Define to 1 if you have the `sendfile' function. */ -/* #undef EVENT__HAVE_SENDFILE */ +/* #undef EVENT__HAVE_SENDFILE */ /* Define if F_SETFD is defined in <fcntl.h> */ -/* #undef EVENT__HAVE_SETFD */ +/* #undef EVENT__HAVE_SETFD */ /* Define to 1 if you have the `sigaction' function. */ -/* #undef EVENT__HAVE_SIGACTION */ +/* #undef EVENT__HAVE_SIGACTION */ /* Define to 1 if you have the `signal' function. */ -#define EVENT__HAVE_SIGNAL 1 +#define EVENT__HAVE_SIGNAL 1 /* Define to 1 if you have the `splice' function. */ -/* #undef EVENT__HAVE_SPLICE */ +/* #undef EVENT__HAVE_SPLICE */ /* Define to 1 if you have the <stdarg.h> header file. */ -#define EVENT__HAVE_STDARG_H 1 +#define EVENT__HAVE_STDARG_H 1 /* Define to 1 if you have the <stddef.h> header file. */ -#define EVENT__HAVE_STDDEF_H 1 +#define EVENT__HAVE_STDDEF_H 1 /* Define to 1 if you have the <stdint.h> header file. */ -#define EVENT__HAVE_STDINT_H 1 +#define EVENT__HAVE_STDINT_H 1 /* Define to 1 if you have the <stdlib.h> header file. */ -#define EVENT__HAVE_STDLIB_H 1 +#define EVENT__HAVE_STDLIB_H 1 /* Define to 1 if you have the <strings.h> header file. */ -#define EVENT__HAVE_STRINGS_H 1 +#define EVENT__HAVE_STRINGS_H 1 /* Define to 1 if you have the <string.h> header file. */ -#define EVENT__HAVE_STRING_H 1 +#define EVENT__HAVE_STRING_H 1 /* Define to 1 if you have the `strlcpy' function. */ -#define EVENT__HAVE_STRLCPY 1 +#define EVENT__HAVE_STRLCPY 1 /* Define to 1 if you have the `strsep' function. */ -/* #undef EVENT__HAVE_STRSEP */ +/* #undef EVENT__HAVE_STRSEP */ /* Define to 1 if you have the `strtok_r' function. */ -/* #undef EVENT__HAVE_STRTOK_R */ +/* #undef EVENT__HAVE_STRTOK_R */ /* Define to 1 if you have the `strtoll' function. */ -/* #define EVENT__HAVE_STRTOLL 1 */ +/* #define EVENT__HAVE_STRTOLL 1 */ -#define EVENT__HAVE_STRUCT_ADDRINFO 1 +#define EVENT__HAVE_STRUCT_ADDRINFO 1 /* Define to 1 if the system has the type `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR 1 /* Define to 1 if `s6_addr16' is member of `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 1 /* Define to 1 if `s6_addr32' is member of `struct in6_addr'. */ -#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 +#define EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 1 /* Define to 1 if the system has the type `struct sockaddr_in6'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 1 /* Define to 1 if `sin6_len' is member of `struct sockaddr_in6'. */ -/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN */ /* Define to 1 if `sin_len' is member of `struct sockaddr_in'. */ -/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ /* Define to 1 if the system has the type `struct sockaddr_storage'. */ -#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE 1 +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE 1 /* Define to 1 if you have the <sys/devpoll.h> header file. */ -/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ +/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ /* Define to 1 if you have the <sys/epoll.h> header file. */ -/* #undef EVENT__HAVE_SYS_EPOLL_H */ +/* #undef EVENT__HAVE_SYS_EPOLL_H */ /* Define to 1 if you have the <sys/eventfd.h> header file. */ -/* #undef EVENT__HAVE_SYS_EVENTFD_H */ +/* #undef EVENT__HAVE_SYS_EVENTFD_H */ /* Define to 1 if you have the <sys/event.h> header file. */ -/* #undef EVENT__HAVE_SYS_EVENT_H */ +/* #undef EVENT__HAVE_SYS_EVENT_H */ /* Define to 1 if you have the <sys/ioctl.h> header file. */ -/* #undef EVENT__HAVE_SYS_IOCTL_H */ +/* #undef EVENT__HAVE_SYS_IOCTL_H */ /* Define to 1 if you have the <sys/mman.h> header file. */ -/* #undef EVENT__HAVE_SYS_MMAN_H */ +/* #undef EVENT__HAVE_SYS_MMAN_H */ /* Define to 1 if you have the <sys/param.h> header file. */ -/* #define EVENT__HAVE_SYS_PARAM_H 1 */ +/* #define EVENT__HAVE_SYS_PARAM_H 1 */ /* Define to 1 if you have the <sys/queue.h> header file. */ -/* #undef EVENT__HAVE_SYS_QUEUE_H */ +/* #undef EVENT__HAVE_SYS_QUEUE_H */ /* Define to 1 if you have the <sys/select.h> header file. */ -/* #undef EVENT__HAVE_SYS_SELECT_H */ +/* #undef EVENT__HAVE_SYS_SELECT_H */ /* Define to 1 if you have the <sys/sendfile.h> header file. */ -/* #undef EVENT__HAVE_SYS_SENDFILE_H */ +/* #undef EVENT__HAVE_SYS_SENDFILE_H */ /* Define to 1 if you have the <sys/socket.h> header file. */ -/* #undef EVENT__HAVE_SYS_SOCKET_H */ +/* #undef EVENT__HAVE_SYS_SOCKET_H */ /* Define to 1 if you have the <sys/stat.h> header file. */ -#define EVENT__HAVE_SYS_STAT_H 1 +#define EVENT__HAVE_SYS_STAT_H 1 /* Define to 1 if you have the <sys/time.h> header file. */ -/* #define EVENT__HAVE_SYS_TIME_H 1 */ +/* #define EVENT__HAVE_SYS_TIME_H 1 */ /* Define to 1 if you have the <sys/types.h> header file. */ -#define EVENT__HAVE_SYS_TYPES_H 1 +#define EVENT__HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the <sys/uio.h> header file. */ -/* #undef EVENT__HAVE_SYS_UIO_H */ +/* #undef EVENT__HAVE_SYS_UIO_H */ /* Define if TAILQ_FOREACH is defined in <sys/queue.h> */ -/* #undef EVENT__HAVE_TAILQFOREACH */ +/* #undef EVENT__HAVE_TAILQFOREACH */ /* Define if timeradd is defined in <sys/time.h> */ -/* #undef EVENT__HAVE_TIMERADD */ +/* #undef EVENT__HAVE_TIMERADD */ /* Define if timerclear is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERCLEAR 1 +#define EVENT__HAVE_TIMERCLEAR 1 /* Define if timercmp is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERCMP 1 +#define EVENT__HAVE_TIMERCMP 1 /* Define if timerisset is defined in <sys/time.h> */ -#define EVENT__HAVE_TIMERISSET 1 +#define EVENT__HAVE_TIMERISSET 1 /* Define to 1 if the system has the type `uint16_t'. */ -/* #define EVENT__HAVE_UINT16_T 1 */ +/* #define EVENT__HAVE_UINT16_T 1 */ /* Define to 1 if the system has the type `uint32_t'. */ -/* #define EVENT__HAVE_UINT32_T 1 */ +/* #define EVENT__HAVE_UINT32_T 1 */ /* Define to 1 if the system has the type `uint64_t'. */ -/* #define EVENT__HAVE_UINT64_T 1 */ +/* #define EVENT__HAVE_UINT64_T 1 */ /* Define to 1 if the system has the type `uint8_t'. */ -/* #define EVENT__HAVE_UINT8_T 1 */ +/* #define EVENT__HAVE_UINT8_T 1 */ /* Define to 1 if you have the <unistd.h> header file. */ -/* #define EVENT__HAVE_UNISTD_H 1 */ +/* #define EVENT__HAVE_UNISTD_H 1 */ /* Define to 1 if you have the `vasprintf' function. */ -/* #undef EVENT__HAVE_VASPRINTF */ +/* #undef EVENT__HAVE_VASPRINTF */ /* Define if kqueue works correctly with pipes */ -/* #undef EVENT__HAVE_WORKING_KQUEUE */ +/* #undef EVENT__HAVE_WORKING_KQUEUE */ /* Numeric representation of the version */ #define EVENT__NUMERIC_VERSION 0x02010c00 /* Name of package */ -#define EVENT__PACKAGE "libevent" +#define EVENT__PACKAGE "libevent" /* Define to the address where bug reports for this package should be sent. */ -#define EVENT__PACKAGE_BUGREPORT "" +#define EVENT__PACKAGE_BUGREPORT "" /* Define to the full name of this package. */ -#define EVENT__PACKAGE_NAME "" +#define EVENT__PACKAGE_NAME "" /* Define to the full name and version of this package. */ #define EVENT__PACKAGE_STRING "libevent 2.1.12-stable" /* Define to the one symbol short name of this package. */ -#define EVENT__PACKAGE_TARNAME "" +#define EVENT__PACKAGE_TARNAME "" /* Define to the version of this package. */ #define EVENT__PACKAGE_VERSION "2.1.12-stable" /* Define to necessary symbol if this constant uses a non-standard name on your system. */ -/* #undef EVENT__PTHREAD_CREATE_JOINABLE */ +/* #undef EVENT__PTHREAD_CREATE_JOINABLE */ /* The size of a `int', as computed by sizeof. */ -#define EVENT__SIZEOF_INT 4 +#define EVENT__SIZEOF_INT 4 /* The size of a `long', as computed by sizeof. */ -#define EVENT__SIZEOF_LONG 4 +#define EVENT__SIZEOF_LONG 4 /* The size of a `long long', as computed by sizeof. */ -#define EVENT__SIZEOF_LONG_LONG 8 +#define EVENT__SIZEOF_LONG_LONG 8 /* The size of a `short', as computed by sizeof. */ -#define EVENT__SIZEOF_SHORT 2 +#define EVENT__SIZEOF_SHORT 2 /* The size of `size_t', as computed by sizeof. */ #ifdef _WIN64 -#define EVENT__SIZEOF_SIZE_T 8 +#define EVENT__SIZEOF_SIZE_T 8 #else -#define EVENT__SIZEOF_SIZE_T 4 +#define EVENT__SIZEOF_SIZE_T 4 #endif /* The size of `void *', as computed by sizeof. */ #ifdef _WIN64 -#define EVENT__SIZEOF_VOID_P 8 +#define EVENT__SIZEOF_VOID_P 8 #else -#define EVENT__SIZEOF_VOID_P 4 +#define EVENT__SIZEOF_VOID_P 4 #endif /* Define to 1 if you have the ANSI C header files. */ -#define EVENT__STDC_HEADERS 1 +#define EVENT__STDC_HEADERS 1 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ -#define EVENT__TIME_WITH_SYS_TIME 1 +#define EVENT__TIME_WITH_SYS_TIME 1 /* Version number of package */ #define EVENT__VERSION "2.1.12-stable" /* Define to appropriate substitue if compiler doesnt have __func__ */ -#define EVENT____func__ __FUNCTION__ +#define EVENT____func__ __FUNCTION__ /* Define to empty if `const' does not conform to ANSI C. */ -/* #undef EVENT__const */ +/* #undef EVENT__const */ /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef EVENT____cplusplus -#define EVENT__inline __inline +#ifndef EVENT____cplusplus +#define EVENT__inline __inline #endif /* Define to `int' if <sys/types.h> does not define. */ -/* #undef EVENT__pid_t */ +/* #undef EVENT__pid_t */ /* Define to `unsigned' if <sys/types.h> does not define. */ -/* #undef EVENT__size_t */ +/* #undef EVENT__size_t */ /* Define to unsigned int if you dont have it */ -#define EVENT__socklen_t unsigned int +#define EVENT__socklen_t unsigned int /* Define to `int' if <sys/types.h> does not define. */ -#define EVENT__ssize_t SSIZE_T +#define EVENT__ssize_t SSIZE_T #endif diff --git a/contrib/libs/libevent/include/event2/event-config.h b/contrib/libs/libevent/include/event2/event-config.h index 8a6043c9ba..44473fab49 100644 --- a/contrib/libs/libevent/include/event2/event-config.h +++ b/contrib/libs/libevent/include/event2/event-config.h @@ -1,13 +1,13 @@ #pragma once -#if defined(__APPLE__) +#if defined(__APPLE__) # include "event-config-osx.h" #elif defined(_MSC_VER) # include "event-config-win.h" #else # include "event-config-linux.h" -#endif - +#endif + #if defined(_musl_) # include "event-config-musl.h" #endif diff --git a/contrib/libs/libevent/include/event2/event.h b/contrib/libs/libevent/include/event2/event.h index a6b6144a92..c432250a24 100644 --- a/contrib/libs/libevent/include/event2/event.h +++ b/contrib/libs/libevent/include/event2/event.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_EVENT_H_INCLUDED_ -#define EVENT2_EVENT_H_INCLUDED_ +#ifndef EVENT2_EVENT_H_INCLUDED_ +#define EVENT2_EVENT_H_INCLUDED_ /** @mainpage @@ -39,7 +39,7 @@ to signals or regular timeouts. Libevent is meant to replace the event loop found in event driven network - servers. An application just needs to call event_base_dispatch() and then add or + servers. An application just needs to call event_base_dispatch() and then add or remove events dynamically without having to change the event loop. @@ -54,7 +54,7 @@ @section usage Standard usage - Every program that uses Libevent must include the <event2/event.h> + Every program that uses Libevent must include the <event2/event.h> header, and pass the -levent flag to the linker. (You can instead link -levent_core if you only want the main event and buffered IO-based code, and don't want to link any protocol code.) @@ -90,7 +90,7 @@ remain allocated as long as it is active, so it should generally be allocated on the heap. - @section loop Dispatching events. + @section loop Dispatching events. Finally, you call event_base_dispatch() to loop and dispatch events. You can also use event_base_loop() for more fine-grained control. @@ -124,11 +124,11 @@ @section timers Timers Libevent can also be used to create timers that invoke a callback after a - certain amount of time has expired. The evtimer_new() macro returns + certain amount of time has expired. The evtimer_new() macro returns an event struct to use as a timer. To activate the timer, call evtimer_add(). Timers can be deactivated by calling evtimer_del(). - (These macros are thin wrappers around event_new(), event_add(), - and event_del(); you can also use those instead.) + (These macros are thin wrappers around event_new(), event_add(), + and event_del(); you can also use those instead.) @section evdns Asynchronous DNS resolution @@ -182,17 +182,17 @@ Core functions for waiting for and receiving events, and using event bases. */ -#include <event2/visibility.h> - +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -215,7 +215,7 @@ extern "C" { * event_base_new_with_config() */ struct event_base -#ifdef EVENT_IN_DOXYGEN_ +#ifdef EVENT_IN_DOXYGEN_ {/*Empty body so that doxygen will generate documentation here.*/} #endif ; @@ -232,7 +232,7 @@ struct event_base * * Generally, you can create events with event_new(), then make them * pending with event_add(). As your event_base runs, it will run the - * callbacks of an events whose conditions are triggered. When you no + * callbacks of an events whose conditions are triggered. When you no * longer want the event, free it with event_free(). * * In more depth: @@ -274,7 +274,7 @@ struct event_base * event_priority_set() */ struct event -#ifdef EVENT_IN_DOXYGEN_ +#ifdef EVENT_IN_DOXYGEN_ {/*Empty body so that doxygen will generate documentation here.*/} #endif ; @@ -285,7 +285,7 @@ struct event * There are many options that can be used to alter the behavior and * implementation of an event_base. To avoid having to pass them all in a * complex many-argument constructor, we provide an abstract data type - * where you set up configuration information before passing it to + * where you set up configuration information before passing it to * event_base_new_with_config(). * * @see event_config_new(), event_config_free(), event_base_new_with_config(), @@ -293,7 +293,7 @@ struct event * event_config_set_flag(), event_config_set_num_cpus_hint() */ struct event_config -#ifdef EVENT_IN_DOXYGEN_ +#ifdef EVENT_IN_DOXYGEN_ {/*Empty body so that doxygen will generate documentation here.*/} #endif ; @@ -318,7 +318,7 @@ struct event_config * * @see event_debug_unassign() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_enable_debug_mode(void); /** @@ -330,7 +330,7 @@ void event_enable_debug_mode(void); * * @see event_enable_debug_mode() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_debug_unassign(struct event *); /** @@ -340,7 +340,7 @@ void event_debug_unassign(struct event *); * * @see event_base_free(), event_base_new_with_config() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *event_base_new(void); /** @@ -353,7 +353,7 @@ struct event_base *event_base_new(void); @return 0 if successful, or -1 if some events could not be re-added. @see event_base_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_reinit(struct event_base *base); /** @@ -369,7 +369,7 @@ int event_reinit(struct event_base *base); no events were pending or active. @see event_base_loop() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_dispatch(struct event_base *); /** @@ -378,7 +378,7 @@ int event_base_dispatch(struct event_base *); @param eb the event_base structure returned by event_base_new() @return a string identifying the kernel event mechanism (kqueue, epoll, etc.) */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *event_base_get_method(const struct event_base *); /** @@ -393,67 +393,67 @@ const char *event_base_get_method(const struct event_base *); The end of the array is indicated by a NULL pointer. If an error is encountered NULL is returned. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char **event_get_supported_methods(void); -/** Query the current monotonic time from a the timer for a struct - * event_base. - */ -EVENT2_EXPORT_SYMBOL -int event_gettime_monotonic(struct event_base *base, struct timeval *tp); - -/** - @name event type flag - - Flags to pass to event_base_get_num_events() to specify the kinds of events - we want to aggregate counts for -*/ -/**@{*/ -/** count the number of active events, which have been triggered.*/ -#define EVENT_BASE_COUNT_ACTIVE 1U -/** count the number of virtual events, which is used to represent an internal - * condition, other than a pending event, that keeps the loop from exiting. */ -#define EVENT_BASE_COUNT_VIRTUAL 2U -/** count the number of events which have been added to event base, including - * internal events. */ -#define EVENT_BASE_COUNT_ADDED 4U -/**@}*/ - -/** - Gets the number of events in event_base, as specified in the flags. - - Since event base has some internal events added to make some of its - functionalities work, EVENT_BASE_COUNT_ADDED may return more than the - number of events you added using event_add(). - - If you pass EVENT_BASE_COUNT_ACTIVE and EVENT_BASE_COUNT_ADDED together, an - active event will be counted twice. However, this might not be the case in - future libevent versions. The return value is an indication of the work - load, but the user shouldn't rely on the exact value as this may change in - the future. - - @param eb the event_base structure returned by event_base_new() - @param flags a bitwise combination of the kinds of events to aggregate - counts for - @return the number of events specified in the flags -*/ -EVENT2_EXPORT_SYMBOL -int event_base_get_num_events(struct event_base *, unsigned int); - -/** - Get the maximum number of events in a given event_base as specified in the - flags. - - @param eb the event_base structure returned by event_base_new() - @param flags a bitwise combination of the kinds of events to aggregate - counts for - @param clear option used to reset the maximum count. - @return the number of events specified in the flags - */ -EVENT2_EXPORT_SYMBOL -int event_base_get_max_events(struct event_base *, unsigned int, int); - -/** +/** Query the current monotonic time from a the timer for a struct + * event_base. + */ +EVENT2_EXPORT_SYMBOL +int event_gettime_monotonic(struct event_base *base, struct timeval *tp); + +/** + @name event type flag + + Flags to pass to event_base_get_num_events() to specify the kinds of events + we want to aggregate counts for +*/ +/**@{*/ +/** count the number of active events, which have been triggered.*/ +#define EVENT_BASE_COUNT_ACTIVE 1U +/** count the number of virtual events, which is used to represent an internal + * condition, other than a pending event, that keeps the loop from exiting. */ +#define EVENT_BASE_COUNT_VIRTUAL 2U +/** count the number of events which have been added to event base, including + * internal events. */ +#define EVENT_BASE_COUNT_ADDED 4U +/**@}*/ + +/** + Gets the number of events in event_base, as specified in the flags. + + Since event base has some internal events added to make some of its + functionalities work, EVENT_BASE_COUNT_ADDED may return more than the + number of events you added using event_add(). + + If you pass EVENT_BASE_COUNT_ACTIVE and EVENT_BASE_COUNT_ADDED together, an + active event will be counted twice. However, this might not be the case in + future libevent versions. The return value is an indication of the work + load, but the user shouldn't rely on the exact value as this may change in + the future. + + @param eb the event_base structure returned by event_base_new() + @param flags a bitwise combination of the kinds of events to aggregate + counts for + @return the number of events specified in the flags +*/ +EVENT2_EXPORT_SYMBOL +int event_base_get_num_events(struct event_base *, unsigned int); + +/** + Get the maximum number of events in a given event_base as specified in the + flags. + + @param eb the event_base structure returned by event_base_new() + @param flags a bitwise combination of the kinds of events to aggregate + counts for + @param clear option used to reset the maximum count. + @return the number of events specified in the flags + */ +EVENT2_EXPORT_SYMBOL +int event_base_get_max_events(struct event_base *, unsigned int, int); + +/** Allocates a new event configuration object. The event configuration object can be used to change the behavior of @@ -463,7 +463,7 @@ int event_base_get_max_events(struct event_base *, unsigned int, int); NULL if an error is encountered. @see event_base_new_with_config(), event_config_free(), event_config */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_config *event_config_new(void); /** @@ -471,7 +471,7 @@ struct event_config *event_config_new(void); @param cfg the event configuration object to be freed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_config_free(struct event_config *cfg); /** @@ -486,7 +486,7 @@ void event_config_free(struct event_config *cfg); @param method the name of the event method to avoid @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_config_avoid_method(struct event_config *cfg, const char *method); /** @@ -508,14 +508,14 @@ enum event_method_feature { EV_FEATURE_O1 = 0x02, /** Require an event method that allows file descriptors as well as * sockets. */ - EV_FEATURE_FDS = 0x04, - /** Require an event method that allows you to use EV_CLOSED to detect - * connection close without the necessity of reading all the pending data. - * - * Methods that do support EV_CLOSED may not be able to provide support on - * all kernel versions. - **/ - EV_FEATURE_EARLY_CLOSE = 0x08 + EV_FEATURE_FDS = 0x04, + /** Require an event method that allows you to use EV_CLOSED to detect + * connection close without the necessity of reading all the pending data. + * + * Methods that do support EV_CLOSED may not be able to provide support on + * all kernel versions. + **/ + EV_FEATURE_EARLY_CLOSE = 0x08 }; /** @@ -528,11 +528,11 @@ enum event_method_feature { */ enum event_base_config_flag { /** Do not allocate a lock for the event base, even if we have - locking set up. - - Setting this option will make it unsafe and nonfunctional to call - functions on the base concurrently from multiple threads. - */ + locking set up. + + Setting this option will make it unsafe and nonfunctional to call + functions on the base concurrently from multiple threads. + */ EVENT_BASE_FLAG_NOLOCK = 0x01, /** Do not check the EVENT_* environment variables when configuring an event_base */ @@ -557,20 +557,20 @@ enum event_base_config_flag { if you have any fds cloned by dup() or its variants. Doing so will produce strange and hard-to-diagnose bugs. - This flag can also be activated by setting the + This flag can also be activated by setting the EVENT_EPOLL_USE_CHANGELIST environment variable. This flag has no effect if you wind up using a backend other than epoll. */ - EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10, - - /** Ordinarily, Libevent implements its time and timeout code using - the fastest monotonic timer that we have. If this flag is set, - however, we use less efficient more precise timer, assuming one is - present. - */ - EVENT_BASE_FLAG_PRECISE_TIMER = 0x20 + EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10, + + /** Ordinarily, Libevent implements its time and timeout code using + the fastest monotonic timer that we have. If this flag is set, + however, we use less efficient more precise timer, assuming one is + present. + */ + EVENT_BASE_FLAG_PRECISE_TIMER = 0x20 }; /** @@ -580,7 +580,7 @@ enum event_base_config_flag { @see event_method_feature */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_get_features(const struct event_base *base); /** @@ -605,7 +605,7 @@ int event_base_get_features(const struct event_base *base); @return 0 on success, -1 on failure. @see event_method_feature, event_base_new_with_config() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_config_require_features(struct event_config *cfg, int feature); /** @@ -614,7 +614,7 @@ int event_config_require_features(struct event_config *cfg, int feature); * * @see event_base_config_flags, event_base_new_with_config() **/ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_config_set_flag(struct event_config *cfg, int flag); /** @@ -626,43 +626,43 @@ int event_config_set_flag(struct event_config *cfg, int flag); * @param cpus the number of cpus * @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_config_set_num_cpus_hint(struct event_config *cfg, int cpus); /** - * Record an interval and/or a number of callbacks after which the event base - * should check for new events. By default, the event base will run as many - * events are as activated at the highest activated priority before checking - * for new events. If you configure it by setting max_interval, it will check - * the time after each callback, and not allow more than max_interval to - * elapse before checking for new events. If you configure it by setting - * max_callbacks to a value >= 0, it will run no more than max_callbacks - * callbacks before checking for new events. - * - * This option can decrease the latency of high-priority events, and - * avoid priority inversions where multiple low-priority events keep us from - * polling for high-priority events, but at the expense of slightly decreasing - * the throughput. Use it with caution! - * - * @param cfg The event_base configuration object. - * @param max_interval An interval after which Libevent should stop running - * callbacks and check for more events, or NULL if there should be - * no such interval. - * @param max_callbacks A number of callbacks after which Libevent should - * stop running callbacks and check for more events, or -1 if there - * should be no such limit. - * @param min_priority A priority below which max_interval and max_callbacks - * should not be enforced. If this is set to 0, they are enforced - * for events of every priority; if it's set to 1, they're enforced - * for events of priority 1 and above, and so on. - * @return 0 on success, -1 on failure. - **/ -EVENT2_EXPORT_SYMBOL -int event_config_set_max_dispatch_interval(struct event_config *cfg, - const struct timeval *max_interval, int max_callbacks, - int min_priority); - -/** + * Record an interval and/or a number of callbacks after which the event base + * should check for new events. By default, the event base will run as many + * events are as activated at the highest activated priority before checking + * for new events. If you configure it by setting max_interval, it will check + * the time after each callback, and not allow more than max_interval to + * elapse before checking for new events. If you configure it by setting + * max_callbacks to a value >= 0, it will run no more than max_callbacks + * callbacks before checking for new events. + * + * This option can decrease the latency of high-priority events, and + * avoid priority inversions where multiple low-priority events keep us from + * polling for high-priority events, but at the expense of slightly decreasing + * the throughput. Use it with caution! + * + * @param cfg The event_base configuration object. + * @param max_interval An interval after which Libevent should stop running + * callbacks and check for more events, or NULL if there should be + * no such interval. + * @param max_callbacks A number of callbacks after which Libevent should + * stop running callbacks and check for more events, or -1 if there + * should be no such limit. + * @param min_priority A priority below which max_interval and max_callbacks + * should not be enforced. If this is set to 0, they are enforced + * for events of every priority; if it's set to 1, they're enforced + * for events of priority 1 and above, and so on. + * @return 0 on success, -1 on failure. + **/ +EVENT2_EXPORT_SYMBOL +int event_config_set_max_dispatch_interval(struct event_config *cfg, + const struct timeval *max_interval, int max_callbacks, + int min_priority); + +/** Initialize the event API. Use event_base_new_with_config() to initialize a new event base, taking @@ -674,7 +674,7 @@ int event_config_set_max_dispatch_interval(struct event_config *cfg, or NULL if no event base can be created with the requested event_config. @see event_base_new(), event_base_free(), event_init(), event_assign() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *event_base_new_with_config(const struct event_config *); /** @@ -683,20 +683,20 @@ struct event_base *event_base_new_with_config(const struct event_config *); Note that this function will not close any fds or free any memory passed to event_new as the argument to callback. - If there are any pending finalizer callbacks, this function will invoke - them. - + If there are any pending finalizer callbacks, this function will invoke + them. + @param eb an event_base to be freed */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_base_free(struct event_base *); -/** - As event_base_free, but do not run finalizers. - */ -EVENT2_EXPORT_SYMBOL -void event_base_free_nofinalize(struct event_base *); - +/** + As event_base_free, but do not run finalizers. + */ +EVENT2_EXPORT_SYMBOL +void event_base_free_nofinalize(struct event_base *); + /** @name Log severities */ /**@{*/ @@ -723,13 +723,13 @@ typedef void (*event_log_cb)(int severity, const char *msg); Redirect Libevent's log messages. @param cb a function taking two arguments: an integer severity between - EVENT_LOG_DEBUG and EVENT_LOG_ERR, and a string. If cb is NULL, + EVENT_LOG_DEBUG and EVENT_LOG_ERR, and a string. If cb is NULL, then the default log is used. NOTE: The function you provide *must not* call any other libevent functionality. Doing so can produce undefined behavior. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_set_log_callback(event_log_cb cb); /** @@ -748,33 +748,33 @@ typedef void (*event_fatal_cb)(int err); something is wrong with your program, or with Libevent: any subsequent calls to Libevent may result in undefined behavior. - Libevent will (almost) always log an EVENT_LOG_ERR message before calling + Libevent will (almost) always log an EVENT_LOG_ERR message before calling this function; look at the last log message to see why Libevent has died. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_set_fatal_callback(event_fatal_cb cb); -#define EVENT_DBG_ALL 0xffffffffu -#define EVENT_DBG_NONE 0 - -/** - Turn on debugging logs and have them sent to the default log handler. - - This is a global setting; if you are going to call it, you must call this - before any calls that create an event-base. You must call it before any - multithreaded use of Libevent. - - Debug logs are verbose. - - @param which Controls which debug messages are turned on. This option is - unused for now; for forward compatibility, you must pass in the constant - "EVENT_DBG_ALL" to turn debugging logs on, or "EVENT_DBG_NONE" to turn - debugging logs off. - */ -EVENT2_EXPORT_SYMBOL -void event_enable_debug_logging(ev_uint32_t which); - -/** +#define EVENT_DBG_ALL 0xffffffffu +#define EVENT_DBG_NONE 0 + +/** + Turn on debugging logs and have them sent to the default log handler. + + This is a global setting; if you are going to call it, you must call this + before any calls that create an event-base. You must call it before any + multithreaded use of Libevent. + + Debug logs are verbose. + + @param which Controls which debug messages are turned on. This option is + unused for now; for forward compatibility, you must pass in the constant + "EVENT_DBG_ALL" to turn debugging logs on, or "EVENT_DBG_NONE" to turn + debugging logs off. + */ +EVENT2_EXPORT_SYMBOL +void event_enable_debug_logging(ev_uint32_t which); + +/** Associate a different event base with an event. The event to be associated must not be currently active or pending. @@ -783,7 +783,7 @@ void event_enable_debug_logging(ev_uint32_t which); @param ev the event @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_set(struct event_base *, struct event *); /** @name Loop flags @@ -797,11 +797,11 @@ int event_base_set(struct event_base *, struct event *); /** Do not block: see which events are ready now, run the callbacks * of the highest-priority ones, then exit. */ #define EVLOOP_NONBLOCK 0x02 -/** Do not exit the loop because we have no pending events. Instead, keep - * running until event_base_loopexit() or event_base_loopbreak() makes us - * stop. - */ -#define EVLOOP_NO_EXIT_ON_EMPTY 0x04 +/** Do not exit the loop because we have no pending events. Instead, keep + * running until event_base_loopexit() or event_base_loopbreak() makes us + * stop. + */ +#define EVLOOP_NO_EXIT_ON_EMPTY 0x04 /**@}*/ /** @@ -822,7 +822,7 @@ int event_base_set(struct event_base *, struct event *); @see event_base_loopexit(), event_base_dispatch(), EVLOOP_ONCE, EVLOOP_NONBLOCK */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_loop(struct event_base *, int); /** @@ -840,7 +840,7 @@ int event_base_loop(struct event_base *, int); @return 0 if successful, or -1 if an error occurred @see event_base_loopbreak() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_loopexit(struct event_base *, const struct timeval *); /** @@ -850,38 +850,38 @@ int event_base_loopexit(struct event_base *, const struct timeval *); event_base_loopbreak() is typically invoked from this event's callback. This behavior is analogous to the "break;" statement. - Subsequent invocations of event_base_loop() will proceed normally. + Subsequent invocations of event_base_loop() will proceed normally. @param eb the event_base structure returned by event_init() @return 0 if successful, or -1 if an error occurred @see event_base_loopexit() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_loopbreak(struct event_base *); /** - Tell the active event_base_loop() to scan for new events immediately. - - Calling this function makes the currently active event_base_loop() - start the loop over again (scanning for new events) after the current - event callback finishes. If the event loop is not running, this - function has no effect. - - event_base_loopbreak() is typically invoked from this event's callback. - This behavior is analogous to the "continue;" statement. - - Subsequent invocations of event loop will proceed normally. - - @param eb the event_base structure returned by event_init() - @return 0 if successful, or -1 if an error occurred - @see event_base_loopbreak() - */ -EVENT2_EXPORT_SYMBOL -int event_base_loopcontinue(struct event_base *); - -/** - Checks if the event loop was told to exit by event_base_loopexit(). - + Tell the active event_base_loop() to scan for new events immediately. + + Calling this function makes the currently active event_base_loop() + start the loop over again (scanning for new events) after the current + event callback finishes. If the event loop is not running, this + function has no effect. + + event_base_loopbreak() is typically invoked from this event's callback. + This behavior is analogous to the "continue;" statement. + + Subsequent invocations of event loop will proceed normally. + + @param eb the event_base structure returned by event_init() + @return 0 if successful, or -1 if an error occurred + @see event_base_loopbreak() + */ +EVENT2_EXPORT_SYMBOL +int event_base_loopcontinue(struct event_base *); + +/** + Checks if the event loop was told to exit by event_base_loopexit(). + This function will return true for an event_base at every point after event_loopexit() is called, until the event loop is next entered. @@ -891,14 +891,14 @@ int event_base_loopcontinue(struct event_base *); @see event_base_loopexit() @see event_base_got_break() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_got_exit(struct event_base *); /** - Checks if the event loop was told to abort immediately by event_base_loopbreak(). + Checks if the event loop was told to abort immediately by event_base_loopbreak(). This function will return true for an event_base at every point after - event_base_loopbreak() is called, until the event loop is next entered. + event_base_loopbreak() is called, until the event loop is next entered. @param eb the event_base structure returned by event_init() @return true if event_base_loopbreak() was called on this event base, @@ -906,7 +906,7 @@ int event_base_got_exit(struct event_base *); @see event_base_loopbreak() @see event_base_got_exit() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_got_break(struct event_base *); /** @@ -933,37 +933,37 @@ int event_base_got_break(struct event_base *); */ #define EV_PERSIST 0x10 /** Select edge-triggered behavior, if supported by the backend. */ -#define EV_ET 0x20 -/** - * If this option is provided, then event_del() will not block in one thread - * while waiting for the event callback to complete in another thread. - * - * To use this option safely, you may need to use event_finalize() or - * event_free_finalize() in order to safely tear down an event in a - * multithreaded application. See those functions for more information. - **/ -#define EV_FINALIZE 0x40 -/** - * Detects connection close events. You can use this to detect when a - * connection has been closed, without having to read all the pending data - * from a connection. - * - * Not all backends support EV_CLOSED. To detect or require it, use the - * feature flag EV_FEATURE_EARLY_CLOSE. - **/ -#define EV_CLOSED 0x80 +#define EV_ET 0x20 +/** + * If this option is provided, then event_del() will not block in one thread + * while waiting for the event callback to complete in another thread. + * + * To use this option safely, you may need to use event_finalize() or + * event_free_finalize() in order to safely tear down an event in a + * multithreaded application. See those functions for more information. + **/ +#define EV_FINALIZE 0x40 +/** + * Detects connection close events. You can use this to detect when a + * connection has been closed, without having to read all the pending data + * from a connection. + * + * Not all backends support EV_CLOSED. To detect or require it, use the + * feature flag EV_FEATURE_EARLY_CLOSE. + **/ +#define EV_CLOSED 0x80 /**@}*/ /** @name evtimer_* macros - Aliases for working with one-shot timer events - If you need EV_PERSIST timer use event_*() functions. - */ + Aliases for working with one-shot timer events + If you need EV_PERSIST timer use event_*() functions. + */ /**@{*/ #define evtimer_assign(ev, b, cb, arg) \ event_assign((ev), (b), -1, 0, (cb), (arg)) -#define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) +#define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) #define evtimer_add(ev, tv) event_add((ev), (tv)) #define evtimer_del(ev) event_del(ev) #define evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv)) @@ -987,20 +987,20 @@ int event_base_got_break(struct event_base *); /**@}*/ /** - @name evuser_* macros - - Aliases for working with user-triggered events - If you need EV_PERSIST event use event_*() functions. - */ -/**@{*/ -#define evuser_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) -#define evuser_del(ev) event_del(ev) -#define evuser_pending(ev, tv) event_pending((ev), 0, (tv)) -#define evuser_initialized(ev) event_initialized(ev) -#define evuser_trigger(ev) event_active((ev), 0, 0) -/**@}*/ - -/** + @name evuser_* macros + + Aliases for working with user-triggered events + If you need EV_PERSIST event use event_*() functions. + */ +/**@{*/ +#define evuser_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) +#define evuser_del(ev) event_del(ev) +#define evuser_pending(ev, tv) event_pending((ev), 0, (tv)) +#define evuser_initialized(ev) event_initialized(ev) +#define evuser_trigger(ev) event_active((ev), 0, 0) +/**@}*/ + +/** A callback function for an event. It receives three arguments: @@ -1014,33 +1014,33 @@ int event_base_got_break(struct event_base *); typedef void (*event_callback_fn)(evutil_socket_t, short, void *); /** - Return a value used to specify that the event itself must be used as the callback argument. - - The function event_new() takes a callback argument which is passed - to the event's callback function. To specify that the argument to be - passed to the callback function is the event that event_new() returns, - pass in the return value of event_self_cbarg() as the callback argument - for event_new(). - - For example: - <pre> - struct event *ev = event_new(base, sock, events, callback, %event_self_cbarg()); - </pre> - - For consistency with event_new(), it is possible to pass the return value - of this function as the callback argument for event_assign() – this - achieves the same result as passing the event in directly. - - @return a value to be passed as the callback argument to event_new() or - event_assign(). - @see event_new(), event_assign() - */ -EVENT2_EXPORT_SYMBOL -void *event_self_cbarg(void); - -/** - Allocate and assign a new event structure, ready to be added. - + Return a value used to specify that the event itself must be used as the callback argument. + + The function event_new() takes a callback argument which is passed + to the event's callback function. To specify that the argument to be + passed to the callback function is the event that event_new() returns, + pass in the return value of event_self_cbarg() as the callback argument + for event_new(). + + For example: + <pre> + struct event *ev = event_new(base, sock, events, callback, %event_self_cbarg()); + </pre> + + For consistency with event_new(), it is possible to pass the return value + of this function as the callback argument for event_assign() – this + achieves the same result as passing the event in directly. + + @return a value to be passed as the callback argument to event_new() or + event_assign(). + @see event_new(), event_assign() + */ +EVENT2_EXPORT_SYMBOL +void *event_self_cbarg(void); + +/** + Allocate and assign a new event structure, ready to be added. + The function event_new() returns a new event that can be used in future calls to event_add() and event_del(). The fd and events arguments determine which conditions will trigger the event; the @@ -1065,10 +1065,10 @@ void *event_self_cbarg(void); The EV_TIMEOUT flag has no effect here. It is okay to have multiple events all listening on the same fds; but - they must either all be edge-triggered, or all not be edge triggered. + they must either all be edge-triggered, or all not be edge triggered. When the event becomes active, the event loop will run the provided - callback function, with three arguments. The first will be the provided + callback function, with three arguments. The first will be the provided fd value. The second will be a bitfield of the events that triggered: EV_READ, EV_WRITE, or EV_SIGNAL. Here the EV_TIMEOUT flag indicates that a timeout occurred, and EV_ET indicates that an edge-triggered @@ -1083,10 +1083,10 @@ void *event_self_cbarg(void); @param callback_arg an argument to be passed to the callback function @return a newly allocated struct event that must later be freed with - event_free() or NULL if an error occurred. + event_free() or NULL if an error occurred. @see event_free(), event_add(), event_del(), event_assign() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event *event_new(struct event_base *, evutil_socket_t, short, event_callback_fn, void *); @@ -1128,71 +1128,71 @@ struct event *event_new(struct event_base *, evutil_socket_t, short, event_callb @see event_new(), event_add(), event_del(), event_base_once(), event_get_struct_event_size() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_assign(struct event *, struct event_base *, evutil_socket_t, short, event_callback_fn, void *); /** Deallocate a struct event * returned by event_new(). - If the event is pending or active, this function makes it non-pending - and non-active first. + If the event is pending or active, this function makes it non-pending + and non-active first. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_free(struct event *); /** - * Callback type for event_finalize and event_free_finalize(). - **/ -typedef void (*event_finalize_callback_fn)(struct event *, void *); -/** - @name Finalization functions - - These functions are used to safely tear down an event in a multithreaded - application. If you construct your events with EV_FINALIZE to avoid - deadlocks, you will need a way to remove an event in the certainty that - it will definitely not be running its callback when you deallocate it - and its callback argument. - - To do this, call one of event_finalize() or event_free_finalize with - 0 for its first argument, the event to tear down as its second argument, - and a callback function as its third argument. The callback will be - invoked as part of the event loop, with the event's priority. - - After you call a finalizer function, event_add() and event_active() will - no longer work on the event, and event_del() will produce a no-op. You - must not try to change the event's fields with event_assign() or - event_set() while the finalize callback is in progress. Once the - callback has been invoked, you should treat the event structure as - containing uninitialized memory. - - The event_free_finalize() function frees the event after it's finalized; - event_finalize() does not. - - A finalizer callback must not make events pending or active. It must not - add events, activate events, or attempt to "resuscitate" the event being - finalized in any way. - - @return 0 on success, -1 on failure. - */ -/**@{*/ -EVENT2_EXPORT_SYMBOL -int event_finalize(unsigned, struct event *, event_finalize_callback_fn); -EVENT2_EXPORT_SYMBOL -int event_free_finalize(unsigned, struct event *, event_finalize_callback_fn); -/**@}*/ - -/** + * Callback type for event_finalize and event_free_finalize(). + **/ +typedef void (*event_finalize_callback_fn)(struct event *, void *); +/** + @name Finalization functions + + These functions are used to safely tear down an event in a multithreaded + application. If you construct your events with EV_FINALIZE to avoid + deadlocks, you will need a way to remove an event in the certainty that + it will definitely not be running its callback when you deallocate it + and its callback argument. + + To do this, call one of event_finalize() or event_free_finalize with + 0 for its first argument, the event to tear down as its second argument, + and a callback function as its third argument. The callback will be + invoked as part of the event loop, with the event's priority. + + After you call a finalizer function, event_add() and event_active() will + no longer work on the event, and event_del() will produce a no-op. You + must not try to change the event's fields with event_assign() or + event_set() while the finalize callback is in progress. Once the + callback has been invoked, you should treat the event structure as + containing uninitialized memory. + + The event_free_finalize() function frees the event after it's finalized; + event_finalize() does not. + + A finalizer callback must not make events pending or active. It must not + add events, activate events, or attempt to "resuscitate" the event being + finalized in any way. + + @return 0 on success, -1 on failure. + */ +/**@{*/ +EVENT2_EXPORT_SYMBOL +int event_finalize(unsigned, struct event *, event_finalize_callback_fn); +EVENT2_EXPORT_SYMBOL +int event_free_finalize(unsigned, struct event *, event_finalize_callback_fn); +/**@}*/ + +/** Schedule a one-time event - The function event_base_once() is similar to event_new(). However, it + The function event_base_once() is similar to event_new(). However, it schedules a callback to be called exactly once, and does not require the caller to prepare an event structure. - Note that in Libevent 2.0 and earlier, if the event is never triggered, the - internal memory used to hold it will never be freed. In Libevent 2.1, - the internal memory will get freed by event_base_free() if the event - is never triggered. The 'arg' value, however, will not get freed in either - case--you'll need to free that on your own if you want it to go away. + Note that in Libevent 2.0 and earlier, if the event is never triggered, the + internal memory used to hold it will never be freed. In Libevent 2.1, + the internal memory will get freed by event_base_free() if the event + is never triggered. The 'arg' value, however, will not get freed in either + case--you'll need to free that on your own if you want it to go away. @param base an event_base @param fd a file descriptor to monitor, or -1 for no fd. @@ -1202,18 +1202,18 @@ int event_free_finalize(unsigned, struct event *, event_finalize_callback_fn); @param arg an argument to be passed to the callback function @param timeout the maximum amount of time to wait for the event. NULL makes an EV_READ/EV_WRITE event make forever; NULL makes an - EV_TIMEOUT event success immediately. + EV_TIMEOUT event success immediately. @return 0 if successful, or -1 if an error occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_fn, void *, const struct timeval *); /** Add an event to the set of pending events. - The function event_add() schedules the execution of the event 'ev' when the - condition specified by event_assign() or event_new() occurs, or when the time - specified in timeout has elapsed. If a timeout is NULL, no timeout + The function event_add() schedules the execution of the event 'ev' when the + condition specified by event_assign() or event_new() occurs, or when the time + specified in timeout has elapsed. If a timeout is NULL, no timeout occurs and the function will only be called if a matching event occurs. The event in the ev argument must be already initialized by event_assign() or event_new() @@ -1221,30 +1221,30 @@ int event_base_once(struct event_base *, evutil_socket_t, short, event_callback_ in calls to event_assign() until it is no longer pending. If the event in the ev argument already has a scheduled timeout, calling - event_add() replaces the old timeout with the new one if tv is non-NULL. + event_add() replaces the old timeout with the new one if tv is non-NULL. - @param ev an event struct initialized via event_assign() or event_new() + @param ev an event struct initialized via event_assign() or event_new() @param timeout the maximum amount of time to wait for the event, or NULL to wait forever @return 0 if successful, or -1 if an error occurred @see event_del(), event_assign(), event_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_add(struct event *ev, const struct timeval *timeout); /** - Remove a timer from a pending event without removing the event itself. - - If the event has a scheduled timeout, this function unschedules it but - leaves the event otherwise pending. - - @param ev an event struct initialized via event_assign() or event_new() - @return 0 on success, or -1 if an error occurred. -*/ -EVENT2_EXPORT_SYMBOL -int event_remove_timer(struct event *ev); - -/** + Remove a timer from a pending event without removing the event itself. + + If the event has a scheduled timeout, this function unschedules it but + leaves the event otherwise pending. + + @param ev an event struct initialized via event_assign() or event_new() + @return 0 on success, or -1 if an error occurred. +*/ +EVENT2_EXPORT_SYMBOL +int event_remove_timer(struct event *ev); + +/** Remove an event from the set of monitored events. The function event_del() will cancel the event in the argument ev. If the @@ -1255,23 +1255,23 @@ int event_remove_timer(struct event *ev); @return 0 if successful, or -1 if an error occurred @see event_add() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_del(struct event *); -/** - As event_del(), but never blocks while the event's callback is running - in another thread, even if the event was constructed without the - EV_FINALIZE flag. - */ -EVENT2_EXPORT_SYMBOL -int event_del_noblock(struct event *ev); -/** - As event_del(), but always blocks while the event's callback is running - in another thread, even if the event was constructed with the - EV_FINALIZE flag. - */ -EVENT2_EXPORT_SYMBOL -int event_del_block(struct event *ev); +/** + As event_del(), but never blocks while the event's callback is running + in another thread, even if the event was constructed without the + EV_FINALIZE flag. + */ +EVENT2_EXPORT_SYMBOL +int event_del_noblock(struct event *ev); +/** + As event_del(), but always blocks while the event's callback is running + in another thread, even if the event was constructed with the + EV_FINALIZE flag. + */ +EVENT2_EXPORT_SYMBOL +int event_del_block(struct event *ev); /** Make an event active. @@ -1287,7 +1287,7 @@ int event_del_block(struct event *ev); @param res a set of flags to pass to the event's callback. @param ncalls an obsolete argument: this is ignored. **/ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_active(struct event *ev, int res, short ncalls); /** @@ -1303,25 +1303,25 @@ void event_active(struct event *ev, int res, short ncalls); @return true if the event is pending on any of the events in 'what', (that is to say, it has been added), or 0 if the event is not added. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_pending(const struct event *ev, short events, struct timeval *tv); -/** - If called from within the callback for an event, returns that event. - - The behavior of this function is not defined when called from outside the - callback function for an event. - */ -EVENT2_EXPORT_SYMBOL -struct event *event_base_get_running_event(struct event_base *base); +/** + If called from within the callback for an event, returns that event. + The behavior of this function is not defined when called from outside the + callback function for an event. + */ +EVENT2_EXPORT_SYMBOL +struct event *event_base_get_running_event(struct event_base *base); + /** Test if an event structure might be initialized. The event_initialized() function can be used to check if an event has been initialized. - Warning: This function is only useful for distinguishing a zeroed-out + Warning: This function is only useful for distinguishing a zeroed-out piece of memory from an initialized event, it can easily be confused by uninitialized memory. Thus, it should ONLY be used to distinguish an initialized event from zero. @@ -1330,7 +1330,7 @@ struct event *event_base_get_running_event(struct event_base *base); @return 1 if the structure might be initialized, or 0 if it has not been initialized */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_initialized(const struct event *ev); /** @@ -1342,48 +1342,48 @@ int event_initialized(const struct event *ev); Get the socket or signal assigned to an event, or -1 if the event has no socket. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL evutil_socket_t event_get_fd(const struct event *ev); /** Get the event_base associated with an event. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *event_get_base(const struct event *ev); /** Return the events (EV_READ, EV_WRITE, etc) assigned to an event. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL short event_get_events(const struct event *ev); /** Return the callback assigned to an event. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL event_callback_fn event_get_callback(const struct event *ev); /** Return the callback argument assigned to an event. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void *event_get_callback_arg(const struct event *ev); /** - Return the priority of an event. - @see event_priority_init(), event_get_priority() -*/ -EVENT2_EXPORT_SYMBOL -int event_get_priority(const struct event *ev); - -/** + Return the priority of an event. + @see event_priority_init(), event_get_priority() +*/ +EVENT2_EXPORT_SYMBOL +int event_get_priority(const struct event *ev); + +/** Extract _all_ of arguments given to construct a given event. The event_base is copied into *base_out, the fd is copied into *fd_out, and so on. If any of the "_out" arguments is NULL, it will be ignored. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_get_assignment(const struct event *event, struct event_base **base_out, evutil_socket_t *fd_out, short *events_out, event_callback_fn *callback_out, void **arg_out); @@ -1401,7 +1401,7 @@ void event_get_assignment(const struct event *event, We might do this to help ensure ABI-compatibility between different versions of Libevent. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL size_t event_get_struct_event_size(void); /** @@ -1413,7 +1413,7 @@ size_t event_get_struct_event_size(void); @return a string containing the version number of Libevent */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *event_get_version(void); /** @@ -1427,14 +1427,14 @@ const char *event_get_version(void); the version number. The low-order byte is unused. For example, version 2.0.1-alpha has a numeric representation of 0x02000100 */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_uint32_t event_get_version_number(void); /** As event_get_version, but gives the version of Libevent's headers. */ -#define LIBEVENT_VERSION EVENT__VERSION +#define LIBEVENT_VERSION EVENT__VERSION /** As event_get_version_number, but gives the version number of Libevent's * headers. */ -#define LIBEVENT_VERSION_NUMBER EVENT__NUMERIC_VERSION +#define LIBEVENT_VERSION_NUMBER EVENT__NUMERIC_VERSION /** Largest number of priorities that Libevent can support. */ #define EVENT_MAX_PRIORITIES 256 @@ -1465,28 +1465,28 @@ ev_uint32_t event_get_version_number(void); @return 0 if successful, or -1 if an error occurred @see event_priority_set() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_priority_init(struct event_base *, int); /** - Get the number of different event priorities. - - @param eb the event_base structure returned by event_base_new() - @return Number of different event priorities - @see event_base_priority_init() -*/ -EVENT2_EXPORT_SYMBOL -int event_base_get_npriorities(struct event_base *eb); - -/** + Get the number of different event priorities. + + @param eb the event_base structure returned by event_base_new() + @return Number of different event priorities + @see event_base_priority_init() +*/ +EVENT2_EXPORT_SYMBOL +int event_base_get_npriorities(struct event_base *eb); + +/** Assign a priority to an event. @param ev an event struct @param priority the new priority to be assigned @return 0 if successful, or -1 if an error occurred - @see event_priority_init(), event_get_priority() + @see event_priority_init(), event_get_priority() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_priority_set(struct event *, int); /** @@ -1508,11 +1508,11 @@ int event_priority_set(struct event *, int); (This optimization probably will not be worthwhile until you have thousands or tens of thousands of events with the same timeout.) */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const struct timeval *event_base_init_common_timeout(struct event_base *base, const struct timeval *duration); -#if !defined(EVENT__DISABLE_MM_REPLACEMENT) || defined(EVENT_IN_DOXYGEN_) +#if !defined(EVENT__DISABLE_MM_REPLACEMENT) || defined(EVENT_IN_DOXYGEN_) /** Override the functions that Libevent uses for memory management. @@ -1528,14 +1528,14 @@ const struct timeval *event_base_init_common_timeout(struct event_base *base, Note also that if you are going to call this function, you should do so before any call to any Libevent function that does allocation. - Otherwise, those functions will allocate their memory using malloc(), but + Otherwise, those functions will allocate their memory using malloc(), but then later free it using your provided free_fn. @param malloc_fn A replacement for malloc. @param realloc_fn A replacement for realloc @param free_fn A replacement for free. **/ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_set_mem_functions( void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), @@ -1545,128 +1545,128 @@ void event_set_mem_functions( #define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED #endif -/** - Writes a human-readable description of all inserted and/or active - events to a provided stdio stream. - - This is intended for debugging; its format is not guaranteed to be the same - between libevent versions. - - @param base An event_base on which to scan the events. - @param output A stdio file to write on. - */ -EVENT2_EXPORT_SYMBOL +/** + Writes a human-readable description of all inserted and/or active + events to a provided stdio stream. + + This is intended for debugging; its format is not guaranteed to be the same + between libevent versions. + + @param base An event_base on which to scan the events. + @param output A stdio file to write on. + */ +EVENT2_EXPORT_SYMBOL void event_base_dump_events(struct event_base *, FILE *); - -/** - Activates all pending events for the given fd and event mask. - - This function activates pending events only. Events which have not been - added will not become active. - - @param base the event_base on which to activate the events. - @param fd An fd to active events on. - @param events One or more of EV_{READ,WRITE,TIMEOUT}. - */ -EVENT2_EXPORT_SYMBOL -void event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events); - -/** - Activates all pending signals with a given signal number - - This function activates pending events only. Events which have not been - added will not become active. - - @param base the event_base on which to activate the events. - @param fd The signal to active events on. - */ -EVENT2_EXPORT_SYMBOL -void event_base_active_by_signal(struct event_base *base, int sig); - -/** - * Callback for iterating events in an event base via event_base_foreach_event - */ -typedef int (*event_base_foreach_event_cb)(const struct event_base *, const struct event *, void *); - -/** - Iterate over all added or active events events in an event loop, and invoke - a given callback on each one. - - The callback must not call any function that modifies the event base, that - modifies any event in the event base, or that adds or removes any event to - the event base. Doing so is unsupported and will lead to undefined - behavior -- likely, to crashes. - - event_base_foreach_event() holds a lock on the event_base() for the whole - time it's running: slow callbacks are not advisable. - - Note that Libevent adds some events of its own to make pieces of its - functionality work. You must not assume that the only events you'll - encounter will be the ones you added yourself. - - The callback function must return 0 to continue iteration, or some other - integer to stop iterating. - - @param base An event_base on which to scan the events. - @param fn A callback function to receive the events. - @param arg An argument passed to the callback function. - @return 0 if we iterated over every event, or the value returned by the - callback function if the loop exited early. -*/ -EVENT2_EXPORT_SYMBOL -int event_base_foreach_event(struct event_base *base, event_base_foreach_event_cb fn, void *arg); - - + +/** + Activates all pending events for the given fd and event mask. + + This function activates pending events only. Events which have not been + added will not become active. + + @param base the event_base on which to activate the events. + @param fd An fd to active events on. + @param events One or more of EV_{READ,WRITE,TIMEOUT}. + */ +EVENT2_EXPORT_SYMBOL +void event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events); + +/** + Activates all pending signals with a given signal number + + This function activates pending events only. Events which have not been + added will not become active. + + @param base the event_base on which to activate the events. + @param fd The signal to active events on. + */ +EVENT2_EXPORT_SYMBOL +void event_base_active_by_signal(struct event_base *base, int sig); + +/** + * Callback for iterating events in an event base via event_base_foreach_event + */ +typedef int (*event_base_foreach_event_cb)(const struct event_base *, const struct event *, void *); + +/** + Iterate over all added or active events events in an event loop, and invoke + a given callback on each one. + + The callback must not call any function that modifies the event base, that + modifies any event in the event base, or that adds or removes any event to + the event base. Doing so is unsupported and will lead to undefined + behavior -- likely, to crashes. + + event_base_foreach_event() holds a lock on the event_base() for the whole + time it's running: slow callbacks are not advisable. + + Note that Libevent adds some events of its own to make pieces of its + functionality work. You must not assume that the only events you'll + encounter will be the ones you added yourself. + + The callback function must return 0 to continue iteration, or some other + integer to stop iterating. + + @param base An event_base on which to scan the events. + @param fn A callback function to receive the events. + @param arg An argument passed to the callback function. + @return 0 if we iterated over every event, or the value returned by the + callback function if the loop exited early. +*/ +EVENT2_EXPORT_SYMBOL +int event_base_foreach_event(struct event_base *base, event_base_foreach_event_cb fn, void *arg); + + /** Sets 'tv' to the current time (as returned by gettimeofday()), looking at the cached value in 'base' if possible, and calling gettimeofday() or clock_gettime() as appropriate if there is no cached time. Generally, this value will only be cached while actually - processing event callbacks, and may be very inaccurate if your + processing event callbacks, and may be very inaccurate if your callbacks take a long time to execute. Returns 0 on success, negative on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_base_gettimeofday_cached(struct event_base *base, struct timeval *tv); -/** Update cached_tv in the 'base' to the current time - * - * You can use this function is useful for selectively increasing - * the accuracy of the cached time value in 'base' during callbacks - * that take a long time to execute. - * - * This function has no effect if the base is currently not in its - * event loop, or if timeval caching is disabled via - * EVENT_BASE_FLAG_NO_CACHE_TIME. - * - * @return 0 on success, -1 on failure - */ -EVENT2_EXPORT_SYMBOL -int event_base_update_cache_time(struct event_base *base); - -/** Release up all globally-allocated resources allocated by Libevent. - - This function does not free developer-controlled resources like - event_bases, events, bufferevents, listeners, and so on. It only releases - resources like global locks that there is no other way to free. - - It is not actually necessary to call this function before exit: every - resource that it frees would be released anyway on exit. It mainly exists - so that resource-leak debugging tools don't see Libevent as holding - resources at exit. - - You should only call this function when no other Libevent functions will - be invoked -- e.g., when cleanly exiting a program. - */ -EVENT2_EXPORT_SYMBOL -void libevent_global_shutdown(void); - +/** Update cached_tv in the 'base' to the current time + * + * You can use this function is useful for selectively increasing + * the accuracy of the cached time value in 'base' during callbacks + * that take a long time to execute. + * + * This function has no effect if the base is currently not in its + * event loop, or if timeval caching is disabled via + * EVENT_BASE_FLAG_NO_CACHE_TIME. + * + * @return 0 on success, -1 on failure + */ +EVENT2_EXPORT_SYMBOL +int event_base_update_cache_time(struct event_base *base); + +/** Release up all globally-allocated resources allocated by Libevent. + + This function does not free developer-controlled resources like + event_bases, events, bufferevents, listeners, and so on. It only releases + resources like global locks that there is no other way to free. + + It is not actually necessary to call this function before exit: every + resource that it frees would be released anyway on exit. It mainly exists + so that resource-leak debugging tools don't see Libevent as holding + resources at exit. + + You should only call this function when no other Libevent functions will + be invoked -- e.g., when cleanly exiting a program. + */ +EVENT2_EXPORT_SYMBOL +void libevent_global_shutdown(void); + #ifdef __cplusplus } #endif -#endif /* EVENT2_EVENT_H_INCLUDED_ */ +#endif /* EVENT2_EVENT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/event_compat.h b/contrib/libs/libevent/include/event2/event_compat.h index 5110175a1b..67612da65b 100644 --- a/contrib/libs/libevent/include/event2/event_compat.h +++ b/contrib/libs/libevent/include/event2/event_compat.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_EVENT_COMPAT_H_INCLUDED_ -#define EVENT2_EVENT_COMPAT_H_INCLUDED_ +#ifndef EVENT2_EVENT_COMPAT_H_INCLUDED_ +#define EVENT2_EVENT_COMPAT_H_INCLUDED_ /** @file event2/event_compat.h @@ -41,17 +41,17 @@ @deprecated All functions in this file are by definition deprecated. */ -#include <event2/visibility.h> +#include <event2/visibility.h> #ifdef __cplusplus extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -71,7 +71,7 @@ extern "C" { @see event_base_set(), event_base_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *event_init(void); /** @@ -85,7 +85,7 @@ struct event_base *event_init(void); @see event_base_dispatch(), event_init() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_dispatch(void); /** @@ -99,7 +99,7 @@ int event_dispatch(void); @see event_base_loop(), event_init() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_loop(int); @@ -115,7 +115,7 @@ int event_loop(int); @see event_init, event_base_loopexit() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_loopexit(const struct timeval *); @@ -131,7 +131,7 @@ int event_loopexit(const struct timeval *); @see event_base_loopbreak(), event_init() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_loopbreak(void); /** @@ -143,7 +143,7 @@ int event_loopbreak(void); @see event_base_once() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_once(evutil_socket_t , short, void (*)(evutil_socket_t, short, void *), void *, const struct timeval *); @@ -157,7 +157,7 @@ int event_once(evutil_socket_t , short, @see event_base_get_method() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *event_get_method(void); @@ -170,7 +170,7 @@ const char *event_get_method(void); @see event_base_priority_init() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int event_priority_init(int); /** @@ -180,7 +180,7 @@ int event_priority_init(int); a subsequent call to event_base_set() to be safe under most circumstances. Use event_assign() or event_new() instead. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, short, void *), void *); #define evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) @@ -227,4 +227,4 @@ void event_set(struct event *, evutil_socket_t, short, void (*)(evutil_socket_t, } #endif -#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ +#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/event_struct.h b/contrib/libs/libevent/include/event2/event_struct.h index 1c8b71b6b0..d6b5a5b56a 100644 --- a/contrib/libs/libevent/include/event2/event_struct.h +++ b/contrib/libs/libevent/include/event2/event_struct.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_ -#define EVENT2_EVENT_STRUCT_H_INCLUDED_ +#ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_ +#define EVENT2_EVENT_STRUCT_H_INCLUDED_ /** @file event2/event_struct.h @@ -41,10 +41,10 @@ extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -54,20 +54,20 @@ extern "C" { /* For evkeyvalq */ #include <event2/keyvalq_struct.h> -#define EVLIST_TIMEOUT 0x01 -#define EVLIST_INSERTED 0x02 -#define EVLIST_SIGNAL 0x04 -#define EVLIST_ACTIVE 0x08 -#define EVLIST_INTERNAL 0x10 -#define EVLIST_ACTIVE_LATER 0x20 -#define EVLIST_FINALIZING 0x40 -#define EVLIST_INIT 0x80 +#define EVLIST_TIMEOUT 0x01 +#define EVLIST_INSERTED 0x02 +#define EVLIST_SIGNAL 0x04 +#define EVLIST_ACTIVE 0x08 +#define EVLIST_INTERNAL 0x10 +#define EVLIST_ACTIVE_LATER 0x20 +#define EVLIST_FINALIZING 0x40 +#define EVLIST_INIT 0x80 -#define EVLIST_ALL 0xff +#define EVLIST_ALL 0xff /* Fix so that people don't have to run with <sys/queue.h> */ #ifndef TAILQ_ENTRY -#define EVENT_DEFINED_TQENTRY_ +#define EVENT_DEFINED_TQENTRY_ #define TAILQ_ENTRY(type) \ struct { \ struct type *tqe_next; /* next element */ \ @@ -76,7 +76,7 @@ struct { \ #endif /* !TAILQ_ENTRY */ #ifndef TAILQ_HEAD -#define EVENT_DEFINED_TQHEAD_ +#define EVENT_DEFINED_TQHEAD_ #define TAILQ_HEAD(name, type) \ struct name { \ struct type *tqh_first; \ @@ -84,45 +84,45 @@ struct name { \ } #endif -/* Fix so that people don't have to run with <sys/queue.h> */ -#ifndef LIST_ENTRY -#define EVENT_DEFINED_LISTENTRY_ -#define LIST_ENTRY(type) \ -struct { \ - struct type *le_next; /* next element */ \ - struct type **le_prev; /* address of previous next element */ \ -} -#endif /* !LIST_ENTRY */ - -#ifndef LIST_HEAD -#define EVENT_DEFINED_LISTHEAD_ -#define LIST_HEAD(name, type) \ -struct name { \ - struct type *lh_first; /* first element */ \ - } -#endif /* !LIST_HEAD */ - -struct event; - -struct event_callback { - TAILQ_ENTRY(event_callback) evcb_active_next; - short evcb_flags; - ev_uint8_t evcb_pri; /* smaller numbers are higher priority */ - ev_uint8_t evcb_closure; - /* allows us to adopt for different types of events */ - union { - void (*evcb_callback)(evutil_socket_t, short, void *); - void (*evcb_selfcb)(struct event_callback *, void *); - void (*evcb_evfinalize)(struct event *, void *); - void (*evcb_cbfinalize)(struct event_callback *, void *); - } evcb_cb_union; - void *evcb_arg; -}; - +/* Fix so that people don't have to run with <sys/queue.h> */ +#ifndef LIST_ENTRY +#define EVENT_DEFINED_LISTENTRY_ +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} +#endif /* !LIST_ENTRY */ + +#ifndef LIST_HEAD +#define EVENT_DEFINED_LISTHEAD_ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ + } +#endif /* !LIST_HEAD */ + +struct event; + +struct event_callback { + TAILQ_ENTRY(event_callback) evcb_active_next; + short evcb_flags; + ev_uint8_t evcb_pri; /* smaller numbers are higher priority */ + ev_uint8_t evcb_closure; + /* allows us to adopt for different types of events */ + union { + void (*evcb_callback)(evutil_socket_t, short, void *); + void (*evcb_selfcb)(struct event_callback *, void *); + void (*evcb_evfinalize)(struct event *, void *); + void (*evcb_cbfinalize)(struct event_callback *, void *); + } evcb_cb_union; + void *evcb_arg; +}; + struct event_base; struct event { - struct event_callback ev_evcallback; - + struct event_callback ev_evcallback; + /* for managing timeouts */ union { TAILQ_ENTRY(event) ev_next_with_common_timeout; @@ -135,18 +135,18 @@ struct event { union { /* used for io events */ struct { - LIST_ENTRY (event) ev_io_next; + LIST_ENTRY (event) ev_io_next; struct timeval ev_timeout; } ev_io; /* used by signal events */ struct { - LIST_ENTRY (event) ev_signal_next; + LIST_ENTRY (event) ev_signal_next; short ev_ncalls; /* Allows deletes in callback */ short *ev_pncalls; } ev_signal; - } ev_; + } ev_; short ev_events; short ev_res; /* result passed to event callback */ @@ -155,26 +155,26 @@ struct event { TAILQ_HEAD (event_list, event); -#ifdef EVENT_DEFINED_TQENTRY_ +#ifdef EVENT_DEFINED_TQENTRY_ #undef TAILQ_ENTRY #endif -#ifdef EVENT_DEFINED_TQHEAD_ +#ifdef EVENT_DEFINED_TQHEAD_ #undef TAILQ_HEAD #endif -LIST_HEAD (event_dlist, event); - -#ifdef EVENT_DEFINED_LISTENTRY_ -#undef LIST_ENTRY -#endif - -#ifdef EVENT_DEFINED_LISTHEAD_ -#undef LIST_HEAD -#endif - +LIST_HEAD (event_dlist, event); + +#ifdef EVENT_DEFINED_LISTENTRY_ +#undef LIST_ENTRY +#endif + +#ifdef EVENT_DEFINED_LISTHEAD_ +#undef LIST_HEAD +#endif + #ifdef __cplusplus } #endif -#endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */ +#endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/http.h b/contrib/libs/libevent/include/event2/http.h index 40d411ddd2..cfb0c2c404 100644 --- a/contrib/libs/libevent/include/event2/http.h +++ b/contrib/libs/libevent/include/event2/http.h @@ -24,12 +24,12 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_HTTP_H_INCLUDED_ -#define EVENT2_HTTP_H_INCLUDED_ +#ifndef EVENT2_HTTP_H_INCLUDED_ +#define EVENT2_HTTP_H_INCLUDED_ /* For int types. */ #include <event2/util.h> -#include <event2/visibility.h> +#include <event2/visibility.h> #ifdef __cplusplus extern "C" { @@ -39,7 +39,7 @@ extern "C" { struct evbuffer; struct event_base; struct bufferevent; -struct evhttp_connection; +struct evhttp_connection; /** @file event2/http.h * @@ -78,11 +78,11 @@ struct evdns_base; * Create a new HTTP server. * * @param base (optional) the event base to receive the HTTP events - * @return a pointer to a newly initialized evhttp server structure or NULL - * on error + * @return a pointer to a newly initialized evhttp server structure or NULL + * on error * @see evhttp_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp *evhttp_new(struct event_base *base); /** @@ -97,7 +97,7 @@ struct evhttp *evhttp_new(struct event_base *base); * @return 0 on success, -1 on failure. * @see evhttp_accept_socket() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port); /** @@ -111,7 +111,7 @@ int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t por * @return Handle for the socket on success, NULL on failure. * @see evhttp_bind_socket(), evhttp_del_accept_socket() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket *evhttp_bind_socket_with_handle(struct evhttp *http, const char *address, ev_uint16_t port); /** @@ -130,7 +130,7 @@ struct evhttp_bound_socket *evhttp_bind_socket_with_handle(struct evhttp *http, * @return 0 on success, -1 on failure. * @see evhttp_bind_socket() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd); /** @@ -143,7 +143,7 @@ int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd); * @return Handle for the socket on success, NULL on failure. * @see evhttp_accept_socket(), evhttp_del_accept_socket() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http, evutil_socket_t fd); /** @@ -151,30 +151,30 @@ struct evhttp_bound_socket *evhttp_accept_socket_with_handle(struct evhttp *http * returns an evhttp_bound_socket. The listener will be freed when the bound * socket is freed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket *evhttp_bind_listener(struct evhttp *http, struct evconnlistener *listener); /** * Return the listener used to implement a bound socket. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evconnlistener *evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound); -typedef void evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *); -/** - * Applies the function specified in the first argument to all - * evhttp_bound_sockets associated with "http". The user must not - * attempt to free or remove any connections, sockets or listeners - * in the callback "function". - * - * @param http pointer to an evhttp object - * @param function function to apply to every bound socket - * @param argument pointer value passed to function for every socket iterated - */ -EVENT2_EXPORT_SYMBOL -void evhttp_foreach_bound_socket(struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument); - -/** +typedef void evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *); +/** + * Applies the function specified in the first argument to all + * evhttp_bound_sockets associated with "http". The user must not + * attempt to free or remove any connections, sockets or listeners + * in the callback "function". + * + * @param http pointer to an evhttp object + * @param function function to apply to every bound socket + * @param argument pointer value passed to function for every socket iterated + */ +EVENT2_EXPORT_SYMBOL +void evhttp_foreach_bound_socket(struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument); + +/** * Makes an HTTP server stop accepting connections on the specified socket * * This may be useful when a socket has been sent via file descriptor passing @@ -191,7 +191,7 @@ void evhttp_foreach_bound_socket(struct evhttp *http, evhttp_bound_socket_foreac * @param bound_socket a handle returned by evhttp_{bind,accept}_socket_with_handle * @see evhttp_bind_socket_with_handle(), evhttp_accept_socket_with_handle() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound_socket); /** @@ -201,7 +201,7 @@ void evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *b * @return the file descriptor used by the bound socket * @see evhttp_bind_socket_with_handle(), evhttp_accept_socket_with_handle() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound_socket); /** @@ -212,32 +212,32 @@ evutil_socket_t evhttp_bound_socket_get_fd(struct evhttp_bound_socket *bound_soc * @param http the evhttp server object to be freed * @see evhttp_start() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_free(struct evhttp* http); /** XXX Document. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_size); /** XXX Document. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size); /** - Set the value to use for the Content-Type header when none was provided. If - the content type string is NULL, the Content-Type header will not be - automatically added. - - @param http the http server on which to set the default content type - @param content_type the value for the Content-Type header -*/ -EVENT2_EXPORT_SYMBOL -void evhttp_set_default_content_type(struct evhttp *http, - const char *content_type); - -void evhttp_set_bevcb(struct evhttp *http, - struct bufferevent* (*cb)(struct event_base *, void *), void *arg); - -/** + Set the value to use for the Content-Type header when none was provided. If + the content type string is NULL, the Content-Type header will not be + automatically added. + + @param http the http server on which to set the default content type + @param content_type the value for the Content-Type header +*/ +EVENT2_EXPORT_SYMBOL +void evhttp_set_default_content_type(struct evhttp *http, + const char *content_type); + +void evhttp_set_bevcb(struct evhttp *http, + struct bufferevent* (*cb)(struct event_base *, void *), void *arg); + +/** Sets the what HTTP methods are supported in requests accepted by this server, and passed to user callbacks. @@ -248,7 +248,7 @@ void evhttp_set_bevcb(struct evhttp *http, @param http the http server on which to set the methods @param methods bit mask constructed from evhttp_cmd_type values */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods); /** @@ -260,16 +260,16 @@ void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods); @param cb_arg an additional context argument for the callback @return 0 on success, -1 if the callback existed already, -2 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_set_cb(struct evhttp *http, const char *path, void (*cb)(struct evhttp_request *, void *), void *cb_arg); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_set_chunk_cb(struct evhttp *http, const char *path, void (*chunk_cb)(struct evhttp_request *, void *), void *cb_arg); /** Removes the callback for a specified URI */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_del_cb(struct evhttp *, const char *); /** @@ -283,27 +283,27 @@ int evhttp_del_cb(struct evhttp *, const char *); @param cb the callback to invoke for any unmatched requests @param arg an context argument for the callback */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_set_gencb(struct evhttp *http, void (*cb)(struct evhttp_request *, void *), void *arg); -/** - Set a callback used to create new bufferevents for connections - to a given evhttp object. - - You can use this to override the default bufferevent type -- for example, - to make this evhttp object use SSL bufferevents rather than unencrypted - ones. - - New bufferevents must be allocated with no fd set on them. - - @param http the evhttp server object for which to set the callback - @param cb the callback to invoke for incoming connections - @param arg an context argument for the callback - */ -EVENT2_EXPORT_SYMBOL +/** + Set a callback used to create new bufferevents for connections + to a given evhttp object. + + You can use this to override the default bufferevent type -- for example, + to make this evhttp object use SSL bufferevents rather than unencrypted + ones. + + New bufferevents must be allocated with no fd set on them. + + @param http the evhttp server object for which to set the callback + @param cb the callback to invoke for incoming connections + @param arg an context argument for the callback + */ +EVENT2_EXPORT_SYMBOL void evhttp_set_bevcb(struct evhttp *http, - struct bufferevent *(*cb)(struct event_base *, void *), void *arg); + struct bufferevent *(*cb)(struct event_base *, void *), void *arg); /** Adds a virtual host to the http server. @@ -327,7 +327,7 @@ void evhttp_set_bevcb(struct evhttp *http, @return 0 on success, -1 on failure @see evhttp_remove_virtual_host() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_add_virtual_host(struct evhttp* http, const char *pattern, struct evhttp* vhost); @@ -339,7 +339,7 @@ int evhttp_add_virtual_host(struct evhttp* http, const char *pattern, @return 0 on success, -1 on failure @see evhttp_add_virtual_host() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_remove_virtual_host(struct evhttp* http, struct evhttp* vhost); /** @@ -350,7 +350,7 @@ int evhttp_remove_virtual_host(struct evhttp* http, struct evhttp* vhost); @param alias the alias to add @see evhttp_add_remove_alias() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_add_server_alias(struct evhttp *http, const char *alias); /** @@ -360,7 +360,7 @@ int evhttp_add_server_alias(struct evhttp *http, const char *alias); @param alias the alias to remove @see evhttp_add_server_alias() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_remove_server_alias(struct evhttp *http, const char *alias); /** @@ -369,38 +369,38 @@ int evhttp_remove_server_alias(struct evhttp *http, const char *alias); * @param http an evhttp object * @param timeout_in_secs the timeout, in seconds */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs); -/** - * Set the timeout for an HTTP request. - * - * @param http an evhttp object - * @param tv the timeout, or NULL - */ -EVENT2_EXPORT_SYMBOL -void evhttp_set_timeout_tv(struct evhttp *http, const struct timeval* tv); - -/* Read all the clients body, and only after this respond with an error if the - * clients body exceed max_body_size */ -#define EVHTTP_SERVER_LINGERING_CLOSE 0x0001 -/** - * Set connection flags for HTTP server. - * - * @see EVHTTP_SERVER_* - * @return 0 on success, otherwise non zero (for example if flag doesn't - * supported). - */ -EVENT2_EXPORT_SYMBOL -int evhttp_set_flags(struct evhttp *http, int flags); - +/** + * Set the timeout for an HTTP request. + * + * @param http an evhttp object + * @param tv the timeout, or NULL + */ +EVENT2_EXPORT_SYMBOL +void evhttp_set_timeout_tv(struct evhttp *http, const struct timeval* tv); + +/* Read all the clients body, and only after this respond with an error if the + * clients body exceed max_body_size */ +#define EVHTTP_SERVER_LINGERING_CLOSE 0x0001 +/** + * Set connection flags for HTTP server. + * + * @see EVHTTP_SERVER_* + * @return 0 on success, otherwise non zero (for example if flag doesn't + * supported). + */ +EVENT2_EXPORT_SYMBOL +int evhttp_set_flags(struct evhttp *http, int flags); + /* Request/Response functionality */ -struct evhttp_connection *evhttp_connection_base_bufferevent_new( - struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, unsigned short port); - -struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon); - +struct evhttp_connection *evhttp_connection_base_bufferevent_new( + struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, unsigned short port); + +struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon); + /** * Send an HTML error message to the client. * @@ -409,7 +409,7 @@ struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection * * @param reason a brief explanation of the error. If this is NULL, we'll * just use the standard meaning of the error code. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_send_error(struct evhttp_request *req, int error, const char *reason); @@ -426,7 +426,7 @@ void evhttp_send_error(struct evhttp_request *req, int error, * @param reason a brief message to send with the response code * @param databuf the body of the response */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_send_reply(struct evhttp_request *req, int code, const char *reason, struct evbuffer *databuf); @@ -446,7 +446,7 @@ void evhttp_send_reply(struct evhttp_request *req, int code, @param code the HTTP response code to send @param reason a brief message to send with the response code */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_send_reply_start(struct evhttp_request *req, int code, const char *reason); @@ -461,33 +461,33 @@ void evhttp_send_reply_start(struct evhttp_request *req, int code, @param req a request object @param databuf the data chunk to send as part of the reply. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf); - -/** - Send another data chunk as part of an ongoing chunked reply. - - The reply chunk consists of the data in databuf. After calling - evhttp_send_reply_chunk() databuf will be empty, but the buffer is - still owned by the caller and needs to be deallocated by the caller - if necessary. - - @param req a request object - @param databuf the data chunk to send as part of the reply. - @param cb callback funcion - @param call back's argument. -*/ -EVENT2_EXPORT_SYMBOL -void evhttp_send_reply_chunk_with_cb(struct evhttp_request *, struct evbuffer *, - void (*cb)(struct evhttp_connection *, void *), void *arg); - -/** + +/** + Send another data chunk as part of an ongoing chunked reply. + + The reply chunk consists of the data in databuf. After calling + evhttp_send_reply_chunk() databuf will be empty, but the buffer is + still owned by the caller and needs to be deallocated by the caller + if necessary. + + @param req a request object + @param databuf the data chunk to send as part of the reply. + @param cb callback funcion + @param call back's argument. +*/ +EVENT2_EXPORT_SYMBOL +void evhttp_send_reply_chunk_with_cb(struct evhttp_request *, struct evbuffer *, + void (*cb)(struct evhttp_connection *, void *), void *arg); + +/** Complete a chunked reply, freeing the request as appropriate. @param req a request object */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_send_reply_end(struct evhttp_request *req); /* @@ -517,24 +517,24 @@ enum evhttp_cmd_type { enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE }; /** - * Create and return a connection object that can be used to for making HTTP - * requests. The connection object tries to resolve address and establish the - * connection when it is given an http request object. + * Create and return a connection object that can be used to for making HTTP + * requests. The connection object tries to resolve address and establish the + * connection when it is given an http request object. * * @param base the event_base to use for handling the connection * @param dnsbase the dns_base to use for resolving host names; if not * specified host name resolution will block. - * @param bev a bufferevent to use for connecting to the server; if NULL, a - * socket-based bufferevent will be created. This buffrevent will be freed - * when the connection closes. It must have no fd set on it. + * @param bev a bufferevent to use for connecting to the server; if NULL, a + * socket-based bufferevent will be created. This buffrevent will be freed + * when the connection closes. It must have no fd set on it. * @param address the address to which to connect * @param port the port to connect to - * @return an evhttp_connection object that can be used for making requests or - * NULL on error + * @return an evhttp_connection object that can be used for making requests or + * NULL on error */ -EVENT2_EXPORT_SYMBOL -struct evhttp_connection *evhttp_connection_base_bufferevent_new( - struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, ev_uint16_t port); +EVENT2_EXPORT_SYMBOL +struct evhttp_connection *evhttp_connection_base_bufferevent_new( + struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, ev_uint16_t port); /** * Creates and returns a new bufferevent object. @@ -571,163 +571,163 @@ struct evhttp_connection *evhttp_connection_base_bufferevent_factory_new( /** * Return the bufferevent that an evhttp_connection is using. */ -EVENT2_EXPORT_SYMBOL -struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon); - -/** - * Return the HTTP server associated with this connection, or NULL. - */ -EVENT2_EXPORT_SYMBOL -struct evhttp *evhttp_connection_get_server(struct evhttp_connection *evcon); - -/** - * Creates a new request object that needs to be filled in with the request - * parameters. The callback is executed when the request completed or an - * error occurred. - */ -EVENT2_EXPORT_SYMBOL -struct evhttp_request *evhttp_request_new( - void (*cb)(struct evhttp_request *, void *), void *arg); - -/** - * Enable delivery of chunks to requestor. - * @param cb will be called after every read of data with the same argument - * as the completion callback. Will never be called on an empty - * response. May drain the input buffer; it will be drained - * automatically on return. - */ -EVENT2_EXPORT_SYMBOL -void evhttp_request_set_chunked_cb(struct evhttp_request *, - void (*cb)(struct evhttp_request *, void *), void *arg); - -/** - * Register callback for additional parsing of request headers. - * @param cb will be called after receiving and parsing the full header. - * It allows analyzing the header and possibly closing the connection - * by returning a value < 0. - */ -EVENT2_EXPORT_SYMBOL -void evhttp_request_set_header_cb(struct evhttp_request *, - int (*cb)(struct evhttp_request *, void *)); - -/** - * The different error types supported by evhttp - * - * @see evhttp_request_set_error_cb() - */ -enum evhttp_request_error { - /** - * Timeout reached, also @see evhttp_connection_set_timeout() - */ - EVREQ_HTTP_TIMEOUT, - /** - * EOF reached - */ - EVREQ_HTTP_EOF, - /** - * Error while reading header, or invalid header - */ - EVREQ_HTTP_INVALID_HEADER, - /** - * Error encountered while reading or writing - */ - EVREQ_HTTP_BUFFER_ERROR, - /** - * The evhttp_cancel_request() called on this request. - */ - EVREQ_HTTP_REQUEST_CANCEL, - /** - * Body is greater then evhttp_connection_set_max_body_size() - */ - EVREQ_HTTP_DATA_TOO_LONG -}; -/** - * Set a callback for errors - * @see evhttp_request_error for error types. - * - * On error, both the error callback and the regular callback will be called, - * error callback is called before the regular callback. - **/ -EVENT2_EXPORT_SYMBOL -void evhttp_request_set_error_cb(struct evhttp_request *, - void (*)(enum evhttp_request_error, void *)); - -/** - * Set a callback to be called on request completion of evhttp_send_* function. - * - * The callback function will be called on the completion of the request after - * the output data has been written and before the evhttp_request object - * is destroyed. This can be useful for tracking resources associated with a - * request (ex: timing metrics). - * - * @param req a request object - * @param cb callback function that will be called on request completion - * @param cb_arg an additional context argument for the callback - */ -EVENT2_EXPORT_SYMBOL -void evhttp_request_set_on_complete_cb(struct evhttp_request *req, - void (*cb)(struct evhttp_request *, void *), void *cb_arg); - -/** Frees the request object and removes associated events. */ -EVENT2_EXPORT_SYMBOL -void evhttp_request_free(struct evhttp_request *req); - -/** - * Create and return a connection object that can be used to for making HTTP - * requests. The connection object tries to resolve address and establish the - * connection when it is given an http request object. - * - * @param base the event_base to use for handling the connection - * @param dnsbase the dns_base to use for resolving host names; if not - * specified host name resolution will block. - * @param address the address to which to connect - * @param port the port to connect to - * @return an evhttp_connection object that can be used for making requests or - * NULL on error - */ -EVENT2_EXPORT_SYMBOL -struct evhttp_connection *evhttp_connection_base_new( - struct event_base *base, struct evdns_base *dnsbase, - const char *address, ev_uint16_t port); - -/** - * Set family hint for DNS requests. - */ -EVENT2_EXPORT_SYMBOL -void evhttp_connection_set_family(struct evhttp_connection *evcon, - int family); - -/* reuse connection address on retry */ -#define EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008 -/* Try to read error, since server may already send and close - * connection, but if at that time we have some data to send then we - * can send get EPIPE and fail, while we can read that HTTP error. */ -#define EVHTTP_CON_READ_ON_WRITE_ERROR 0x0010 -/* @see EVHTTP_SERVER_LINGERING_CLOSE */ -#define EVHTTP_CON_LINGERING_CLOSE 0x0020 -/* Padding for public flags, @see EVHTTP_CON_* in http-internal.h */ -#define EVHTTP_CON_PUBLIC_FLAGS_END 0x100000 -/** - * Set connection flags. - * - * @see EVHTTP_CON_* - * @return 0 on success, otherwise non zero (for example if flag doesn't - * supported). - */ -EVENT2_EXPORT_SYMBOL -int evhttp_connection_set_flags(struct evhttp_connection *evcon, - int flags); - +EVENT2_EXPORT_SYMBOL +struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon); + +/** + * Return the HTTP server associated with this connection, or NULL. + */ +EVENT2_EXPORT_SYMBOL +struct evhttp *evhttp_connection_get_server(struct evhttp_connection *evcon); + +/** + * Creates a new request object that needs to be filled in with the request + * parameters. The callback is executed when the request completed or an + * error occurred. + */ +EVENT2_EXPORT_SYMBOL +struct evhttp_request *evhttp_request_new( + void (*cb)(struct evhttp_request *, void *), void *arg); + +/** + * Enable delivery of chunks to requestor. + * @param cb will be called after every read of data with the same argument + * as the completion callback. Will never be called on an empty + * response. May drain the input buffer; it will be drained + * automatically on return. + */ +EVENT2_EXPORT_SYMBOL +void evhttp_request_set_chunked_cb(struct evhttp_request *, + void (*cb)(struct evhttp_request *, void *), void *arg); + +/** + * Register callback for additional parsing of request headers. + * @param cb will be called after receiving and parsing the full header. + * It allows analyzing the header and possibly closing the connection + * by returning a value < 0. + */ +EVENT2_EXPORT_SYMBOL +void evhttp_request_set_header_cb(struct evhttp_request *, + int (*cb)(struct evhttp_request *, void *)); + +/** + * The different error types supported by evhttp + * + * @see evhttp_request_set_error_cb() + */ +enum evhttp_request_error { + /** + * Timeout reached, also @see evhttp_connection_set_timeout() + */ + EVREQ_HTTP_TIMEOUT, + /** + * EOF reached + */ + EVREQ_HTTP_EOF, + /** + * Error while reading header, or invalid header + */ + EVREQ_HTTP_INVALID_HEADER, + /** + * Error encountered while reading or writing + */ + EVREQ_HTTP_BUFFER_ERROR, + /** + * The evhttp_cancel_request() called on this request. + */ + EVREQ_HTTP_REQUEST_CANCEL, + /** + * Body is greater then evhttp_connection_set_max_body_size() + */ + EVREQ_HTTP_DATA_TOO_LONG +}; +/** + * Set a callback for errors + * @see evhttp_request_error for error types. + * + * On error, both the error callback and the regular callback will be called, + * error callback is called before the regular callback. + **/ +EVENT2_EXPORT_SYMBOL +void evhttp_request_set_error_cb(struct evhttp_request *, + void (*)(enum evhttp_request_error, void *)); + +/** + * Set a callback to be called on request completion of evhttp_send_* function. + * + * The callback function will be called on the completion of the request after + * the output data has been written and before the evhttp_request object + * is destroyed. This can be useful for tracking resources associated with a + * request (ex: timing metrics). + * + * @param req a request object + * @param cb callback function that will be called on request completion + * @param cb_arg an additional context argument for the callback + */ +EVENT2_EXPORT_SYMBOL +void evhttp_request_set_on_complete_cb(struct evhttp_request *req, + void (*cb)(struct evhttp_request *, void *), void *cb_arg); + +/** Frees the request object and removes associated events. */ +EVENT2_EXPORT_SYMBOL +void evhttp_request_free(struct evhttp_request *req); + +/** + * Create and return a connection object that can be used to for making HTTP + * requests. The connection object tries to resolve address and establish the + * connection when it is given an http request object. + * + * @param base the event_base to use for handling the connection + * @param dnsbase the dns_base to use for resolving host names; if not + * specified host name resolution will block. + * @param address the address to which to connect + * @param port the port to connect to + * @return an evhttp_connection object that can be used for making requests or + * NULL on error + */ +EVENT2_EXPORT_SYMBOL +struct evhttp_connection *evhttp_connection_base_new( + struct event_base *base, struct evdns_base *dnsbase, + const char *address, ev_uint16_t port); + +/** + * Set family hint for DNS requests. + */ +EVENT2_EXPORT_SYMBOL +void evhttp_connection_set_family(struct evhttp_connection *evcon, + int family); + +/* reuse connection address on retry */ +#define EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008 +/* Try to read error, since server may already send and close + * connection, but if at that time we have some data to send then we + * can send get EPIPE and fail, while we can read that HTTP error. */ +#define EVHTTP_CON_READ_ON_WRITE_ERROR 0x0010 +/* @see EVHTTP_SERVER_LINGERING_CLOSE */ +#define EVHTTP_CON_LINGERING_CLOSE 0x0020 +/* Padding for public flags, @see EVHTTP_CON_* in http-internal.h */ +#define EVHTTP_CON_PUBLIC_FLAGS_END 0x100000 +/** + * Set connection flags. + * + * @see EVHTTP_CON_* + * @return 0 on success, otherwise non zero (for example if flag doesn't + * supported). + */ +EVENT2_EXPORT_SYMBOL +int evhttp_connection_set_flags(struct evhttp_connection *evcon, + int flags); + /** Takes ownership of the request object * * Can be used in a request callback to keep onto the request until * evhttp_request_free() is explicitly called by the user. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_request_own(struct evhttp_request *req); /** Returns 1 if the request is owned by the user */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_request_is_owned(struct evhttp_request *req); /** @@ -736,89 +736,89 @@ int evhttp_request_is_owned(struct evhttp_request *req); * The user needs to either free the request explicitly or call * evhttp_send_reply_end(). */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_connection *evhttp_request_get_connection(struct evhttp_request *req); /** * Returns the underlying event_base for this connection */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *evhttp_connection_get_base(struct evhttp_connection *req); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon, ev_ssize_t new_max_headers_size); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, ev_ssize_t new_max_body_size); /** Frees an http connection */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_free(struct evhttp_connection *evcon); -/** Disowns a given connection object - * - * Can be used to tell libevent to free the connection object after - * the last request has completed or failed. - */ -EVENT2_EXPORT_SYMBOL -void evhttp_connection_free_on_completion(struct evhttp_connection *evcon); - +/** Disowns a given connection object + * + * Can be used to tell libevent to free the connection object after + * the last request has completed or failed. + */ +EVENT2_EXPORT_SYMBOL +void evhttp_connection_free_on_completion(struct evhttp_connection *evcon); + /** sets the ip address from which http connections are made */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_local_address(struct evhttp_connection *evcon, const char *address); /** sets the local port from which http connections are made */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_local_port(struct evhttp_connection *evcon, ev_uint16_t port); -/** Sets the timeout in seconds for events related to this connection */ -EVENT2_EXPORT_SYMBOL +/** Sets the timeout in seconds for events related to this connection */ +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout(struct evhttp_connection *evcon, int timeout_in_secs); -/** Sets the timeout for events related to this connection. Takes a struct - * timeval. */ -EVENT2_EXPORT_SYMBOL -void evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, - const struct timeval *tv); - -/** Sets the delay before retrying requests on this connection. This is only - * used if evhttp_connection_set_retries is used to make the number of retries - * at least one. Each retry after the first is twice as long as the one before - * it. */ -EVENT2_EXPORT_SYMBOL -void evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, - const struct timeval *tv); - +/** Sets the timeout for events related to this connection. Takes a struct + * timeval. */ +EVENT2_EXPORT_SYMBOL +void evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, + const struct timeval *tv); + +/** Sets the delay before retrying requests on this connection. This is only + * used if evhttp_connection_set_retries is used to make the number of retries + * at least one. Each retry after the first is twice as long as the one before + * it. */ +EVENT2_EXPORT_SYMBOL +void evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, + const struct timeval *tv); + /** Sets the retry limit for this connection - -1 repeats indefinitely */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_retries(struct evhttp_connection *evcon, int retry_max); /** Set a callback for connection close. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_closecb(struct evhttp_connection *evcon, void (*)(struct evhttp_connection *, void *), void *); /** Get the remote address and port associated with this connection. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_get_peer(struct evhttp_connection *evcon, char **address, ev_uint16_t *port); -/** Get the remote address associated with this connection. - * extracted from getpeername() OR from nameserver. - * - * @return NULL if getpeername() return non success, - * or connection is not connected, - * otherwise it return pointer to struct sockaddr_storage */ -EVENT2_EXPORT_SYMBOL -const struct sockaddr* -evhttp_connection_get_addr(struct evhttp_connection *evcon); - +/** Get the remote address associated with this connection. + * extracted from getpeername() OR from nameserver. + * + * @return NULL if getpeername() return non success, + * or connection is not connected, + * otherwise it return pointer to struct sockaddr_storage */ +EVENT2_EXPORT_SYMBOL +const struct sockaddr* +evhttp_connection_get_addr(struct evhttp_connection *evcon); + /** Make an HTTP request over the specified connection. @@ -832,7 +832,7 @@ evhttp_connection_get_addr(struct evhttp_connection *evcon); @return 0 on success, -1 on failure @see evhttp_cancel_request() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_make_request(struct evhttp_connection *evcon, struct evhttp_request *req, enum evhttp_cmd_type type, const char *uri); @@ -850,7 +850,7 @@ int evhttp_make_request(struct evhttp_connection *evcon, @param req the evhttp_request to cancel; req becomes invalid after this call. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_cancel_request(struct evhttp_request *req); /** @@ -859,37 +859,37 @@ void evhttp_cancel_request(struct evhttp_request *req); struct evhttp_uri; /** Returns the request URI */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_request_get_uri(const struct evhttp_request *req); /** Returns the request URI (parsed) */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const struct evhttp_uri *evhttp_request_get_evhttp_uri(const struct evhttp_request *req); /** Returns the request command */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL enum evhttp_cmd_type evhttp_request_get_command(const struct evhttp_request *req); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_request_get_response_code(const struct evhttp_request *req); -EVENT2_EXPORT_SYMBOL -const char * evhttp_request_get_response_code_line(const struct evhttp_request *req); +EVENT2_EXPORT_SYMBOL +const char * evhttp_request_get_response_code_line(const struct evhttp_request *req); /** Returns the input headers */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req); /** Returns the output headers */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evkeyvalq *evhttp_request_get_output_headers(struct evhttp_request *req); /** Returns the input buffer */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *req); /** Returns the output buffer */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req); /** Returns the host associated with the request. If a client sends an absolute URI, the host part of that is preferred. Otherwise, the input headers are searched for a Host: header. NULL is returned if no absolute URI or Host: header is provided. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_request_get_host(struct evhttp_request *req); /* Interfaces for dealing with HTTP headers */ @@ -900,10 +900,10 @@ const char *evhttp_request_get_host(struct evhttp_request *req); @param headers the evkeyvalq object in which to find the header @param key the name of the header to find @returns a pointer to the value for the header or NULL if the header - could not be found. + could not be found. @see evhttp_add_header(), evhttp_remove_header() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_find_header(const struct evkeyvalq *headers, const char *key); @@ -915,7 +915,7 @@ const char *evhttp_find_header(const struct evkeyvalq *headers, @returns 0 if the header was removed, -1 otherwise. @see evhttp_find_header(), evhttp_add_header() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_remove_header(struct evkeyvalq *headers, const char *key); /** @@ -927,7 +927,7 @@ int evhttp_remove_header(struct evkeyvalq *headers, const char *key); @returns 0 on success, -1 otherwise. @see evhttp_find_header(), evhttp_clear_headers() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value); /** @@ -935,7 +935,7 @@ int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *va @param headers the evkeyvalq object from which to remove all headers */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_clear_headers(struct evkeyvalq *headers); /* Miscellaneous utility functions */ @@ -952,7 +952,7 @@ void evhttp_clear_headers(struct evkeyvalq *headers); @param str an unencoded string @return a newly allocated URI-encoded string or NULL on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evhttp_encode_uri(const char *str); /** @@ -969,24 +969,24 @@ char *evhttp_encode_uri(const char *str); as +, not %20. @return a newly allocate URI-encoded string, or NULL on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evhttp_uriencode(const char *str, ev_ssize_t size, int space_to_plus); /** Helper function to sort of decode a URI-encoded string. Unlike - evhttp_uridecode, it decodes all plus characters that appear + evhttp_uridecode, it decodes all plus characters that appear _after_ the first question mark character, but no plusses that occur before. This is not a good way to decode URIs in whole or in part. The returned string must be freed by the caller @deprecated This function is deprecated; you probably want to use - evhttp_uridecode instead. + evhttp_uridecode instead. @param uri an encoded URI @return a newly allocated unencoded URI or NULL on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evhttp_decode_uri(const char *uri); /** @@ -999,12 +999,12 @@ char *evhttp_decode_uri(const char *uri); The returned string must be freed by the caller. @param uri a URI-encode encoded URI - @param decode_plus determines whether we convert '+' to space. + @param decode_plus determines whether we convert '+' to space. @param size_out if size_out is not NULL, *size_out is set to the size of the returned string @return a newly allocated unencoded URI or NULL on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evhttp_uridecode(const char *uri, int decode_plus, size_t *size_out); @@ -1027,7 +1027,7 @@ char *evhttp_uridecode(const char *uri, int decode_plus, @param headers the head of the evkeyval queue @return 0 on success, -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_parse_query(const char *uri, struct evkeyvalq *headers); /** @@ -1047,7 +1047,7 @@ int evhttp_parse_query(const char *uri, struct evkeyvalq *headers); @param headers the head of the evkeyval queue @return 0 on success, -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str(const char *uri, struct evkeyvalq *headers); /** @@ -1061,31 +1061,31 @@ int evhttp_parse_query_str(const char *uri, struct evkeyvalq *headers); * @param html an unescaped HTML string * @return an escaped HTML string or NULL on error */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evhttp_htmlescape(const char *html); /** * Return a new empty evhttp_uri with no fields set. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_uri *evhttp_uri_new(void); /** * Changes the flags set on a given URI. See EVHTTP_URI_* for * a list of flags. **/ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_uri_set_flags(struct evhttp_uri *uri, unsigned flags); /** Return the scheme of an evhttp_uri, or NULL if there is no scheme has * been set and the evhttp_uri contains a Relative-Ref. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_uri_get_scheme(const struct evhttp_uri *uri); /** * Return the userinfo part of an evhttp_uri, or NULL if it has no userinfo * set. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri); /** * Return the host part of an evhttp_uri, or NULL if it has no host set. @@ -1099,52 +1099,52 @@ const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri); * "mailto:user@example.com" has a host of NULL, but "file:///etc/motd" * has a host of "". */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_uri_get_host(const struct evhttp_uri *uri); /** Return the port part of an evhttp_uri, or -1 if there is no port set. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_get_port(const struct evhttp_uri *uri); /** Return the path part of an evhttp_uri, or NULL if it has no path set */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_uri_get_path(const struct evhttp_uri *uri); /** Return the query part of an evhttp_uri (excluding the leading "?"), or * NULL if it has no query set */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_uri_get_query(const struct evhttp_uri *uri); /** Return the fragment part of an evhttp_uri (excluding the leading "#"), * or NULL if it has no fragment set */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evhttp_uri_get_fragment(const struct evhttp_uri *uri); /** Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL. * Returns 0 on success, -1 if scheme is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme); /** Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL. * Returns 0 on success, -1 if userinfo is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo); /** Set the host of an evhttp_uri, or clear the host if host==NULL. * Returns 0 on success, -1 if host is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host); /** Set the port of an evhttp_uri, or clear the port if port==-1. * Returns 0 on success, -1 if port is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_port(struct evhttp_uri *uri, int port); /** Set the path of an evhttp_uri, or clear the path if path==NULL. * Returns 0 on success, -1 if path is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_path(struct evhttp_uri *uri, const char *path); /** Set the query of an evhttp_uri, or clear the query if query==NULL. * The query should not include a leading "?". * Returns 0 on success, -1 if query is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_query(struct evhttp_uri *uri, const char *query); /** Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL. * The fragment should not include a leading "#". * Returns 0 on success, -1 if fragment is not well-formed. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment); /** @@ -1181,7 +1181,7 @@ int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment); * @return uri container to hold parsed data, or NULL if there is error * @see evhttp_uri_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri, unsigned flags); @@ -1200,7 +1200,7 @@ struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri, #define EVHTTP_URI_NONCONFORMANT 0x01 /** Alias for evhttp_uri_parse_with_flags(source_uri, 0) */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_uri *evhttp_uri_parse(const char *source_uri); /** @@ -1210,7 +1210,7 @@ struct evhttp_uri *evhttp_uri_parse(const char *source_uri); * @param uri container with parsed data * @see evhttp_uri_parse() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_uri_free(struct evhttp_uri *uri); /** @@ -1226,11 +1226,11 @@ void evhttp_uri_free(struct evhttp_uri *uri); * @return an joined uri as string or NULL on error * @see evhttp_uri_parse() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL char *evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit); #ifdef __cplusplus } #endif -#endif /* EVENT2_HTTP_H_INCLUDED_ */ +#endif /* EVENT2_HTTP_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/http_compat.h b/contrib/libs/libevent/include/event2/http_compat.h index 794a581083..7bad9bf22f 100644 --- a/contrib/libs/libevent/include/event2/http_compat.h +++ b/contrib/libs/libevent/include/event2/http_compat.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_HTTP_COMPAT_H_INCLUDED_ -#define EVENT2_HTTP_COMPAT_H_INCLUDED_ +#ifndef EVENT2_HTTP_COMPAT_H_INCLUDED_ +#define EVENT2_HTTP_COMPAT_H_INCLUDED_ /** @file event2/http_compat.h @@ -39,10 +39,10 @@ extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -56,11 +56,11 @@ extern "C" { * * @param address the address to which the HTTP server should be bound * @param port the port number on which the HTTP server should listen - * @return a pointer to a newly initialized evhttp server structure - * or NULL on error + * @return a pointer to a newly initialized evhttp server structure + * or NULL on error */ -EVENT2_EXPORT_SYMBOL -struct evhttp *evhttp_start(const char *address, ev_uint16_t port); +EVENT2_EXPORT_SYMBOL +struct evhttp *evhttp_start(const char *address, ev_uint16_t port); /** * A connection object that can be used to for making HTTP requests. The @@ -69,9 +69,9 @@ struct evhttp *evhttp_start(const char *address, ev_uint16_t port); * * @deprecated It does not allow an event base to be specified */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_connection *evhttp_connection_new( - const char *address, ev_uint16_t port); + const char *address, ev_uint16_t port); /** * Associates an event base with the connection - can only be called @@ -79,7 +79,7 @@ struct evhttp_connection *evhttp_connection_new( * * @deprecated XXXX Why? */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evhttp_connection_set_base(struct evhttp_connection *evcon, struct event_base *base); @@ -91,4 +91,4 @@ void evhttp_connection_set_base(struct evhttp_connection *evcon, } #endif -#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ +#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/http_struct.h b/contrib/libs/libevent/include/event2/http_struct.h index 2691c8c037..55d2335dd2 100644 --- a/contrib/libs/libevent/include/event2/http_struct.h +++ b/contrib/libs/libevent/include/event2/http_struct.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_HTTP_STRUCT_H_INCLUDED_ -#define EVENT2_HTTP_STRUCT_H_INCLUDED_ +#ifndef EVENT2_HTTP_STRUCT_H_INCLUDED_ +#define EVENT2_HTTP_STRUCT_H_INCLUDED_ /** @file event2/http_struct.h @@ -39,10 +39,10 @@ extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -123,33 +123,33 @@ struct { */ void (*chunk_cb)(struct evhttp_request *, void *); void *chunk_cb_arg; - - /* - * Callback added for forked-daapd so they can collect ICY - * (shoutcast) metadata from the http header. If return - * int is negative the connection will be closed. - */ - int (*header_cb)(struct evhttp_request *, void *); - - /* - * Error callback - called when error is occured. - * @see evhttp_request_error for error types. - * - * @see evhttp_request_set_error_cb() - */ - void (*error_cb)(enum evhttp_request_error, void *); - - /* - * Send complete callback - called when the request is actually - * sent and completed. - */ - void (*on_complete_cb)(struct evhttp_request *, void *); - void *on_complete_cb_arg; + + /* + * Callback added for forked-daapd so they can collect ICY + * (shoutcast) metadata from the http header. If return + * int is negative the connection will be closed. + */ + int (*header_cb)(struct evhttp_request *, void *); + + /* + * Error callback - called when error is occured. + * @see evhttp_request_error for error types. + * + * @see evhttp_request_set_error_cb() + */ + void (*error_cb)(enum evhttp_request_error, void *); + + /* + * Send complete callback - called when the request is actually + * sent and completed. + */ + void (*on_complete_cb)(struct evhttp_request *, void *); + void *on_complete_cb_arg; }; #ifdef __cplusplus } #endif -#endif /* EVENT2_HTTP_STRUCT_H_INCLUDED_ */ +#endif /* EVENT2_HTTP_STRUCT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/keyvalq_struct.h b/contrib/libs/libevent/include/event2/keyvalq_struct.h index bffa54b3a7..def0a525fb 100644 --- a/contrib/libs/libevent/include/event2/keyvalq_struct.h +++ b/contrib/libs/libevent/include/event2/keyvalq_struct.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ -#define EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ +#ifndef EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ +#define EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ #ifdef __cplusplus extern "C" { @@ -34,7 +34,7 @@ extern "C" { /* Fix so that people don't have to run with <sys/queue.h> */ /* XXXX This code is duplicated with event_struct.h */ #ifndef TAILQ_ENTRY -#define EVENT_DEFINED_TQENTRY_ +#define EVENT_DEFINED_TQENTRY_ #define TAILQ_ENTRY(type) \ struct { \ struct type *tqe_next; /* next element */ \ @@ -43,7 +43,7 @@ struct { \ #endif /* !TAILQ_ENTRY */ #ifndef TAILQ_HEAD -#define EVENT_DEFINED_TQHEAD_ +#define EVENT_DEFINED_TQHEAD_ #define TAILQ_HEAD(name, type) \ struct name { \ struct type *tqh_first; \ @@ -65,11 +65,11 @@ struct evkeyval { TAILQ_HEAD (evkeyvalq, evkeyval); /* XXXX This code is duplicated with event_struct.h */ -#ifdef EVENT_DEFINED_TQENTRY_ +#ifdef EVENT_DEFINED_TQENTRY_ #undef TAILQ_ENTRY #endif -#ifdef EVENT_DEFINED_TQHEAD_ +#ifdef EVENT_DEFINED_TQHEAD_ #undef TAILQ_HEAD #endif diff --git a/contrib/libs/libevent/include/event2/listener.h b/contrib/libs/libevent/include/event2/listener.h index 789a27c2aa..b82d6d2c29 100644 --- a/contrib/libs/libevent/include/event2/listener.h +++ b/contrib/libs/libevent/include/event2/listener.h @@ -24,11 +24,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_LISTENER_H_INCLUDED_ -#define EVENT2_LISTENER_H_INCLUDED_ - -#include <event2/visibility.h> +#ifndef EVENT2_LISTENER_H_INCLUDED_ +#define EVENT2_LISTENER_H_INCLUDED_ +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif @@ -71,44 +71,44 @@ typedef void (*evconnlistener_errorcb)(struct evconnlistener *, void *); /** Flag: Indicates that the listener should be locked so it's safe to use * from multiple threadcs at once. */ #define LEV_OPT_THREADSAFE (1u<<4) -/** Flag: Indicates that the listener should be created in disabled - * state. Use evconnlistener_enable() to enable it later. */ -#define LEV_OPT_DISABLED (1u<<5) -/** Flag: Indicates that the listener should defer accept() until data is - * available, if possible. Ignored on platforms that do not support this. - * - * This option can help performance for protocols where the client transmits - * immediately after connecting. Do not use this option if your protocol - * _doesn't_ start out with the client transmitting data, since in that case - * this option will sometimes cause the kernel to never tell you about the - * connection. - * - * This option is only supported by evconnlistener_new_bind(): it can't - * work with evconnlistener_new_fd(), since the listener needs to be told - * to use the option before it is actually bound. - */ -#define LEV_OPT_DEFERRED_ACCEPT (1u<<6) -/** Flag: Indicates that we ask to allow multiple servers (processes or - * threads) to bind to the same port if they each set the option. +/** Flag: Indicates that the listener should be created in disabled + * state. Use evconnlistener_enable() to enable it later. */ +#define LEV_OPT_DISABLED (1u<<5) +/** Flag: Indicates that the listener should defer accept() until data is + * available, if possible. Ignored on platforms that do not support this. * - * SO_REUSEPORT is what most people would expect SO_REUSEADDR to be, however - * SO_REUSEPORT does not imply SO_REUSEADDR. - * - * This is only available on Linux and kernel 3.9+ - */ -#define LEV_OPT_REUSEABLE_PORT (1u<<7) -/** Flag: Indicates that the listener wants to work only in IPv6 socket. - * - * According to RFC3493 and most Linux distributions, default value is to - * work in IPv4-mapped mode. If there is a requirement to bind same port - * on same ip addresses but different handlers for both IPv4 and IPv6, - * it is required to set IPV6_V6ONLY socket option to be sure that the - * code works as expected without affected by bindv6only sysctl setting in - * system. - * - * This socket option also supported by Windows. - */ -#define LEV_OPT_BIND_IPV6ONLY (1u<<8) + * This option can help performance for protocols where the client transmits + * immediately after connecting. Do not use this option if your protocol + * _doesn't_ start out with the client transmitting data, since in that case + * this option will sometimes cause the kernel to never tell you about the + * connection. + * + * This option is only supported by evconnlistener_new_bind(): it can't + * work with evconnlistener_new_fd(), since the listener needs to be told + * to use the option before it is actually bound. + */ +#define LEV_OPT_DEFERRED_ACCEPT (1u<<6) +/** Flag: Indicates that we ask to allow multiple servers (processes or + * threads) to bind to the same port if they each set the option. + * + * SO_REUSEPORT is what most people would expect SO_REUSEADDR to be, however + * SO_REUSEPORT does not imply SO_REUSEADDR. + * + * This is only available on Linux and kernel 3.9+ + */ +#define LEV_OPT_REUSEABLE_PORT (1u<<7) +/** Flag: Indicates that the listener wants to work only in IPv6 socket. + * + * According to RFC3493 and most Linux distributions, default value is to + * work in IPv4-mapped mode. If there is a requirement to bind same port + * on same ip addresses but different handlers for both IPv4 and IPv6, + * it is required to set IPV6_V6ONLY socket option to be sure that the + * code works as expected without affected by bindv6only sysctl setting in + * system. + * + * This socket option also supported by Windows. + */ +#define LEV_OPT_BIND_IPV6ONLY (1u<<8) /** Allocate a new evconnlistener object to listen for incoming TCP connections @@ -127,7 +127,7 @@ typedef void (*evconnlistener_errorcb)(struct evconnlistener *, void *); file descriptor, and it should already be bound to an appropriate port and address. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evconnlistener *evconnlistener_new(struct event_base *base, evconnlistener_cb cb, void *ptr, unsigned flags, int backlog, evutil_socket_t fd); @@ -146,42 +146,42 @@ struct evconnlistener *evconnlistener_new(struct event_base *base, @param addr The address to listen for connections on. @param socklen The length of the address. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evconnlistener *evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb, void *ptr, unsigned flags, int backlog, const struct sockaddr *sa, int socklen); /** Disable and deallocate an evconnlistener. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evconnlistener_free(struct evconnlistener *lev); /** Re-enable an evconnlistener that has been disabled. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evconnlistener_enable(struct evconnlistener *lev); /** Stop listening for connections on an evconnlistener. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evconnlistener_disable(struct evconnlistener *lev); /** Return an evconnlistener's associated event_base. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct event_base *evconnlistener_get_base(struct evconnlistener *lev); /** Return the socket that an evconnlistner is listening on. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL evutil_socket_t evconnlistener_get_fd(struct evconnlistener *lev); /** Change the callback on the listener to cb and its user_data to arg. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evconnlistener_set_cb(struct evconnlistener *lev, evconnlistener_cb cb, void *arg); /** Set an evconnlistener's error callback. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evconnlistener_set_error_cb(struct evconnlistener *lev, evconnlistener_errorcb errorcb); diff --git a/contrib/libs/libevent/include/event2/rpc.h b/contrib/libs/libevent/include/event2/rpc.h index 1bc31d5711..d59ca3dfe6 100644 --- a/contrib/libs/libevent/include/event2/rpc.h +++ b/contrib/libs/libevent/include/event2/rpc.h @@ -24,13 +24,13 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_RPC_H_INCLUDED_ -#define EVENT2_RPC_H_INCLUDED_ - -/* For int types. */ -#include <event2/util.h> -#include <event2/visibility.h> +#ifndef EVENT2_RPC_H_INCLUDED_ +#define EVENT2_RPC_H_INCLUDED_ +/* For int types. */ +#include <event2/util.h> +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif @@ -80,7 +80,7 @@ extern "C" { #define EVTAG_HAS(msg, member) \ ((msg)->member##_set == 1) -#ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ +#ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ /** Assigns a value to the member in the message. @@ -123,7 +123,7 @@ extern "C" { #define EVTAG_GET_WITH_LEN(msg, member, pvalue, plen) \ (*(msg)->base->member##_get)((msg), (pvalue), (plen)) -#endif /* EVENT2_RPC_COMPAT_H_INCLUDED_ */ +#endif /* EVENT2_RPC_COMPAT_H_INCLUDED_ */ /** Adds a value to an array. @@ -182,7 +182,7 @@ EVRPC_STRUCT(rpcname) { \ struct evhttp_request* http_req; \ struct evbuffer* rpc_data; \ }; \ -EVENT2_EXPORT_SYMBOL \ +EVENT2_EXPORT_SYMBOL \ int evrpc_send_request_##rpcname(struct evrpc_pool *, \ struct reqstruct *, struct rplystruct *, \ void (*)(struct evrpc_status *, \ @@ -192,7 +192,7 @@ int evrpc_send_request_##rpcname(struct evrpc_pool *, \ struct evrpc_pool; /** use EVRPC_GENERATE instead */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evrpc_request_wrapper *evrpc_make_request_ctx( struct evrpc_pool *pool, void *request, void *reply, const char *rpcname, @@ -263,13 +263,13 @@ struct evrpc_request_wrapper *evrpc_make_request_ctx( #define EVRPC_REQUEST_HTTP(rpc_req) (rpc_req)->http_req /** completes the server response to an rpc request */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_request_done(struct evrpc_req_generic *req); /** accessors for request and reply */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void *evrpc_get_request(struct evrpc_req_generic *req); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void *evrpc_get_reply(struct evrpc_req_generic *req); /** Creates the reply to an RPC request @@ -281,8 +281,8 @@ void *evrpc_get_reply(struct evrpc_req_generic *req); * @param rpc_req the rpc request structure provided to the server callback */ #define EVRPC_REQUEST_DONE(rpc_req) do { \ - struct evrpc_req_generic *req_ = (struct evrpc_req_generic *)(rpc_req); \ - evrpc_request_done(req_); \ + struct evrpc_req_generic *req_ = (struct evrpc_req_generic *)(rpc_req); \ + evrpc_request_done(req_); \ } while (0) @@ -294,10 +294,10 @@ struct evhttp; /** Creates a new rpc base from which RPC requests can be received * * @param server a pointer to an existing HTTP server - * @return a newly allocated evrpc_base struct or NULL if an error occurred + * @return a newly allocated evrpc_base struct or NULL if an error occurred * @see evrpc_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evrpc_base *evrpc_init(struct evhttp *server); /** @@ -308,7 +308,7 @@ struct evrpc_base *evrpc_init(struct evhttp *server); * @param base the evrpc_base object to be freed * @see evrpc_init */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_free(struct evrpc_base *base); /** register RPCs with the HTTP Server @@ -330,10 +330,10 @@ void evrpc_free(struct evrpc_base *base); #define EVRPC_REGISTER(base, name, request, reply, callback, cbarg) \ evrpc_register_generic(base, #name, \ (void (*)(struct evrpc_req_generic *, void *))callback, cbarg, \ - (void *(*)(void *))request##_new_with_arg, NULL, \ + (void *(*)(void *))request##_new_with_arg, NULL, \ (void (*)(void *))request##_free, \ (int (*)(void *, struct evbuffer *))request##_unmarshal, \ - (void *(*)(void *))reply##_new_with_arg, NULL, \ + (void *(*)(void *))reply##_new_with_arg, NULL, \ (void (*)(void *))reply##_free, \ (int (*)(void *))reply##_complete, \ (void (*)(struct evbuffer *, void *))reply##_marshal) @@ -345,7 +345,7 @@ void evrpc_free(struct evrpc_base *base); @see EVRPC_REGISTER() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evrpc_register_rpc(struct evrpc_base *, struct evrpc *, void (*)(struct evrpc_req_generic*, void *), void *); @@ -359,7 +359,7 @@ int evrpc_register_rpc(struct evrpc_base *, struct evrpc *, */ #define EVRPC_UNREGISTER(base, name) evrpc_unregister_rpc((base), #name) -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evrpc_unregister_rpc(struct evrpc_base *base, const char *name); /* @@ -398,7 +398,7 @@ struct evrpc_status; @returns 0 on success, -1 otherwise. @see EVRPC_MAKE_REQUEST(), EVRPC_MAKE_CTX() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evrpc_make_request(struct evrpc_request_wrapper *ctx); /** creates an rpc connection pool @@ -408,18 +408,18 @@ int evrpc_make_request(struct evrpc_request_wrapper *ctx); * * @param base a pointer to an struct event_based object; can be left NULL * in singled-threaded applications - * @return a newly allocated struct evrpc_pool object or NULL if an error - * occurred + * @return a newly allocated struct evrpc_pool object or NULL if an error + * occurred * @see evrpc_pool_free() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evrpc_pool *evrpc_pool_new(struct event_base *base); /** frees an rpc connection pool * * @param pool a pointer to an evrpc_pool allocated via evrpc_pool_new() * @see evrpc_pool_new() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_pool_free(struct evrpc_pool *pool); /** @@ -430,7 +430,7 @@ void evrpc_pool_free(struct evrpc_pool *pool); * @param pool the pool to which to add the connection * @param evcon the connection to add to the pool. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_pool_add_connection(struct evrpc_pool *pool, struct evhttp_connection *evcon); @@ -442,7 +442,7 @@ void evrpc_pool_add_connection(struct evrpc_pool *pool, * @param pool the pool from which to remove the connection * @param evcon the connection to remove from the pool. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_pool_remove_connection(struct evrpc_pool *pool, struct evhttp_connection *evcon); @@ -461,7 +461,7 @@ void evrpc_pool_remove_connection(struct evrpc_pool *pool, * @param timeout_in_secs the number of seconds after which a request should * timeout and a failure be returned to the callback. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_pool_set_timeout(struct evrpc_pool *pool, int timeout_in_secs); /** @@ -474,7 +474,7 @@ enum EVRPC_HOOK_TYPE { EVRPC_OUTPUT /**< apply the function to an output hook */ }; -#ifndef _WIN32 +#ifndef _WIN32 /** Deprecated alias for EVRPC_INPUT. Not available on windows, where it * conflicts with platform headers. */ #define INPUT EVRPC_INPUT @@ -509,7 +509,7 @@ enum EVRPC_HOOK_RESULT { * @return a handle to the hook so it can be removed later * @see evrpc_remove_hook() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void *evrpc_add_hook(void *vbase, enum EVRPC_HOOK_TYPE hook_type, int (*cb)(void *, struct evhttp_request *, struct evbuffer *, void *), @@ -523,7 +523,7 @@ void *evrpc_add_hook(void *vbase, * @return 1 on success or 0 on failure * @see evrpc_add_hook() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evrpc_remove_hook(void *vbase, enum EVRPC_HOOK_TYPE hook_type, void *handle); @@ -533,8 +533,8 @@ int evrpc_remove_hook(void *vbase, * @param vbase a pointer to either struct evrpc_base or struct evrpc_pool * @param ctx the context pointer provided to the original hook call */ -EVENT2_EXPORT_SYMBOL -int evrpc_resume_request(void *vbase, void *ctx, enum EVRPC_HOOK_RESULT res); +EVENT2_EXPORT_SYMBOL +int evrpc_resume_request(void *vbase, void *ctx, enum EVRPC_HOOK_RESULT res); /** adds meta data to request * @@ -547,7 +547,7 @@ int evrpc_resume_request(void *vbase, void *ctx, enum EVRPC_HOOK_RESULT res); * @param data the data to be associated with the key * @param data_size the size of the data */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_hook_add_meta(void *ctx, const char *key, const void *data, size_t data_size); @@ -561,7 +561,7 @@ void evrpc_hook_add_meta(void *ctx, const char *key, * @param data_size pointer to the size of the data * @return 0 on success or -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evrpc_hook_find_meta(void *ctx, const char *key, void **data, size_t *data_size); @@ -569,10 +569,10 @@ int evrpc_hook_find_meta(void *ctx, const char *key, * returns the connection object associated with the request * * @param ctx the context provided to the hook call - * @return a pointer to the evhttp_connection object or NULL if an error - * occurred + * @return a pointer to the evhttp_connection object or NULL if an error + * occurred */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evhttp_connection *evrpc_hook_get_connection(void *ctx); /** @@ -582,7 +582,7 @@ struct evhttp_connection *evrpc_hook_get_connection(void *ctx); @see EVRPC_MAKE_REQUEST() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evrpc_send_request_generic(struct evrpc_pool *pool, void *request, void *reply, void (*cb)(struct evrpc_status *, void *, void *, void *), @@ -599,8 +599,8 @@ int evrpc_send_request_generic(struct evrpc_pool *pool, @see EVRPC_REGISTER() */ -EVENT2_EXPORT_SYMBOL -int evrpc_register_generic(struct evrpc_base *base, const char *name, +EVENT2_EXPORT_SYMBOL +int evrpc_register_generic(struct evrpc_base *base, const char *name, void (*callback)(struct evrpc_req_generic *, void *), void *cbarg, void *(*req_new)(void *), void *req_new_arg, void (*req_free)(void *), int (*req_unmarshal)(void *, struct evbuffer *), @@ -609,12 +609,12 @@ int evrpc_register_generic(struct evrpc_base *base, const char *name, void (*rpl_marshal)(struct evbuffer *, void *)); /** accessors for obscure and undocumented functionality */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL struct evrpc_pool* evrpc_request_get_pool(struct evrpc_request_wrapper *ctx); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_request_set_pool(struct evrpc_request_wrapper *ctx, struct evrpc_pool *pool); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evrpc_request_set_cb(struct evrpc_request_wrapper *ctx, void (*cb)(struct evrpc_status*, void *request, void *reply, void *arg), void *cb_arg); @@ -623,4 +623,4 @@ void evrpc_request_set_cb(struct evrpc_request_wrapper *ctx, } #endif -#endif /* EVENT2_RPC_H_INCLUDED_ */ +#endif /* EVENT2_RPC_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/rpc_compat.h b/contrib/libs/libevent/include/event2/rpc_compat.h index 8d8334d25f..74634a0d7f 100644 --- a/contrib/libs/libevent/include/event2/rpc_compat.h +++ b/contrib/libs/libevent/include/event2/rpc_compat.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ -#define EVENT2_RPC_COMPAT_H_INCLUDED_ +#ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ +#define EVENT2_RPC_COMPAT_H_INCLUDED_ /** @file event2/rpc_compat.h @@ -58,4 +58,4 @@ extern "C" { } #endif -#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ +#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/rpc_struct.h b/contrib/libs/libevent/include/event2/rpc_struct.h index f3cb460aed..b60eff2425 100644 --- a/contrib/libs/libevent/include/event2/rpc_struct.h +++ b/contrib/libs/libevent/include/event2/rpc_struct.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_RPC_STRUCT_H_INCLUDED_ -#define EVENT2_RPC_STRUCT_H_INCLUDED_ +#ifndef EVENT2_RPC_STRUCT_H_INCLUDED_ +#define EVENT2_RPC_STRUCT_H_INCLUDED_ #ifdef __cplusplus extern "C" { @@ -38,16 +38,16 @@ extern "C" { */ -/* Fix so that people don't have to run with <sys/queue.h> */ -#ifndef TAILQ_ENTRY -#define EVENT_DEFINED_TQENTRY_ -#define TAILQ_ENTRY(type) \ -struct { \ - struct type *tqe_next; /* next element */ \ - struct type **tqe_prev; /* address of previous next element */ \ -} -#endif /* !TAILQ_ENTRY */ - +/* Fix so that people don't have to run with <sys/queue.h> */ +#ifndef TAILQ_ENTRY +#define EVENT_DEFINED_TQENTRY_ +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} +#endif /* !TAILQ_ENTRY */ + /** * provides information about the completed RPC request. */ @@ -103,12 +103,12 @@ struct evrpc { struct evrpc_base *base; }; -#ifdef EVENT_DEFINED_TQENTRY_ -#undef TAILQ_ENTRY -#endif - +#ifdef EVENT_DEFINED_TQENTRY_ +#undef TAILQ_ENTRY +#endif + #ifdef __cplusplus } #endif -#endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */ +#endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/tag.h b/contrib/libs/libevent/include/event2/tag.h index 2f73bfc00e..19fc6d56a1 100644 --- a/contrib/libs/libevent/include/event2/tag.h +++ b/contrib/libs/libevent/include/event2/tag.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_TAG_H_INCLUDED_ -#define EVENT2_TAG_H_INCLUDED_ +#ifndef EVENT2_TAG_H_INCLUDED_ +#define EVENT2_TAG_H_INCLUDED_ /** @file event2/tag.h @@ -33,17 +33,17 @@ */ -#include <event2/visibility.h> - +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif @@ -58,7 +58,7 @@ struct evbuffer; * known ones - and we can just ignore the end of an event buffer. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_init(void); /** @@ -68,13 +68,13 @@ void evtag_init(void); @param ptag a pointer in which the tag id is being stored @returns -1 on failure or the number of bytes in the remaining payload. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal_header(struct evbuffer *evbuf, ev_uint32_t *ptag); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_marshal(struct evbuffer *evbuf, ev_uint32_t tag, const void *data, ev_uint32_t len); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag, struct evbuffer *data); @@ -88,54 +88,54 @@ void evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag, @param evbuf evbuffer to store the encoded number @param number a 32-bit integer */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_marshal_int(struct evbuffer *evbuf, ev_uint32_t tag, ev_uint32_t integer); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_marshal_int64(struct evbuffer *evbuf, ev_uint32_t tag, ev_uint64_t integer); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_marshal_string(struct evbuffer *buf, ev_uint32_t tag, const char *string); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evtag_marshal_timeval(struct evbuffer *evbuf, ev_uint32_t tag, struct timeval *tv); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal(struct evbuffer *src, ev_uint32_t *ptag, struct evbuffer *dst); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_peek(struct evbuffer *evbuf, ev_uint32_t *ptag); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_peek_length(struct evbuffer *evbuf, ev_uint32_t *plength); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_payload_length(struct evbuffer *evbuf, ev_uint32_t *plength); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_consume(struct evbuffer *evbuf); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal_int(struct evbuffer *evbuf, ev_uint32_t need_tag, ev_uint32_t *pinteger); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal_int64(struct evbuffer *evbuf, ev_uint32_t need_tag, ev_uint64_t *pinteger); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal_fixed(struct evbuffer *src, ev_uint32_t need_tag, void *data, size_t len); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal_string(struct evbuffer *evbuf, ev_uint32_t need_tag, char **pstring); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evtag_unmarshal_timeval(struct evbuffer *evbuf, ev_uint32_t need_tag, struct timeval *ptv); @@ -143,4 +143,4 @@ int evtag_unmarshal_timeval(struct evbuffer *evbuf, ev_uint32_t need_tag, } #endif -#endif /* EVENT2_TAG_H_INCLUDED_ */ +#endif /* EVENT2_TAG_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/tag_compat.h b/contrib/libs/libevent/include/event2/tag_compat.h index a276c0d35b..8087a2ac45 100644 --- a/contrib/libs/libevent/include/event2/tag_compat.h +++ b/contrib/libs/libevent/include/event2/tag_compat.h @@ -24,8 +24,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_TAG_COMPAT_H_INCLUDED_ -#define EVENT2_TAG_COMPAT_H_INCLUDED_ +#ifndef EVENT2_TAG_COMPAT_H_INCLUDED_ +#define EVENT2_TAG_COMPAT_H_INCLUDED_ /** @file event2/tag_compat.h @@ -46,4 +46,4 @@ #define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number)) /**@}*/ -#endif /* EVENT2_TAG_H_INCLUDED_ */ +#endif /* EVENT2_TAG_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/thread.h b/contrib/libs/libevent/include/event2/thread.h index b51998631b..2a1f4c7b95 100644 --- a/contrib/libs/libevent/include/event2/thread.h +++ b/contrib/libs/libevent/include/event2/thread.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_THREAD_H_INCLUDED_ -#define EVENT2_THREAD_H_INCLUDED_ +#ifndef EVENT2_THREAD_H_INCLUDED_ +#define EVENT2_THREAD_H_INCLUDED_ /** @file event2/thread.h @@ -46,8 +46,8 @@ */ -#include <event2/visibility.h> - +#include <event2/visibility.h> + #ifdef __cplusplus extern "C" { #endif @@ -71,7 +71,7 @@ extern "C" { #define EVTHREAD_TRY 0x10 /**@}*/ -#if !defined(EVENT__DISABLE_THREAD_SUPPORT) || defined(EVENT_IN_DOXYGEN_) +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) || defined(EVENT_IN_DOXYGEN_) #define EVTHREAD_LOCK_API_VERSION 1 @@ -126,7 +126,7 @@ struct evthread_lock_callbacks { * probably shouldn't call this function; instead, use * evthread_use_windows_threads() or evthread_use_posix_threads() if you can. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evthread_set_lock_callbacks(const struct evthread_lock_callbacks *); #define EVTHREAD_CONDITION_API_VERSION 1 @@ -177,7 +177,7 @@ struct evthread_condition_callbacks { * probably shouldn't call this function; instead, use * evthread_use_windows_threads() or evthread_use_pthreads() if you can. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evthread_set_condition_callbacks( const struct evthread_condition_callbacks *); @@ -188,16 +188,16 @@ int evthread_set_condition_callbacks( @param id_fn the identify function Libevent should invoke to determine the identity of a thread. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evthread_set_id_callback( unsigned long (*id_fn)(void)); -#if (defined(_WIN32) && !defined(EVENT__DISABLE_THREAD_SUPPORT)) || defined(EVENT_IN_DOXYGEN_) +#if (defined(_WIN32) && !defined(EVENT__DISABLE_THREAD_SUPPORT)) || defined(EVENT_IN_DOXYGEN_) /** Sets up Libevent for use with Windows builtin locking and thread ID functions. Unavailable if Libevent is not built for Windows. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evthread_use_windows_threads(void); /** Defined if Libevent was built with support for evthread_use_windows_threads() @@ -205,13 +205,13 @@ int evthread_use_windows_threads(void); #define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1 #endif -#if defined(EVENT__HAVE_PTHREADS) || defined(EVENT_IN_DOXYGEN_) +#if defined(EVENT__HAVE_PTHREADS) || defined(EVENT_IN_DOXYGEN_) /** Sets up Libevent for use with Pthreads locking and thread ID functions. Unavailable if Libevent is not build for use with pthreads. Requires libraries to link against Libevent_pthreads as well as Libevent. @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evthread_use_pthreads(void); /** Defined if Libevent was built with support for evthread_use_pthreads() */ #define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1 @@ -224,30 +224,30 @@ int evthread_use_pthreads(void); * If you're going to call this function, you must do so before any locks are * allocated. **/ -EVENT2_EXPORT_SYMBOL -void evthread_enable_lock_debugging(void); - -/* Old (misspelled) version: This is deprecated; use - * evthread_enable_log_debugging instead. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL +void evthread_enable_lock_debugging(void); + +/* Old (misspelled) version: This is deprecated; use + * evthread_enable_log_debugging instead. */ +EVENT2_EXPORT_SYMBOL void evthread_enable_lock_debuging(void); -#endif /* EVENT__DISABLE_THREAD_SUPPORT */ +#endif /* EVENT__DISABLE_THREAD_SUPPORT */ struct event_base; /** Make sure it's safe to tell an event base to wake up from another thread or a signal handler. - You shouldn't need to call this by hand; configuring the base with thread - support should be necessary and sufficient. - + You shouldn't need to call this by hand; configuring the base with thread + support should be necessary and sufficient. + @return 0 on success, -1 on failure. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evthread_make_base_notifiable(struct event_base *base); #ifdef __cplusplus } #endif -#endif /* EVENT2_THREAD_H_INCLUDED_ */ +#endif /* EVENT2_THREAD_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/util.h b/contrib/libs/libevent/include/event2/util.h index 02aa7ba9da..f54f93ef4f 100644 --- a/contrib/libs/libevent/include/event2/util.h +++ b/contrib/libs/libevent/include/event2/util.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef EVENT2_UTIL_H_INCLUDED_ -#define EVENT2_UTIL_H_INCLUDED_ +#ifndef EVENT2_UTIL_H_INCLUDED_ +#define EVENT2_UTIL_H_INCLUDED_ /** @file event2/util.h @@ -32,53 +32,53 @@ related socket manipulations. */ -#include <event2/visibility.h> +#include <event2/visibility.h> #ifdef __cplusplus extern "C" { #endif #include <event2/event-config.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif -#ifdef EVENT__HAVE_STDINT_H +#ifdef EVENT__HAVE_STDINT_H #include <stdint.h> -#elif defined(EVENT__HAVE_INTTYPES_H) +#elif defined(EVENT__HAVE_INTTYPES_H) #include <inttypes.h> #endif -#ifdef EVENT__HAVE_SYS_TYPES_H +#ifdef EVENT__HAVE_SYS_TYPES_H #include <sys/types.h> #endif -#ifdef EVENT__HAVE_STDDEF_H +#ifdef EVENT__HAVE_STDDEF_H #include <stddef.h> #endif #ifdef _MSC_VER #include <BaseTsd.h> #endif #include <stdarg.h> -#ifdef EVENT__HAVE_NETDB_H +#ifdef EVENT__HAVE_NETDB_H #include <netdb.h> #endif -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> -#ifdef EVENT__HAVE_GETADDRINFO -/* for EAI_* definitions. */ -#include <ws2tcpip.h> -#endif -#else -#ifdef EVENT__HAVE_ERRNO_H -#include <errno.h> -#endif +#ifdef EVENT__HAVE_GETADDRINFO +/* for EAI_* definitions. */ +#include <ws2tcpip.h> +#endif +#else +#ifdef EVENT__HAVE_ERRNO_H +#include <errno.h> +#endif #include <sys/socket.h> #endif -#include <time.h> - +#include <time.h> + /* Some openbsd autoconf versions get the name of this macro wrong. */ -#if defined(EVENT__SIZEOF_VOID__) && !defined(EVENT__SIZEOF_VOID_P) -#define EVENT__SIZEOF_VOID_P EVENT__SIZEOF_VOID__ +#if defined(EVENT__SIZEOF_VOID__) && !defined(EVENT__SIZEOF_VOID_P) +#define EVENT__SIZEOF_VOID_P EVENT__SIZEOF_VOID__ #endif /** @@ -110,67 +110,67 @@ extern "C" { * * @{ */ -#ifdef EVENT__HAVE_UINT64_T +#ifdef EVENT__HAVE_UINT64_T #define ev_uint64_t uint64_t #define ev_int64_t int64_t -#elif defined(_WIN32) +#elif defined(_WIN32) #define ev_uint64_t unsigned __int64 #define ev_int64_t signed __int64 -#elif EVENT__SIZEOF_LONG_LONG == 8 +#elif EVENT__SIZEOF_LONG_LONG == 8 #define ev_uint64_t unsigned long long #define ev_int64_t long long -#elif EVENT__SIZEOF_LONG == 8 +#elif EVENT__SIZEOF_LONG == 8 #define ev_uint64_t unsigned long #define ev_int64_t long -#elif defined(EVENT_IN_DOXYGEN_) +#elif defined(EVENT_IN_DOXYGEN_) #define ev_uint64_t ... #define ev_int64_t ... #else #error "No way to define ev_uint64_t" #endif -#ifdef EVENT__HAVE_UINT32_T +#ifdef EVENT__HAVE_UINT32_T #define ev_uint32_t uint32_t #define ev_int32_t int32_t -#elif defined(_WIN32) +#elif defined(_WIN32) #define ev_uint32_t unsigned int #define ev_int32_t signed int -#elif EVENT__SIZEOF_LONG == 4 +#elif EVENT__SIZEOF_LONG == 4 #define ev_uint32_t unsigned long #define ev_int32_t signed long -#elif EVENT__SIZEOF_INT == 4 +#elif EVENT__SIZEOF_INT == 4 #define ev_uint32_t unsigned int #define ev_int32_t signed int -#elif defined(EVENT_IN_DOXYGEN_) +#elif defined(EVENT_IN_DOXYGEN_) #define ev_uint32_t ... #define ev_int32_t ... #else #error "No way to define ev_uint32_t" #endif -#ifdef EVENT__HAVE_UINT16_T +#ifdef EVENT__HAVE_UINT16_T #define ev_uint16_t uint16_t #define ev_int16_t int16_t -#elif defined(_WIN32) +#elif defined(_WIN32) #define ev_uint16_t unsigned short #define ev_int16_t signed short -#elif EVENT__SIZEOF_INT == 2 +#elif EVENT__SIZEOF_INT == 2 #define ev_uint16_t unsigned int #define ev_int16_t signed int -#elif EVENT__SIZEOF_SHORT == 2 +#elif EVENT__SIZEOF_SHORT == 2 #define ev_uint16_t unsigned short #define ev_int16_t signed short -#elif defined(EVENT_IN_DOXYGEN_) +#elif defined(EVENT_IN_DOXYGEN_) #define ev_uint16_t ... #define ev_int16_t ... #else #error "No way to define ev_uint16_t" #endif -#ifdef EVENT__HAVE_UINT8_T +#ifdef EVENT__HAVE_UINT8_T #define ev_uint8_t uint8_t #define ev_int8_t int8_t -#elif defined(EVENT_IN_DOXYGEN_) +#elif defined(EVENT_IN_DOXYGEN_) #define ev_uint8_t ... #define ev_int8_t ... #else @@ -178,43 +178,43 @@ extern "C" { #define ev_int8_t signed char #endif -#ifdef EVENT__HAVE_UINTPTR_T +#ifdef EVENT__HAVE_UINTPTR_T #define ev_uintptr_t uintptr_t #define ev_intptr_t intptr_t -#elif EVENT__SIZEOF_VOID_P <= 4 +#elif EVENT__SIZEOF_VOID_P <= 4 #define ev_uintptr_t ev_uint32_t #define ev_intptr_t ev_int32_t -#elif EVENT__SIZEOF_VOID_P <= 8 +#elif EVENT__SIZEOF_VOID_P <= 8 #define ev_uintptr_t ev_uint64_t #define ev_intptr_t ev_int64_t -#elif defined(EVENT_IN_DOXYGEN_) +#elif defined(EVENT_IN_DOXYGEN_) #define ev_uintptr_t ... #define ev_intptr_t ... #else #error "No way to define ev_uintptr_t" #endif -#ifdef EVENT__ssize_t -#define ev_ssize_t EVENT__ssize_t +#ifdef EVENT__ssize_t +#define ev_ssize_t EVENT__ssize_t #else #define ev_ssize_t ssize_t #endif -/* Note that we define ev_off_t based on the compile-time size of off_t that - * we used to build Libevent, and not based on the current size of off_t. - * (For example, we don't define ev_off_t to off_t.). We do this because - * some systems let you build your software with different off_t sizes - * at runtime, and so putting in any dependency on off_t would risk API - * mismatch. - */ -#ifdef _WIN32 +/* Note that we define ev_off_t based on the compile-time size of off_t that + * we used to build Libevent, and not based on the current size of off_t. + * (For example, we don't define ev_off_t to off_t.). We do this because + * some systems let you build your software with different off_t sizes + * at runtime, and so putting in any dependency on off_t would risk API + * mismatch. + */ +#ifdef _WIN32 #define ev_off_t ev_int64_t -#elif EVENT__SIZEOF_OFF_T == 8 -#define ev_off_t ev_int64_t -#elif EVENT__SIZEOF_OFF_T == 4 -#define ev_off_t ev_int32_t -#elif defined(EVENT_IN_DOXYGEN_) -#define ev_off_t ... +#elif EVENT__SIZEOF_OFF_T == 8 +#define ev_off_t ev_int64_t +#elif EVENT__SIZEOF_OFF_T == 4 +#define ev_off_t ev_int32_t +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_off_t ... #else #define ev_off_t off_t #endif @@ -235,7 +235,7 @@ extern "C" { @{ */ -#ifndef EVENT__HAVE_STDINT_H +#ifndef EVENT__HAVE_STDINT_H #define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) | 0xffffffffUL) #define EV_INT64_MAX ((((ev_int64_t) 0x7fffffffL) << 32) | 0xffffffffL) #define EV_INT64_MIN ((-EV_INT64_MAX) - 1) @@ -248,35 +248,35 @@ extern "C" { #define EV_UINT8_MAX 255 #define EV_INT8_MAX 127 #define EV_INT8_MIN ((-EV_INT8_MAX) - 1) -#else -#define EV_UINT64_MAX UINT64_MAX -#define EV_INT64_MAX INT64_MAX -#define EV_INT64_MIN INT64_MIN -#define EV_UINT32_MAX UINT32_MAX -#define EV_INT32_MAX INT32_MAX -#define EV_INT32_MIN INT32_MIN -#define EV_UINT16_MAX UINT16_MAX -#define EV_INT16_MIN INT16_MIN -#define EV_INT16_MAX INT16_MAX -#define EV_UINT8_MAX UINT8_MAX -#define EV_INT8_MAX INT8_MAX -#define EV_INT8_MIN INT8_MIN +#else +#define EV_UINT64_MAX UINT64_MAX +#define EV_INT64_MAX INT64_MAX +#define EV_INT64_MIN INT64_MIN +#define EV_UINT32_MAX UINT32_MAX +#define EV_INT32_MAX INT32_MAX +#define EV_INT32_MIN INT32_MIN +#define EV_UINT16_MAX UINT16_MAX +#define EV_INT16_MIN INT16_MIN +#define EV_INT16_MAX INT16_MAX +#define EV_UINT8_MAX UINT8_MAX +#define EV_INT8_MAX INT8_MAX +#define EV_INT8_MIN INT8_MIN /** @} */ -#endif - +#endif + /** @name Limits for SIZE_T and SSIZE_T @{ */ -#if EVENT__SIZEOF_SIZE_T == 8 +#if EVENT__SIZEOF_SIZE_T == 8 #define EV_SIZE_MAX EV_UINT64_MAX #define EV_SSIZE_MAX EV_INT64_MAX -#elif EVENT__SIZEOF_SIZE_T == 4 +#elif EVENT__SIZEOF_SIZE_T == 4 #define EV_SIZE_MAX EV_UINT32_MAX #define EV_SSIZE_MAX EV_INT32_MAX -#elif defined(EVENT_IN_DOXYGEN_) +#elif defined(EVENT_IN_DOXYGEN_) #define EV_SIZE_MAX ... #define EV_SSIZE_MAX ... #else @@ -286,16 +286,16 @@ extern "C" { #define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1) /**@}*/ -#ifdef _WIN32 +#ifdef _WIN32 #define ev_socklen_t int -#elif defined(EVENT__socklen_t) -#define ev_socklen_t EVENT__socklen_t +#elif defined(EVENT__socklen_t) +#define ev_socklen_t EVENT__socklen_t #else #define ev_socklen_t socklen_t #endif -#ifdef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY -#if !defined(EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) \ +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY +#if !defined(EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) \ && !defined(ss_family) #define ss_family __ss_family #endif @@ -304,77 +304,77 @@ extern "C" { /** * A type wide enough to hold the output of "socket()" or "accept()". On * Windows, this is an intptr_t; elsewhere, it is an int. */ -#ifdef _WIN32 +#ifdef _WIN32 #define evutil_socket_t intptr_t #else #define evutil_socket_t int #endif -/** - * Structure to hold information about a monotonic timer - * - * Use this with evutil_configure_monotonic_time() and - * evutil_gettime_monotonic(). - * - * This is an opaque structure; you can allocate one using - * evutil_monotonic_timer_new(). - * - * @see evutil_monotonic_timer_new(), evutil_monotonic_timer_free(), - * evutil_configure_monotonic_time(), evutil_gettime_monotonic() - */ -struct evutil_monotonic_timer -#ifdef EVENT_IN_DOXYGEN_ -{/*Empty body so that doxygen will generate documentation here.*/} -#endif -; - -#define EV_MONOT_PRECISE 1 -#define EV_MONOT_FALLBACK 2 - -/** Format a date string using RFC 1123 format (used in HTTP). - * If `tm` is NULL, current system's time will be used. - * The number of characters written will be returned. - * One should check if the return value is smaller than `datelen` to check if - * the result is truncated or not. - */ -EVENT2_EXPORT_SYMBOL int -evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm); - -/** Allocate a new struct evutil_monotonic_timer for use with the - * evutil_configure_monotonic_time() and evutil_gettime_monotonic() - * functions. You must configure the timer with - * evutil_configure_monotonic_time() before using it. - */ -EVENT2_EXPORT_SYMBOL -struct evutil_monotonic_timer * evutil_monotonic_timer_new(void); - -/** Free a struct evutil_monotonic_timer that was allocated using - * evutil_monotonic_timer_new(). - */ -EVENT2_EXPORT_SYMBOL -void evutil_monotonic_timer_free(struct evutil_monotonic_timer *timer); - -/** Set up a struct evutil_monotonic_timer; flags can include - * EV_MONOT_PRECISE and EV_MONOT_FALLBACK. - */ -EVENT2_EXPORT_SYMBOL -int evutil_configure_monotonic_time(struct evutil_monotonic_timer *timer, - int flags); - -/** Query the current monotonic time from a struct evutil_monotonic_timer - * previously configured with evutil_configure_monotonic_time(). Monotonic - * time is guaranteed never to run in reverse, but is not necessarily epoch- - * based, or relative to any other definite point. Use it to make reliable - * measurements of elapsed time between events even when the system time - * may be changed. - * - * It is not safe to use this funtion on the same timer from multiple - * threads. - */ -EVENT2_EXPORT_SYMBOL -int evutil_gettime_monotonic(struct evutil_monotonic_timer *timer, - struct timeval *tp); - +/** + * Structure to hold information about a monotonic timer + * + * Use this with evutil_configure_monotonic_time() and + * evutil_gettime_monotonic(). + * + * This is an opaque structure; you can allocate one using + * evutil_monotonic_timer_new(). + * + * @see evutil_monotonic_timer_new(), evutil_monotonic_timer_free(), + * evutil_configure_monotonic_time(), evutil_gettime_monotonic() + */ +struct evutil_monotonic_timer +#ifdef EVENT_IN_DOXYGEN_ +{/*Empty body so that doxygen will generate documentation here.*/} +#endif +; + +#define EV_MONOT_PRECISE 1 +#define EV_MONOT_FALLBACK 2 + +/** Format a date string using RFC 1123 format (used in HTTP). + * If `tm` is NULL, current system's time will be used. + * The number of characters written will be returned. + * One should check if the return value is smaller than `datelen` to check if + * the result is truncated or not. + */ +EVENT2_EXPORT_SYMBOL int +evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm); + +/** Allocate a new struct evutil_monotonic_timer for use with the + * evutil_configure_monotonic_time() and evutil_gettime_monotonic() + * functions. You must configure the timer with + * evutil_configure_monotonic_time() before using it. + */ +EVENT2_EXPORT_SYMBOL +struct evutil_monotonic_timer * evutil_monotonic_timer_new(void); + +/** Free a struct evutil_monotonic_timer that was allocated using + * evutil_monotonic_timer_new(). + */ +EVENT2_EXPORT_SYMBOL +void evutil_monotonic_timer_free(struct evutil_monotonic_timer *timer); + +/** Set up a struct evutil_monotonic_timer; flags can include + * EV_MONOT_PRECISE and EV_MONOT_FALLBACK. + */ +EVENT2_EXPORT_SYMBOL +int evutil_configure_monotonic_time(struct evutil_monotonic_timer *timer, + int flags); + +/** Query the current monotonic time from a struct evutil_monotonic_timer + * previously configured with evutil_configure_monotonic_time(). Monotonic + * time is guaranteed never to run in reverse, but is not necessarily epoch- + * based, or relative to any other definite point. Use it to make reliable + * measurements of elapsed time between events even when the system time + * may be changed. + * + * It is not safe to use this funtion on the same timer from multiple + * threads. + */ +EVENT2_EXPORT_SYMBOL +int evutil_gettime_monotonic(struct evutil_monotonic_timer *timer, + struct timeval *tp); + /** Create two new sockets that are connected to each other. On Unix, this simply calls socketpair(). On Windows, it uses the @@ -386,14 +386,14 @@ int evutil_gettime_monotonic(struct evutil_monotonic_timer *timer, Parameters and return values are as for socketpair() */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_socketpair(int d, int type, int protocol, evutil_socket_t sv[2]); /** Do platform-specific operations as needed to make a socket nonblocking. @param sock The socket to make nonblocking @return 0 on success, -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_make_socket_nonblocking(evutil_socket_t sock); /** Do platform-specific operations to make a listener socket reusable. @@ -407,82 +407,82 @@ int evutil_make_socket_nonblocking(evutil_socket_t sock); @param sock The socket to make reusable @return 0 on success, -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_make_listen_socket_reuseable(evutil_socket_t sock); -/** Do platform-specific operations to make a listener port reusable. - - Specifically, we want to make sure that multiple programs which also - set the same socket option will be able to bind, listen at the same time. - - This is a feature available only to Linux 3.9+ - - @param sock The socket to make reusable - @return 0 on success, -1 on failure - */ -EVENT2_EXPORT_SYMBOL -int evutil_make_listen_socket_reuseable_port(evutil_socket_t sock); - -/** Set ipv6 only bind socket option to make listener work only in ipv6 sockets. - - According to RFC3493 and most Linux distributions, default value for the - sockets is to work in IPv4-mapped mode. In IPv4-mapped mode, it is not possible - to bind same port from different IPv4 and IPv6 handlers. - - @param sock The socket to make in ipv6only working mode - @return 0 on success, -1 on failure - */ -EVENT2_EXPORT_SYMBOL -int evutil_make_listen_socket_ipv6only(evutil_socket_t sock); - +/** Do platform-specific operations to make a listener port reusable. + + Specifically, we want to make sure that multiple programs which also + set the same socket option will be able to bind, listen at the same time. + + This is a feature available only to Linux 3.9+ + + @param sock The socket to make reusable + @return 0 on success, -1 on failure + */ +EVENT2_EXPORT_SYMBOL +int evutil_make_listen_socket_reuseable_port(evutil_socket_t sock); + +/** Set ipv6 only bind socket option to make listener work only in ipv6 sockets. + + According to RFC3493 and most Linux distributions, default value for the + sockets is to work in IPv4-mapped mode. In IPv4-mapped mode, it is not possible + to bind same port from different IPv4 and IPv6 handlers. + + @param sock The socket to make in ipv6only working mode + @return 0 on success, -1 on failure + */ +EVENT2_EXPORT_SYMBOL +int evutil_make_listen_socket_ipv6only(evutil_socket_t sock); + /** Do platform-specific operations as needed to close a socket upon a successful execution of one of the exec*() functions. @param sock The socket to be closed @return 0 on success, -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_make_socket_closeonexec(evutil_socket_t sock); /** Do the platform-specific call needed to close a socket returned from socket() or accept(). @param sock The socket to be closed - @return 0 on success (whether the operation is supported or not), - -1 on failure + @return 0 on success (whether the operation is supported or not), + -1 on failure */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_closesocket(evutil_socket_t sock); #define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s) -/** Do platform-specific operations, if possible, to make a tcp listener - * socket defer accept()s until there is data to read. - * - * Not all platforms support this. You don't want to do this for every - * listener socket: only the ones that implement a protocol where the - * client transmits before the server needs to respond. - * - * @param sock The listening socket to to make deferred - * @return 0 on success (whether the operation is supported or not), - * -1 on failure -*/ -EVENT2_EXPORT_SYMBOL -int evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock); - -#ifdef _WIN32 +/** Do platform-specific operations, if possible, to make a tcp listener + * socket defer accept()s until there is data to read. + * + * Not all platforms support this. You don't want to do this for every + * listener socket: only the ones that implement a protocol where the + * client transmits before the server needs to respond. + * + * @param sock The listening socket to to make deferred + * @return 0 on success (whether the operation is supported or not), + * -1 on failure +*/ +EVENT2_EXPORT_SYMBOL +int evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock); + +#ifdef _WIN32 /** Return the most recent socket error. Not idempotent on all platforms. */ #define EVUTIL_SOCKET_ERROR() WSAGetLastError() /** Replace the most recent socket error with errcode */ #define EVUTIL_SET_SOCKET_ERROR(errcode) \ do { WSASetLastError(errcode); } while (0) /** Return the most recent socket error to occur on sock. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_socket_geterror(evutil_socket_t sock); /** Convert a socket error to a string. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evutil_socket_error_to_string(int errcode); -#define EVUTIL_INVALID_SOCKET INVALID_SOCKET -#elif defined(EVENT_IN_DOXYGEN_) +#define EVUTIL_INVALID_SOCKET INVALID_SOCKET +#elif defined(EVENT_IN_DOXYGEN_) /** @name Socket error functions @@ -505,16 +505,16 @@ const char *evutil_socket_error_to_string(int errcode); #define evutil_socket_geterror(sock) ... /** Convert a socket error to a string. */ #define evutil_socket_error_to_string(errcode) ... -#define EVUTIL_INVALID_SOCKET -1 +#define EVUTIL_INVALID_SOCKET -1 /**@}*/ -#else /** !EVENT_IN_DOXYGEN_ && !_WIN32 */ +#else /** !EVENT_IN_DOXYGEN_ && !_WIN32 */ #define EVUTIL_SOCKET_ERROR() (errno) #define EVUTIL_SET_SOCKET_ERROR(errcode) \ do { errno = (errcode); } while (0) #define evutil_socket_geterror(sock) (errno) #define evutil_socket_error_to_string(errcode) (strerror(errcode)) -#define EVUTIL_INVALID_SOCKET -1 -#endif /** !_WIN32 */ +#define EVUTIL_INVALID_SOCKET -1 +#endif /** !_WIN32 */ /** @@ -525,7 +525,7 @@ const char *evutil_socket_error_to_string(int errcode); * * @{ */ -#ifdef EVENT__HAVE_TIMERADD +#ifdef EVENT__HAVE_TIMERADD #define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp)) #define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp)) #else @@ -547,9 +547,9 @@ const char *evutil_socket_error_to_string(int errcode); (vvp)->tv_usec += 1000000; \ } \ } while (0) -#endif /* !EVENT__HAVE_TIMERADD */ +#endif /* !EVENT__HAVE_TIMERADD */ -#ifdef EVENT__HAVE_TIMERCLEAR +#ifdef EVENT__HAVE_TIMERCLEAR #define evutil_timerclear(tvp) timerclear(tvp) #else #define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 @@ -563,7 +563,7 @@ const char *evutil_socket_error_to_string(int errcode); ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ ((tvp)->tv_sec cmp (uvp)->tv_sec)) -#ifdef EVENT__HAVE_TIMERISSET +#ifdef EVENT__HAVE_TIMERISSET #define evutil_timerisset(tvp) timerisset(tvp) #else #define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) @@ -578,22 +578,22 @@ const char *evutil_socket_error_to_string(int errcode); /* big-int related functions */ /** Parse a 64-bit value from a string. Arguments are as for strtol. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL ev_int64_t evutil_strtoll(const char *s, char **endptr, int base); /** Replacement for gettimeofday on platforms that lack it. */ -#ifdef EVENT__HAVE_GETTIMEOFDAY +#ifdef EVENT__HAVE_GETTIMEOFDAY #define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz)) #else struct timezone; -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_gettimeofday(struct timeval *tv, struct timezone *tz); #endif /** Replacement for snprintf to get consistent behavior on platforms for which the return value of snprintf does not conform to C99. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_snprintf(char *buf, size_t buflen, const char *format, ...) #ifdef __GNUC__ __attribute__((format(printf, 3, 4))) @@ -602,7 +602,7 @@ int evutil_snprintf(char *buf, size_t buflen, const char *format, ...) /** Replacement for vsnprintf to get consistent behavior on platforms for which the return value of snprintf does not conform to C99. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap) #ifdef __GNUC__ __attribute__((format(printf, 3, 0))) @@ -610,7 +610,7 @@ int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap) ; /** Replacement for inet_ntop for platforms which lack it. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evutil_inet_ntop(int af, const void *src, char *dst, size_t len); /** Variation of inet_pton that also parses IPv6 scopes. Public for unit tests. No reason to call this directly. @@ -619,7 +619,7 @@ EVENT2_EXPORT_SYMBOL int evutil_inet_pton_scope(int af, const char *src, void *dst, unsigned *indexp); /** Replacement for inet_pton for platforms which lack it. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_inet_pton(int af, const char *src, void *dst); struct sockaddr; @@ -643,7 +643,7 @@ struct sockaddr; or if out is not large enough to hold the result. Otherwise returns 0 on success. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_parse_sockaddr_port(const char *str, struct sockaddr *out, int *outlen); /** Compare two sockaddrs; return 0 if they are equal, or less than 0 if sa1 @@ -651,24 +651,24 @@ int evutil_parse_sockaddr_port(const char *str, struct sockaddr *out, int *outle * true, consider the port as well as the address. Only implemented for * AF_INET and AF_INET6 addresses. The ordering is not guaranteed to remain * the same between Libevent versions. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_sockaddr_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2, int include_port); /** As strcasecmp, but always compares the characters in locale-independent ASCII. That's useful if you're handling data in ASCII-based protocols. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_ascii_strcasecmp(const char *str1, const char *str2); /** As strncasecmp, but always compares the characters in locale-independent ASCII. That's useful if you're handling data in ASCII-based protocols. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_ascii_strncasecmp(const char *str1, const char *str2, size_t n); /* Here we define evutil_addrinfo to the native addrinfo type, or redefine it * if this system has no getaddrinfo(). */ -#ifdef EVENT__HAVE_STRUCT_ADDRINFO +#ifdef EVENT__HAVE_STRUCT_ADDRINFO #define evutil_addrinfo addrinfo #else /** A definition of struct addrinfo for systems that lack it. @@ -694,32 +694,32 @@ struct evutil_addrinfo { @{ */ -#if defined(EAI_ADDRFAMILY) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_ADDRFAMILY) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_ADDRFAMILY EAI_ADDRFAMILY #else #define EVUTIL_EAI_ADDRFAMILY -901 #endif -#if defined(EAI_AGAIN) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_AGAIN) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_AGAIN EAI_AGAIN #else #define EVUTIL_EAI_AGAIN -902 #endif -#if defined(EAI_BADFLAGS) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_BADFLAGS) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_BADFLAGS EAI_BADFLAGS #else #define EVUTIL_EAI_BADFLAGS -903 #endif -#if defined(EAI_FAIL) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_FAIL) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_FAIL EAI_FAIL #else #define EVUTIL_EAI_FAIL -904 #endif -#if defined(EAI_FAMILY) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_FAMILY) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_FAMILY EAI_FAMILY #else #define EVUTIL_EAI_FAMILY -905 #endif -#if defined(EAI_MEMORY) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_MEMORY) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_MEMORY EAI_MEMORY #else #define EVUTIL_EAI_MEMORY -906 @@ -727,27 +727,27 @@ struct evutil_addrinfo { /* This test is a bit complicated, since some MS SDKs decide to * remove NODATA or redefine it to be the same as NONAME, in a * fun interpretation of RFC 2553 and RFC 3493. */ -#if defined(EAI_NODATA) && defined(EVENT__HAVE_GETADDRINFO) && (!defined(EAI_NONAME) || EAI_NODATA != EAI_NONAME) +#if defined(EAI_NODATA) && defined(EVENT__HAVE_GETADDRINFO) && (!defined(EAI_NONAME) || EAI_NODATA != EAI_NONAME) #define EVUTIL_EAI_NODATA EAI_NODATA #else #define EVUTIL_EAI_NODATA -907 #endif -#if defined(EAI_NONAME) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_NONAME) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_NONAME EAI_NONAME #else #define EVUTIL_EAI_NONAME -908 #endif -#if defined(EAI_SERVICE) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_SERVICE) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_SERVICE EAI_SERVICE #else #define EVUTIL_EAI_SERVICE -909 #endif -#if defined(EAI_SOCKTYPE) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_SOCKTYPE) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_SOCKTYPE EAI_SOCKTYPE #else #define EVUTIL_EAI_SOCKTYPE -910 #endif -#if defined(EAI_SYSTEM) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(EAI_SYSTEM) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_EAI_SYSTEM EAI_SYSTEM #else #define EVUTIL_EAI_SYSTEM -911 @@ -755,37 +755,37 @@ struct evutil_addrinfo { #define EVUTIL_EAI_CANCEL -90001 -#if defined(AI_PASSIVE) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_PASSIVE) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_PASSIVE AI_PASSIVE #else #define EVUTIL_AI_PASSIVE 0x1000 #endif -#if defined(AI_CANONNAME) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_CANONNAME) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_CANONNAME AI_CANONNAME #else #define EVUTIL_AI_CANONNAME 0x2000 #endif -#if defined(AI_NUMERICHOST) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_NUMERICHOST) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_NUMERICHOST AI_NUMERICHOST #else #define EVUTIL_AI_NUMERICHOST 0x4000 #endif -#if defined(AI_NUMERICSERV) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_NUMERICSERV) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_NUMERICSERV AI_NUMERICSERV #else #define EVUTIL_AI_NUMERICSERV 0x8000 #endif -#if defined(AI_V4MAPPED) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_V4MAPPED) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_V4MAPPED AI_V4MAPPED #else #define EVUTIL_AI_V4MAPPED 0x10000 #endif -#if defined(AI_ALL) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_ALL) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_ALL AI_ALL #else #define EVUTIL_AI_ALL 0x20000 #endif -#if defined(AI_ADDRCONFIG) && defined(EVENT__HAVE_GETADDRINFO) +#if defined(AI_ADDRCONFIG) && defined(EVENT__HAVE_GETADDRINFO) #define EVUTIL_AI_ADDRCONFIG AI_ADDRCONFIG #else #define EVUTIL_AI_ADDRCONFIG 0x40000 @@ -804,15 +804,15 @@ struct evutil_addrinfo; * * For a nonblocking variant, see evdns_getaddrinfo. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_getaddrinfo(const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, struct evutil_addrinfo **res); /** Release storage allocated by evutil_getaddrinfo or evdns_getaddrinfo. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evutil_freeaddrinfo(struct evutil_addrinfo *ai); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL const char *evutil_gai_strerror(int err); /** Generate n bytes of secure pseudorandom data, and store them in buf. @@ -824,7 +824,7 @@ const char *evutil_gai_strerror(int err); * provides only rudimentary prediction- and backtracking-resistance. Don't * use this for serious cryptographic applications. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evutil_secure_rng_get_bytes(void *buf, size_t n); /** @@ -843,7 +843,7 @@ void evutil_secure_rng_get_bytes(void *buf, size_t n); * whatever), and you want to make sure that seeding happens before your * program loses the ability to do it. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_secure_rng_init(void); /** @@ -859,10 +859,10 @@ int evutil_secure_rng_init(void); * * This API is unstable, and might change in a future libevent version. */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL int evutil_secure_rng_set_urandom_device_file(char *fname); -#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM) +#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM) /** Seed the random number generator with extra random bytes. You should almost never need to call this function; it should be @@ -877,12 +877,12 @@ int evutil_secure_rng_set_urandom_device_file(char *fname); @param dat a buffer full of a strong source of random numbers @param datlen the number of bytes to read from datlen */ -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void evutil_secure_rng_add_bytes(const char *dat, size_t datlen); -#endif +#endif #ifdef __cplusplus } #endif -#endif /* EVENT1_EVUTIL_H_INCLUDED_ */ +#endif /* EVENT1_EVUTIL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/event2/visibility.h b/contrib/libs/libevent/include/event2/visibility.h index 006bbf06d8..221cb1f7b8 100644 --- a/contrib/libs/libevent/include/event2/visibility.h +++ b/contrib/libs/libevent/include/event2/visibility.h @@ -1,67 +1,67 @@ -/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EVENT2_VISIBILITY_H_INCLUDED_ -#define EVENT2_VISIBILITY_H_INCLUDED_ - -#include <event2/event-config.h> - -#if defined(event_shared_EXPORTS) || \ - defined(event_extra_shared_EXPORTS) || \ - defined(event_core_shared_EXPORTS) || \ - defined(event_pthreads_shared_EXPORTS) || \ - defined(event_openssl_shared_EXPORTS) - -# if defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) -# define EVENT2_EXPORT_SYMBOL __global -# elif defined __GNUC__ -# define EVENT2_EXPORT_SYMBOL __attribute__ ((visibility("default"))) -# elif defined(_MSC_VER) -# define EVENT2_EXPORT_SYMBOL __declspec(dllexport) -# else -# define EVENT2_EXPORT_SYMBOL /* unknown compiler */ -# endif - -#else /* event_*_EXPORTS */ - -# define EVENT2_EXPORT_SYMBOL - -#endif /* event_*_EXPORTS */ - -/** We need to dllimport event_debug_logging_mask_ into event_extra */ -#if defined(_MSC_VER) -# if defined(event_core_shared_EXPORTS) /** from core export */ -# define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllexport) -# elif defined(event_extra_shared_EXPORTS) || /** from extra import */ \ - defined(EVENT_VISIBILITY_WANT_DLLIMPORT) -# define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllimport) -# endif -#endif /* _MSC_VER */ -#if !defined(EVENT2_CORE_EXPORT_SYMBOL) -# define EVENT2_CORE_EXPORT_SYMBOL EVENT2_EXPORT_SYMBOL -#endif - -#endif /* EVENT2_VISIBILITY_H_INCLUDED_ */ +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT2_VISIBILITY_H_INCLUDED_ +#define EVENT2_VISIBILITY_H_INCLUDED_ + +#include <event2/event-config.h> + +#if defined(event_shared_EXPORTS) || \ + defined(event_extra_shared_EXPORTS) || \ + defined(event_core_shared_EXPORTS) || \ + defined(event_pthreads_shared_EXPORTS) || \ + defined(event_openssl_shared_EXPORTS) + +# if defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) +# define EVENT2_EXPORT_SYMBOL __global +# elif defined __GNUC__ +# define EVENT2_EXPORT_SYMBOL __attribute__ ((visibility("default"))) +# elif defined(_MSC_VER) +# define EVENT2_EXPORT_SYMBOL __declspec(dllexport) +# else +# define EVENT2_EXPORT_SYMBOL /* unknown compiler */ +# endif + +#else /* event_*_EXPORTS */ + +# define EVENT2_EXPORT_SYMBOL + +#endif /* event_*_EXPORTS */ + +/** We need to dllimport event_debug_logging_mask_ into event_extra */ +#if defined(_MSC_VER) +# if defined(event_core_shared_EXPORTS) /** from core export */ +# define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllexport) +# elif defined(event_extra_shared_EXPORTS) || /** from extra import */ \ + defined(EVENT_VISIBILITY_WANT_DLLIMPORT) +# define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllimport) +# endif +#endif /* _MSC_VER */ +#if !defined(EVENT2_CORE_EXPORT_SYMBOL) +# define EVENT2_CORE_EXPORT_SYMBOL EVENT2_EXPORT_SYMBOL +#endif + +#endif /* EVENT2_VISIBILITY_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/evhttp.h b/contrib/libs/libevent/include/evhttp.h index 549bc9b14a..d876f5219e 100644 --- a/contrib/libs/libevent/include/evhttp.h +++ b/contrib/libs/libevent/include/evhttp.h @@ -1,45 +1,45 @@ -/* - * Copyright 2000-2007 Niels Provos <provos@citi.umich.edu> - * Copyright 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EVENT1_EVHTTP_H_INCLUDED_ -#define EVENT1_EVHTTP_H_INCLUDED_ - -/** @file evhttp.h - - An http implementation subsystem for Libevent. - - The <evhttp.h> header is deprecated in Libevent 2.0 and later; please - use <event2/http.h> instead. Depending on what functionality you - need, you may also want to include more of the other <event2/...> - headers. - */ - -#include <event.h> -#include <event2/http.h> -#include <event2/http_struct.h> -#include <event2/http_compat.h> - -#endif /* EVENT1_EVHTTP_H_INCLUDED_ */ +/* + * Copyright 2000-2007 Niels Provos <provos@citi.umich.edu> + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT1_EVHTTP_H_INCLUDED_ +#define EVENT1_EVHTTP_H_INCLUDED_ + +/** @file evhttp.h + + An http implementation subsystem for Libevent. + + The <evhttp.h> header is deprecated in Libevent 2.0 and later; please + use <event2/http.h> instead. Depending on what functionality you + need, you may also want to include more of the other <event2/...> + headers. + */ + +#include <event.h> +#include <event2/http.h> +#include <event2/http_struct.h> +#include <event2/http_compat.h> + +#endif /* EVENT1_EVHTTP_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/evrpc.h b/contrib/libs/libevent/include/evrpc.h index 7e986f7dab..8c01a3e356 100644 --- a/contrib/libs/libevent/include/evrpc.h +++ b/contrib/libs/libevent/include/evrpc.h @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EVENT1_EVRPC_H_INCLUDED_ -#define EVENT1_EVRPC_H_INCLUDED_ - -/** @file evrpc.h - - An RPC system for Libevent. - - The <evrpc.h> header is deprecated in Libevent 2.0 and later; please - use <event2/rpc.h> instead. Depending on what functionality you - need, you may also want to include more of the other <event2/...> - headers. - */ - -#include <event.h> -#include <event2/rpc.h> -#include <event2/rpc_struct.h> -#include <event2/rpc_compat.h> - -#endif /* EVENT1_EVRPC_H_INCLUDED_ */ +/* + * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT1_EVRPC_H_INCLUDED_ +#define EVENT1_EVRPC_H_INCLUDED_ + +/** @file evrpc.h + + An RPC system for Libevent. + + The <evrpc.h> header is deprecated in Libevent 2.0 and later; please + use <event2/rpc.h> instead. Depending on what functionality you + need, you may also want to include more of the other <event2/...> + headers. + */ + +#include <event.h> +#include <event2/rpc.h> +#include <event2/rpc_struct.h> +#include <event2/rpc_compat.h> + +#endif /* EVENT1_EVRPC_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/include/evutil.h b/contrib/libs/libevent/include/evutil.h index 12c137d745..fc513cc5bc 100644 --- a/contrib/libs/libevent/include/evutil.h +++ b/contrib/libs/libevent/include/evutil.h @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef EVENT1_EVUTIL_H_INCLUDED_ -#define EVENT1_EVUTIL_H_INCLUDED_ - -/** @file evutil.h - - Utility and compatibility functions for Libevent. - - The <evutil.h> header is deprecated in Libevent 2.0 and later; please - use <event2/util.h> instead. -*/ - -#include <event2/util.h> - -#endif /* EVENT1_EVUTIL_H_INCLUDED_ */ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT1_EVUTIL_H_INCLUDED_ +#define EVENT1_EVUTIL_H_INCLUDED_ + +/** @file evutil.h + + Utility and compatibility functions for Libevent. + + The <evutil.h> header is deprecated in Libevent 2.0 and later; please + use <event2/util.h> instead. +*/ + +#include <event2/util.h> + +#endif /* EVENT1_EVUTIL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/iocp-internal.h b/contrib/libs/libevent/iocp-internal.h index 21e0e0af68..f54e487042 100644 --- a/contrib/libs/libevent/iocp-internal.h +++ b/contrib/libs/libevent/iocp-internal.h @@ -24,8 +24,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef IOCP_INTERNAL_H_INCLUDED_ -#define IOCP_INTERNAL_H_INCLUDED_ +#ifndef IOCP_INTERNAL_H_INCLUDED_ +#define IOCP_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { @@ -39,7 +39,7 @@ typedef void (*iocp_callback)(struct event_overlapped *, ev_uintptr_t, ev_ssize_ /* This whole file is actually win32 only. We wrap the structures in a win32 * ifdef so that we can test-compile code that uses these interfaces on * non-win32 platforms. */ -#ifdef _WIN32 +#ifdef _WIN32 /** Internal use only. Wraps an OVERLAPPED that we're using for libevent @@ -92,8 +92,8 @@ struct event_iocp_port { HANDLE *shutdownSemaphore; }; -EVENT2_EXPORT_SYMBOL -const struct win32_extension_fns *event_get_win32_extension_fns_(void); +EVENT2_EXPORT_SYMBOL +const struct win32_extension_fns *event_get_win32_extension_fns_(void); #else /* Dummy definition so we can test-compile more things on unix. */ struct event_overlapped { @@ -107,69 +107,69 @@ struct event_overlapped { @param cb The callback that should be invoked once the IO operation has finished. */ -EVENT2_EXPORT_SYMBOL -void event_overlapped_init_(struct event_overlapped *, iocp_callback cb); +EVENT2_EXPORT_SYMBOL +void event_overlapped_init_(struct event_overlapped *, iocp_callback cb); /** Allocate and return a new evbuffer that supports overlapped IO on a given socket. The socket must be associated with an IO completion port using - event_iocp_port_associate_. + event_iocp_port_associate_. */ -EVENT2_EXPORT_SYMBOL -struct evbuffer *evbuffer_overlapped_new_(evutil_socket_t fd); +EVENT2_EXPORT_SYMBOL +struct evbuffer *evbuffer_overlapped_new_(evutil_socket_t fd); /** XXXX Document (nickm) */ -evutil_socket_t evbuffer_overlapped_get_fd_(struct evbuffer *buf); +evutil_socket_t evbuffer_overlapped_get_fd_(struct evbuffer *buf); -void evbuffer_overlapped_set_fd_(struct evbuffer *buf, evutil_socket_t fd); +void evbuffer_overlapped_set_fd_(struct evbuffer *buf, evutil_socket_t fd); /** Start reading data onto the end of an overlapped evbuffer. An evbuffer can only have one read pending at a time. While the read is in progress, no other data may be added to the end of the buffer. - The buffer must be created with event_overlapped_init_(). - evbuffer_commit_read_() must be called in the completion callback. + The buffer must be created with event_overlapped_init_(). + evbuffer_commit_read_() must be called in the completion callback. @param buf The buffer to read onto @param n The number of bytes to try to read. @param ol Overlapped object with associated completion callback. @return 0 on success, -1 on error. */ -EVENT2_EXPORT_SYMBOL -int evbuffer_launch_read_(struct evbuffer *buf, size_t n, struct event_overlapped *ol); +EVENT2_EXPORT_SYMBOL +int evbuffer_launch_read_(struct evbuffer *buf, size_t n, struct event_overlapped *ol); /** Start writing data from the start of an evbuffer. An evbuffer can only have one write pending at a time. While the write is in progress, no other data may be removed from the front of the buffer. - The buffer must be created with event_overlapped_init_(). - evbuffer_commit_write_() must be called in the completion callback. + The buffer must be created with event_overlapped_init_(). + evbuffer_commit_write_() must be called in the completion callback. @param buf The buffer to read onto @param n The number of bytes to try to read. @param ol Overlapped object with associated completion callback. @return 0 on success, -1 on error. */ -EVENT2_EXPORT_SYMBOL -int evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t n, struct event_overlapped *ol); +EVENT2_EXPORT_SYMBOL +int evbuffer_launch_write_(struct evbuffer *buf, ev_ssize_t n, struct event_overlapped *ol); /** XXX document */ -EVENT2_EXPORT_SYMBOL -void evbuffer_commit_read_(struct evbuffer *, ev_ssize_t); -EVENT2_EXPORT_SYMBOL -void evbuffer_commit_write_(struct evbuffer *, ev_ssize_t); +EVENT2_EXPORT_SYMBOL +void evbuffer_commit_read_(struct evbuffer *, ev_ssize_t); +EVENT2_EXPORT_SYMBOL +void evbuffer_commit_write_(struct evbuffer *, ev_ssize_t); /** Create an IOCP, and launch its worker threads. Internal use only. This interface is unstable, and will change. */ -EVENT2_EXPORT_SYMBOL -struct event_iocp_port *event_iocp_port_launch_(int n_cpus); +EVENT2_EXPORT_SYMBOL +struct event_iocp_port *event_iocp_port_launch_(int n_cpus); /** Associate a file descriptor with an iocp, such that overlapped IO on the fd will happen on one of the iocp's worker threads. */ -EVENT2_EXPORT_SYMBOL -int event_iocp_port_associate_(struct event_iocp_port *port, evutil_socket_t fd, +EVENT2_EXPORT_SYMBOL +int event_iocp_port_associate_(struct event_iocp_port *port, evutil_socket_t fd, ev_uintptr_t key); /** Tell all threads serving an iocp to stop. Wait for up to waitMsec for all @@ -178,34 +178,34 @@ int event_iocp_port_associate_(struct event_iocp_port *port, evutil_socket_t fd, 0. Otherwise, return -1. If you get a -1 return value, it is safe to call this function again. */ -EVENT2_EXPORT_SYMBOL -int event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec); +EVENT2_EXPORT_SYMBOL +int event_iocp_shutdown_(struct event_iocp_port *port, long waitMsec); /* FIXME document. */ -EVENT2_EXPORT_SYMBOL -int event_iocp_activate_overlapped_(struct event_iocp_port *port, +EVENT2_EXPORT_SYMBOL +int event_iocp_activate_overlapped_(struct event_iocp_port *port, struct event_overlapped *o, ev_uintptr_t key, ev_uint32_t n_bytes); struct event_base; /* FIXME document. */ -EVENT2_EXPORT_SYMBOL -struct event_iocp_port *event_base_get_iocp_(struct event_base *base); +EVENT2_EXPORT_SYMBOL +struct event_iocp_port *event_base_get_iocp_(struct event_base *base); /* FIXME document. */ -EVENT2_EXPORT_SYMBOL -int event_base_start_iocp_(struct event_base *base, int n_cpus); -void event_base_stop_iocp_(struct event_base *base); +EVENT2_EXPORT_SYMBOL +int event_base_start_iocp_(struct event_base *base, int n_cpus); +void event_base_stop_iocp_(struct event_base *base); /* FIXME document. */ -EVENT2_EXPORT_SYMBOL -struct bufferevent *bufferevent_async_new_(struct event_base *base, +EVENT2_EXPORT_SYMBOL +struct bufferevent *bufferevent_async_new_(struct event_base *base, evutil_socket_t fd, int options); /* FIXME document. */ -void bufferevent_async_set_connected_(struct bufferevent *bev); -int bufferevent_async_can_connect_(struct bufferevent *bev); -int bufferevent_async_connect_(struct bufferevent *bev, evutil_socket_t fd, +void bufferevent_async_set_connected_(struct bufferevent *bev); +int bufferevent_async_can_connect_(struct bufferevent *bev); +int bufferevent_async_connect_(struct bufferevent *bev, evutil_socket_t fd, const struct sockaddr *sa, int socklen); #ifdef __cplusplus diff --git a/contrib/libs/libevent/ipv6-internal.h b/contrib/libs/libevent/ipv6-internal.h index 0c207377b8..b619ffff4e 100644 --- a/contrib/libs/libevent/ipv6-internal.h +++ b/contrib/libs/libevent/ipv6-internal.h @@ -27,14 +27,14 @@ /* Internal use only: Fake IPv6 structures and values on platforms that * do not have them */ -#ifndef IPV6_INTERNAL_H_INCLUDED_ -#define IPV6_INTERNAL_H_INCLUDED_ - -#include "event2/event-config.h" -#include "evconfig-private.h" +#ifndef IPV6_INTERNAL_H_INCLUDED_ +#define IPV6_INTERNAL_H_INCLUDED_ +#include "event2/event-config.h" +#include "evconfig-private.h" + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #include "event2/util.h" @@ -49,17 +49,17 @@ extern "C" { * properly. */ -#ifndef EVENT__HAVE_STRUCT_IN6_ADDR +#ifndef EVENT__HAVE_STRUCT_IN6_ADDR struct in6_addr { ev_uint8_t s6_addr[16]; }; #endif -#ifndef EVENT__HAVE_SA_FAMILY_T +#ifndef EVENT__HAVE_SA_FAMILY_T typedef int sa_family_t; #endif -#ifndef EVENT__HAVE_STRUCT_SOCKADDR_IN6 +#ifndef EVENT__HAVE_STRUCT_SOCKADDR_IN6 struct sockaddr_in6 { /* This will fail if we find a struct sockaddr that doesn't have * sa_family as the first element. */ diff --git a/contrib/libs/libevent/kqueue-internal.h b/contrib/libs/libevent/kqueue-internal.h index 02c5a3606c..89fed6b5ac 100644 --- a/contrib/libs/libevent/kqueue-internal.h +++ b/contrib/libs/libevent/kqueue-internal.h @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef KQUEUE_INTERNAL_H_INCLUDED_ -#define KQUEUE_INTERNAL_H_INCLUDED_ - -/** Notification function, used to tell an event base to wake up from another - * thread. Only works when event_kq_add_notify_event_() has previously been - * called successfully on that base. */ -int event_kq_notify_base_(struct event_base *base); - -/** Prepare a kqueue-using event base to receive notifications via an internal - * EVFILT_USER event. Return 0 on sucess, -1 on failure. - */ -int event_kq_add_notify_event_(struct event_base *base); - -#endif +/* + * Copyright (c) 2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef KQUEUE_INTERNAL_H_INCLUDED_ +#define KQUEUE_INTERNAL_H_INCLUDED_ + +/** Notification function, used to tell an event base to wake up from another + * thread. Only works when event_kq_add_notify_event_() has previously been + * called successfully on that base. */ +int event_kq_notify_base_(struct event_base *base); + +/** Prepare a kqueue-using event base to receive notifications via an internal + * EVFILT_USER event. Return 0 on sucess, -1 on failure. + */ +int event_kq_add_notify_event_(struct event_base *base); + +#endif diff --git a/contrib/libs/libevent/kqueue.c b/contrib/libs/libevent/kqueue.c index dfd7751d64..a5ec6d6734 100644 --- a/contrib/libs/libevent/kqueue.c +++ b/contrib/libs/libevent/kqueue.c @@ -27,24 +27,24 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_KQUEUE +#include "evconfig-private.h" +#ifdef EVENT__HAVE_KQUEUE + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> #include <sys/event.h> -#include <limits.h> +#include <limits.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> -#ifdef EVENT__HAVE_INTTYPES_H +#ifdef EVENT__HAVE_INTTYPES_H #include <inttypes.h> #endif @@ -66,12 +66,12 @@ #include "log-internal.h" #include "evmap-internal.h" #include "event2/thread.h" -#include "event2/util.h" +#include "event2/util.h" #include "evthread-internal.h" #include "changelist-internal.h" -#include "kqueue-internal.h" - +#include "kqueue-internal.h" + #define NEVENT 64 struct kqop { @@ -81,7 +81,7 @@ struct kqop { struct kevent *events; int events_size; int kq; - int notify_event_added; + int notify_event_added; pid_t pid; }; @@ -96,8 +96,8 @@ static void kq_dealloc(struct event_base *); const struct eventop kqops = { "kqueue", kq_init, - event_changelist_add_, - event_changelist_del_, + event_changelist_add_, + event_changelist_del_, kq_dispatch, kq_dealloc, 1 /* need reinit */, @@ -212,17 +212,17 @@ kq_build_changes_list(const struct event_changelist *changelist, struct event_change *in_ch = &changelist->changes[i]; struct kevent *out_ch; if (n_changes >= kqop->changes_size - 1) { - int newsize; + int newsize; struct kevent *newchanges; - if (kqop->changes_size > INT_MAX / 2 || - (size_t)kqop->changes_size * 2 > EV_SIZE_MAX / - sizeof(struct kevent)) { - event_warnx("%s: int overflow", __func__); - return (-1); - } - - newsize = kqop->changes_size * 2; + if (kqop->changes_size > INT_MAX / 2 || + (size_t)kqop->changes_size * 2 > EV_SIZE_MAX / + sizeof(struct kevent)) { + event_warnx("%s: int overflow", __func__); + return (-1); + } + + newsize = kqop->changes_size * 2; newchanges = mm_realloc(kqop->changes, newsize * sizeof(struct kevent)); if (newchanges == NULL) { @@ -273,8 +273,8 @@ kq_dispatch(struct event_base *base, struct timeval *tv) int i, n_changes, res; if (tv != NULL) { - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec * 1000; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; ts_p = &ts; } @@ -284,7 +284,7 @@ kq_dispatch(struct event_base *base, struct timeval *tv) if (n_changes < 0) return -1; - event_changelist_remove_all_(&base->changelist, base); + event_changelist_remove_all_(&base->changelist, base); /* steal the changes array in case some broken code tries to call * dispatch twice at once. */ @@ -346,23 +346,23 @@ kq_dispatch(struct event_base *base, struct timeval *tv) * on FreeBSD. */ case EINVAL: continue; -#if defined(__FreeBSD__) - /* - * This currently occurs if an FD is closed - * before the EV_DELETE makes it out via kevent(). - * The FreeBSD capabilities code sees the blank - * capability set and rejects the request to - * modify an event. - * - * To be strictly correct - when an FD is closed, - * all the registered events are also removed. - * Queuing EV_DELETE to a closed FD is wrong. - * The event(s) should just be deleted from - * the pending changelist. - */ - case ENOTCAPABLE: - continue; -#endif +#if defined(__FreeBSD__) + /* + * This currently occurs if an FD is closed + * before the EV_DELETE makes it out via kevent(). + * The FreeBSD capabilities code sees the blank + * capability set and rejects the request to + * modify an event. + * + * To be strictly correct - when an FD is closed, + * all the registered events are also removed. + * Queuing EV_DELETE to a closed FD is wrong. + * The event(s) should just be deleted from + * the pending changelist. + */ + case ENOTCAPABLE: + continue; +#endif /* Can occur on a delete if the fd is closed. */ case EBADF: @@ -403,19 +403,19 @@ kq_dispatch(struct event_base *base, struct timeval *tv) which |= EV_WRITE; } else if (events[i].filter == EVFILT_SIGNAL) { which |= EV_SIGNAL; -#ifdef EVFILT_USER - } else if (events[i].filter == EVFILT_USER) { - base->is_notify_pending = 0; -#endif +#ifdef EVFILT_USER + } else if (events[i].filter == EVFILT_USER) { + base->is_notify_pending = 0; +#endif } if (!which) continue; if (events[i].filter == EVFILT_SIGNAL) { - evmap_signal_active_(base, events[i].ident, 1); + evmap_signal_active_(base, events[i].ident, 1); } else { - evmap_io_active_(base, events[i].ident, which | EV_ET); + evmap_io_active_(base, events[i].ident, which | EV_ET); } } @@ -445,7 +445,7 @@ static void kq_dealloc(struct event_base *base) { struct kqop *kqop = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); kqop_free(kqop); } @@ -471,13 +471,13 @@ kq_sig_add(struct event_base *base, int nsignal, short old, short events, void * if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) return (-1); - /* We can set the handler for most signals to SIG_IGN and - * still have them reported to us in the queue. However, - * if the handler for SIGCHLD is SIG_IGN, the system reaps - * zombie processes for us, and we don't get any notification. - * This appears to be the only signal with this quirk. */ - if (evsig_set_handler_(base, nsignal, - nsignal == SIGCHLD ? SIG_DFL : SIG_IGN) == -1) + /* We can set the handler for most signals to SIG_IGN and + * still have them reported to us in the queue. However, + * if the handler for SIGCHLD is SIG_IGN, the system reaps + * zombie processes for us, and we don't get any notification. + * This appears to be the only signal with this quirk. */ + if (evsig_set_handler_(base, nsignal, + nsignal == SIGCHLD ? SIG_DFL : SIG_IGN) == -1) return (-1); return (0); @@ -505,76 +505,76 @@ kq_sig_del(struct event_base *base, int nsignal, short old, short events, void * if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) return (-1); - if (evsig_restore_handler_(base, nsignal) == -1) + if (evsig_restore_handler_(base, nsignal) == -1) return (-1); return (0); } - - -/* OSX 10.6 and FreeBSD 8.1 add support for EVFILT_USER, which we can use - * to wake up the event loop from another thread. */ - -/* Magic number we use for our filter ID. */ -#define NOTIFY_IDENT 42 - -int -event_kq_add_notify_event_(struct event_base *base) -{ - struct kqop *kqop = base->evbase; -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - struct kevent kev; - struct timespec timeout = { 0, 0 }; -#endif - - if (kqop->notify_event_added) - return 0; - -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - memset(&kev, 0, sizeof(kev)); - kev.ident = NOTIFY_IDENT; - kev.filter = EVFILT_USER; - kev.flags = EV_ADD | EV_CLEAR; - - if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { - event_warn("kevent: adding EVFILT_USER event"); - return -1; - } - - kqop->notify_event_added = 1; - - return 0; -#else - return -1; -#endif -} - -int -event_kq_notify_base_(struct event_base *base) -{ - struct kqop *kqop = base->evbase; -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - struct kevent kev; - struct timespec timeout = { 0, 0 }; -#endif - if (! kqop->notify_event_added) - return -1; - -#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) - memset(&kev, 0, sizeof(kev)); - kev.ident = NOTIFY_IDENT; - kev.filter = EVFILT_USER; - kev.fflags = NOTE_TRIGGER; - - if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { - event_warn("kevent: triggering EVFILT_USER event"); - return -1; - } - - return 0; -#else - return -1; -#endif -} - -#endif /* EVENT__HAVE_KQUEUE */ + + +/* OSX 10.6 and FreeBSD 8.1 add support for EVFILT_USER, which we can use + * to wake up the event loop from another thread. */ + +/* Magic number we use for our filter ID. */ +#define NOTIFY_IDENT 42 + +int +event_kq_add_notify_event_(struct event_base *base) +{ + struct kqop *kqop = base->evbase; +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + struct kevent kev; + struct timespec timeout = { 0, 0 }; +#endif + + if (kqop->notify_event_added) + return 0; + +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + memset(&kev, 0, sizeof(kev)); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.flags = EV_ADD | EV_CLEAR; + + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { + event_warn("kevent: adding EVFILT_USER event"); + return -1; + } + + kqop->notify_event_added = 1; + + return 0; +#else + return -1; +#endif +} + +int +event_kq_notify_base_(struct event_base *base) +{ + struct kqop *kqop = base->evbase; +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + struct kevent kev; + struct timespec timeout = { 0, 0 }; +#endif + if (! kqop->notify_event_added) + return -1; + +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + memset(&kev, 0, sizeof(kev)); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.fflags = NOTE_TRIGGER; + + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { + event_warn("kevent: triggering EVFILT_USER event"); + return -1; + } + + return 0; +#else + return -1; +#endif +} + +#endif /* EVENT__HAVE_KQUEUE */ diff --git a/contrib/libs/libevent/listener.c b/contrib/libs/libevent/listener.c index f5c00c9c0e..9d039a1df9 100644 --- a/contrib/libs/libevent/listener.c +++ b/contrib/libs/libevent/listener.c @@ -24,29 +24,29 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "event2/event-config.h" -#include "evconfig-private.h" - +#include "event2/event-config.h" +#include "evconfig-private.h" + #include <sys/types.h> -#ifdef _WIN32 +#ifdef _WIN32 #ifndef _WIN32_WINNT /* Minimum required for InitializeCriticalSectionAndSpinCount */ #define _WIN32_WINNT 0x0403 #endif #include <winsock2.h> -#include <winerror.h> +#include <winerror.h> #include <ws2tcpip.h> #include <mswsock.h> #endif #include <errno.h> -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif -#ifdef EVENT__HAVE_FCNTL_H +#ifdef EVENT__HAVE_FCNTL_H #include <fcntl.h> #endif -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif @@ -58,7 +58,7 @@ #include "util-internal.h" #include "log-internal.h" #include "evthread-internal.h" -#ifdef _WIN32 +#ifdef _WIN32 #include "iocp-internal.h" #include "defer-internal.h" #include "event-internal.h" @@ -81,7 +81,7 @@ struct evconnlistener { void *user_data; unsigned flags; short refcnt; - int accept4_flags; + int accept4_flags; unsigned enabled : 1; }; @@ -90,7 +90,7 @@ struct evconnlistener_event { struct event listener; }; -#ifdef _WIN32 +#ifdef _WIN32 struct evconnlistener_iocp { struct evconnlistener base; evutil_socket_t fd; @@ -160,10 +160,10 @@ evconnlistener_new(struct event_base *base, { struct evconnlistener_event *lev; -#ifdef _WIN32 - if (base && event_base_get_iocp_(base)) { +#ifdef _WIN32 + if (base && event_base_get_iocp_(base)) { const struct win32_extension_fns *ext = - event_get_win32_extension_fns_(); + event_get_win32_extension_fns_(); if (ext->AcceptEx && ext->GetAcceptExSockaddrs) return evconnlistener_new_async(base, cb, ptr, flags, backlog, fd); @@ -188,12 +188,12 @@ evconnlistener_new(struct event_base *base, lev->base.flags = flags; lev->base.refcnt = 1; - lev->base.accept4_flags = 0; - if (!(flags & LEV_OPT_LEAVE_SOCKETS_BLOCKING)) - lev->base.accept4_flags |= EVUTIL_SOCK_NONBLOCK; - if (flags & LEV_OPT_CLOSE_ON_EXEC) - lev->base.accept4_flags |= EVUTIL_SOCK_CLOEXEC; - + lev->base.accept4_flags = 0; + if (!(flags & LEV_OPT_LEAVE_SOCKETS_BLOCKING)) + lev->base.accept4_flags |= EVUTIL_SOCK_NONBLOCK; + if (flags & LEV_OPT_CLOSE_ON_EXEC) + lev->base.accept4_flags |= EVUTIL_SOCK_CLOEXEC; + if (flags & LEV_OPT_THREADSAFE) { EVTHREAD_ALLOC_LOCK(lev->base.lock, EVTHREAD_LOCKTYPE_RECURSIVE); } @@ -201,8 +201,8 @@ evconnlistener_new(struct event_base *base, event_assign(&lev->listener, base, fd, EV_READ|EV_PERSIST, listener_read_cb, lev); - if (!(flags & LEV_OPT_DISABLED)) - evconnlistener_enable(&lev->base); + if (!(flags & LEV_OPT_DISABLED)) + evconnlistener_enable(&lev->base); return &lev->base; } @@ -216,54 +216,54 @@ evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb, evutil_socket_t fd; int on = 1; int family = sa ? sa->sa_family : AF_UNSPEC; - int socktype = SOCK_STREAM | EVUTIL_SOCK_NONBLOCK; + int socktype = SOCK_STREAM | EVUTIL_SOCK_NONBLOCK; if (backlog == 0) return NULL; - if (flags & LEV_OPT_CLOSE_ON_EXEC) - socktype |= EVUTIL_SOCK_CLOEXEC; - - fd = evutil_socket_(family, socktype, 0); + if (flags & LEV_OPT_CLOSE_ON_EXEC) + socktype |= EVUTIL_SOCK_CLOEXEC; + + fd = evutil_socket_(family, socktype, 0); if (fd == -1) return NULL; - if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on))<0) - goto err; - - if (flags & LEV_OPT_REUSEABLE) { - if (evutil_make_listen_socket_reuseable(fd) < 0) - goto err; + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on))<0) + goto err; + + if (flags & LEV_OPT_REUSEABLE) { + if (evutil_make_listen_socket_reuseable(fd) < 0) + goto err; } - if (flags & LEV_OPT_REUSEABLE_PORT) { - if (evutil_make_listen_socket_reuseable_port(fd) < 0) - goto err; + if (flags & LEV_OPT_REUSEABLE_PORT) { + if (evutil_make_listen_socket_reuseable_port(fd) < 0) + goto err; } - if (flags & LEV_OPT_DEFERRED_ACCEPT) { - if (evutil_make_tcp_listen_socket_deferred(fd) < 0) - goto err; + if (flags & LEV_OPT_DEFERRED_ACCEPT) { + if (evutil_make_tcp_listen_socket_deferred(fd) < 0) + goto err; } - - if (flags & LEV_OPT_BIND_IPV6ONLY) { - if (evutil_make_listen_socket_ipv6only(fd) < 0) - goto err; + + if (flags & LEV_OPT_BIND_IPV6ONLY) { + if (evutil_make_listen_socket_ipv6only(fd) < 0) + goto err; } if (sa) { - if (bind(fd, sa, socklen)<0) - goto err; + if (bind(fd, sa, socklen)<0) + goto err; } listener = evconnlistener_new(base, cb, ptr, flags, backlog, fd); - if (!listener) - goto err; + if (!listener) + goto err; return listener; -err: - evutil_closesocket(fd); - return NULL; +err: + evutil_closesocket(fd); + return NULL; } void @@ -401,8 +401,8 @@ listener_read_cb(evutil_socket_t fd, short what, void *p) LOCK(lev); while (1) { struct sockaddr_storage ss; - ev_socklen_t socklen = sizeof(ss); - evutil_socket_t new_fd = evutil_accept4_(fd, (struct sockaddr*)&ss, &socklen, lev->accept4_flags); + ev_socklen_t socklen = sizeof(ss); + evutil_socket_t new_fd = evutil_accept4_(fd, (struct sockaddr*)&ss, &socklen, lev->accept4_flags); if (new_fd < 0) break; if (socklen == 0) { @@ -430,11 +430,11 @@ listener_read_cb(evutil_socket_t fd, short what, void *p) return; } --lev->refcnt; - if (!lev->enabled) { - /* the callback could have disabled the listener */ - UNLOCK(lev); - return; - } + if (!lev->enabled) { + /* the callback could have disabled the listener */ + UNLOCK(lev); + return; + } } err = evutil_socket_geterror(fd); if (EVUTIL_ERR_ACCEPT_RETRIABLE(err)) { @@ -451,17 +451,17 @@ listener_read_cb(evutil_socket_t fd, short what, void *p) listener_decref_and_unlock(lev); } else { event_sock_warn(fd, "Error from accept() call"); - UNLOCK(lev); + UNLOCK(lev); } } -#ifdef _WIN32 +#ifdef _WIN32 struct accepting_socket { CRITICAL_SECTION lock; struct event_overlapped overlapped; SOCKET s; int error; - struct event_callback deferred; + struct event_callback deferred; struct evconnlistener_iocp *lev; ev_uint8_t buflen; ev_uint8_t family; @@ -471,7 +471,7 @@ struct accepting_socket { static void accepted_socket_cb(struct event_overlapped *o, ev_uintptr_t key, ev_ssize_t n, int ok); -static void accepted_socket_invoke_user_cb(struct event_callback *cb, void *arg); +static void accepted_socket_invoke_user_cb(struct event_callback *cb, void *arg); static void iocp_listener_event_add(struct evconnlistener_iocp *lev) @@ -480,7 +480,7 @@ iocp_listener_event_add(struct evconnlistener_iocp *lev) return; lev->event_added = 1; - event_base_add_virtual_(lev->event_base); + event_base_add_virtual_(lev->event_base); } static void @@ -490,7 +490,7 @@ iocp_listener_event_del(struct evconnlistener_iocp *lev) return; lev->event_added = 0; - event_base_del_virtual_(lev->event_base); + event_base_del_virtual_(lev->event_base); } static struct accepting_socket * @@ -512,15 +512,15 @@ new_accepting_socket(struct evconnlistener_iocp *lev, int family) if (!res) return NULL; - event_overlapped_init_(&res->overlapped, accepted_socket_cb); - res->s = EVUTIL_INVALID_SOCKET; + event_overlapped_init_(&res->overlapped, accepted_socket_cb); + res->s = EVUTIL_INVALID_SOCKET; res->lev = lev; res->buflen = buflen; res->family = family; - event_deferred_cb_init_(&res->deferred, - event_base_get_npriorities(lev->event_base) / 2, - accepted_socket_invoke_user_cb, res); + event_deferred_cb_init_(&res->deferred, + event_base_get_npriorities(lev->event_base) / 2, + accepted_socket_invoke_user_cb, res); InitializeCriticalSectionAndSpinCount(&res->lock, 1000); @@ -531,7 +531,7 @@ static void free_and_unlock_accepting_socket(struct accepting_socket *as) { /* requires lock. */ - if (as->s != EVUTIL_INVALID_SOCKET) + if (as->s != EVUTIL_INVALID_SOCKET) closesocket(as->s); LeaveCriticalSection(&as->lock); @@ -543,7 +543,7 @@ static int start_accepting(struct accepting_socket *as) { /* requires lock */ - const struct win32_extension_fns *ext = event_get_win32_extension_fns_(); + const struct win32_extension_fns *ext = event_get_win32_extension_fns_(); DWORD pending = 0; SOCKET s = socket(as->family, SOCK_STREAM, 0); int error = 0; @@ -551,7 +551,7 @@ start_accepting(struct accepting_socket *as) if (!as->lev->base.enabled) return 0; - if (s == EVUTIL_INVALID_SOCKET) { + if (s == EVUTIL_INVALID_SOCKET) { error = WSAGetLastError(); goto report_err; } @@ -564,7 +564,7 @@ start_accepting(struct accepting_socket *as) if (!(as->lev->base.flags & LEV_OPT_LEAVE_SOCKETS_BLOCKING)) evutil_make_socket_nonblocking(s); - if (event_iocp_port_associate_(as->lev->port, s, 1) < 0) { + if (event_iocp_port_associate_(as->lev->port, s, 1) < 0) { closesocket(s); return -1; } @@ -587,8 +587,8 @@ start_accepting(struct accepting_socket *as) report_err: as->error = error; - event_deferred_cb_schedule_( - as->lev->event_base, + event_deferred_cb_schedule_( + as->lev->event_base, &as->deferred); return 0; } @@ -598,18 +598,18 @@ stop_accepting(struct accepting_socket *as) { /* requires lock. */ SOCKET s = as->s; - as->s = EVUTIL_INVALID_SOCKET; + as->s = EVUTIL_INVALID_SOCKET; closesocket(s); } static void -accepted_socket_invoke_user_cb(struct event_callback *dcb, void *arg) +accepted_socket_invoke_user_cb(struct event_callback *dcb, void *arg) { struct accepting_socket *as = arg; struct sockaddr *sa_local=NULL, *sa_remote=NULL; int socklen_local=0, socklen_remote=0; - const struct win32_extension_fns *ext = event_get_win32_extension_fns_(); + const struct win32_extension_fns *ext = event_get_win32_extension_fns_(); struct evconnlistener *lev = &as->lev->base; evutil_socket_t sock=-1; void *data; @@ -640,7 +640,7 @@ accepted_socket_invoke_user_cb(struct event_callback *dcb, void *arg) &socklen_remote); sock = as->s; cb = lev->cb; - as->s = EVUTIL_INVALID_SOCKET; + as->s = EVUTIL_INVALID_SOCKET; /* We need to call this so getsockname, getpeername, and * shutdown work correctly on the accepted socket. */ @@ -679,8 +679,8 @@ accepted_socket_cb(struct event_overlapped *o, ev_uintptr_t key, ev_ssize_t n, i EnterCriticalSection(&as->lock); if (ok) { /* XXXX Don't do this if some EV_MT flag is set. */ - event_deferred_cb_schedule_( - as->lev->event_base, + event_deferred_cb_schedule_( + as->lev->event_base, &as->deferred); LeaveCriticalSection(&as->lock); } else if (as->free_on_cb) { @@ -688,7 +688,7 @@ accepted_socket_cb(struct event_overlapped *o, ev_uintptr_t key, ev_ssize_t n, i free_and_unlock_accepting_socket(as); listener_decref_and_unlock(lev); return; - } else if (as->s == EVUTIL_INVALID_SOCKET) { + } else if (as->s == EVUTIL_INVALID_SOCKET) { /* This is okay; we were disabled by iocp_listener_disable. */ LeaveCriticalSection(&as->lock); } else { @@ -704,8 +704,8 @@ accepted_socket_cb(struct event_overlapped *o, ev_uintptr_t key, ev_ssize_t n, i } else { as->error = WSAGetLastError(); } - event_deferred_cb_schedule_( - as->lev->event_base, + event_deferred_cb_schedule_( + as->lev->event_base, &as->deferred); LeaveCriticalSection(&as->lock); } @@ -726,7 +726,7 @@ iocp_listener_enable(struct evconnlistener *lev) if (!as) continue; EnterCriticalSection(&as->lock); - if (!as->free_on_cb && as->s == EVUTIL_INVALID_SOCKET) + if (!as->free_on_cb && as->s == EVUTIL_INVALID_SOCKET) start_accepting(as); LeaveCriticalSection(&as->lock); } @@ -748,7 +748,7 @@ iocp_listener_disable_impl(struct evconnlistener *lev, int shutdown) if (!as) continue; EnterCriticalSection(&as->lock); - if (!as->free_on_cb && as->s != EVUTIL_INVALID_SOCKET) { + if (!as->free_on_cb && as->s != EVUTIL_INVALID_SOCKET) { if (shutdown) as->free_on_cb = 1; stop_accepting(as); @@ -821,7 +821,7 @@ evconnlistener_new_async(struct event_base *base, flags |= LEV_OPT_THREADSAFE; - if (!base || !event_base_get_iocp_(base)) + if (!base || !event_base_get_iocp_(base)) goto err; /* XXXX duplicate code */ @@ -848,12 +848,12 @@ evconnlistener_new_async(struct event_base *base, lev->base.refcnt = 1; lev->base.enabled = 1; - lev->port = event_base_get_iocp_(base); + lev->port = event_base_get_iocp_(base); lev->fd = fd; lev->event_base = base; - if (event_iocp_port_associate_(lev->port, fd, 1) < 0) + if (event_iocp_port_associate_(lev->port, fd, 1) < 0) goto err_free_lev; EVTHREAD_ALLOC_LOCK(lev->base.lock, EVTHREAD_LOCKTYPE_RECURSIVE); diff --git a/contrib/libs/libevent/log-internal.h b/contrib/libs/libevent/log-internal.h index 2c31608b25..d2538f5226 100644 --- a/contrib/libs/libevent/log-internal.h +++ b/contrib/libs/libevent/log-internal.h @@ -24,15 +24,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef LOG_INTERNAL_H_INCLUDED_ -#define LOG_INTERNAL_H_INCLUDED_ +#ifndef LOG_INTERNAL_H_INCLUDED_ +#define LOG_INTERNAL_H_INCLUDED_ #include "event2/util.h" -#ifdef __cplusplus -extern "C" { -#endif - +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __GNUC__ #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b))) #define EV_NORETURN __attribute__((noreturn)) @@ -41,54 +41,54 @@ extern "C" { #define EV_NORETURN #endif -#define EVENT_ERR_ABORT_ ((int)0xdeaddead) +#define EVENT_ERR_ABORT_ ((int)0xdeaddead) -#if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG) -#define EVENT_DEBUG_LOGGING_ENABLED -#endif - -#ifdef EVENT_DEBUG_LOGGING_ENABLED -EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_; -#define event_debug_get_logging_mask_() (event_debug_logging_mask_) -#else -#define event_debug_get_logging_mask_() (0) -#endif - -EVENT2_EXPORT_SYMBOL +#if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG) +#define EVENT_DEBUG_LOGGING_ENABLED +#endif + +#ifdef EVENT_DEBUG_LOGGING_ENABLED +EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_; +#define event_debug_get_logging_mask_() (event_debug_logging_mask_) +#else +#define event_debug_get_logging_mask_() (0) +#endif + +EVENT2_EXPORT_SYMBOL void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN; -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN; -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN; -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2); -EVENT2_EXPORT_SYMBOL -void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2); +EVENT2_EXPORT_SYMBOL +void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2); -EVENT2_EXPORT_SYMBOL -void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap) - EV_CHECK_FMT(3,0); - -#ifdef EVENT_DEBUG_LOGGING_ENABLED -#define event_debug(x) do { \ - if (event_debug_get_logging_mask_()) { \ - event_debugx_ x; \ - } \ - } while (0) +EVENT2_EXPORT_SYMBOL +void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap) + EV_CHECK_FMT(3,0); + +#ifdef EVENT_DEBUG_LOGGING_ENABLED +#define event_debug(x) do { \ + if (event_debug_get_logging_mask_()) { \ + event_debugx_ x; \ + } \ + } while (0) #else -#define event_debug(x) ((void)0) +#define event_debug(x) ((void)0) #endif #undef EV_CHECK_FMT -#ifdef __cplusplus -} +#ifdef __cplusplus +} #endif - -#endif /* LOG_INTERNAL_H_INCLUDED_ */ + +#endif /* LOG_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/log.c b/contrib/libs/libevent/log.c index a9debb864e..da480ecb21 100644 --- a/contrib/libs/libevent/log.c +++ b/contrib/libs/libevent/log.c @@ -38,9 +38,9 @@ */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #include <winsock2.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> @@ -62,25 +62,25 @@ static void event_exit(int errcode) EV_NORETURN; static event_fatal_cb fatal_fn = NULL; -#ifdef EVENT_DEBUG_LOGGING_ENABLED -#ifdef USE_DEBUG -#define DEFAULT_MASK EVENT_DBG_ALL -#else -#define DEFAULT_MASK 0 -#endif - -EVENT2_EXPORT_SYMBOL ev_uint32_t event_debug_logging_mask_ = DEFAULT_MASK; -#endif /* EVENT_DEBUG_LOGGING_ENABLED */ - -void -event_enable_debug_logging(ev_uint32_t which) -{ -#ifdef EVENT_DEBUG_LOGGING_ENABLED - event_debug_logging_mask_ = which; -#endif -} - +#ifdef EVENT_DEBUG_LOGGING_ENABLED +#ifdef USE_DEBUG +#define DEFAULT_MASK EVENT_DBG_ALL +#else +#define DEFAULT_MASK 0 +#endif + +EVENT2_EXPORT_SYMBOL ev_uint32_t event_debug_logging_mask_ = DEFAULT_MASK; +#endif /* EVENT_DEBUG_LOGGING_ENABLED */ + void +event_enable_debug_logging(ev_uint32_t which) +{ +#ifdef EVENT_DEBUG_LOGGING_ENABLED + event_debug_logging_mask_ = which; +#endif +} + +void event_set_fatal_callback(event_fatal_cb cb) { fatal_fn = cb; @@ -92,7 +92,7 @@ event_exit(int errcode) if (fatal_fn) { fatal_fn(errcode); exit(errcode); /* should never be reached */ - } else if (errcode == EVENT_ERR_ABORT_) + } else if (errcode == EVENT_ERR_ABORT_) abort(); else exit(errcode); @@ -104,7 +104,7 @@ event_err(int eval, const char *fmt, ...) va_list ap; va_start(ap, fmt); - event_logv_(EVENT_LOG_ERR, strerror(errno), fmt, ap); + event_logv_(EVENT_LOG_ERR, strerror(errno), fmt, ap); va_end(ap); event_exit(eval); } @@ -115,7 +115,7 @@ event_warn(const char *fmt, ...) va_list ap; va_start(ap, fmt); - event_logv_(EVENT_LOG_WARN, strerror(errno), fmt, ap); + event_logv_(EVENT_LOG_WARN, strerror(errno), fmt, ap); va_end(ap); } @@ -126,7 +126,7 @@ event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) int err = evutil_socket_geterror(sock); va_start(ap, fmt); - event_logv_(EVENT_LOG_ERR, evutil_socket_error_to_string(err), fmt, ap); + event_logv_(EVENT_LOG_ERR, evutil_socket_error_to_string(err), fmt, ap); va_end(ap); event_exit(eval); } @@ -138,7 +138,7 @@ event_sock_warn(evutil_socket_t sock, const char *fmt, ...) int err = evutil_socket_geterror(sock); va_start(ap, fmt); - event_logv_(EVENT_LOG_WARN, evutil_socket_error_to_string(err), fmt, ap); + event_logv_(EVENT_LOG_WARN, evutil_socket_error_to_string(err), fmt, ap); va_end(ap); } @@ -148,7 +148,7 @@ event_errx(int eval, const char *fmt, ...) va_list ap; va_start(ap, fmt); - event_logv_(EVENT_LOG_ERR, NULL, fmt, ap); + event_logv_(EVENT_LOG_ERR, NULL, fmt, ap); va_end(ap); event_exit(eval); } @@ -159,7 +159,7 @@ event_warnx(const char *fmt, ...) va_list ap; va_start(ap, fmt); - event_logv_(EVENT_LOG_WARN, NULL, fmt, ap); + event_logv_(EVENT_LOG_WARN, NULL, fmt, ap); va_end(ap); } @@ -169,29 +169,29 @@ event_msgx(const char *fmt, ...) va_list ap; va_start(ap, fmt); - event_logv_(EVENT_LOG_MSG, NULL, fmt, ap); + event_logv_(EVENT_LOG_MSG, NULL, fmt, ap); va_end(ap); } void -event_debugx_(const char *fmt, ...) +event_debugx_(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - event_logv_(EVENT_LOG_DEBUG, NULL, fmt, ap); + event_logv_(EVENT_LOG_DEBUG, NULL, fmt, ap); va_end(ap); } -void -event_logv_(int severity, const char *errstr, const char *fmt, va_list ap) +void +event_logv_(int severity, const char *errstr, const char *fmt, va_list ap) { char buf[1024]; size_t len; - if (severity == EVENT_LOG_DEBUG && !event_debug_get_logging_mask_()) - return; - + if (severity == EVENT_LOG_DEBUG && !event_debug_get_logging_mask_()) + return; + if (fmt != NULL) evutil_vsnprintf(buf, sizeof(buf), fmt, ap); else @@ -223,16 +223,16 @@ event_log(int severity, const char *msg) else { const char *severity_str; switch (severity) { - case EVENT_LOG_DEBUG: + case EVENT_LOG_DEBUG: severity_str = "debug"; break; - case EVENT_LOG_MSG: + case EVENT_LOG_MSG: severity_str = "msg"; break; - case EVENT_LOG_WARN: + case EVENT_LOG_WARN: severity_str = "warn"; break; - case EVENT_LOG_ERR: + case EVENT_LOG_ERR: severity_str = "err"; break; default: diff --git a/contrib/libs/libevent/minheap-internal.h b/contrib/libs/libevent/minheap-internal.h index b3a0eb1fb5..ee5138ea0e 100644 --- a/contrib/libs/libevent/minheap-internal.h +++ b/contrib/libs/libevent/minheap-internal.h @@ -25,11 +25,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MINHEAP_INTERNAL_H_INCLUDED_ -#define MINHEAP_INTERNAL_H_INCLUDED_ +#ifndef MINHEAP_INTERNAL_H_INCLUDED_ +#define MINHEAP_INTERNAL_H_INCLUDED_ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" #include "event2/event.h" #include "event2/event_struct.h" #include "event2/util.h" @@ -42,41 +42,41 @@ typedef struct min_heap unsigned n, a; } min_heap_t; -static inline void min_heap_ctor_(min_heap_t* s); -static inline void min_heap_dtor_(min_heap_t* s); -static inline void min_heap_elem_init_(struct event* e); -static inline int min_heap_elt_is_top_(const struct event *e); -static inline int min_heap_empty_(min_heap_t* s); -static inline unsigned min_heap_size_(min_heap_t* s); -static inline struct event* min_heap_top_(min_heap_t* s); -static inline int min_heap_reserve_(min_heap_t* s, unsigned n); -static inline int min_heap_push_(min_heap_t* s, struct event* e); -static inline struct event* min_heap_pop_(min_heap_t* s); -static inline int min_heap_adjust_(min_heap_t *s, struct event* e); -static inline int min_heap_erase_(min_heap_t* s, struct event* e); +static inline void min_heap_ctor_(min_heap_t* s); +static inline void min_heap_dtor_(min_heap_t* s); +static inline void min_heap_elem_init_(struct event* e); +static inline int min_heap_elt_is_top_(const struct event *e); +static inline int min_heap_empty_(min_heap_t* s); +static inline unsigned min_heap_size_(min_heap_t* s); +static inline struct event* min_heap_top_(min_heap_t* s); +static inline int min_heap_reserve_(min_heap_t* s, unsigned n); +static inline int min_heap_push_(min_heap_t* s, struct event* e); +static inline struct event* min_heap_pop_(min_heap_t* s); +static inline int min_heap_adjust_(min_heap_t *s, struct event* e); +static inline int min_heap_erase_(min_heap_t* s, struct event* e); static inline void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e); -static inline void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e); +static inline void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e); static inline void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e); -#define min_heap_elem_greater(a, b) \ - (evutil_timercmp(&(a)->ev_timeout, &(b)->ev_timeout, >)) +#define min_heap_elem_greater(a, b) \ + (evutil_timercmp(&(a)->ev_timeout, &(b)->ev_timeout, >)) -void min_heap_ctor_(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; } -void min_heap_dtor_(min_heap_t* s) { if (s->p) mm_free(s->p); } -void min_heap_elem_init_(struct event* e) { e->ev_timeout_pos.min_heap_idx = -1; } -int min_heap_empty_(min_heap_t* s) { return 0u == s->n; } -unsigned min_heap_size_(min_heap_t* s) { return s->n; } -struct event* min_heap_top_(min_heap_t* s) { return s->n ? *s->p : 0; } +void min_heap_ctor_(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; } +void min_heap_dtor_(min_heap_t* s) { if (s->p) mm_free(s->p); } +void min_heap_elem_init_(struct event* e) { e->ev_timeout_pos.min_heap_idx = -1; } +int min_heap_empty_(min_heap_t* s) { return 0u == s->n; } +unsigned min_heap_size_(min_heap_t* s) { return s->n; } +struct event* min_heap_top_(min_heap_t* s) { return s->n ? *s->p : 0; } -int min_heap_push_(min_heap_t* s, struct event* e) +int min_heap_push_(min_heap_t* s, struct event* e) { - if (s->n == UINT32_MAX || min_heap_reserve_(s, s->n + 1)) + if (s->n == UINT32_MAX || min_heap_reserve_(s, s->n + 1)) return -1; min_heap_shift_up_(s, s->n++, e); return 0; } -struct event* min_heap_pop_(min_heap_t* s) +struct event* min_heap_pop_(min_heap_t* s) { if (s->n) { @@ -88,12 +88,12 @@ struct event* min_heap_pop_(min_heap_t* s) return 0; } -int min_heap_elt_is_top_(const struct event *e) +int min_heap_elt_is_top_(const struct event *e) { return e->ev_timeout_pos.min_heap_idx == 0; } -int min_heap_erase_(min_heap_t* s, struct event* e) +int min_heap_erase_(min_heap_t* s, struct event* e) { if (-1 != e->ev_timeout_pos.min_heap_idx) { @@ -105,7 +105,7 @@ int min_heap_erase_(min_heap_t* s, struct event* e) to be less than the parent, it can't need to shift both up and down. */ if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], last)) - min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, last); + min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, last); else min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, last); e->ev_timeout_pos.min_heap_idx = -1; @@ -114,34 +114,34 @@ int min_heap_erase_(min_heap_t* s, struct event* e) return -1; } -int min_heap_adjust_(min_heap_t *s, struct event *e) -{ - if (-1 == e->ev_timeout_pos.min_heap_idx) { - return min_heap_push_(s, e); - } else { - unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; - /* The position of e has changed; we shift it up or down - * as needed. We can't need to do both. */ - if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], e)) - min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, e); - else - min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, e); - return 0; - } -} - -int min_heap_reserve_(min_heap_t* s, unsigned n) +int min_heap_adjust_(min_heap_t *s, struct event *e) { + if (-1 == e->ev_timeout_pos.min_heap_idx) { + return min_heap_push_(s, e); + } else { + unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; + /* The position of e has changed; we shift it up or down + * as needed. We can't need to do both. */ + if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], e)) + min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, e); + else + min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, e); + return 0; + } +} + +int min_heap_reserve_(min_heap_t* s, unsigned n) +{ if (s->a < n) { struct event** p; unsigned a = s->a ? s->a * 2 : 8; if (a < n) a = n; -#if (SIZE_MAX == UINT32_MAX) - if (a > SIZE_MAX / sizeof *p) - return -1; -#endif +#if (SIZE_MAX == UINT32_MAX) + if (a > SIZE_MAX / sizeof *p) + return -1; +#endif if (!(p = (struct event**)mm_realloc(s->p, a * sizeof *p))) return -1; s->p = p; @@ -150,18 +150,18 @@ int min_heap_reserve_(min_heap_t* s, unsigned n) return 0; } -void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e) -{ - unsigned parent = (hole_index - 1) / 2; - do - { - (s->p[hole_index] = s->p[parent])->ev_timeout_pos.min_heap_idx = hole_index; - hole_index = parent; - parent = (hole_index - 1) / 2; - } while (hole_index && min_heap_elem_greater(s->p[parent], e)); - (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; -} - +void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e) +{ + unsigned parent = (hole_index - 1) / 2; + do + { + (s->p[hole_index] = s->p[parent])->ev_timeout_pos.min_heap_idx = hole_index; + hole_index = parent; + parent = (hole_index - 1) / 2; + } while (hole_index && min_heap_elem_greater(s->p[parent], e)); + (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; +} + void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e) { unsigned parent = (hole_index - 1) / 2; @@ -189,4 +189,4 @@ void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e) (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; } -#endif /* MINHEAP_INTERNAL_H_INCLUDED_ */ +#endif /* MINHEAP_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/mm-internal.h b/contrib/libs/libevent/mm-internal.h index 7a95c99561..77825d850c 100644 --- a/contrib/libs/libevent/mm-internal.h +++ b/contrib/libs/libevent/mm-internal.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef MM_INTERNAL_H_INCLUDED_ -#define MM_INTERNAL_H_INCLUDED_ +#ifndef MM_INTERNAL_H_INCLUDED_ +#define MM_INTERNAL_H_INCLUDED_ #include <sys/types.h> @@ -32,45 +32,45 @@ extern "C" { #endif -#ifndef EVENT__DISABLE_MM_REPLACEMENT +#ifndef EVENT__DISABLE_MM_REPLACEMENT /* Internal use only: Memory allocation functions. We give them nice short * mm_names for our own use, but make sure that the symbols have longer names * so they don't conflict with other libraries (like, say, libmm). */ - -/** Allocate uninitialized memory. - * - * @return On success, return a pointer to sz newly allocated bytes. - * On failure, set errno to ENOMEM and return NULL. - * If the argument sz is 0, simply return NULL. - */ -EVENT2_EXPORT_SYMBOL + +/** Allocate uninitialized memory. + * + * @return On success, return a pointer to sz newly allocated bytes. + * On failure, set errno to ENOMEM and return NULL. + * If the argument sz is 0, simply return NULL. + */ +EVENT2_EXPORT_SYMBOL void *event_mm_malloc_(size_t sz); - -/** Allocate memory initialized to zero. - * - * @return On success, return a pointer to (count * size) newly allocated - * bytes, initialized to zero. - * On failure, or if the product would result in an integer overflow, - * set errno to ENOMEM and return NULL. - * If either arguments are 0, simply return NULL. - */ -EVENT2_EXPORT_SYMBOL + +/** Allocate memory initialized to zero. + * + * @return On success, return a pointer to (count * size) newly allocated + * bytes, initialized to zero. + * On failure, or if the product would result in an integer overflow, + * set errno to ENOMEM and return NULL. + * If either arguments are 0, simply return NULL. + */ +EVENT2_EXPORT_SYMBOL void *event_mm_calloc_(size_t count, size_t size); - -/** Duplicate a string. - * - * @return On success, return a pointer to a newly allocated duplicate - * of a string. - * Set errno to ENOMEM and return NULL if a memory allocation error - * occurs (or would occur) in the process. - * If the argument str is NULL, set errno to EINVAL and return NULL. - */ -EVENT2_EXPORT_SYMBOL -char *event_mm_strdup_(const char *str); - -EVENT2_EXPORT_SYMBOL + +/** Duplicate a string. + * + * @return On success, return a pointer to a newly allocated duplicate + * of a string. + * Set errno to ENOMEM and return NULL if a memory allocation error + * occurs (or would occur) in the process. + * If the argument str is NULL, set errno to EINVAL and return NULL. + */ +EVENT2_EXPORT_SYMBOL +char *event_mm_strdup_(const char *str); + +EVENT2_EXPORT_SYMBOL void *event_mm_realloc_(void *p, size_t sz); -EVENT2_EXPORT_SYMBOL +EVENT2_EXPORT_SYMBOL void event_mm_free_(void *p); #define mm_malloc(sz) event_mm_malloc_(sz) #define mm_calloc(count, size) event_mm_calloc_((count), (size)) diff --git a/contrib/libs/libevent/openssl-compat.h b/contrib/libs/libevent/openssl-compat.h index a23e34251b..c0ac9e03ee 100644 --- a/contrib/libs/libevent/openssl-compat.h +++ b/contrib/libs/libevent/openssl-compat.h @@ -1,47 +1,47 @@ #ifndef OPENSSL_COMPAT_H #define OPENSSL_COMPAT_H -#include <openssl/bio.h> -#include "util-internal.h" +#include <openssl/bio.h> +#include "util-internal.h" -#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ - (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) - -static inline BIO_METHOD *BIO_meth_new(int type, const char *name) +#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ + (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) + +static inline BIO_METHOD *BIO_meth_new(int type, const char *name) { - BIO_METHOD *biom = calloc(1, sizeof(BIO_METHOD)); + BIO_METHOD *biom = calloc(1, sizeof(BIO_METHOD)); - if (biom != NULL) { - biom->type = type; - biom->name = name; - } - return biom; + if (biom != NULL) { + biom->type = type; + biom->name = name; + } + return biom; } -#define BIO_meth_set_write(b, f) (b)->bwrite = (f) -#define BIO_meth_set_read(b, f) (b)->bread = (f) -#define BIO_meth_set_puts(b, f) (b)->bputs = (f) -#define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f) -#define BIO_meth_set_create(b, f) (b)->create = (f) -#define BIO_meth_set_destroy(b, f) (b)->destroy = (f) +#define BIO_meth_set_write(b, f) (b)->bwrite = (f) +#define BIO_meth_set_read(b, f) (b)->bread = (f) +#define BIO_meth_set_puts(b, f) (b)->bputs = (f) +#define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f) +#define BIO_meth_set_create(b, f) (b)->create = (f) +#define BIO_meth_set_destroy(b, f) (b)->destroy = (f) -#define BIO_set_init(b, val) (b)->init = (val) -#define BIO_set_data(b, val) (b)->ptr = (val) -#define BIO_set_shutdown(b, val) (b)->shutdown = (val) -#define BIO_get_init(b) (b)->init -#define BIO_get_data(b) (b)->ptr -#define BIO_get_shutdown(b) (b)->shutdown +#define BIO_set_init(b, val) (b)->init = (val) +#define BIO_set_data(b, val) (b)->ptr = (val) +#define BIO_set_shutdown(b, val) (b)->shutdown = (val) +#define BIO_get_init(b) (b)->init +#define BIO_get_data(b) (b)->ptr +#define BIO_get_shutdown(b) (b)->shutdown -#define TLS_method SSLv23_method +#define TLS_method SSLv23_method #define X509_getm_notBefore X509_get_notBefore #define X509_getm_notAfter X509_get_notAfter -#endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ - (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */ - -#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L -#define BIO_get_init(b) (b)->init -#endif - +#endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ + (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */ + +#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L +#define BIO_get_init(b) (b)->init +#endif + #endif /* OPENSSL_COMPAT_H */ diff --git a/contrib/libs/libevent/poll.c b/contrib/libs/libevent/poll.c index c3c9aac52a..ab13047a5f 100644 --- a/contrib/libs/libevent/poll.c +++ b/contrib/libs/libevent/poll.c @@ -27,12 +27,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_POLL +#include "evconfig-private.h" +#ifdef EVENT__HAVE_POLL + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> @@ -51,7 +51,7 @@ #include "evmap-internal.h" #include "event2/thread.h" #include "evthread-internal.h" -#include "time-internal.h" +#include "time-internal.h" /* Since Linux 2.6.17, poll is able to report about peer half-closed connection using special POLLRDHUP flag on a read event. @@ -78,8 +78,8 @@ struct pollop { }; static void *poll_init(struct event_base *); -static int poll_add(struct event_base *, int, short old, short events, void *idx); -static int poll_del(struct event_base *, int, short old, short events, void *idx); +static int poll_add(struct event_base *, int, short old, short events, void *idx); +static int poll_del(struct event_base *, int, short old, short events, void *idx); static int poll_dispatch(struct event_base *, struct timeval *); static void poll_dealloc(struct event_base *); @@ -103,10 +103,10 @@ poll_init(struct event_base *base) if (!(pollop = mm_calloc(1, sizeof(struct pollop)))) return (NULL); - evsig_init_(base); - - evutil_weakrand_seed_(&base->weakrand_seed, 0); + evsig_init_(base); + evutil_weakrand_seed_(&base->weakrand_seed, 0); + return (pollop); } @@ -144,7 +144,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv) nfds = pop->nfds; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT if (base->th_base_lock) { /* If we're using this backend in a multithreaded setting, * then we need to work on a copy of event_set, so that we can @@ -172,7 +172,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv) #endif if (tv != NULL) { - msec = evutil_tv_to_msec_(tv); + msec = evutil_tv_to_msec_(tv); if (msec < 0 || msec > INT_MAX) msec = INT_MAX; } @@ -197,7 +197,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv) if (res == 0 || nfds == 0) return (0); - i = evutil_weakrand_range_(&base->weakrand_seed, nfds); + i = evutil_weakrand_range_(&base->weakrand_seed, nfds); for (j = 0; j < nfds; j++) { int what; if (++i == nfds) @@ -209,7 +209,7 @@ poll_dispatch(struct event_base *base, struct timeval *tv) res = 0; /* If the file gets closed notify */ - if (what & (POLLHUP|POLLERR|POLLNVAL)) + if (what & (POLLHUP|POLLERR|POLLNVAL)) what |= POLLIN|POLLOUT; if (what & POLLIN) res |= EV_READ; @@ -220,18 +220,18 @@ poll_dispatch(struct event_base *base, struct timeval *tv) if (res == 0) continue; - evmap_io_active_(base, event_set[i].fd, res); + evmap_io_active_(base, event_set[i].fd, res); } return (0); } static int -poll_add(struct event_base *base, int fd, short old, short events, void *idx_) +poll_add(struct event_base *base, int fd, short old, short events, void *idx_) { struct pollop *pop = base->evbase; struct pollfd *pfd = NULL; - struct pollidx *idx = idx_; + struct pollidx *idx = idx_; int i; EVUTIL_ASSERT((events & EV_SIGNAL) == 0); @@ -290,11 +290,11 @@ poll_add(struct event_base *base, int fd, short old, short events, void *idx_) */ static int -poll_del(struct event_base *base, int fd, short old, short events, void *idx_) +poll_del(struct event_base *base, int fd, short old, short events, void *idx_) { struct pollop *pop = base->evbase; struct pollfd *pfd = NULL; - struct pollidx *idx = idx_; + struct pollidx *idx = idx_; int i; EVUTIL_ASSERT((events & EV_SIGNAL) == 0); @@ -330,7 +330,7 @@ poll_del(struct event_base *base, int fd, short old, short events, void *idx_) */ memcpy(&pop->event_set[i], &pop->event_set[pop->nfds], sizeof(struct pollfd)); - idx = evmap_io_get_fdinfo_(&base->io, pop->event_set[i].fd); + idx = evmap_io_get_fdinfo_(&base->io, pop->event_set[i].fd); EVUTIL_ASSERT(idx); EVUTIL_ASSERT(idx->idxplus1 == pop->nfds + 1); idx->idxplus1 = i + 1; @@ -345,7 +345,7 @@ poll_dealloc(struct event_base *base) { struct pollop *pop = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); if (pop->event_set) mm_free(pop->event_set); if (pop->event_set_copy) @@ -354,5 +354,5 @@ poll_dealloc(struct event_base *base) memset(pop, 0, sizeof(struct pollop)); mm_free(pop); } - -#endif /* EVENT__HAVE_POLL */ + +#endif /* EVENT__HAVE_POLL */ diff --git a/contrib/libs/libevent/ratelim-internal.h b/contrib/libs/libevent/ratelim-internal.h index 6cc1cdde2c..174c93a416 100644 --- a/contrib/libs/libevent/ratelim-internal.h +++ b/contrib/libs/libevent/ratelim-internal.h @@ -23,8 +23,8 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef RATELIM_INTERNAL_H_INCLUDED_ -#define RATELIM_INTERNAL_H_INCLUDED_ +#ifndef RATELIM_INTERNAL_H_INCLUDED_ +#define RATELIM_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { @@ -65,13 +65,13 @@ struct ev_token_bucket_cfg { /** The current tick is 'current_tick': add bytes to 'bucket' as specified in * 'cfg'. */ -int ev_token_bucket_update_(struct ev_token_bucket *bucket, +int ev_token_bucket_update_(struct ev_token_bucket *bucket, const struct ev_token_bucket_cfg *cfg, ev_uint32_t current_tick); /** In which tick does 'tv' fall according to 'cfg'? Note that ticks can * overflow easily; your code needs to handle this. */ -ev_uint32_t ev_token_bucket_get_tick_(const struct timeval *tv, +ev_uint32_t ev_token_bucket_get_tick_(const struct timeval *tv, const struct ev_token_bucket_cfg *cfg); /** Adjust 'bucket' to respect 'cfg', and note that it was last updated in @@ -79,12 +79,12 @@ ev_uint32_t ev_token_bucket_get_tick_(const struct timeval *tv, * configuration of 'bucket'; otherwise, we are setting it up for the first * time. */ -int ev_token_bucket_init_(struct ev_token_bucket *bucket, +int ev_token_bucket_init_(struct ev_token_bucket *bucket, const struct ev_token_bucket_cfg *cfg, ev_uint32_t current_tick, int reinitialize); -int bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, +int bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, int unsuspend); /** Decrease the read limit of 'b' by 'n' bytes */ diff --git a/contrib/libs/libevent/select.c b/contrib/libs/libevent/select.c index b1db0e44b6..8925a63ca6 100644 --- a/contrib/libs/libevent/select.c +++ b/contrib/libs/libevent/select.c @@ -27,21 +27,21 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_SELECT - -#ifdef __APPLE__ -/* Apple wants us to define this if we might ever pass more than - * FD_SETSIZE bits to select(). */ -#define _DARWIN_UNLIMITED_SELECT -#endif - +#include "evconfig-private.h" + +#ifdef EVENT__HAVE_SELECT + +#ifdef __APPLE__ +/* Apple wants us to define this if we might ever pass more than + * FD_SETSIZE bits to select(). */ +#define _DARWIN_UNLIMITED_SELECT +#endif + #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif -#ifdef EVENT__HAVE_SYS_SELECT_H +#ifdef EVENT__HAVE_SYS_SELECT_H #include <sys/select.h> #endif #include <sys/queue.h> @@ -59,7 +59,7 @@ #include "log-internal.h" #include "evmap-internal.h" -#ifndef EVENT__HAVE_FD_MASK +#ifndef EVENT__HAVE_FD_MASK /* This type is mandatory, but Android doesn't define it. */ typedef unsigned long fd_mask; #endif @@ -119,10 +119,10 @@ select_init(struct event_base *base) return (NULL); } - evsig_init_(base); - - evutil_weakrand_seed_(&base->weakrand_seed, 0); + evsig_init_(base); + evutil_weakrand_seed_(&base->weakrand_seed, 0); + return (sop); } @@ -188,7 +188,7 @@ select_dispatch(struct event_base *base, struct timeval *tv) event_debug(("%s: select reports %d", __func__, res)); check_selectop(sop); - i = evutil_weakrand_range_(&base->weakrand_seed, nfds); + i = evutil_weakrand_range_(&base->weakrand_seed, nfds); for (j = 0; j < nfds; ++j) { if (++i >= nfds) i = 0; @@ -201,7 +201,7 @@ select_dispatch(struct event_base *base, struct timeval *tv) if (res == 0) continue; - evmap_io_active_(base, i, res); + evmap_io_active_(base, i, res); } check_selectop(sop); @@ -338,9 +338,9 @@ select_free_selectop(struct selectop *sop) static void select_dealloc(struct event_base *base) { - evsig_dealloc_(base); + evsig_dealloc_(base); select_free_selectop(base->evbase); } - -#endif /* EVENT__HAVE_SELECT */ + +#endif /* EVENT__HAVE_SELECT */ diff --git a/contrib/libs/libevent/signal.c b/contrib/libs/libevent/signal.c index 89f5fc1717..875dbcf9b9 100644 --- a/contrib/libs/libevent/signal.c +++ b/contrib/libs/libevent/signal.c @@ -27,31 +27,31 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "event2/event-config.h" -#include "evconfig-private.h" +#include "evconfig-private.h" -#ifdef _WIN32 +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include <winsock2.h> #include <windows.h> #undef WIN32_LEAN_AND_MEAN #endif #include <sys/types.h> -#ifdef EVENT__HAVE_SYS_TIME_H +#ifdef EVENT__HAVE_SYS_TIME_H #include <sys/time.h> #endif #include <sys/queue.h> -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef EVENT__HAVE_UNISTD_H +#ifdef EVENT__HAVE_UNISTD_H #include <unistd.h> #endif #include <errno.h> -#ifdef EVENT__HAVE_FCNTL_H +#ifdef EVENT__HAVE_FCNTL_H #include <fcntl.h> #endif @@ -82,13 +82,13 @@ on Linux do a reasonable thing using signalfd. */ -#ifndef _WIN32 +#ifndef _WIN32 /* Windows wants us to call our signal handlers as __cdecl. Nobody else * expects you to do anything crazy like this. */ -#ifndef __cdecl +#ifndef __cdecl #define __cdecl #endif -#endif +#endif static int evsig_add(struct event_base *, evutil_socket_t, short, short, void *); static int evsig_del(struct event_base *, evutil_socket_t, short, short, void *); @@ -103,7 +103,7 @@ static const struct eventop evsigops = { 0, 0, 0 }; -#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_THREAD_SUPPORT /* Lock for evsig_base and evsig_base_n_signals_added fields. */ static void *evsig_base_lock = NULL; #endif @@ -119,12 +119,12 @@ static void __cdecl evsig_handler(int sig); #define EVSIGBASE_UNLOCK() EVLOCK_UNLOCK(evsig_base_lock, 0) void -evsig_set_base_(struct event_base *base) +evsig_set_base_(struct event_base *base) { EVSIGBASE_LOCK(); evsig_base = base; evsig_base_n_signals_added = base->sig.ev_n_signals_added; - evsig_base_fd = base->sig.ev_signal_pair[1]; + evsig_base_fd = base->sig.ev_signal_pair[1]; EVSIGBASE_UNLOCK(); } @@ -143,11 +143,11 @@ evsig_cb(evutil_socket_t fd, short what, void *arg) memset(&ncaught, 0, sizeof(ncaught)); while (1) { -#ifdef _WIN32 +#ifdef _WIN32 n = recv(fd, signals, sizeof(signals), 0); -#else - n = read(fd, signals, sizeof(signals)); -#endif +#else + n = read(fd, signals, sizeof(signals)); +#endif if (n == -1) { int err = evutil_socket_geterror(fd); if (! EVUTIL_ERR_RW_RETRIABLE(err)) @@ -167,21 +167,21 @@ evsig_cb(evutil_socket_t fd, short what, void *arg) EVBASE_ACQUIRE_LOCK(base, th_base_lock); for (i = 0; i < NSIG; ++i) { if (ncaught[i]) - evmap_signal_active_(base, i, ncaught[i]); + evmap_signal_active_(base, i, ncaught[i]); } EVBASE_RELEASE_LOCK(base, th_base_lock); } int -evsig_init_(struct event_base *base) +evsig_init_(struct event_base *base) { /* * Our signal handler is going to write to one end of the socket * pair to wake up our event loop. The event loop then scans for * signals that got delivered. */ - if (evutil_make_internal_pipe_(base->sig.ev_signal_pair) == -1) { -#ifdef _WIN32 + if (evutil_make_internal_pipe_(base->sig.ev_signal_pair) == -1) { +#ifdef _WIN32 /* Make this nonfatal on win32, where sometimes people have localhost firewalled. */ event_sock_warn(-1, "%s: socketpair", __func__); @@ -191,13 +191,13 @@ evsig_init_(struct event_base *base) return -1; } - if (base->sig.sh_old) { - mm_free(base->sig.sh_old); - } + if (base->sig.sh_old) { + mm_free(base->sig.sh_old); + } base->sig.sh_old = NULL; base->sig.sh_old_max = 0; - event_assign(&base->sig.ev_signal, base, base->sig.ev_signal_pair[0], + event_assign(&base->sig.ev_signal, base, base->sig.ev_signal_pair[0], EV_READ | EV_PERSIST, evsig_cb, base); base->sig.ev_signal.ev_flags |= EVLIST_INTERNAL; @@ -211,10 +211,10 @@ evsig_init_(struct event_base *base) /* Helper: set the signal handler for evsignal to handler in base, so that * we can restore the original handler when we clear the current one. */ int -evsig_set_handler_(struct event_base *base, +evsig_set_handler_(struct event_base *base, int evsignal, void (__cdecl *handler)(int)) { -#ifdef EVENT__HAVE_SIGACTION +#ifdef EVENT__HAVE_SIGACTION struct sigaction sa; #else ev_sighandler_t sh; @@ -251,7 +251,7 @@ evsig_set_handler_(struct event_base *base, } /* save previous handler and setup new handler */ -#ifdef EVENT__HAVE_SIGACTION +#ifdef EVENT__HAVE_SIGACTION memset(&sa, 0, sizeof(sa)); sa.sa_handler = handler; sa.sa_flags |= SA_RESTART; @@ -297,17 +297,17 @@ evsig_add(struct event_base *base, evutil_socket_t evsignal, short old, short ev } evsig_base = base; evsig_base_n_signals_added = ++sig->ev_n_signals_added; - evsig_base_fd = base->sig.ev_signal_pair[1]; + evsig_base_fd = base->sig.ev_signal_pair[1]; EVSIGBASE_UNLOCK(); event_debug(("%s: %d: changing signal handler", __func__, (int)evsignal)); - if (evsig_set_handler_(base, (int)evsignal, evsig_handler) == -1) { + if (evsig_set_handler_(base, (int)evsignal, evsig_handler) == -1) { goto err; } if (!sig->ev_signal_added) { - if (event_add_nolock_(&sig->ev_signal, NULL, 0)) + if (event_add_nolock_(&sig->ev_signal, NULL, 0)) goto err; sig->ev_signal_added = 1; } @@ -323,26 +323,26 @@ err: } int -evsig_restore_handler_(struct event_base *base, int evsignal) +evsig_restore_handler_(struct event_base *base, int evsignal) { int ret = 0; struct evsig_info *sig = &base->sig; -#ifdef EVENT__HAVE_SIGACTION +#ifdef EVENT__HAVE_SIGACTION struct sigaction *sh; #else ev_sighandler_t *sh; #endif - if (evsignal >= sig->sh_old_max) { - /* Can't actually restore. */ - /* XXXX.*/ - return 0; - } - + if (evsignal >= sig->sh_old_max) { + /* Can't actually restore. */ + /* XXXX.*/ + return 0; + } + /* restore previous handler */ sh = sig->sh_old[evsignal]; sig->sh_old[evsignal] = NULL; -#ifdef EVENT__HAVE_SIGACTION +#ifdef EVENT__HAVE_SIGACTION if (sigaction(evsignal, sh, NULL) == -1) { event_warn("sigaction"); ret = -1; @@ -372,14 +372,14 @@ evsig_del(struct event_base *base, evutil_socket_t evsignal, short old, short ev --base->sig.ev_n_signals_added; EVSIGBASE_UNLOCK(); - return (evsig_restore_handler_(base, (int)evsignal)); + return (evsig_restore_handler_(base, (int)evsignal)); } static void __cdecl evsig_handler(int sig) { int save_errno = errno; -#ifdef _WIN32 +#ifdef _WIN32 int socket_errno = EVUTIL_SOCKET_ERROR(); #endif ev_uint8_t msg; @@ -391,41 +391,41 @@ evsig_handler(int sig) return; } -#ifndef EVENT__HAVE_SIGACTION +#ifndef EVENT__HAVE_SIGACTION signal(sig, evsig_handler); #endif /* Wake up our notification mechanism */ msg = sig; -#ifdef _WIN32 +#ifdef _WIN32 send(evsig_base_fd, (char*)&msg, 1, 0); -#else - { - int r = write(evsig_base_fd, (char*)&msg, 1); - (void)r; /* Suppress 'unused return value' and 'unused var' */ - } -#endif +#else + { + int r = write(evsig_base_fd, (char*)&msg, 1); + (void)r; /* Suppress 'unused return value' and 'unused var' */ + } +#endif errno = save_errno; -#ifdef _WIN32 +#ifdef _WIN32 EVUTIL_SET_SOCKET_ERROR(socket_errno); #endif } void -evsig_dealloc_(struct event_base *base) +evsig_dealloc_(struct event_base *base) { int i = 0; if (base->sig.ev_signal_added) { event_del(&base->sig.ev_signal); base->sig.ev_signal_added = 0; } - /* debug event is created in evsig_init_/event_assign even when + /* debug event is created in evsig_init_/event_assign even when * ev_signal_added == 0, so unassign is required */ event_debug_unassign(&base->sig.ev_signal); for (i = 0; i < NSIG; ++i) { if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL) - evsig_restore_handler_(base, i); + evsig_restore_handler_(base, i); } EVSIGBASE_LOCK(); if (base == evsig_base) { @@ -452,30 +452,30 @@ evsig_dealloc_(struct event_base *base) } } -static void -evsig_free_globals_locks(void) -{ -#ifndef EVENT__DISABLE_THREAD_SUPPORT - if (evsig_base_lock != NULL) { - EVTHREAD_FREE_LOCK(evsig_base_lock, 0); - evsig_base_lock = NULL; - } -#endif - return; -} - -void -evsig_free_globals_(void) -{ - evsig_free_globals_locks(); -} - -#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void +evsig_free_globals_locks(void) +{ +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (evsig_base_lock != NULL) { + EVTHREAD_FREE_LOCK(evsig_base_lock, 0); + evsig_base_lock = NULL; + } +#endif + return; +} + +void +evsig_free_globals_(void) +{ + evsig_free_globals_locks(); +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT int evsig_global_setup_locks_(const int enable_locks) { EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0); return 0; } - + #endif diff --git a/contrib/libs/libevent/strlcpy-internal.h b/contrib/libs/libevent/strlcpy-internal.h index 4151d601d0..308f039d04 100644 --- a/contrib/libs/libevent/strlcpy-internal.h +++ b/contrib/libs/libevent/strlcpy-internal.h @@ -1,19 +1,19 @@ -#ifndef STRLCPY_INTERNAL_H_INCLUDED_ -#define STRLCPY_INTERNAL_H_INCLUDED_ +#ifndef STRLCPY_INTERNAL_H_INCLUDED_ +#define STRLCPY_INTERNAL_H_INCLUDED_ #ifdef __cplusplus extern "C" { #endif #include "event2/event-config.h" -#include "event2/visibility.h" -#include "evconfig-private.h" +#include "event2/visibility.h" +#include "evconfig-private.h" -#ifndef EVENT__HAVE_STRLCPY +#ifndef EVENT__HAVE_STRLCPY #include <string.h> -EVENT2_EXPORT_SYMBOL -size_t event_strlcpy_(char *dst, const char *src, size_t siz); -#define strlcpy event_strlcpy_ +EVENT2_EXPORT_SYMBOL +size_t event_strlcpy_(char *dst, const char *src, size_t siz); +#define strlcpy event_strlcpy_ #endif #ifdef __cplusplus diff --git a/contrib/libs/libevent/time-internal.h b/contrib/libs/libevent/time-internal.h index e79e6a528d..eaad36d53e 100644 --- a/contrib/libs/libevent/time-internal.h +++ b/contrib/libs/libevent/time-internal.h @@ -1,101 +1,101 @@ -/* - * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> - * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef TIME_INTERNAL_H_INCLUDED_ -#define TIME_INTERNAL_H_INCLUDED_ - -#include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef EVENT__HAVE_MACH_MACH_TIME_H -/* For mach_timebase_info */ -#include <mach/mach_time.h> -#endif - -#include <time.h> - -#include "event2/util.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) -#define HAVE_POSIX_MONOTONIC -#elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) -#define HAVE_MACH_MONOTONIC -#elif defined(_WIN32) -#define HAVE_WIN32_MONOTONIC -#else -#define HAVE_FALLBACK_MONOTONIC -#endif - -long evutil_tv_to_msec_(const struct timeval *tv); -EVENT2_EXPORT_SYMBOL -void evutil_usleep_(const struct timeval *tv); - -#ifdef _WIN32 -typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void); -#endif - -struct evutil_monotonic_timer { - -#ifdef HAVE_MACH_MONOTONIC - struct mach_timebase_info mach_timebase_units; -#endif - -#ifdef HAVE_POSIX_MONOTONIC - int monotonic_clock; -#endif - -#ifdef HAVE_WIN32_MONOTONIC - ev_GetTickCount_func GetTickCount64_fn; - ev_GetTickCount_func GetTickCount_fn; - ev_uint64_t last_tick_count; - ev_uint64_t adjust_tick_count; - - ev_uint64_t first_tick; - ev_uint64_t first_counter; - double usec_per_count; - int use_performance_counter; -#endif - - struct timeval adjust_monotonic_clock; - struct timeval last_time; -}; - -EVENT2_EXPORT_SYMBOL -int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, - int flags); -EVENT2_EXPORT_SYMBOL -int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); - - -#ifdef __cplusplus -} -#endif - -#endif /* EVENT_INTERNAL_H_INCLUDED_ */ +/* + * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu> + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef TIME_INTERNAL_H_INCLUDED_ +#define TIME_INTERNAL_H_INCLUDED_ + +#include "event2/event-config.h" +#include "evconfig-private.h" + +#ifdef EVENT__HAVE_MACH_MACH_TIME_H +/* For mach_timebase_info */ +#include <mach/mach_time.h> +#endif + +#include <time.h> + +#include "event2/util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) +#define HAVE_POSIX_MONOTONIC +#elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) +#define HAVE_MACH_MONOTONIC +#elif defined(_WIN32) +#define HAVE_WIN32_MONOTONIC +#else +#define HAVE_FALLBACK_MONOTONIC +#endif + +long evutil_tv_to_msec_(const struct timeval *tv); +EVENT2_EXPORT_SYMBOL +void evutil_usleep_(const struct timeval *tv); + +#ifdef _WIN32 +typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void); +#endif + +struct evutil_monotonic_timer { + +#ifdef HAVE_MACH_MONOTONIC + struct mach_timebase_info mach_timebase_units; +#endif + +#ifdef HAVE_POSIX_MONOTONIC + int monotonic_clock; +#endif + +#ifdef HAVE_WIN32_MONOTONIC + ev_GetTickCount_func GetTickCount64_fn; + ev_GetTickCount_func GetTickCount_fn; + ev_uint64_t last_tick_count; + ev_uint64_t adjust_tick_count; + + ev_uint64_t first_tick; + ev_uint64_t first_counter; + double usec_per_count; + int use_performance_counter; +#endif + + struct timeval adjust_monotonic_clock; + struct timeval last_time; +}; + +EVENT2_EXPORT_SYMBOL +int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, + int flags); +EVENT2_EXPORT_SYMBOL +int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); + + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT_INTERNAL_H_INCLUDED_ */ diff --git a/contrib/libs/libevent/util-internal.h b/contrib/libs/libevent/util-internal.h index 39576c71ca..6eac196626 100644 --- a/contrib/libs/libevent/util-internal.h +++ b/contrib/libs/libevent/util-internal.h @@ -23,77 +23,77 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef UTIL_INTERNAL_H_INCLUDED_ -#define UTIL_INTERNAL_H_INCLUDED_ +#ifndef UTIL_INTERNAL_H_INCLUDED_ +#define UTIL_INTERNAL_H_INCLUDED_ #include "event2/event-config.h" -#include "evconfig-private.h" - +#include "evconfig-private.h" + #include <errno.h> /* For EVUTIL_ASSERT */ #include "log-internal.h" #include <stdio.h> #include <stdlib.h> -#ifdef EVENT__HAVE_SYS_SOCKET_H +#ifdef EVENT__HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif -#ifdef EVENT__HAVE_SYS_EVENTFD_H -#include <sys/eventfd.h> -#endif +#ifdef EVENT__HAVE_SYS_EVENTFD_H +#include <sys/eventfd.h> +#endif #include "event2/util.h" -#include "time-internal.h" +#include "time-internal.h" #include "ipv6-internal.h" #ifdef __cplusplus extern "C" { #endif -/* __has_attribute() wrapper */ -#ifdef __has_attribute -# define EVUTIL_HAS_ATTRIBUTE __has_attribute -#endif -/** clang 3 __has_attribute misbehaves in some versions */ -#if defined(__clang__) && __clang__ == 1 -# if defined(__apple_build_version__) -# if __clang_major__ <= 6 -# undef EVUTIL_HAS_ATTRIBUTE -# endif -# else /* !__apple_build_version__ */ -# if __clang_major__ == 3 && __clang_minor__ >= 2 && __clang_minor__ <= 5 -# undef EVUTIL_HAS_ATTRIBUTE -# endif -# endif /* __apple_build_version__ */ -#endif /*\ defined(__clang__) && __clang__ == 1 */ -#ifndef EVUTIL_HAS_ATTRIBUTE -# define EVUTIL_HAS_ATTRIBUTE(x) 0 -#endif - +/* __has_attribute() wrapper */ +#ifdef __has_attribute +# define EVUTIL_HAS_ATTRIBUTE __has_attribute +#endif +/** clang 3 __has_attribute misbehaves in some versions */ +#if defined(__clang__) && __clang__ == 1 +# if defined(__apple_build_version__) +# if __clang_major__ <= 6 +# undef EVUTIL_HAS_ATTRIBUTE +# endif +# else /* !__apple_build_version__ */ +# if __clang_major__ == 3 && __clang_minor__ >= 2 && __clang_minor__ <= 5 +# undef EVUTIL_HAS_ATTRIBUTE +# endif +# endif /* __apple_build_version__ */ +#endif /*\ defined(__clang__) && __clang__ == 1 */ +#ifndef EVUTIL_HAS_ATTRIBUTE +# define EVUTIL_HAS_ATTRIBUTE(x) 0 +#endif + /* If we need magic to say "inline", get it for free internally. */ -#ifdef EVENT__inline -#define inline EVENT__inline +#ifdef EVENT__inline +#define inline EVENT__inline #endif - -/* Define to appropriate substitute if compiler doesnt have __func__ */ -#if defined(EVENT__HAVE___func__) -# ifndef __func__ -# define __func__ __func__ -# endif -#elif defined(EVENT__HAVE___FUNCTION__) -# define __func__ __FUNCTION__ -#else -# define __func__ __FILE__ + +/* Define to appropriate substitute if compiler doesnt have __func__ */ +#if defined(EVENT__HAVE___func__) +# ifndef __func__ +# define __func__ __func__ +# endif +#elif defined(EVENT__HAVE___FUNCTION__) +# define __func__ __FUNCTION__ +#else +# define __func__ __FILE__ #endif /* A good no-op to use in macro definitions. */ -#define EVUTIL_NIL_STMT_ ((void)0) +#define EVUTIL_NIL_STMT_ ((void)0) /* A no-op that tricks the compiler into thinking a condition is used while * definitely not making any code for it. Used to compile out asserts while * avoiding "unused variable" warnings. The "!" forces the compiler to * do the sizeof() on an int, in case "condition" is a bitfield value. */ -#define EVUTIL_NIL_CONDITION_(condition) do { \ +#define EVUTIL_NIL_CONDITION_(condition) do { \ (void)sizeof(!(condition)); \ } while(0) @@ -105,36 +105,36 @@ extern "C" { data," and we need to look at the error code. Second, Windows defines a different set of error codes for sockets. */ -#ifndef _WIN32 - -#if EAGAIN == EWOULDBLOCK -#define EVUTIL_ERR_IS_EAGAIN(e) \ - ((e) == EAGAIN) -#else -#define EVUTIL_ERR_IS_EAGAIN(e) \ - ((e) == EAGAIN || (e) == EWOULDBLOCK) -#endif +#ifndef _WIN32 +#if EAGAIN == EWOULDBLOCK +#define EVUTIL_ERR_IS_EAGAIN(e) \ + ((e) == EAGAIN) +#else +#define EVUTIL_ERR_IS_EAGAIN(e) \ + ((e) == EAGAIN || (e) == EWOULDBLOCK) +#endif + /* True iff e is an error that means a read/write operation can be retried. */ #define EVUTIL_ERR_RW_RETRIABLE(e) \ - ((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e)) + ((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e)) /* True iff e is an error that means an connect can be retried. */ #define EVUTIL_ERR_CONNECT_RETRIABLE(e) \ ((e) == EINTR || (e) == EINPROGRESS) /* True iff e is an error that means a accept can be retried. */ #define EVUTIL_ERR_ACCEPT_RETRIABLE(e) \ - ((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e) || (e) == ECONNABORTED) + ((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e) || (e) == ECONNABORTED) /* True iff e is an error that means the connection was refused */ #define EVUTIL_ERR_CONNECT_REFUSED(e) \ ((e) == ECONNREFUSED) #else -/* Win32 */ - -#define EVUTIL_ERR_IS_EAGAIN(e) \ - ((e) == WSAEWOULDBLOCK || (e) == EAGAIN) +/* Win32 */ +#define EVUTIL_ERR_IS_EAGAIN(e) \ + ((e) == WSAEWOULDBLOCK || (e) == EAGAIN) + #define EVUTIL_ERR_RW_RETRIABLE(e) \ ((e) == WSAEWOULDBLOCK || \ (e) == WSAEINTR) @@ -162,7 +162,7 @@ extern "C" { #ifdef SHUT_WR #define EVUTIL_SHUT_WR SHUT_WR #else -#define EVUTIL_SHUT_WR 1 /* SD_SEND */ +#define EVUTIL_SHUT_WR 1 /* SD_SEND */ #endif #ifdef SHUT_BOTH #define EVUTIL_SHUT_BOTH SHUT_BOTH @@ -170,106 +170,106 @@ extern "C" { #define EVUTIL_SHUT_BOTH 2 #endif -/* Helper: Verify that all the elements in 'dlist' are internally consistent. - * Checks for circular lists and bad prev/next pointers. - * - * Example usage: - * EVUTIL_ASSERT_LIST_OK(eventlist, event, ev_next); - */ -#define EVUTIL_ASSERT_LIST_OK(dlist, type, field) do { \ - struct type *elm1, *elm2, **nextp; \ - if (LIST_EMPTY((dlist))) \ - break; \ - \ - /* Check list for circularity using Floyd's */ \ - /* 'Tortoise and Hare' algorithm */ \ - elm1 = LIST_FIRST((dlist)); \ - elm2 = LIST_NEXT(elm1, field); \ - while (elm1 && elm2) { \ - EVUTIL_ASSERT(elm1 != elm2); \ - elm1 = LIST_NEXT(elm1, field); \ - elm2 = LIST_NEXT(elm2, field); \ - if (!elm2) \ - break; \ - EVUTIL_ASSERT(elm1 != elm2); \ - elm2 = LIST_NEXT(elm2, field); \ - } \ - \ - /* Now check next and prev pointers for consistency. */ \ - nextp = &LIST_FIRST((dlist)); \ - elm1 = LIST_FIRST((dlist)); \ - while (elm1) { \ - EVUTIL_ASSERT(*nextp == elm1); \ - EVUTIL_ASSERT(nextp == elm1->field.le_prev); \ - nextp = &LIST_NEXT(elm1, field); \ - elm1 = *nextp; \ - } \ - } while (0) - -/* Helper: Verify that all the elements in a TAILQ are internally consistent. - * Checks for circular lists and bad prev/next pointers. - * - * Example usage: - * EVUTIL_ASSERT_TAILQ_OK(activelist, event, ev_active_next); - */ -#define EVUTIL_ASSERT_TAILQ_OK(tailq, type, field) do { \ - struct type *elm1, *elm2, **nextp; \ - if (TAILQ_EMPTY((tailq))) \ - break; \ - \ - /* Check list for circularity using Floyd's */ \ - /* 'Tortoise and Hare' algorithm */ \ - elm1 = TAILQ_FIRST((tailq)); \ - elm2 = TAILQ_NEXT(elm1, field); \ - while (elm1 && elm2) { \ - EVUTIL_ASSERT(elm1 != elm2); \ - elm1 = TAILQ_NEXT(elm1, field); \ - elm2 = TAILQ_NEXT(elm2, field); \ - if (!elm2) \ - break; \ - EVUTIL_ASSERT(elm1 != elm2); \ - elm2 = TAILQ_NEXT(elm2, field); \ - } \ - \ - /* Now check next and prev pointers for consistency. */ \ - nextp = &TAILQ_FIRST((tailq)); \ - elm1 = TAILQ_FIRST((tailq)); \ - while (elm1) { \ - EVUTIL_ASSERT(*nextp == elm1); \ - EVUTIL_ASSERT(nextp == elm1->field.tqe_prev); \ - nextp = &TAILQ_NEXT(elm1, field); \ - elm1 = *nextp; \ - } \ - EVUTIL_ASSERT(nextp == (tailq)->tqh_last); \ - } while (0) - +/* Helper: Verify that all the elements in 'dlist' are internally consistent. + * Checks for circular lists and bad prev/next pointers. + * + * Example usage: + * EVUTIL_ASSERT_LIST_OK(eventlist, event, ev_next); + */ +#define EVUTIL_ASSERT_LIST_OK(dlist, type, field) do { \ + struct type *elm1, *elm2, **nextp; \ + if (LIST_EMPTY((dlist))) \ + break; \ + \ + /* Check list for circularity using Floyd's */ \ + /* 'Tortoise and Hare' algorithm */ \ + elm1 = LIST_FIRST((dlist)); \ + elm2 = LIST_NEXT(elm1, field); \ + while (elm1 && elm2) { \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm1 = LIST_NEXT(elm1, field); \ + elm2 = LIST_NEXT(elm2, field); \ + if (!elm2) \ + break; \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm2 = LIST_NEXT(elm2, field); \ + } \ + \ + /* Now check next and prev pointers for consistency. */ \ + nextp = &LIST_FIRST((dlist)); \ + elm1 = LIST_FIRST((dlist)); \ + while (elm1) { \ + EVUTIL_ASSERT(*nextp == elm1); \ + EVUTIL_ASSERT(nextp == elm1->field.le_prev); \ + nextp = &LIST_NEXT(elm1, field); \ + elm1 = *nextp; \ + } \ + } while (0) + +/* Helper: Verify that all the elements in a TAILQ are internally consistent. + * Checks for circular lists and bad prev/next pointers. + * + * Example usage: + * EVUTIL_ASSERT_TAILQ_OK(activelist, event, ev_active_next); + */ +#define EVUTIL_ASSERT_TAILQ_OK(tailq, type, field) do { \ + struct type *elm1, *elm2, **nextp; \ + if (TAILQ_EMPTY((tailq))) \ + break; \ + \ + /* Check list for circularity using Floyd's */ \ + /* 'Tortoise and Hare' algorithm */ \ + elm1 = TAILQ_FIRST((tailq)); \ + elm2 = TAILQ_NEXT(elm1, field); \ + while (elm1 && elm2) { \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm1 = TAILQ_NEXT(elm1, field); \ + elm2 = TAILQ_NEXT(elm2, field); \ + if (!elm2) \ + break; \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm2 = TAILQ_NEXT(elm2, field); \ + } \ + \ + /* Now check next and prev pointers for consistency. */ \ + nextp = &TAILQ_FIRST((tailq)); \ + elm1 = TAILQ_FIRST((tailq)); \ + while (elm1) { \ + EVUTIL_ASSERT(*nextp == elm1); \ + EVUTIL_ASSERT(nextp == elm1->field.tqe_prev); \ + nextp = &TAILQ_NEXT(elm1, field); \ + elm1 = *nextp; \ + } \ + EVUTIL_ASSERT(nextp == (tailq)->tqh_last); \ + } while (0) + /* Locale-independent replacements for some ctypes functions. Use these * when you care about ASCII's notion of character types, because you are about * to send those types onto the wire. */ -EVENT2_EXPORT_SYMBOL -int EVUTIL_ISALPHA_(char c); -EVENT2_EXPORT_SYMBOL -int EVUTIL_ISALNUM_(char c); -int EVUTIL_ISSPACE_(char c); -EVENT2_EXPORT_SYMBOL -int EVUTIL_ISDIGIT_(char c); -EVENT2_EXPORT_SYMBOL -int EVUTIL_ISXDIGIT_(char c); -int EVUTIL_ISPRINT_(char c); -int EVUTIL_ISLOWER_(char c); -int EVUTIL_ISUPPER_(char c); -EVENT2_EXPORT_SYMBOL -char EVUTIL_TOUPPER_(char c); -EVENT2_EXPORT_SYMBOL -char EVUTIL_TOLOWER_(char c); - -/** Remove all trailing horizontal whitespace (space or tab) from the end of a - * string */ -EVENT2_EXPORT_SYMBOL -void evutil_rtrim_lws_(char *); - - +EVENT2_EXPORT_SYMBOL +int EVUTIL_ISALPHA_(char c); +EVENT2_EXPORT_SYMBOL +int EVUTIL_ISALNUM_(char c); +int EVUTIL_ISSPACE_(char c); +EVENT2_EXPORT_SYMBOL +int EVUTIL_ISDIGIT_(char c); +EVENT2_EXPORT_SYMBOL +int EVUTIL_ISXDIGIT_(char c); +int EVUTIL_ISPRINT_(char c); +int EVUTIL_ISLOWER_(char c); +int EVUTIL_ISUPPER_(char c); +EVENT2_EXPORT_SYMBOL +char EVUTIL_TOUPPER_(char c); +EVENT2_EXPORT_SYMBOL +char EVUTIL_TOLOWER_(char c); + +/** Remove all trailing horizontal whitespace (space or tab) from the end of a + * string */ +EVENT2_EXPORT_SYMBOL +void evutil_rtrim_lws_(char *); + + /** Helper macro. If we know that a given pointer points to a field in a structure, return a pointer to the structure itself. Used to implement our half-baked C OO. Example: @@ -291,56 +291,56 @@ void evutil_rtrim_lws_(char *); /* As open(pathname, flags, mode), except that the file is always opened with * the close-on-exec flag set. (And the mode argument is mandatory.) */ -int evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode); +int evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode); -EVENT2_EXPORT_SYMBOL -int evutil_read_file_(const char *filename, char **content_out, size_t *len_out, +EVENT2_EXPORT_SYMBOL +int evutil_read_file_(const char *filename, char **content_out, size_t *len_out, int is_binary); -EVENT2_EXPORT_SYMBOL -int evutil_socket_connect_(evutil_socket_t *fd_ptr, const struct sockaddr *sa, int socklen); +EVENT2_EXPORT_SYMBOL +int evutil_socket_connect_(evutil_socket_t *fd_ptr, const struct sockaddr *sa, int socklen); -int evutil_socket_finished_connecting_(evutil_socket_t fd); +int evutil_socket_finished_connecting_(evutil_socket_t fd); -EVENT2_EXPORT_SYMBOL -int evutil_ersatz_socketpair_(int, int , int, evutil_socket_t[]); +EVENT2_EXPORT_SYMBOL +int evutil_ersatz_socketpair_(int, int , int, evutil_socket_t[]); -int evutil_resolve_(int family, const char *hostname, struct sockaddr *sa, +int evutil_resolve_(int family, const char *hostname, struct sockaddr *sa, ev_socklen_t *socklen, int port); -const char *evutil_getenv_(const char *name); - -/* Structure to hold the state of our weak random number generator. - */ -struct evutil_weakrand_state { - ev_uint32_t seed; -}; - -#define EVUTIL_WEAKRAND_MAX EV_INT32_MAX - -/* Initialize the state of a week random number generator based on 'seed'. If - * the seed is 0, construct a new seed based on not-very-strong platform - * entropy, like the PID and the time of day. - * - * This function, and the other evutil_weakrand* functions, are meant for - * speed, not security or statistical strength. If you need a RNG which an - * attacker can't predict, or which passes strong statistical tests, use the - * evutil_secure_rng* functions instead. - */ -EVENT2_EXPORT_SYMBOL -ev_uint32_t evutil_weakrand_seed_(struct evutil_weakrand_state *state, ev_uint32_t seed); -/* Return a pseudorandom value between 0 and EVUTIL_WEAKRAND_MAX inclusive. - * Updates the state in 'seed' as needed -- this value must be protected by a - * lock. - */ -EVENT2_EXPORT_SYMBOL -ev_int32_t evutil_weakrand_(struct evutil_weakrand_state *seed); -/* Return a pseudorandom value x such that 0 <= x < top. top must be no more - * than EVUTIL_WEAKRAND_MAX. Updates the state in 'seed' as needed -- this - * value must be proteced by a lock */ -EVENT2_EXPORT_SYMBOL -ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t top); - +const char *evutil_getenv_(const char *name); + +/* Structure to hold the state of our weak random number generator. + */ +struct evutil_weakrand_state { + ev_uint32_t seed; +}; + +#define EVUTIL_WEAKRAND_MAX EV_INT32_MAX + +/* Initialize the state of a week random number generator based on 'seed'. If + * the seed is 0, construct a new seed based on not-very-strong platform + * entropy, like the PID and the time of day. + * + * This function, and the other evutil_weakrand* functions, are meant for + * speed, not security or statistical strength. If you need a RNG which an + * attacker can't predict, or which passes strong statistical tests, use the + * evutil_secure_rng* functions instead. + */ +EVENT2_EXPORT_SYMBOL +ev_uint32_t evutil_weakrand_seed_(struct evutil_weakrand_state *state, ev_uint32_t seed); +/* Return a pseudorandom value between 0 and EVUTIL_WEAKRAND_MAX inclusive. + * Updates the state in 'seed' as needed -- this value must be protected by a + * lock. + */ +EVENT2_EXPORT_SYMBOL +ev_int32_t evutil_weakrand_(struct evutil_weakrand_state *seed); +/* Return a pseudorandom value x such that 0 <= x < top. top must be no more + * than EVUTIL_WEAKRAND_MAX. Updates the state in 'seed' as needed -- this + * value must be proteced by a lock */ +EVENT2_EXPORT_SYMBOL +ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t top); + /* Evaluates to the same boolean value as 'p', and hints to the compiler that * we expect this value to be false. */ #if defined(__GNUC__) && __GNUC__ >= 3 /* gcc 3.0 or later */ @@ -349,21 +349,21 @@ ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t #define EVUTIL_UNLIKELY(p) (p) #endif -#if EVUTIL_HAS_ATTRIBUTE(fallthrough) -#define EVUTIL_FALLTHROUGH __attribute__((fallthrough)) -#else -#define EVUTIL_FALLTHROUGH /* fallthrough */ -#endif - +#if EVUTIL_HAS_ATTRIBUTE(fallthrough) +#define EVUTIL_FALLTHROUGH __attribute__((fallthrough)) +#else +#define EVUTIL_FALLTHROUGH /* fallthrough */ +#endif + /* Replacement for assert() that calls event_errx on failure. */ #ifdef NDEBUG -#define EVUTIL_ASSERT(cond) EVUTIL_NIL_CONDITION_(cond) +#define EVUTIL_ASSERT(cond) EVUTIL_NIL_CONDITION_(cond) #define EVUTIL_FAILURE_CHECK(cond) 0 #else #define EVUTIL_ASSERT(cond) \ do { \ if (EVUTIL_UNLIKELY(!(cond))) { \ - event_errx(EVENT_ERR_ABORT_, \ + event_errx(EVENT_ERR_ABORT_, \ "%s:%d: Assertion %s failed in %s", \ __FILE__,__LINE__,#cond,__func__); \ /* In case a user-supplied handler tries to */ \ @@ -377,7 +377,7 @@ ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t #define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond) #endif -#ifndef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE +#ifndef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE /* Replacement for sockaddr storage that we can use internally on platforms * that lack it. It is not space-efficient, but neither is sockaddr_storage. */ @@ -393,7 +393,7 @@ struct sockaddr_storage { #endif /* Internal addrinfo error code. This one is returned from only from - * evutil_getaddrinfo_common_, when we are sure that we'll have to hit a DNS + * evutil_getaddrinfo_common_, when we are sure that we'll have to hit a DNS * server. */ #define EVUTIL_EAI_NEED_RESOLVE -90002 @@ -404,36 +404,36 @@ typedef struct evdns_getaddrinfo_request* (*evdns_getaddrinfo_fn)( const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, void (*cb)(int, struct evutil_addrinfo *, void *), void *arg); -EVENT2_EXPORT_SYMBOL -void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn); -typedef void (*evdns_getaddrinfo_cancel_fn)( - struct evdns_getaddrinfo_request *req); -EVENT2_EXPORT_SYMBOL -void evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn); - -EVENT2_EXPORT_SYMBOL -struct evutil_addrinfo *evutil_new_addrinfo_(struct sockaddr *sa, +EVENT2_EXPORT_SYMBOL +void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn); +typedef void (*evdns_getaddrinfo_cancel_fn)( + struct evdns_getaddrinfo_request *req); +EVENT2_EXPORT_SYMBOL +void evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn); + +EVENT2_EXPORT_SYMBOL +struct evutil_addrinfo *evutil_new_addrinfo_(struct sockaddr *sa, ev_socklen_t socklen, const struct evutil_addrinfo *hints); -EVENT2_EXPORT_SYMBOL -struct evutil_addrinfo *evutil_addrinfo_append_(struct evutil_addrinfo *first, +EVENT2_EXPORT_SYMBOL +struct evutil_addrinfo *evutil_addrinfo_append_(struct evutil_addrinfo *first, struct evutil_addrinfo *append); -EVENT2_EXPORT_SYMBOL -void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints); -EVENT2_EXPORT_SYMBOL -int evutil_getaddrinfo_common_(const char *nodename, const char *servname, +EVENT2_EXPORT_SYMBOL +void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints); +EVENT2_EXPORT_SYMBOL +int evutil_getaddrinfo_common_(const char *nodename, const char *servname, struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum); -struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_( - struct evdns_base *dns_base, +struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_( + struct evdns_base *dns_base, const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, void (*cb)(int, struct evutil_addrinfo *, void *), void *arg); -void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data); +void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data); /** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or * ::1). */ -EVENT2_EXPORT_SYMBOL -int evutil_sockaddr_is_loopback_(const struct sockaddr *sa); +EVENT2_EXPORT_SYMBOL +int evutil_sockaddr_is_loopback_(const struct sockaddr *sa); /** @@ -441,18 +441,18 @@ int evutil_sockaddr_is_loopback_(const struct sockaddr *sa); Returns a pointer to out. Always writes something into out, so it's safe to use the output of this function without checking it for NULL. */ -EVENT2_EXPORT_SYMBOL -const char *evutil_format_sockaddr_port_(const struct sockaddr *sa, char *out, size_t outlen); - -int evutil_hex_char_to_int_(char c); +EVENT2_EXPORT_SYMBOL +const char *evutil_format_sockaddr_port_(const struct sockaddr *sa, char *out, size_t outlen); +int evutil_hex_char_to_int_(char c); -void evutil_free_secure_rng_globals_(void); -void evutil_free_globals_(void); -#ifdef _WIN32 -EVENT2_EXPORT_SYMBOL -HMODULE evutil_load_windows_system_library_(const TCHAR *library_name); +void evutil_free_secure_rng_globals_(void); +void evutil_free_globals_(void); + +#ifdef _WIN32 +EVENT2_EXPORT_SYMBOL +HMODULE evutil_load_windows_system_library_(const TCHAR *library_name); #endif #ifndef EV_SIZE_FMT @@ -477,7 +477,7 @@ HMODULE evutil_load_windows_system_library_(const TCHAR *library_name); #define EV_SOCK_ARG(x) (x) #endif -#if defined(__STDC__) && defined(__STDC_VERSION__) && !defined(__MINGW64_VERSION_MAJOR) +#if defined(__STDC__) && defined(__STDC_VERSION__) && !defined(__MINGW64_VERSION_MAJOR) #if (__STDC_VERSION__ >= 199901L) #define EV_SIZE_FMT "%zu" #define EV_SSIZE_FMT "%zd" @@ -487,7 +487,7 @@ HMODULE evutil_load_windows_system_library_(const TCHAR *library_name); #endif #ifndef EV_SIZE_FMT -#if (EVENT__SIZEOF_SIZE_T <= EVENT__SIZEOF_LONG) +#if (EVENT__SIZEOF_SIZE_T <= EVENT__SIZEOF_LONG) #define EV_SIZE_FMT "%lu" #define EV_SSIZE_FMT "%ld" #define EV_SIZE_ARG(x) ((unsigned long)(x)) @@ -500,50 +500,50 @@ HMODULE evutil_load_windows_system_library_(const TCHAR *library_name); #endif #endif -EVENT2_EXPORT_SYMBOL -evutil_socket_t evutil_socket_(int domain, int type, int protocol); -evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr, - ev_socklen_t *addrlen, int flags); - - /* used by one of the test programs.. */ -EVENT2_EXPORT_SYMBOL -int evutil_make_internal_pipe_(evutil_socket_t fd[2]); -evutil_socket_t evutil_eventfd_(unsigned initval, int flags); - -#ifdef SOCK_NONBLOCK -#define EVUTIL_SOCK_NONBLOCK SOCK_NONBLOCK -#else -#define EVUTIL_SOCK_NONBLOCK 0x4000000 -#endif -#ifdef SOCK_CLOEXEC -#define EVUTIL_SOCK_CLOEXEC SOCK_CLOEXEC -#else -#define EVUTIL_SOCK_CLOEXEC 0x80000000 -#endif -#ifdef EFD_NONBLOCK -#define EVUTIL_EFD_NONBLOCK EFD_NONBLOCK -#else -#define EVUTIL_EFD_NONBLOCK 0x4000 -#endif -#ifdef EFD_CLOEXEC -#define EVUTIL_EFD_CLOEXEC EFD_CLOEXEC -#else -#define EVUTIL_EFD_CLOEXEC 0x8000 -#endif - +EVENT2_EXPORT_SYMBOL +evutil_socket_t evutil_socket_(int domain, int type, int protocol); +evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr, + ev_socklen_t *addrlen, int flags); + + /* used by one of the test programs.. */ +EVENT2_EXPORT_SYMBOL +int evutil_make_internal_pipe_(evutil_socket_t fd[2]); +evutil_socket_t evutil_eventfd_(unsigned initval, int flags); + +#ifdef SOCK_NONBLOCK +#define EVUTIL_SOCK_NONBLOCK SOCK_NONBLOCK +#else +#define EVUTIL_SOCK_NONBLOCK 0x4000000 +#endif +#ifdef SOCK_CLOEXEC +#define EVUTIL_SOCK_CLOEXEC SOCK_CLOEXEC +#else +#define EVUTIL_SOCK_CLOEXEC 0x80000000 +#endif +#ifdef EFD_NONBLOCK +#define EVUTIL_EFD_NONBLOCK EFD_NONBLOCK +#else +#define EVUTIL_EFD_NONBLOCK 0x4000 +#endif +#ifdef EFD_CLOEXEC +#define EVUTIL_EFD_CLOEXEC EFD_CLOEXEC +#else +#define EVUTIL_EFD_CLOEXEC 0x8000 +#endif + void evutil_memclear_(void *mem, size_t len); -struct in_addr; -struct in6_addr; - -/* This is a any, loopback, link-local, multicast */ -EVENT2_EXPORT_SYMBOL -int evutil_v4addr_is_local_(const struct in_addr *in); -/* This is a reserved, ipv4compat, ipv4map, loopback, - * link-local, multicast, or unspecified address. */ -EVENT2_EXPORT_SYMBOL -int evutil_v6addr_is_local_(const struct in6_addr *in); - +struct in_addr; +struct in6_addr; + +/* This is a any, loopback, link-local, multicast */ +EVENT2_EXPORT_SYMBOL +int evutil_v4addr_is_local_(const struct in_addr *in); +/* This is a reserved, ipv4compat, ipv4map, loopback, + * link-local, multicast, or unspecified address. */ +EVENT2_EXPORT_SYMBOL +int evutil_v6addr_is_local_(const struct in6_addr *in); + #ifdef __cplusplus } #endif diff --git a/contrib/libs/libevent/whatsnew-2.0.txt b/contrib/libs/libevent/whatsnew-2.0.txt index 3561fcb94c..1f685ecd45 100644 --- a/contrib/libs/libevent/whatsnew-2.0.txt +++ b/contrib/libs/libevent/whatsnew-2.0.txt @@ -358,7 +358,7 @@ What's New In Libevent 2.0 so far: any means provided to create an evbuffer except via evbuffer_new which heap-allocated the buffer. - If you need access to the whole buffer as a linear chunk of memory, the + If you need access to the whole buffer as a linear chunk of memory, the EVBUFFER_DATA() function still works. Watch out, though: it needs to copy the buffer's contents in a linear chunk before you can use it. diff --git a/contrib/libs/libevent/win32select.c b/contrib/libs/libevent/win32select.c index d005b587d4..ce8b7cee75 100644 --- a/contrib/libs/libevent/win32select.c +++ b/contrib/libs/libevent/win32select.c @@ -25,11 +25,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "event2/event-config.h" -#include "evconfig-private.h" - -#ifdef _WIN32 +#include "event2/event-config.h" +#include "evconfig-private.h" +#ifdef _WIN32 + #include <winsock2.h> #include <windows.h> #include <sys/types.h> @@ -49,7 +49,7 @@ #include "evmap-internal.h" #include "event2/thread.h" #include "evthread-internal.h" -#include "time-internal.h" +#include "time-internal.h" #define XFREE(ptr) do { if (ptr) mm_free(ptr); } while (0) @@ -57,7 +57,7 @@ extern struct event_list timequeue; extern struct event_list addqueue; struct win_fd_set { - unsigned int fd_count; + unsigned int fd_count; SOCKET fd_array[1]; }; @@ -81,8 +81,8 @@ struct win32op { }; static void *win32_init(struct event_base *); -static int win32_add(struct event_base *, evutil_socket_t, short old, short events, void *idx_); -static int win32_del(struct event_base *, evutil_socket_t, short old, short events, void *idx_); +static int win32_add(struct event_base *, evutil_socket_t, short old, short events, void *idx_); +static int win32_del(struct event_base *, evutil_socket_t, short old, short events, void *idx_); static int win32_dispatch(struct event_base *base, struct timeval *); static void win32_dealloc(struct event_base *); @@ -164,7 +164,7 @@ do_fd_clear(struct event_base *base, SOCKET s2; s2 = set->fd_array[i] = set->fd_array[set->fd_count]; - ent2 = evmap_io_get_fdinfo_(&base->io, s2); + ent2 = evmap_io_get_fdinfo_(&base->io, s2); if (!ent2) /* This indicates a bug. */ return (0); @@ -178,7 +178,7 @@ do_fd_clear(struct event_base *base, #define NEVENT 32 void * -win32_init(struct event_base *base) +win32_init(struct event_base *base) { struct win32op *winop; size_t size; @@ -200,11 +200,11 @@ win32_init(struct event_base *base) winop->readset_out->fd_count = winop->writeset_out->fd_count = winop->exset_out->fd_count = 0; - if (evsig_init_(base) < 0) + if (evsig_init_(base) < 0) winop->signals_are_broken = 1; - evutil_weakrand_seed_(&base->weakrand_seed, 0); - + evutil_weakrand_seed_(&base->weakrand_seed, 0); + return (winop); err: XFREE(winop->readset_in); @@ -218,10 +218,10 @@ win32_init(struct event_base *base) int win32_add(struct event_base *base, evutil_socket_t fd, - short old, short events, void *idx_) + short old, short events, void *idx_) { struct win32op *win32op = base->evbase; - struct idx_info *idx = idx_; + struct idx_info *idx = idx_; if ((events & EV_SIGNAL) && win32op->signals_are_broken) return (-1); @@ -243,10 +243,10 @@ win32_add(struct event_base *base, evutil_socket_t fd, int win32_del(struct event_base *base, evutil_socket_t fd, short old, short events, - void *idx_) + void *idx_) { struct win32op *win32op = base->evbase; - struct idx_info *idx = idx_; + struct idx_info *idx = idx_; event_debug(("%s: Removing event for "EV_SOCK_FMT, __func__, EV_SOCK_ARG(fd))); @@ -305,7 +305,7 @@ win32_dispatch(struct event_base *base, struct timeval *tv) win32op->readset_out->fd_count : win32op->writeset_out->fd_count; if (!fd_count) { - long msec = tv ? evutil_tv_to_msec_(tv) : LONG_MAX; + long msec = tv ? evutil_tv_to_msec_(tv) : LONG_MAX; /* Sleep's DWORD argument is unsigned long */ if (msec < 0) msec = LONG_MAX; @@ -326,50 +326,50 @@ win32_dispatch(struct event_base *base, struct timeval *tv) event_debug(("%s: select returned %d", __func__, res)); if (res <= 0) { - event_debug(("%s: %s", __func__, - evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()))); + event_debug(("%s: %s", __func__, + evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()))); return res; } if (win32op->readset_out->fd_count) { - i = evutil_weakrand_range_(&base->weakrand_seed, - win32op->readset_out->fd_count); + i = evutil_weakrand_range_(&base->weakrand_seed, + win32op->readset_out->fd_count); for (j=0; j<win32op->readset_out->fd_count; ++j) { if (++i >= win32op->readset_out->fd_count) i = 0; s = win32op->readset_out->fd_array[i]; - evmap_io_active_(base, s, EV_READ); + evmap_io_active_(base, s, EV_READ); } } if (win32op->exset_out->fd_count) { - i = evutil_weakrand_range_(&base->weakrand_seed, - win32op->exset_out->fd_count); + i = evutil_weakrand_range_(&base->weakrand_seed, + win32op->exset_out->fd_count); for (j=0; j<win32op->exset_out->fd_count; ++j) { if (++i >= win32op->exset_out->fd_count) i = 0; s = win32op->exset_out->fd_array[i]; - evmap_io_active_(base, s, EV_WRITE); + evmap_io_active_(base, s, EV_WRITE); } } if (win32op->writeset_out->fd_count) { - i = evutil_weakrand_range_(&base->weakrand_seed, - win32op->writeset_out->fd_count); + i = evutil_weakrand_range_(&base->weakrand_seed, + win32op->writeset_out->fd_count); for (j=0; j<win32op->writeset_out->fd_count; ++j) { if (++i >= win32op->writeset_out->fd_count) i = 0; s = win32op->writeset_out->fd_array[i]; - evmap_io_active_(base, s, EV_WRITE); + evmap_io_active_(base, s, EV_WRITE); } } return (0); } void -win32_dealloc(struct event_base *base) +win32_dealloc(struct event_base *base) { - struct win32op *win32op = base->evbase; + struct win32op *win32op = base->evbase; - evsig_dealloc_(base); + evsig_dealloc_(base); if (win32op->readset_in) mm_free(win32op->readset_in); if (win32op->writeset_in) @@ -385,5 +385,5 @@ win32_dealloc(struct event_base *base) memset(win32op, 0, sizeof(*win32op)); mm_free(win32op); } - -#endif + +#endif diff --git a/contrib/libs/libevent/ya.make b/contrib/libs/libevent/ya.make index acfe9868c6..617b52b4b4 100644 --- a/contrib/libs/libevent/ya.make +++ b/contrib/libs/libevent/ya.make @@ -1,5 +1,5 @@ # Generated by devtools/yamaker from nixpkgs d78cb9fc184bc9f4e3d046ed0175734950fd0342. - + LIBRARY() OWNER( @@ -8,9 +8,9 @@ OWNER( kikht g:cpp-contrib ) - + VERSION(2.1.12) - + ORIGINAL_SOURCE(https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz) LICENSE( @@ -22,32 +22,32 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -PEERDIR( - contrib/libs/libevent/event_core - contrib/libs/libevent/event_extra - contrib/libs/libevent/event_openssl - contrib/libs/libevent/event_thread +PEERDIR( + contrib/libs/libevent/event_core + contrib/libs/libevent/event_extra + contrib/libs/libevent/event_openssl + contrib/libs/libevent/event_thread ) ADDINCL( GLOBAL contrib/libs/libevent/include - contrib/libs/libevent + contrib/libs/libevent ) -NO_COMPILER_WARNINGS() +NO_COMPILER_WARNINGS() -NO_RUNTIME() +NO_RUNTIME() -CFLAGS( - -DHAVE_CONFIG_H - -DEVENT__HAVE_STRLCPY=1 +CFLAGS( + -DHAVE_CONFIG_H + -DEVENT__HAVE_STRLCPY=1 ) -END() +END() -RECURSE( - event_core - event_extra - event_openssl - event_thread +RECURSE( + event_core + event_extra + event_openssl + event_thread ) |