├── .clang-format ├── .github └── workflows │ ├── abi.yml │ ├── linux.yml │ ├── macos.yml │ ├── mingw.yml │ └── windows.yml ├── .gitignore ├── .mailmap ├── .uncrustify ├── CMakeLists.txt ├── CONTRIBUTING.md ├── ChangeLog ├── ChangeLog-1.4 ├── ChangeLog-2.0 ├── Doxyfile ├── LICENSE ├── Makefile.am ├── Makefile.nmake ├── README.md ├── Vagrantfile ├── WIN32-Code ├── getopt.c ├── getopt.h ├── getopt_long.c ├── nmake │ ├── evconfig-private.h │ └── event2 │ │ └── event-config.h └── tree.h ├── arc4random.c ├── autogen.sh ├── buffer.c ├── buffer_iocp.c ├── bufferevent-internal.h ├── bufferevent.c ├── bufferevent_async.c ├── bufferevent_filter.c ├── bufferevent_openssl.c ├── bufferevent_pair.c ├── bufferevent_ratelim.c ├── bufferevent_sock.c ├── changelist-internal.h ├── checkpatch.sh ├── cmake ├── AddCompilerFlags.cmake ├── AddEventLibrary.cmake ├── COPYING-CMAKE-SCRIPTS ├── CheckConstExists.cmake ├── CheckFileOffsetBits.c ├── CheckFileOffsetBits.cmake ├── CheckFunctionKeywords.cmake ├── CheckPrototypeDefinition.c.in ├── CheckPrototypeDefinition.cmake ├── CheckWorkingKqueue.cmake ├── CodeCoverage.cmake ├── Copyright.txt ├── LibeventConfig.cmake.in ├── LibeventConfigVersion.cmake.in ├── Macros.cmake ├── Uninstall.cmake.in ├── UseDoxygen.cmake └── VersionViaGit.cmake ├── compat └── sys │ └── queue.h ├── config.h ├── configure.ac ├── defer-internal.h ├── devpoll.c ├── doxygen.am ├── epoll.c ├── epoll_sub.c ├── epolltable-internal.h ├── evbuffer-internal.h ├── evconfig-private.h ├── evconfig-private.h.cmake ├── evconfig-private.h.in ├── evdns.3 ├── evdns.c ├── event-config.h.cmake ├── event-internal.h ├── event.3 ├── event.c ├── event_iocp.c ├── event_rpcgen.py ├── event_tagging.c ├── evmap-internal.h ├── evmap.c ├── evport.c ├── evrpc-internal.h ├── evrpc.c ├── evsignal-internal.h ├── evthread-internal.h ├── evthread.c ├── evthread_pthread.c ├── evthread_win32.c ├── evutil.c ├── evutil_rand.c ├── evutil_time.c ├── extra ├── abi-check │ ├── README.md │ ├── abi_check.sh │ └── libevent.json ├── lsan.supp └── tsan.supp ├── ht-internal.h ├── http-internal.h ├── http.c ├── include ├── evdns.h ├── event.h ├── event2 │ ├── buffer.h │ ├── buffer_compat.h │ ├── bufferevent.h │ ├── bufferevent_compat.h │ ├── bufferevent_ssl.h │ ├── bufferevent_struct.h │ ├── dns.h │ ├── dns_compat.h │ ├── dns_struct.h │ ├── event-config.h │ ├── event.h │ ├── event_compat.h │ ├── event_struct.h │ ├── http.h │ ├── http_compat.h │ ├── http_struct.h │ ├── keyvalq_struct.h │ ├── listener.h │ ├── rpc.h │ ├── rpc_compat.h │ ├── rpc_struct.h │ ├── tag.h │ ├── tag_compat.h │ ├── thread.h │ ├── util.h │ └── visibility.h ├── evhttp.h ├── evrpc.h ├── evutil.h └── include.am ├── iocp-internal.h ├── ipv6-internal.h ├── kqueue-internal.h ├── kqueue.c ├── libevent.pc.in ├── libevent_core.pc.in ├── libevent_extra.pc.in ├── libevent_openssl.pc.in ├── libevent_pthreads.pc.in ├── listener.c ├── log-internal.h ├── log.c ├── m4 ├── ac_backport_259_ssizet.m4 ├── acx_pthread.m4 ├── ax_check_funcs_ex.m4 ├── ax_prog_doxygen.m4 ├── libevent_openssl.m4 └── ntp_pkg_config.m4 ├── make-event-config.sed ├── make_epoll_table.py ├── minheap-internal.h ├── mm-internal.h ├── openssl-compat.h ├── poll.c ├── ratelim-internal.h ├── sample ├── dns-example.c ├── event-read-fifo.c ├── hello-world.c ├── hostcheck.c ├── hostcheck.h ├── http-connect.c ├── http-server.c ├── https-client.c ├── include.am ├── le-proxy.c ├── openssl_hostname_validation.c ├── openssl_hostname_validation.h ├── signal-test.c └── time-test.c ├── select.c ├── signal.c ├── strlcpy-internal.h ├── strlcpy.c ├── test-export ├── CMakeLists.txt ├── test-export.c └── test-export.py ├── test ├── Makefile.nmake ├── bench.c ├── bench_cascade.c ├── bench_http.c ├── bench_httpclient.c ├── check-dumpevents.py ├── include.am ├── print-winsock-errors.c ├── regress.c ├── regress.h ├── regress.rpc ├── regress_buffer.c ├── regress_bufferevent.c ├── regress_dns.c ├── regress_et.c ├── regress_finalize.c ├── regress_http.c ├── regress_iocp.c ├── regress_listener.c ├── regress_main.c ├── regress_minheap.c ├── regress_rpc.c ├── regress_ssl.c ├── regress_testutils.c ├── regress_testutils.h ├── regress_thread.c ├── regress_thread.h ├── regress_util.c ├── regress_zlib.c ├── rpcgen_wrapper.sh ├── test-changelist.c ├── test-closed.c ├── test-dumpevents.c ├── test-eof.c ├── test-fdleak.c ├── test-init.c ├── test-ratelim.c ├── test-ratelim.sh ├── test-time.c ├── test-weof.c ├── test.sh ├── tinytest.c ├── tinytest.h ├── tinytest_demo.c ├── tinytest_local.h └── tinytest_macros.h ├── time-internal.h ├── util-internal.h ├── whatsnew-2.0.txt ├── whatsnew-2.1.txt └── win32select.c /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | 5 | AccessModifierOffset: -4 6 | 7 | AlignAfterOpenBracket: DontAlign 8 | AlignEscapedNewlinesLeft: true 9 | # AlignOperands: true 10 | AlignTrailingComments: true 11 | 12 | AllowAllParametersOfDeclarationOnNextLine: true 13 | AllowShortBlocksOnASingleLine: false 14 | AllowShortCaseLabelsOnASingleLine: false 15 | AllowShortFunctionsOnASingleLine: All 16 | AllowShortIfStatementsOnASingleLine: false 17 | AllowShortLoopsOnASingleLine: false 18 | 19 | AlwaysBreakAfterDefinitionReturnType: All 20 | AlwaysBreakBeforeMultilineStrings: false 21 | AlwaysBreakTemplateDeclarations: false 22 | 23 | # BinPackArguments: false 24 | # BinPackParameters: true 25 | 26 | BreakBeforeBinaryOperators: false 27 | BreakBeforeBraces: Custom 28 | BraceWrapping: { AfterFunction: true } 29 | BreakBeforeTernaryOperators: true 30 | BreakConstructorInitializersBeforeComma: true 31 | 32 | ColumnLimit: 80 33 | 34 | ContinuationIndentWidth: 4 35 | 36 | DerivePointerAlignment: false #XXX 37 | DisableFormat: false 38 | ExperimentalAutoDetectBinPacking: false #XXX 39 | ForEachMacros: [ LIST_FOREACH, SIMPLEQ_FOREACH, CIRCLEQ_FOREACH, TAILQ_FOREACH, TAILQ_FOREACH_REVERSE, HT_FOREACH ] 40 | 41 | IndentCaseLabels: false 42 | IndentFunctionDeclarationAfterType: false 43 | IndentWidth: 4 44 | IndentWrappedFunctionNames: false 45 | 46 | KeepEmptyLinesAtTheStartOfBlocks: true 47 | MaxEmptyLinesToKeep: 2 48 | 49 | PointerAlignment: Right #XXX 50 | 51 | # SpaceAfterCStyleCast: false 52 | SpaceBeforeAssignmentOperators: true 53 | SpaceBeforeParens: ControlStatements 54 | SpaceInEmptyParentheses: false 55 | SpacesBeforeTrailingComments: 1 56 | SpacesInAngles: false 57 | SpacesInCStyleCastParentheses: false 58 | SpacesInParentheses: false 59 | Standard: Cpp03 60 | TabWidth: 4 61 | UseTab: Always 62 | SortIncludes: false 63 | ... 64 | -------------------------------------------------------------------------------- /.github/workflows/abi.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: abi 3 | 4 | on: 5 | push: 6 | branches: 7 | - patches-2.1 8 | - release-*-pull 9 | tags: 10 | - release-* 11 | 12 | jobs: 13 | abi: 14 | runs-on: ubuntu-18.04 15 | if: "!contains(github.event.head_commit.message, 'ci skip')" 16 | strategy: 17 | fail-fast: false 18 | 19 | steps: 20 | - uses: actions/checkout@v2.0.0 21 | 22 | - name: Install Dependencies 23 | run: 24 | sudo apt install 25 | abi-tracker 26 | abi-monitor 27 | abi-dumper 28 | abi-compliance-checker 29 | pkgdiff 30 | vtable-dumper 31 | 32 | - name: Generate 33 | shell: bash 34 | run: | 35 | ./extra/abi-check/abi_check.sh 36 | env: 37 | ABI_CHECK_ROOT: /tmp/le-abi-root 38 | 39 | - uses: actions/upload-artifact@v1 40 | with: 41 | name: build 42 | path: /tmp/le-abi-root/work/abi-check 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### These files should get ignored no matter where they appear. 2 | 3 | # Editors leave these lying around 4 | \#*\# 5 | .#* 6 | *~ 7 | *.swp 8 | 9 | # C stuff 10 | *.o 11 | 12 | # Windows stuff 13 | *.obj 14 | *.exe 15 | *.lib 16 | 17 | # Patch leaves these lying arround 18 | *.orig 19 | *.rej 20 | 21 | # gcov stuff 22 | *.gcno 23 | *.gcov 24 | *.gcda 25 | 26 | # gdb stuff 27 | .gdb_history 28 | 29 | # Autotools stuff 30 | .deps 31 | .dirstamp 32 | Makefile 33 | Makefile.in 34 | 35 | # Libtool stuff 36 | .libs 37 | *.lo 38 | *.la 39 | 40 | # ctags stuff 41 | TAGS 42 | tags 43 | 44 | # cscope stuff 45 | cscope* 46 | 47 | # Stuff made by our makefiles 48 | *.pc 49 | *.log 50 | *.trs 51 | 52 | ## The initial / makes these files only get ignored in particular directories. 53 | /autom4te.cache 54 | 55 | # configure in progress 56 | /.cyg* 57 | /confdefs.* 58 | /conftest.* 59 | 60 | # Libtool adds these, at least sometimes 61 | /m4/libtool.m4 62 | /m4/ltoptions.m4 63 | /m4/ltsugar.m4 64 | /m4/ltversion.m4 65 | /m4/lt~obsolete.m4 66 | 67 | /aclocal.m4 68 | /compile 69 | /config.cache 70 | /config.guess 71 | /config.log 72 | /config.status 73 | /config.sub 74 | /configure 75 | /configure.lineno 76 | /depcomp 77 | /config.h.in 78 | /install-sh 79 | /libtool 80 | /ltmain.sh 81 | /missing 82 | /stamp-h1 83 | /stamp-h2 84 | 85 | # files generated by doxygen 86 | doxygen 87 | CMakeDoxyfile.in 88 | CMakeDoxygenDefaults.cmake 89 | Doxyfile.doxygen 90 | 91 | /sample/dns-example 92 | /sample/event-read-fifo 93 | /sample/hello-world 94 | /sample/http-server 95 | /sample/http-connect 96 | /sample/le-proxy 97 | /sample/https-client 98 | /sample/signal-test 99 | /sample/time-test 100 | /sample/event-test 101 | 102 | /test-driver 103 | /test/bench 104 | /test/bench_cascade 105 | /test/bench_http 106 | /test/bench_httpclient 107 | /test/regress 108 | /test/regress.gen.c 109 | /test/regress.gen.h 110 | /test/rpcgen-attempted 111 | /test/test-dumpevents 112 | /test/test-eof 113 | /test/test-closed 114 | /test/test-init 115 | /test/test-ratelim 116 | /test/test-script.sh 117 | /test/test-time 118 | /test/test-weof 119 | /test/test-changelist 120 | /test/test-fdleak 121 | 122 | **/include/evconfig-private.h 123 | 124 | # Files generated by cmake 125 | CMakeCache.txt 126 | CMakeFiles/ 127 | CTestTestfile.cmake 128 | DartConfiguration.tcl 129 | LibeventConfig.cmake 130 | LibeventConfigVersion.cmake 131 | LibeventTargets*.cmake 132 | bin/ 133 | cmake_install.cmake 134 | Uninstall.cmake 135 | lib/ 136 | tmp/ 137 | verify_tests.sh 138 | verify_tests.bat 139 | event.dir 140 | event_core.dir 141 | event_extra.dir 142 | *.vcxproj 143 | *.sln 144 | *.filters 145 | install_manifest.txt 146 | test-export/build 147 | 148 | # ninja 149 | build.ninja 150 | rules.ninja 151 | .ninja_deps 152 | .ninja_log 153 | 154 | # make dist 155 | /COPYING 156 | /INSTALL 157 | /*.tar.gz 158 | 159 | /.vagrant 160 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # name -> email 2 | Azat Khuzhin 3 | yuangongji 4 | 5 | # primary email -> alias 6 | 7 | yuangongji <82787816@qq.com> 8 | -------------------------------------------------------------------------------- /.uncrustify: -------------------------------------------------------------------------------- 1 | input_tab_size = 8 2 | output_tab_size = 8 3 | indent_with_tabs = 2 4 | indent_cmt_with_tabs = false 5 | indent_brace_parent = false 6 | indent_func_call_param = true 7 | indent_func_def_param = true 8 | sp_enum_before_assign = add 9 | sp_enum_after_assign = add 10 | sp_inside_paren = remove 11 | sp_paren_brace = add 12 | sp_before_ptr_star = add 13 | sp_before_unnamed_ptr_star = add 14 | sp_between_ptr_star = remove 15 | sp_after_ptr_star = remove 16 | sp_after_ptr_star_func = add 17 | sp_before_ptr_star_func = add 18 | sp_before_sparen = add 19 | sp_inside_sparen = remove 20 | sp_inside_sparen_close = remove 21 | sp_after_sparen = add 22 | sp_sparen_brace = add 23 | sp_special_semi = remove 24 | sp_before_semi_for = remove 25 | sp_after_comma = add 26 | sp_after_cast = remove 27 | sp_inside_braces_struct = add 28 | sp_type_func = remove 29 | sp_func_def_paren = remove 30 | sp_inside_fparen = remove 31 | sp_fparen_brace = add 32 | sp_func_call_paren = remove 33 | sp_else_brace = add 34 | sp_after_oc_block_caret = remove 35 | align_keep_tabs = true 36 | align_with_tabs = true 37 | align_on_tabstop = true 38 | nl_fcall_brace = remove 39 | nl_enum_brace = remove 40 | nl_struct_brace = remove 41 | nl_union_brace = remove 42 | nl_if_brace = remove 43 | nl_brace_else = remove 44 | nl_elseif_brace = remove 45 | nl_else_brace = remove 46 | nl_else_if = remove 47 | nl_for_brace = remove 48 | sp_after_semi_for_empty = remove 49 | nl_while_brace = remove 50 | nl_do_brace = remove 51 | nl_brace_while = remove 52 | nl_switch_brace = remove 53 | nl_func_type_name = add 54 | nl_fdef_brace = add 55 | mod_paren_on_return = ignore 56 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the libevent 2 | 3 | ## Coding style 4 | 5 | First and most generic rule: **just look around**. 6 | 7 | But, we have a script for checking patches/files/git-refs: 8 | ```shell 9 | # Chech HEAD git ref 10 | ./checkpatch.sh -r 11 | ./checkpatch.sh -r HEAD 12 | 13 | # Check patch 14 | git format-patch --stdout -1 | ./checkpatch.sh -p 15 | git show -1 | ./checkpatch.sh -p 16 | 17 | # Or via regular files 18 | git format-patch --stdout -2 19 | ./checkpatch.sh *.patch 20 | 21 | # Over a file 22 | ./checkpatch.sh -d event.c 23 | ./checkpatch.sh -d < event.c 24 | 25 | # And print the whole file not only summary 26 | ./checkpatch.sh -f event.c 27 | ./checkpatch.sh -f < event.c 28 | 29 | # See 30 | ./checkpatch.sh -h 31 | ``` 32 | 33 | ## Testing 34 | - Write new unit test in `test/regress_{MORE_SUITABLE_FOR_YOU}.c` 35 | - `make verify` 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Libevent is available for use under the following license, commonly known 2 | as the 3-clause (or "modified") BSD license: 3 | 4 | ============================== 5 | Copyright (c) 2000-2007 Niels Provos 6 | Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | ============================== 30 | 31 | Portions of Libevent are based on works by others, also made available by 32 | them under the three-clause BSD license above. The copyright notices are 33 | available in the corresponding source files; the license is as above. Here's 34 | a list: 35 | 36 | log.c: 37 | Copyright (c) 2000 Dug Song 38 | Copyright (c) 1993 The Regents of the University of California. 39 | 40 | strlcpy.c: 41 | Copyright (c) 1998 Todd C. Miller 42 | 43 | win32select.c: 44 | Copyright (c) 2003 Michael A. Davis 45 | 46 | evport.c: 47 | Copyright (c) 2007 Sun Microsystems 48 | 49 | ht-internal.h: 50 | Copyright (c) 2002 Christopher Clark 51 | 52 | minheap-internal.h: 53 | Copyright (c) 2006 Maxim Yegorushkin 54 | 55 | ============================== 56 | 57 | The arc4module is available under the following, sometimes called the 58 | "OpenBSD" license: 59 | 60 | Copyright (c) 1996, David Mazieres 61 | Copyright (c) 2008, Damien Miller 62 | 63 | Permission to use, copy, modify, and distribute this software for any 64 | purpose with or without fee is hereby granted, provided that the above 65 | copyright notice and this permission notice appear in all copies. 66 | 67 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 68 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 69 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 70 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 71 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 72 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 73 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 74 | 75 | ============================== 76 | 77 | The Windows timer code is based on code from libutp, which is 78 | distributed under this license, sometimes called the "MIT" license. 79 | 80 | 81 | Copyright (c) 2010 BitTorrent, Inc. 82 | 83 | Permission is hereby granted, free of charge, to any person obtaining a copy 84 | of this software and associated documentation files (the "Software"), to deal 85 | in the Software without restriction, including without limitation the rights 86 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 87 | copies of the Software, and to permit persons to whom the Software is 88 | furnished to do so, subject to the following conditions: 89 | 90 | The above copyright notice and this permission notice shall be included in 91 | all copies or substantial portions of the Software. 92 | 93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 98 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 99 | THE SOFTWARE. 100 | -------------------------------------------------------------------------------- /Makefile.nmake: -------------------------------------------------------------------------------- 1 | # WATCH OUT! This makefile is a work in progress. -*- makefile -*- 2 | # 3 | # I'm not very knowledgeable about MSVC and nmake beyond their most basic 4 | # aspects. If anything here looks wrong to you, please let me know. 5 | 6 | # If OPENSSL_DIR is not set, builds without OpenSSL support. If you want 7 | # OpenSSL support, you can set the OPENSSL_DIR variable to where you 8 | # installed OpenSSL. This can be done in the environment: 9 | # set OPENSSL_DIR=c:\openssl 10 | # Or on the nmake command line: 11 | # nmake OPENSSL_DIR=C:\openssl -f Makefile.nmake 12 | # Or by uncommenting the following line here in the makefile... 13 | 14 | # OPENSSL_DIR=c:\openssl 15 | 16 | !IFDEF OPENSSL_DIR 17 | SSL_CFLAGS=/I$(OPENSSL_DIR)\include /DEVENT__HAVE_OPENSSL 18 | !ELSE 19 | SSL_CFLAGS= 20 | !ENDIF 21 | 22 | # Needed for correctness 23 | CFLAGS=/IWIN32-Code /IWIN32-Code/nmake /Iinclude /Icompat /DHAVE_CONFIG_H /I. $(SSL_CFLAGS) 24 | 25 | # For optimization and warnings 26 | CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo 27 | 28 | # XXXX have a debug mode 29 | 30 | LIBFLAGS=/nologo 31 | 32 | CORE_OBJS=event.obj buffer.obj bufferevent.obj bufferevent_sock.obj \ 33 | bufferevent_pair.obj listener.obj evmap.obj log.obj evutil.obj \ 34 | strlcpy.obj signal.obj bufferevent_filter.obj evthread.obj \ 35 | bufferevent_ratelim.obj evutil_rand.obj evutil_time.obj 36 | WIN_OBJS=win32select.obj evthread_win32.obj buffer_iocp.obj \ 37 | event_iocp.obj bufferevent_async.obj 38 | EXTRA_OBJS=event_tagging.obj http.obj evdns.obj evrpc.obj 39 | 40 | !IFDEF OPENSSL_DIR 41 | SSL_OBJS=bufferevent_openssl.obj 42 | SSL_LIBS=libevent_openssl.lib 43 | !ELSE 44 | SSL_OBJS= 45 | SSL_LIBS= 46 | !ENDIF 47 | 48 | ALL_OBJS=$(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS) $(SSL_OBJS) 49 | STATIC_LIBS=libevent_core.lib libevent_extras.lib libevent.lib $(SSL_LIBS) 50 | 51 | 52 | all: static_libs tests 53 | 54 | static_libs: $(STATIC_LIBS) 55 | 56 | libevent_core.lib: $(CORE_OBJS) $(WIN_OBJS) 57 | lib $(LIBFLAGS) $(CORE_OBJS) $(WIN_OBJS) /out:libevent_core.lib 58 | 59 | libevent_extras.lib: $(EXTRA_OBJS) 60 | lib $(LIBFLAGS) $(EXTRA_OBJS) /out:libevent_extras.lib 61 | 62 | libevent.lib: $(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS) 63 | lib $(LIBFLAGS) $(CORE_OBJS) $(EXTRA_OBJS) $(WIN_OBJS) /out:libevent.lib 64 | 65 | libevent_openssl.lib: $(SSL_OBJS) 66 | lib $(LIBFLAGS) $(SSL_OBJS) /out:libevent_openssl.lib 67 | 68 | clean: 69 | del $(ALL_OBJS) 70 | del $(STATIC_LIBS) 71 | cd test 72 | $(MAKE) /F Makefile.nmake clean 73 | cd .. 74 | 75 | tests: 76 | cd test 77 | !IFDEF OPENSSL_DIR 78 | $(MAKE) OPENSSL_DIR=$(OPENSSL_DIR) /F Makefile.nmake 79 | !ELSE 80 | $(MAKE) /F Makefile.nmake 81 | !ENDIF 82 | cd .. 83 | -------------------------------------------------------------------------------- /WIN32-Code/getopt.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: getopt.c,v 1.16 1999/12/02 13:15:56 kleink Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1987, 1993, 1994, 1995 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the names of the copyright holders nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 20 | * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #if 0 33 | static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #define __P(x) x 42 | #define _DIAGASSERT(x) assert(x) 43 | 44 | #ifdef __weak_alias 45 | __weak_alias(getopt,_getopt); 46 | #endif 47 | 48 | 49 | int opterr = 1, /* if error message should be printed */ 50 | optind = 1, /* index into parent argv vector */ 51 | optopt, /* character checked for validity */ 52 | optreset; /* reset getopt */ 53 | char *optarg; /* argument associated with option */ 54 | 55 | static char * _progname __P((char *)); 56 | int getopt_internal __P((int, char * const *, const char *)); 57 | 58 | static char * 59 | _progname(nargv0) 60 | char * nargv0; 61 | { 62 | char * tmp; 63 | 64 | _DIAGASSERT(nargv0 != NULL); 65 | 66 | tmp = strrchr(nargv0, '/'); 67 | if (tmp) 68 | tmp++; 69 | else 70 | tmp = nargv0; 71 | return(tmp); 72 | } 73 | 74 | #define BADCH (int)'?' 75 | #define BADARG (int)':' 76 | #define EMSG "" 77 | 78 | /* 79 | * getopt -- 80 | * Parse argc/argv argument vector. 81 | */ 82 | int 83 | getopt(nargc, nargv, ostr) 84 | int nargc; 85 | char * const nargv[]; 86 | const char *ostr; 87 | { 88 | static char *__progname = 0; 89 | static char *place = EMSG; /* option letter processing */ 90 | char *oli; /* option letter list index */ 91 | __progname = __progname?__progname:_progname(*nargv); 92 | 93 | _DIAGASSERT(nargv != NULL); 94 | _DIAGASSERT(ostr != NULL); 95 | 96 | if (optreset || !*place) { /* update scanning pointer */ 97 | optreset = 0; 98 | if (optind >= nargc || *(place = nargv[optind]) != '-') { 99 | place = EMSG; 100 | return (-1); 101 | } 102 | if (place[1] && *++place == '-' /* found "--" */ 103 | && place[1] == '\0') { 104 | ++optind; 105 | place = EMSG; 106 | return (-1); 107 | } 108 | } /* option letter okay? */ 109 | if ((optopt = (int)*place++) == (int)':' || 110 | !(oli = strchr(ostr, optopt))) { 111 | /* 112 | * if the user didn't specify '-' as an option, 113 | * assume it means -1. 114 | */ 115 | if (optopt == (int)'-') 116 | return (-1); 117 | if (!*place) 118 | ++optind; 119 | if (opterr && *ostr != ':') 120 | (void)fprintf(stderr, 121 | "%s: illegal option -- %c\n", __progname, optopt); 122 | return (BADCH); 123 | } 124 | if (*++oli != ':') { /* don't need argument */ 125 | optarg = NULL; 126 | if (!*place) 127 | ++optind; 128 | } 129 | else { /* need an argument */ 130 | if (*place) /* no white space */ 131 | optarg = place; 132 | else if (nargc <= ++optind) { /* no arg */ 133 | place = EMSG; 134 | if (*ostr == ':') 135 | return (BADARG); 136 | if (opterr) 137 | (void)fprintf(stderr, 138 | "%s: option requires an argument -- %c\n", 139 | __progname, optopt); 140 | return (BADCH); 141 | } 142 | else /* white space */ 143 | optarg = nargv[optind]; 144 | place = EMSG; 145 | ++optind; 146 | } 147 | return (optopt); /* dump back option letter */ 148 | } 149 | 150 | -------------------------------------------------------------------------------- /WIN32-Code/getopt.h: -------------------------------------------------------------------------------- 1 | #ifndef __GETOPT_H__ 2 | #define __GETOPT_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern int opterr; /* if error message should be printed */ 9 | extern int optind; /* index into parent argv vector */ 10 | extern int optopt; /* character checked for validity */ 11 | extern int optreset; /* reset getopt */ 12 | extern char *optarg; /* argument associated with option */ 13 | 14 | struct option 15 | { 16 | const char *name; 17 | int has_arg; 18 | int *flag; 19 | int val; 20 | }; 21 | 22 | #define no_argument 0 23 | #define required_argument 1 24 | #define optional_argument 2 25 | 26 | int getopt(int, char**, const char*); 27 | int getopt_long(int, char**, const char*, const struct option*, int*); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* __GETOPT_H__ */ 34 | -------------------------------------------------------------------------------- /WIN32-Code/nmake/evconfig-private.h: -------------------------------------------------------------------------------- 1 | #if !defined(EVENT_EVCONFIG__PRIVATE_H_) && !defined(__MINGW32__) 2 | #define EVENT_EVCONFIG__PRIVATE_H_ 3 | 4 | /* Nothing to see here. Move along. */ 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | MAKE=make 4 | if command -v gmake >/dev/null 2>/dev/null; then 5 | MAKE=gmake 6 | fi 7 | $MAKE maintainer-clean >/dev/null 2>/dev/null 8 | 9 | if [ -x "`which autoreconf 2>/dev/null`" ] ; then 10 | exec autoreconf -ivf 11 | fi 12 | 13 | LIBTOOLIZE=libtoolize 14 | SYSNAME=`uname` 15 | if [ "x$SYSNAME" = "xDarwin" ] ; then 16 | LIBTOOLIZE=glibtoolize 17 | fi 18 | aclocal -I m4 && \ 19 | autoheader && \ 20 | $LIBTOOLIZE && \ 21 | autoconf && \ 22 | automake --add-missing --force-missing --copy 23 | -------------------------------------------------------------------------------- /cmake/AddCompilerFlags.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCCompilerFlag) 2 | 3 | macro(add_compiler_flags) 4 | foreach(flag ${ARGN}) 5 | string(REGEX REPLACE "[-.+/:= ]" "_" _flag_esc "${flag}") 6 | 7 | check_c_compiler_flag("${flag}" check_c_compiler_flag_${_flag_esc}) 8 | 9 | if (check_c_compiler_flag_${_flag_esc}) 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") 11 | endif() 12 | endforeach() 13 | endmacro() 14 | -------------------------------------------------------------------------------- /cmake/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /cmake/CheckConstExists.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCSourceCompiles) 2 | 3 | macro(check_const_exists CONST FILES VARIABLE) 4 | if (NOT DEFINED ${VARIABLE}) 5 | set(check_const_exists_source "") 6 | foreach(file ${FILES}) 7 | set(check_const_exists_source 8 | "${check_const_exists_source} 9 | #include <${file}>") 10 | endforeach() 11 | set(check_const_exists_source 12 | "${check_const_exists_source} 13 | int main() { (void)${CONST}; return 0; }") 14 | 15 | check_c_source_compiles("${check_const_exists_source}" ${VARIABLE}) 16 | 17 | if (${${VARIABLE}}) 18 | set(${VARIABLE} 1 CACHE INTERNAL "Have const ${CONST}") 19 | message(STATUS "Looking for ${CONST} - found") 20 | else() 21 | set(${VARIABLE} 0 CACHE INTERNAL "Have const ${CONST}") 22 | message(STATUS "Looking for ${CONST} - not found") 23 | endif() 24 | endif() 25 | endmacro(check_const_exists) 26 | -------------------------------------------------------------------------------- /cmake/CheckFileOffsetBits.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define KB ((off_t)1024) 4 | #define MB ((off_t)1024 * KB) 5 | #define GB ((off_t)1024 * MB) 6 | #define TB ((off_t)1024 * GB) 7 | int t2[(((64 * GB -1) % 671088649) == 268434537) 8 | && (((TB - (64 * GB -1) + 255) % 1792151290) == 305159546)? 1: -1]; 9 | 10 | int main() 11 | { 12 | ; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /cmake/CheckFileOffsetBits.cmake: -------------------------------------------------------------------------------- 1 | # - Check if _FILE_OFFSET_BITS macro needed for large files 2 | # CHECK_FILE_OFFSET_BITS () 3 | # 4 | # The following variables may be set before calling this macro to 5 | # modify the way the check is run: 6 | # 7 | # CMAKE_REQUIRED_FLAGS = string of compile command line flags 8 | # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) 9 | # CMAKE_REQUIRED_INCLUDES = list of include directories 10 | # Copyright (c) 2009, Michihiro NAKAJIMA 11 | # 12 | # Redistribution and use is allowed according to the terms of the BSD license. 13 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 14 | 15 | #INCLUDE(CheckCSourceCompiles) 16 | 17 | GET_FILENAME_COMPONENT(_selfdir_CheckFileOffsetBits 18 | "${CMAKE_CURRENT_LIST_FILE}" PATH) 19 | 20 | MACRO (CHECK_FILE_OFFSET_BITS) 21 | IF(NOT DEFINED _FILE_OFFSET_BITS) 22 | MESSAGE(STATUS "Cheking _FILE_OFFSET_BITS for large files") 23 | TRY_COMPILE(__WITHOUT_FILE_OFFSET_BITS_64 24 | ${CMAKE_CURRENT_BINARY_DIR} 25 | ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c 26 | COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}) 27 | IF(NOT __WITHOUT_FILE_OFFSET_BITS_64) 28 | TRY_COMPILE(__WITH_FILE_OFFSET_BITS_64 29 | ${CMAKE_CURRENT_BINARY_DIR} 30 | ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c 31 | COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64) 32 | ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64) 33 | 34 | IF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64) 35 | SET(_FILE_OFFSET_BITS 64 CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files") 36 | MESSAGE(STATUS "Cheking _FILE_OFFSET_BITS for large files - needed") 37 | ELSE(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64) 38 | SET(_FILE_OFFSET_BITS "" CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files") 39 | MESSAGE(STATUS "Cheking _FILE_OFFSET_BITS for large files - not needed") 40 | ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64) 41 | ENDIF(NOT DEFINED _FILE_OFFSET_BITS) 42 | 43 | ENDMACRO (CHECK_FILE_OFFSET_BITS) 44 | -------------------------------------------------------------------------------- /cmake/CheckFunctionKeywords.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCSourceCompiles) 2 | 3 | macro(check_function_keywords _wordlist) 4 | set(${_result} "") 5 | foreach(flag ${_wordlist}) 6 | string(REGEX REPLACE "[-+/ ()]" "_" flagname "${flag}") 7 | string(TOUPPER "${flagname}" flagname) 8 | set(have_flag "HAVE_${flagname}") 9 | check_c_source_compiles("${flag} void func(); void func() { } int main() { func(); return 0; }" ${have_flag}) 10 | if(${have_flag} AND NOT ${_result}) 11 | set(${_result} "${flag}") 12 | endif(${have_flag} AND NOT ${_result}) 13 | endforeach(flag) 14 | endmacro(check_function_keywords) 15 | -------------------------------------------------------------------------------- /cmake/CheckPrototypeDefinition.c.in: -------------------------------------------------------------------------------- 1 | @CHECK_PROTOTYPE_DEFINITION_HEADER@ 2 | 3 | static void cmakeRequireSymbol(int dummy, ...) { 4 | (void) dummy; 5 | } 6 | 7 | static void checkSymbol(void) { 8 | #ifndef @CHECK_PROTOTYPE_DEFINITION_SYMBOL@ 9 | cmakeRequireSymbol(0, &@CHECK_PROTOTYPE_DEFINITION_SYMBOL@); 10 | #endif 11 | } 12 | 13 | @CHECK_PROTOTYPE_DEFINITION_PROTO@ { 14 | return @CHECK_PROTOTYPE_DEFINITION_RETURN@; 15 | } 16 | 17 | #ifdef __CLASSIC_C__ 18 | int main() { 19 | int ac; 20 | char*av[]; 21 | #else 22 | int main(int ac, char *av[]) { 23 | #endif 24 | checkSymbol(); 25 | if (ac > 1000) { 26 | return *av[0]; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /cmake/CheckPrototypeDefinition.cmake: -------------------------------------------------------------------------------- 1 | # - Check if the protoype we expect is correct. 2 | # check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE) 3 | # 4 | # FUNCTION - The name of the function (used to check if prototype exists) 5 | # PROTOTYPE- The prototype to check. 6 | # RETURN - The return value of the function. 7 | # HEADER - The header files required. 8 | # VARIABLE - The variable to store the result. 9 | # 10 | # Example: 11 | # 12 | # check_prototype_definition(getpwent_r 13 | # "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)" 14 | # "NULL" 15 | # "unistd.h;pwd.h" 16 | # SOLARIS_GETPWENT_R) 17 | # 18 | # The following variables may be set before calling this macro to 19 | # modify the way the check is run: 20 | # 21 | # CMAKE_REQUIRED_FLAGS = string of compile command line flags 22 | # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) 23 | # CMAKE_REQUIRED_INCLUDES = list of include directories 24 | # CMAKE_REQUIRED_LIBRARIES = list of libraries to link 25 | 26 | 27 | function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE) 28 | if (${_VARIABLE} MATCHES "^${_VARIABLE}$") 29 | set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n") 30 | 31 | set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS}) 32 | if (CMAKE_REQUIRED_LIBRARIES) 33 | set(CHECK_PROTOTYPE_DEFINITION_LIBS 34 | "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") 35 | else(CMAKE_REQUIRED_LIBRARIES) 36 | set(CHECK_PROTOTYPE_DEFINITION_LIBS) 37 | endif(CMAKE_REQUIRED_LIBRARIES) 38 | if (CMAKE_REQUIRED_INCLUDES) 39 | set(CMAKE_SYMBOL_EXISTS_INCLUDES 40 | "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") 41 | else(CMAKE_REQUIRED_INCLUDES) 42 | set(CMAKE_SYMBOL_EXISTS_INCLUDES) 43 | endif(CMAKE_REQUIRED_INCLUDES) 44 | 45 | foreach(_FILE ${_HEADER}) 46 | set(CHECK_PROTOTYPE_DEFINITION_HEADER 47 | "${CHECK_PROTOTYPE_DEFINITION_HEADER}#include <${_FILE}>\n") 48 | endforeach(_FILE) 49 | 50 | set(CHECK_PROTOTYPE_DEFINITION_SYMBOL ${_FUNCTION}) 51 | set(CHECK_PROTOTYPE_DEFINITION_PROTO ${_PROTOTYPE}) 52 | set(CHECK_PROTOTYPE_DEFINITION_RETURN ${_RETURN}) 53 | 54 | configure_file("${PROJECT_SOURCE_DIR}/cmake/CheckPrototypeDefinition.c.in" 55 | "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY) 56 | 57 | file(READ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c _SOURCE) 58 | 59 | try_compile(${_VARIABLE} 60 | ${CMAKE_BINARY_DIR} 61 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c 62 | COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} 63 | CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS} 64 | "${CHECK_PROTOTYPE_DEFINITION_LIBS}" 65 | "${CMAKE_SYMBOL_EXISTS_INCLUDES}" 66 | OUTPUT_VARIABLE OUTPUT) 67 | 68 | if (${_VARIABLE}) 69 | set(${_VARIABLE} 1 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}") 70 | message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - True") 71 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 72 | "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} passed with the following output:\n" 73 | "${OUTPUT}\n\n") 74 | else (${_VARIABLE}) 75 | message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - False") 76 | set(${_VARIABLE} 0 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}") 77 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 78 | "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} failed with the following output:\n" 79 | "${OUTPUT}\n\n${_SOURCE}\n\n") 80 | endif (${_VARIABLE}) 81 | endif() 82 | endfunction(CHECK_PROTOTYPE_DEFINITION) 83 | -------------------------------------------------------------------------------- /cmake/CheckWorkingKqueue.cmake: -------------------------------------------------------------------------------- 1 | include(CheckCSourceRuns) 2 | 3 | check_c_source_runs( 4 | " 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int 13 | main(int argc, char **argv) 14 | { 15 | int kq; 16 | int n; 17 | int fd[2]; 18 | struct kevent ev; 19 | struct timespec ts; 20 | char buf[80000]; 21 | 22 | if (pipe(fd) == -1) 23 | exit(1); 24 | if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1) 25 | exit(1); 26 | 27 | while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf)) 28 | ; 29 | 30 | if ((kq = kqueue()) == -1) 31 | exit(1); 32 | 33 | memset(&ev, 0, sizeof(ev)); 34 | ev.ident = fd[1]; 35 | ev.filter = EVFILT_WRITE; 36 | ev.flags = EV_ADD | EV_ENABLE; 37 | n = kevent(kq, &ev, 1, NULL, 0, NULL); 38 | if (n == -1) 39 | exit(1); 40 | 41 | read(fd[0], buf, sizeof(buf)); 42 | 43 | ts.tv_sec = 0; 44 | ts.tv_nsec = 0; 45 | n = kevent(kq, NULL, 0, &ev, 1, &ts); 46 | if (n == -1 || n == 0) 47 | exit(1); 48 | 49 | exit(0); 50 | } 51 | 52 | " EVENT__HAVE_WORKING_KQUEUE) 53 | -------------------------------------------------------------------------------- /cmake/Copyright.txt: -------------------------------------------------------------------------------- 1 | CMake - Cross Platform Makefile Generator 2 | Copyright 2000-2013 Kitware, Inc. 3 | Copyright 2000-2011 Insight Software Consortium 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | * Neither the names of Kitware, Inc., the Insight Software Consortium, 18 | nor the names of their contributors may be used to endorse or promote 19 | products derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | ------------------------------------------------------------------------------ 35 | 36 | The above copyright and license notice applies to distributions of 37 | CMake in source and binary form. Some source files contain additional 38 | notices of original copyright by their contributors; see each source 39 | for details. Third-party software packages supplied with CMake under 40 | compatible licenses provide their own copyright notices documented in 41 | corresponding subdirectories. 42 | 43 | ------------------------------------------------------------------------------ 44 | 45 | CMake was initially developed by Kitware with the following sponsorship: 46 | 47 | * National Library of Medicine at the National Institutes of Health 48 | as part of the Insight Segmentation and Registration Toolkit (ITK). 49 | 50 | * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel 51 | Visualization Initiative. 52 | 53 | * National Alliance for Medical Image Computing (NAMIC) is funded by the 54 | National Institutes of Health through the NIH Roadmap for Medical Research, 55 | Grant U54 EB005149. 56 | 57 | * Kitware, Inc. -------------------------------------------------------------------------------- /cmake/LibeventConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@EVENT_PACKAGE_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /cmake/Macros.cmake: -------------------------------------------------------------------------------- 1 | include(CheckSymbolExists) 2 | include(CheckIncludeFiles) 3 | 4 | # Check if each symbol in the symbol list exists, 5 | # and define PREFIX__HAVE_SYMNAME to 1 if yes. 6 | # 7 | # SYMLIST: list of symbols to check 8 | # HEADERS: header files to be included in check code 9 | # PREFIX: the prefix of definition 10 | macro(CHECK_SYMBOLS_EXIST SYMLIST HEADERS PREFIX) 11 | foreach(SYMNAME ${SYMLIST}) 12 | string(TOUPPER "${SYMNAME}" SYMNAME_UPPER) 13 | if ("${PREFIX}" STREQUAL "") 14 | set(HAVE_SYM_DEF "HAVE_${SYMNAME_UPPER}") 15 | else() 16 | set(HAVE_SYM_DEF "${PREFIX}__HAVE_${SYMNAME_UPPER}") 17 | endif() 18 | CHECK_SYMBOL_EXISTS(${SYMNAME} "${HEADERS}" ${HAVE_SYM_DEF}) 19 | endforeach() 20 | endmacro() 21 | 22 | # Check if file exists, define PREFIX__HAVE_FILE to 1 if yes, 23 | # and collect file to EVENT_INCLUDES 24 | macro(CHECK_INCLUDE_FILE_CONCAT FILE PREFIX) 25 | string(REGEX REPLACE "[./]" "_" FILE_UL ${FILE}) 26 | string(TOUPPER "${FILE_UL}" FILE_UL_UPPER) 27 | if ("${PREFIX}" STREQUAL "") 28 | set(HAVE_FILE_DEF "HAVE_${FILE_UL_UPPER}") 29 | else() 30 | set(HAVE_FILE_DEF "${PREFIX}__HAVE_${FILE_UL_UPPER}") 31 | endif() 32 | CHECK_INCLUDE_FILES("${EVENT_INCLUDES};${FILE}" ${HAVE_FILE_DEF}) 33 | if(${HAVE_FILE_DEF}) 34 | set(EVENT_INCLUDES ${EVENT_INCLUDES} ${FILE}) 35 | endif() 36 | endmacro() 37 | -------------------------------------------------------------------------------- /cmake/Uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake 2 | 3 | if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 4 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") 5 | endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 6 | 7 | file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 8 | string(REGEX REPLACE "\n" ";" files "${files}") 9 | foreach(file ${files}) 10 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 11 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program( 13 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 14 | OUTPUT_VARIABLE rm_out 15 | RETURN_VALUE rm_retval 16 | ) 17 | if(NOT "${rm_retval}" STREQUAL 0) 18 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 19 | endif(NOT "${rm_retval}" STREQUAL 0) 20 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 22 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 23 | endforeach(file) 24 | -------------------------------------------------------------------------------- /cmake/UseDoxygen.cmake: -------------------------------------------------------------------------------- 1 | # Use FindDoxygen.cmake to generate documentation. 2 | 3 | option(DOXYGEN_GENERATE_HTML "Generate HTML" ON) 4 | option(DOXYGEN_GENERATE_MAN "Generate man pages" OFF) 5 | option(DOXYGEN_MAN_LINKS "Generate man links" ON) 6 | option(DOXYGEN_GENERATE_LATEX "Generate LaTeX" OFF) 7 | 8 | # If the case-insensitive value of the cmake option is one of 9 | # "off, no, false" or 0, it is equal to false, otherwise true. 10 | # And the values of the doxygen config does not exactly match it. 11 | # So we need to convert the cmake option to a doxygen config. 12 | macro(_convert_to_dx_cfg CMK_OPTION) 13 | if (${CMK_OPTION}) 14 | set(${CMK_OPTION} YES) 15 | else() 16 | set(${CMK_OPTION} NO) 17 | endif() 18 | endmacro() 19 | 20 | macro(UseDoxygen) 21 | if (${CMAKE_VERSION} VERSION_LESS "3.9") 22 | # Old versions of cmake have poor support for Doxygen generation. 23 | message(FATAL_ERROR "Doxygen generation only enabled for cmake 3.9 and higher") 24 | else() 25 | find_package(Doxygen) 26 | if (DOXYGEN_FOUND) 27 | set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME}) 28 | set(DOXYGEN_PROJECT_NUMBER ${EVENT_PACKAGE_VERSION}) 29 | set(DOXYGEN_PROJECT_BRIEF "Event notification library") 30 | set(DOXYGEN_OUTPUT_DIRECTORY doxygen) 31 | set(DOXYGEN_STRIP_FROM_PATH include) 32 | set(DOXYGEN_JAVADOC_AUTOBRIEF YES) 33 | set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES) 34 | set(DOXYGEN_SORT_BRIEF_DOCS YES) 35 | set(DOXYGEN_RECURSIVE NO) 36 | 37 | _convert_to_dx_cfg(DOXYGEN_GENERATE_HTML) 38 | _convert_to_dx_cfg(DOXYGEN_GENERATE_MAN) 39 | _convert_to_dx_cfg(DOXYGEN_MAN_LINKS) 40 | _convert_to_dx_cfg(DOXYGEN_GENERATE_LATEX) 41 | 42 | set(DOXYGEN_LATEX_CMD_NAME latex) 43 | set(DOXYGEN_PAPER_TYPE a4wide) 44 | set(DOXYGEN_PDF_HYPERLINKS NO) 45 | 46 | set(DOXYGEN_GENERATE_RTF NO) 47 | set(DOXYGEN_GENERATE_XML NO) 48 | set(DOXYGEN_GENERATE_CHI NO) 49 | 50 | set(DOXYGEN_PREDEFINED TAILQ_ENTRY 51 | RB_ENTRY 52 | EVENT_DEFINED_TQENTRY_ 53 | EVENT_IN_DOXYGEN_ 54 | ) 55 | 56 | set(DOX_INPUT include/event2/buffer.h 57 | include/event2/buffer_compat.h 58 | include/event2/bufferevent.h 59 | include/event2/bufferevent_compat.h 60 | include/event2/bufferevent_ssl.h 61 | include/event2/dns.h 62 | include/event2/dns_compat.h 63 | include/event2/event.h 64 | include/event2/event_compat.h 65 | include/event2/http.h 66 | include/event2/http_compat.h 67 | include/event2/listener.h 68 | include/event2/rpc.h 69 | include/event2/rpc_compat.h 70 | include/event2/tag.h 71 | include/event2/tag_compat.h 72 | include/event2/thread.h 73 | include/event2/util.h 74 | ) 75 | # Add 'doxygen' target 76 | doxygen_add_docs(doxygen 77 | ${DOX_INPUT} 78 | ALL 79 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 80 | COMMENT "Generating doxygen documentation for ${PROJECT_NAME}..." 81 | ) 82 | 83 | # Use 'make clean' to remove the generated directory 84 | set_property(DIRECTORY 85 | PROPERTY ADDITIONAL_MAKE_CLEAN_FILES 86 | "${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}" 87 | ) 88 | 89 | # Install html into /share/doc/ 90 | if ("${DOXYGEN_GENERATE_HTML}" STREQUAL "YES") 91 | install(DIRECTORY 92 | ${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}/html 93 | DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME} 94 | COMPONENT doc 95 | ) 96 | endif() 97 | 98 | # Install manual into /share/man/man3 99 | if ("${DOXYGEN_GENERATE_MAN}" STREQUAL "YES") 100 | install(DIRECTORY 101 | ${PROJECT_BINARY_DIR}/${DOXYGEN_OUTPUT_DIRECTORY}/man/man3 102 | DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man 103 | COMPONENT doc 104 | ) 105 | endif() 106 | 107 | else(DOXYGEN_FOUND) 108 | message(FATAL_ERROR "Doxygen command not found, set EVENT__DOXYGEN to disable") 109 | endif (DOXYGEN_FOUND) 110 | endif() 111 | endmacro() 112 | -------------------------------------------------------------------------------- /cmake/VersionViaGit.cmake: -------------------------------------------------------------------------------- 1 | # This module defines the following variables utilizing 2 | # git to determine the parent tag. And if found the macro 3 | # will attempt to parse them in the github tag fomat 4 | # 5 | # Useful for auto-versioning in our CMakeLists 6 | # 7 | # EVENT_GIT___VERSION_MAJOR - Major version. 8 | # EVENT_GIT___VERSION_MINOR - Minor version 9 | # EVENT_GIT___VERSION_STAGE - Stage version 10 | # 11 | # Example usage: 12 | # 13 | # event_fuzzy_version_from_git() 14 | # message("Libvent major=${EVENT_GIT___VERSION_MAJOR}") 15 | # message(" minor=${EVENT_GIT___VERSION_MINOR}") 16 | # message(" patch=${EVENT_GIT___VERSION_PATCH}") 17 | # message(" stage=${EVENT_GIT___VERSION_STAGE}") 18 | # endif() 19 | 20 | include(FindGit) 21 | 22 | macro(event_fuzzy_version_from_git) 23 | # set our defaults. 24 | set(EVENT_GIT___VERSION_MAJOR 2) 25 | set(EVENT_GIT___VERSION_MINOR 1) 26 | set(EVENT_GIT___VERSION_PATCH 12) 27 | set(EVENT_GIT___VERSION_STAGE "stable") 28 | 29 | find_package(Git) 30 | 31 | if (GIT_FOUND) 32 | execute_process( 33 | COMMAND 34 | ${GIT_EXECUTABLE} describe --abbrev=0 --always 35 | WORKING_DIRECTORY 36 | ${PROJECT_SOURCE_DIR} 37 | RESULT_VARIABLE 38 | GITRET 39 | OUTPUT_VARIABLE 40 | GITVERSION 41 | OUTPUT_STRIP_TRAILING_WHITESPACE 42 | ) 43 | 44 | string(REGEX REPLACE "[\\._-]" ";" VERSION_LIST "${GITVERSION}") 45 | if(VERSION_LIST) 46 | list(LENGTH VERSION_LIST VERSION_LIST_LENGTH) 47 | endif() 48 | 49 | if ((GITRET EQUAL 0) AND (VERSION_LIST_LENGTH EQUAL 5)) 50 | list(GET VERSION_LIST 1 _MAJOR) 51 | list(GET VERSION_LIST 2 _MINOR) 52 | list(GET VERSION_LIST 3 _PATCH) 53 | list(GET VERSION_LIST 4 _STAGE) 54 | 55 | set(_DEFAULT_VERSION "${EVENT_GIT___VERSION_MAJOR}.${EVENT_GIT___VERSION_MINOR}.${EVENT_GIT___VERSION_PATCH}-${EVENT_GIT___VERSION_STAGE}") 56 | set(_GIT_VERSION "${_MAJOR}.${_MINOR}.${_PATCH}-${_STAGE}") 57 | 58 | if (${_DEFAULT_VERSION} VERSION_LESS ${_GIT_VERSION}) 59 | set(EVENT_GIT___VERSION_MAJOR ${_MAJOR}) 60 | set(EVENT_GIT___VERSION_MINOR ${_MINOR}) 61 | set(EVENT_GIT___VERSION_PATCH ${_PATCH}) 62 | set(EVENT_GIT___VERSION_STAGE ${_STAGE}) 63 | endif() 64 | endif() 65 | endif() 66 | endmacro() 67 | -------------------------------------------------------------------------------- /defer-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef DEFER_INTERNAL_H_INCLUDED_ 27 | #define DEFER_INTERNAL_H_INCLUDED_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include "event2/event-config.h" 34 | #include "evconfig-private.h" 35 | 36 | #include 37 | 38 | struct event_callback; 39 | typedef void (*deferred_cb_fn)(struct event_callback *, void *); 40 | 41 | /** 42 | Initialize an empty, non-pending event_callback. 43 | 44 | @param deferred The struct event_callback structure to initialize. 45 | @param priority The priority that the callback should run at. 46 | @param cb The function to run when the struct event_callback executes. 47 | @param arg The function's second argument. 48 | */ 49 | EVENT2_EXPORT_SYMBOL 50 | void event_deferred_cb_init_(struct event_callback *, ev_uint8_t, deferred_cb_fn, void *); 51 | /** 52 | Change the priority of a non-pending event_callback. 53 | */ 54 | void event_deferred_cb_set_priority_(struct event_callback *, ev_uint8_t); 55 | /** 56 | Cancel a struct event_callback if it is currently scheduled in an event_base. 57 | */ 58 | EVENT2_EXPORT_SYMBOL 59 | void event_deferred_cb_cancel_(struct event_base *, struct event_callback *); 60 | /** 61 | Activate a struct event_callback if it is not currently scheduled in an event_base. 62 | 63 | Return true if it was not previously scheduled. 64 | */ 65 | EVENT2_EXPORT_SYMBOL 66 | int event_deferred_cb_schedule_(struct event_base *, struct event_callback *); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 73 | 74 | -------------------------------------------------------------------------------- /doxygen.am: -------------------------------------------------------------------------------- 1 | # Doxygen documentation will not be generated with default configuration, 2 | # unless '--enable-doxygen-doc' is configured. 3 | # The following targets are all about doxygen: 4 | # make # 'make doxygen' would be auto executed 5 | # make doxygen # generating doxygen documentation 6 | # make doxygen-doc # same as 'make doxygen' 7 | # make clean # clean docs generated by doxygen 8 | # make install # install doxygen documentation 9 | # make uninstall # uninstall doxygen documentation 10 | 11 | if ENABLE_DOXYGEN 12 | 13 | # Add all needed rules defined in ax_prog_doxygen.m4 14 | @DX_RULES@ 15 | 16 | # Use 'make clean' to clean docs generated by doxygen. 17 | clean-local: 18 | -rm -rf $(DX_CLEANFILES) 19 | 20 | # integrate doxygen with automake targets 21 | man3_MANS = @DX_DOCDIR@/man/man3/* 22 | $(man3_MANS): doxygen-doc 23 | 24 | # Docs will be installed. It may be one or more docs supported 25 | # by doxygen, but does not include 'man'. 26 | docdirs = $(DX_INSTALL_DOCS) 27 | 28 | # Rules for installing docs generated by doxygen into $(htmldir), 29 | # The typical value of $(htmldir) is '/usr/local/share/doc/$(PACKAGE)' 30 | install-data-local: 31 | @if ! test -d "$(DESTDIR)$(htmldir)"; then \ 32 | echo "$(mkinstalldirs) '$(DESTDIR)$(htmldir)'"; \ 33 | $(mkinstalldirs) '$(DESTDIR)$(htmldir)'; \ 34 | fi 35 | @for d in $(docdirs); do \ 36 | echo "cp -pR $$d '$(DESTDIR)$(htmldir)/'"; \ 37 | cp -pR $$d '$(DESTDIR)$(htmldir)/'; \ 38 | done 39 | 40 | # Rules for uninstalling docs generated by doxygen from $(htmldir) 41 | uninstall-local: 42 | @for d in $(docdirs); do \ 43 | d=`basename $$d`; \ 44 | echo "test ! -d '$(DESTDIR)$(htmldir)/'$$d || \ 45 | { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \ 46 | rm -rf '$(DESTDIR)$(htmldir)/'$$d; }"; \ 47 | test ! -d '$(DESTDIR)$(htmldir)/'$$d || \ 48 | { find '$(DESTDIR)$(htmldir)/'$$d -type d ! -perm -200 -exec chmod u+w '{}' ';' && \ 49 | rm -rf '$(DESTDIR)$(htmldir)/'$$d; }; \ 50 | done 51 | rmdir "$(DESTDIR)$(htmldir)/" || true 52 | 53 | doxygen: doxygen-doc 54 | 55 | endif ENABLE_DOXYGEN 56 | -------------------------------------------------------------------------------- /epoll_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2003-2009 Niels Provos 3 | * Copyright 2009-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "evconfig-private.h" 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | int 38 | epoll_create(int size) 39 | { 40 | #if !defined(__NR_epoll_create) && defined(__NR_epoll_create1) 41 | if (size <= 0) { 42 | errno = EINVAL; 43 | return -1; 44 | } 45 | return (syscall(__NR_epoll_create1, 0)); 46 | #else 47 | return (syscall(__NR_epoll_create, size)); 48 | #endif 49 | } 50 | 51 | int 52 | epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) 53 | { 54 | 55 | return (syscall(__NR_epoll_ctl, epfd, op, fd, event)); 56 | } 57 | 58 | int 59 | epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) 60 | { 61 | #if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait) 62 | return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0)); 63 | #else 64 | return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout)); 65 | #endif 66 | } 67 | -------------------------------------------------------------------------------- /evconfig-private.h: -------------------------------------------------------------------------------- 1 | /* evconfig-private.h. Generated from evconfig-private.h.in by configure. */ 2 | /* evconfig-private.h template - see "Configuration Header Templates" */ 3 | /* in AC manual. Kevin Bowling 3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVSIGNAL_INTERNAL_H_INCLUDED_ 28 | #define EVSIGNAL_INTERNAL_H_INCLUDED_ 29 | 30 | #ifndef evutil_socket_t 31 | #include "event2/util.h" 32 | #endif 33 | #include 34 | 35 | typedef void (*ev_sighandler_t)(int); 36 | 37 | /* Data structure for the default signal-handling implementation in signal.c 38 | */ 39 | struct evsig_info { 40 | /* Event watching ev_signal_pair[1] */ 41 | struct event ev_signal; 42 | /* Socketpair used to send notifications from the signal handler */ 43 | evutil_socket_t ev_signal_pair[2]; 44 | /* True iff we've added the ev_signal event yet. */ 45 | int ev_signal_added; 46 | /* Count of the number of signals we're currently watching. */ 47 | int ev_n_signals_added; 48 | 49 | /* Array of previous signal handler objects before Libevent started 50 | * messing with them. Used to restore old signal handlers. */ 51 | #ifdef EVENT__HAVE_SIGACTION 52 | struct sigaction **sh_old; 53 | #else 54 | ev_sighandler_t **sh_old; 55 | #endif 56 | /* Size of sh_old. */ 57 | int sh_old_max; 58 | }; 59 | int evsig_init_(struct event_base *); 60 | void evsig_dealloc_(struct event_base *); 61 | 62 | void evsig_set_base_(struct event_base *base); 63 | void evsig_free_globals_(void); 64 | 65 | #endif /* EVSIGNAL_INTERNAL_H_INCLUDED_ */ 66 | -------------------------------------------------------------------------------- /extra/abi-check/README.md: -------------------------------------------------------------------------------- 1 | ## libevent ABI/API changes 2 | 3 | 4 | This script is used to generate information about changes in libevent ABI/API 5 | between various versions using [LVC tools](https://github.com/lvc). Such an 6 | overview can help developers migrate from one version to another. 7 | 8 | Here is the `abi_check.sh`, which is used to generate ABI/API timeline for 9 | libevent. 10 | 11 | You can limit the number of included libevent versions via a number given 12 | as a parameter to the script. For example 13 | 14 | ```shell 15 | $ ./abi_check.sh 3 16 | ``` 17 | 18 | generates overview for the last 3 versions and the current version. 19 | If no parameter given, it will generate overview for the last 2 versions and 20 | the current version by default. 21 | 22 | But this script requires some tools that are available in the following docker image: 23 | 24 | ``` 25 | docker.pkg.github.com/azat/docker-images/lvc-debian 26 | ``` 27 | 28 | And the full command looks like: 29 | 30 | ```shell 31 | docker run --rm -it -v $PWD:/src:ro -w /src -v tmp/le-abi-check-root:/abi-root -e ABI_CHECK_ROOT=/abi-root docker.pkg.github.com/azat/docker-images/lvc-debian /src/extra/abi-check/abi_check.sh 32 | ``` 33 | 34 | 'timeline/libevent/index.html' is the final result and can be viewed 35 | [here](https://libevent.org/abi) 36 | -------------------------------------------------------------------------------- /extra/abi-check/abi_check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Requirements: 4 | # - wdiff 5 | # - rfcdiff 6 | # - universal-ctags 7 | # - abi-tracker 8 | # - abi-monitor 9 | # - git 10 | # 11 | # All of this are included in: 12 | # docker.pkg.github.com/azat/docker-images/lvc-debian:latest 13 | # 14 | # TODO: 15 | # - move image into libevent namespace 16 | 17 | # verify backward compatibility of API/ABI changes 18 | 19 | set -e 20 | 21 | LIMIT=${1:-2} 22 | EVENT_SOURCE_DIR=${EVENT_SOURCE_DIR:-"$(cd "$(dirname "$0")"/../.. && pwd)"} 23 | ABI_CHECK_ROOT=${ABI_CHECK_ROOT:-$EVENT_SOURCE_DIR/.abi-check} 24 | ABI_CHECK_WORKSPACE=${ABI_CHECK_WORKSPACE:-"work/abi-check"} 25 | 26 | mkdir -p "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE" 27 | cd "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE" 28 | 29 | # copy current source code and profile into workspace 30 | mkdir -p src/libevent/current 31 | mkdir -p installed/libevent/current 32 | ( # to avoid cd back 33 | cd "$EVENT_SOURCE_DIR" 34 | # XXX: not `git archive` since it will not copy changes that are not in index, 35 | # and maybe some issues on CI (since it does not contain full clone) 36 | find . -maxdepth 1 -mindepth 1 | { 37 | git check-ignore --no-index --verbose --non-matching --stdin 38 | } | fgrep :: | cut -f2 | grep -v /.git/ | tee /dev/stderr | { 39 | xargs cp -r -t "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE/src/libevent/current/" 40 | } 41 | cp extra/abi-check/libevent.json "$ABI_CHECK_ROOT/$ABI_CHECK_WORKSPACE/" 42 | ) 43 | 44 | # run LVC tools 45 | abi-monitor -get -limit "$LIMIT" libevent.json 46 | # XXX: abi-monitor 1.12 supports "-make -j8", but 1.10 does not 47 | # (we can detect which version we have, and add this options) 48 | abi-monitor -v current -build libevent.json 49 | abi-monitor -build libevent.json 50 | abi-tracker -build libevent.json 51 | 52 | # remove useless files 53 | rm -rf src installed build_logs libevent.json 54 | -------------------------------------------------------------------------------- /extra/abi-check/libevent.json: -------------------------------------------------------------------------------- 1 | { 2 | "Name": "libevent", 3 | "Title": "Libevent", 4 | "SourceUrl": "https://github.com/libevent/libevent/tags", 5 | "Git": "https://github.com/libevent/libevent.git", 6 | "Maintainer": "Nick Mathewson, Azat Khuzhin and Niels Provos", 7 | "MaintainerUrl": "https://libevent.org", 8 | "BuildSystem": "Autotools", 9 | "HeadersDiff": "On", 10 | "Package": "release-", 11 | "ReleasePattern": "\A([\d\-\.\_]+)(|\-beta|\-rc|\-stable)\Z", 12 | } 13 | -------------------------------------------------------------------------------- /extra/lsan.supp: -------------------------------------------------------------------------------- 1 | # TODO: temporary, until tests itself will be fixed 2 | leak:libcrypto.so 3 | leak:libssl.so 4 | -------------------------------------------------------------------------------- /extra/tsan.supp: -------------------------------------------------------------------------------- 1 | # https://github.com/libevent/libevent/issues/777 2 | race:event_debug_mode_too_late 3 | -------------------------------------------------------------------------------- /include/evdns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVDNS_H_INCLUDED_ 28 | #define EVENT1_EVDNS_H_INCLUDED_ 29 | 30 | /** @file evdns.h 31 | 32 | A dns subsystem for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVDNS_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /include/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVENT_H_INCLUDED_ 28 | #define EVENT1_EVENT_H_INCLUDED_ 29 | 30 | /** @file event.h 31 | 32 | A library for writing event-driven network servers. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other event2/ 37 | headers. 38 | */ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | #ifdef EVENT__HAVE_SYS_TYPES_H 46 | #include 47 | #endif 48 | #ifdef EVENT__HAVE_SYS_TIME_H 49 | #include 50 | #endif 51 | #ifdef EVENT__HAVE_STDINT_H 52 | #include 53 | #endif 54 | #include 55 | 56 | /* For int types. */ 57 | #include 58 | 59 | #ifdef _WIN32 60 | #ifndef WIN32_LEAN_AND_MEAN 61 | #define WIN32_LEAN_AND_MEAN 62 | #endif 63 | #include 64 | #include 65 | #undef WIN32_LEAN_AND_MEAN 66 | #endif 67 | 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* EVENT1_EVENT_H_INCLUDED_ */ 84 | -------------------------------------------------------------------------------- /include/event2/bufferevent_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson 3 | * Copyright (c) 2000-2007 Niels Provos 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote products 15 | * derived from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | #ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ 29 | #define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ 30 | 31 | #include 32 | 33 | #define evbuffercb bufferevent_data_cb 34 | #define everrorcb bufferevent_event_cb 35 | 36 | /** 37 | Create a new bufferevent for an fd. 38 | 39 | This function is deprecated. Use bufferevent_socket_new and 40 | bufferevent_set_callbacks instead. 41 | 42 | Libevent provides an abstraction on top of the regular event callbacks. 43 | This abstraction is called a buffered event. A buffered event provides 44 | input and output buffers that get filled and drained automatically. The 45 | user of a buffered event no longer deals directly with the I/O, but 46 | instead is reading from input and writing to output buffers. 47 | 48 | Once initialized, the bufferevent structure can be used repeatedly with 49 | bufferevent_enable() and bufferevent_disable(). 50 | 51 | When read enabled the bufferevent will try to read from the file descriptor 52 | and call the read callback. The write callback is executed whenever the 53 | output buffer is drained below the write low watermark, which is 0 by 54 | default. 55 | 56 | If multiple bases are in use, bufferevent_base_set() must be called before 57 | enabling the bufferevent for the first time. 58 | 59 | @deprecated This function is deprecated because it uses the current 60 | event base, and as such can be error prone for multithreaded programs. 61 | Use bufferevent_socket_new() instead. 62 | 63 | @param fd the file descriptor from which data is read and written to. 64 | This file descriptor is not allowed to be a pipe(2). 65 | @param readcb callback to invoke when there is data to be read, or NULL if 66 | no callback is desired 67 | @param writecb callback to invoke when the file descriptor is ready for 68 | writing, or NULL if no callback is desired 69 | @param errorcb callback to invoke when there is an error on the file 70 | descriptor 71 | @param cbarg an argument that will be supplied to each of the callbacks 72 | (readcb, writecb, and errorcb) 73 | @return a pointer to a newly allocated bufferevent struct, or NULL if an 74 | error occurred 75 | @see bufferevent_base_set(), bufferevent_free() 76 | */ 77 | EVENT2_EXPORT_SYMBOL 78 | struct bufferevent *bufferevent_new(evutil_socket_t fd, 79 | evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); 80 | 81 | 82 | /** 83 | Set the read and write timeout for a buffered event. 84 | 85 | @param bufev the bufferevent to be modified 86 | @param timeout_read the read timeout 87 | @param timeout_write the write timeout 88 | */ 89 | EVENT2_EXPORT_SYMBOL 90 | void bufferevent_settimeout(struct bufferevent *bufev, 91 | int timeout_read, int timeout_write); 92 | 93 | #define EVBUFFER_READ BEV_EVENT_READING 94 | #define EVBUFFER_WRITE BEV_EVENT_WRITING 95 | #define EVBUFFER_EOF BEV_EVENT_EOF 96 | #define EVBUFFER_ERROR BEV_EVENT_ERROR 97 | #define EVBUFFER_TIMEOUT BEV_EVENT_TIMEOUT 98 | 99 | /** macro for getting access to the input buffer of a bufferevent */ 100 | #define EVBUFFER_INPUT(x) bufferevent_get_input(x) 101 | /** macro for getting access to the output buffer of a bufferevent */ 102 | #define EVBUFFER_OUTPUT(x) bufferevent_get_output(x) 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /include/event2/bufferevent_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ 28 | #define EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ 29 | 30 | /** @file event2/bufferevent_struct.h 31 | 32 | Data structures for bufferevents. Using these structures may hurt forward 33 | compatibility with later versions of Libevent: be careful! 34 | 35 | @deprecated Use of bufferevent_struct.h is completely deprecated; these 36 | structures are only exposed for backward compatibility with programs 37 | written before Libevent 2.0 that used them. 38 | */ 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #include 45 | #ifdef EVENT__HAVE_SYS_TYPES_H 46 | #include 47 | #endif 48 | #ifdef EVENT__HAVE_SYS_TIME_H 49 | #include 50 | #endif 51 | 52 | /* For int types. */ 53 | #include 54 | /* For struct event */ 55 | #include 56 | 57 | struct event_watermark { 58 | size_t low; 59 | size_t high; 60 | }; 61 | 62 | /** 63 | Shared implementation of a bufferevent. 64 | 65 | This type is exposed only because it was exposed in previous versions, 66 | and some people's code may rely on manipulating it. Otherwise, you 67 | should really not rely on the layout, size, or contents of this structure: 68 | it is fairly volatile, and WILL change in future versions of the code. 69 | **/ 70 | struct bufferevent { 71 | /** Event base for which this bufferevent was created. */ 72 | struct event_base *ev_base; 73 | /** Pointer to a table of function pointers to set up how this 74 | bufferevent behaves. */ 75 | const struct bufferevent_ops *be_ops; 76 | 77 | /** A read event that triggers when a timeout has happened or a socket 78 | is ready to read data. Only used by some subtypes of 79 | bufferevent. */ 80 | struct event ev_read; 81 | /** A write event that triggers when a timeout has happened or a socket 82 | is ready to write data. Only used by some subtypes of 83 | bufferevent. */ 84 | struct event ev_write; 85 | 86 | /** An input buffer. Only the bufferevent is allowed to add data to 87 | this buffer, though the user is allowed to drain it. */ 88 | struct evbuffer *input; 89 | 90 | /** An input buffer. Only the bufferevent is allowed to drain data 91 | from this buffer, though the user is allowed to add it. */ 92 | struct evbuffer *output; 93 | 94 | struct event_watermark wm_read; 95 | struct event_watermark wm_write; 96 | 97 | bufferevent_data_cb readcb; 98 | bufferevent_data_cb writecb; 99 | /* This should be called 'eventcb', but renaming it would break 100 | * backward compatibility */ 101 | bufferevent_event_cb errorcb; 102 | void *cbarg; 103 | 104 | struct timeval timeout_read; 105 | struct timeval timeout_write; 106 | 107 | /** Events that are currently enabled: currently EV_READ and EV_WRITE 108 | are supported. */ 109 | short enabled; 110 | }; 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif /* EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ */ 117 | -------------------------------------------------------------------------------- /include/event2/dns_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_DNS_STRUCT_H_INCLUDED_ 28 | #define EVENT2_DNS_STRUCT_H_INCLUDED_ 29 | 30 | /** @file event2/dns_struct.h 31 | 32 | Data structures for dns. Using these structures may hurt forward 33 | compatibility with later versions of Libevent: be careful! 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | #ifdef EVENT__HAVE_SYS_TYPES_H 43 | #include 44 | #endif 45 | #ifdef EVENT__HAVE_SYS_TIME_H 46 | #include 47 | #endif 48 | 49 | /* For int types. */ 50 | #include 51 | 52 | /* 53 | * Structures used to implement a DNS server. 54 | */ 55 | 56 | struct evdns_server_request { 57 | int flags; 58 | int nquestions; 59 | struct evdns_server_question **questions; 60 | }; 61 | struct evdns_server_question { 62 | int type; 63 | #ifdef __cplusplus 64 | int dns_question_class; 65 | #else 66 | /* You should refer to this field as "dns_question_class". The 67 | * name "class" works in C for backward compatibility, and will be 68 | * removed in a future version. (1.5 or later). */ 69 | int class; 70 | #define dns_question_class class 71 | #endif 72 | char name[1]; 73 | }; 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* EVENT2_DNS_STRUCT_H_INCLUDED_ */ 80 | 81 | -------------------------------------------------------------------------------- /include/event2/http_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_HTTP_COMPAT_H_INCLUDED_ 28 | #define EVENT2_HTTP_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/http_compat.h 31 | 32 | Potentially non-threadsafe versions of the functions in http.h: provided 33 | only for backwards compatibility. 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include 42 | #ifdef EVENT__HAVE_SYS_TYPES_H 43 | #include 44 | #endif 45 | #ifdef EVENT__HAVE_SYS_TIME_H 46 | #include 47 | #endif 48 | 49 | /* For int types. */ 50 | #include 51 | 52 | /** 53 | * Start an HTTP server on the specified address and port 54 | * 55 | * @deprecated It does not allow an event base to be specified 56 | * 57 | * @param address the address to which the HTTP server should be bound 58 | * @param port the port number on which the HTTP server should listen 59 | * @return a pointer to a newly initialized evhttp server structure 60 | * or NULL on error 61 | */ 62 | EVENT2_EXPORT_SYMBOL 63 | struct evhttp *evhttp_start(const char *address, ev_uint16_t port); 64 | 65 | /** 66 | * A connection object that can be used to for making HTTP requests. The 67 | * connection object tries to establish the connection when it is given an 68 | * http request object. 69 | * 70 | * @deprecated It does not allow an event base to be specified 71 | */ 72 | EVENT2_EXPORT_SYMBOL 73 | struct evhttp_connection *evhttp_connection_new( 74 | const char *address, ev_uint16_t port); 75 | 76 | /** 77 | * Associates an event base with the connection - can only be called 78 | * on a freshly created connection object that has not been used yet. 79 | * 80 | * @deprecated XXXX Why? 81 | */ 82 | EVENT2_EXPORT_SYMBOL 83 | void evhttp_connection_set_base(struct evhttp_connection *evcon, 84 | struct event_base *base); 85 | 86 | 87 | /** Returns the request URI */ 88 | #define evhttp_request_uri evhttp_request_get_uri 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 95 | -------------------------------------------------------------------------------- /include/event2/keyvalq_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ 28 | #define EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Fix so that people don't have to run with */ 35 | /* XXXX This code is duplicated with event_struct.h */ 36 | #ifndef TAILQ_ENTRY 37 | #define EVENT_DEFINED_TQENTRY_ 38 | #define TAILQ_ENTRY(type) \ 39 | struct { \ 40 | struct type *tqe_next; /* next element */ \ 41 | struct type **tqe_prev; /* address of previous next element */ \ 42 | } 43 | #endif /* !TAILQ_ENTRY */ 44 | 45 | #ifndef TAILQ_HEAD 46 | #define EVENT_DEFINED_TQHEAD_ 47 | #define TAILQ_HEAD(name, type) \ 48 | struct name { \ 49 | struct type *tqh_first; \ 50 | struct type **tqh_last; \ 51 | } 52 | #endif 53 | 54 | /* 55 | * Key-Value pairs. Can be used for HTTP headers but also for 56 | * query argument parsing. 57 | */ 58 | struct evkeyval { 59 | TAILQ_ENTRY(evkeyval) next; 60 | 61 | char *key; 62 | char *value; 63 | }; 64 | 65 | TAILQ_HEAD (evkeyvalq, evkeyval); 66 | 67 | /* XXXX This code is duplicated with event_struct.h */ 68 | #ifdef EVENT_DEFINED_TQENTRY_ 69 | #undef TAILQ_ENTRY 70 | #endif 71 | 72 | #ifdef EVENT_DEFINED_TQHEAD_ 73 | #undef TAILQ_HEAD 74 | #endif 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/event2/rpc_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_RPC_COMPAT_H_INCLUDED_ 28 | #define EVENT2_RPC_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/rpc_compat.h 31 | 32 | Deprecated versions of the functions in rpc.h: provided only for 33 | backwards compatibility. 34 | 35 | */ 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** backwards compatible accessors that work only with gcc */ 42 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 43 | 44 | #undef EVTAG_ASSIGN 45 | #undef EVTAG_GET 46 | #undef EVTAG_ADD 47 | 48 | #define EVTAG_ASSIGN(msg, member, args...) \ 49 | (*(msg)->base->member##_assign)(msg, ## args) 50 | #define EVTAG_GET(msg, member, args...) \ 51 | (*(msg)->base->member##_get)(msg, ## args) 52 | #define EVTAG_ADD(msg, member, args...) \ 53 | (*(msg)->base->member##_add)(msg, ## args) 54 | #endif 55 | #define EVTAG_LEN(msg, member) ((msg)->member##_length) 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ 62 | -------------------------------------------------------------------------------- /include/event2/rpc_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_RPC_STRUCT_H_INCLUDED_ 28 | #define EVENT2_RPC_STRUCT_H_INCLUDED_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** @file event2/rpc_struct.h 35 | 36 | Structures used by rpc.h. Using these structures directly may harm 37 | forward compatibility: be careful! 38 | 39 | */ 40 | 41 | /* Fix so that people don't have to run with */ 42 | #ifndef TAILQ_ENTRY 43 | #define EVENT_DEFINED_TQENTRY_ 44 | #define TAILQ_ENTRY(type) \ 45 | struct { \ 46 | struct type *tqe_next; /* next element */ \ 47 | struct type **tqe_prev; /* address of previous next element */ \ 48 | } 49 | #endif /* !TAILQ_ENTRY */ 50 | 51 | /** 52 | * provides information about the completed RPC request. 53 | */ 54 | struct evrpc_status { 55 | #define EVRPC_STATUS_ERR_NONE 0 56 | #define EVRPC_STATUS_ERR_TIMEOUT 1 57 | #define EVRPC_STATUS_ERR_BADPAYLOAD 2 58 | #define EVRPC_STATUS_ERR_UNSTARTED 3 59 | #define EVRPC_STATUS_ERR_HOOKABORTED 4 60 | int error; 61 | 62 | /* for looking at headers or other information */ 63 | struct evhttp_request *http_req; 64 | }; 65 | 66 | /* the structure below needs to be synchronized with evrpc_req_generic */ 67 | 68 | /* Encapsulates a request */ 69 | struct evrpc { 70 | TAILQ_ENTRY(evrpc) next; 71 | 72 | /* the URI at which the request handler lives */ 73 | const char* uri; 74 | 75 | /* creates a new request structure */ 76 | void *(*request_new)(void *); 77 | void *request_new_arg; 78 | 79 | /* frees the request structure */ 80 | void (*request_free)(void *); 81 | 82 | /* unmarshals the buffer into the proper request structure */ 83 | int (*request_unmarshal)(void *, struct evbuffer *); 84 | 85 | /* creates a new reply structure */ 86 | void *(*reply_new)(void *); 87 | void *reply_new_arg; 88 | 89 | /* frees the reply structure */ 90 | void (*reply_free)(void *); 91 | 92 | /* verifies that the reply is valid */ 93 | int (*reply_complete)(void *); 94 | 95 | /* marshals the reply into a buffer */ 96 | void (*reply_marshal)(struct evbuffer*, void *); 97 | 98 | /* the callback invoked for each received rpc */ 99 | void (*cb)(struct evrpc_req_generic *, void *); 100 | void *cb_arg; 101 | 102 | /* reference for further configuration */ 103 | struct evrpc_base *base; 104 | }; 105 | 106 | #ifdef EVENT_DEFINED_TQENTRY_ 107 | #undef TAILQ_ENTRY 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */ 115 | -------------------------------------------------------------------------------- /include/event2/tag_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_TAG_COMPAT_H_INCLUDED_ 28 | #define EVENT2_TAG_COMPAT_H_INCLUDED_ 29 | 30 | /** @file event2/tag_compat.h 31 | 32 | Obsolete/deprecated functions from tag.h; provided only for backwards 33 | compatibility. 34 | */ 35 | 36 | /** 37 | @name Misnamed functions 38 | 39 | @deprecated These macros are deprecated because their names don't follow 40 | Libevent's naming conventions. Use evtag_encode_int and 41 | evtag_encode_int64 instead. 42 | 43 | @{ 44 | */ 45 | #define encode_int(evbuf, number) evtag_encode_int((evbuf), (number)) 46 | #define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number)) 47 | /**@}*/ 48 | 49 | #endif /* EVENT2_TAG_H_INCLUDED_ */ 50 | -------------------------------------------------------------------------------- /include/event2/visibility.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT2_VISIBILITY_H_INCLUDED_ 28 | #define EVENT2_VISIBILITY_H_INCLUDED_ 29 | 30 | #include 31 | 32 | #if defined(event_shared_EXPORTS) || \ 33 | defined(event_extra_shared_EXPORTS) || \ 34 | defined(event_core_shared_EXPORTS) || \ 35 | defined(event_pthreads_shared_EXPORTS) || \ 36 | defined(event_openssl_shared_EXPORTS) 37 | 38 | # if defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) 39 | # define EVENT2_EXPORT_SYMBOL __global 40 | # elif defined __GNUC__ 41 | # define EVENT2_EXPORT_SYMBOL __attribute__ ((visibility("default"))) 42 | # elif defined(_MSC_VER) 43 | # define EVENT2_EXPORT_SYMBOL __declspec(dllexport) 44 | # else 45 | # define EVENT2_EXPORT_SYMBOL /* unknown compiler */ 46 | # endif 47 | 48 | #else /* event_*_EXPORTS */ 49 | 50 | # define EVENT2_EXPORT_SYMBOL 51 | 52 | #endif /* event_*_EXPORTS */ 53 | 54 | /** We need to dllimport event_debug_logging_mask_ into event_extra */ 55 | #if defined(_MSC_VER) 56 | # if defined(event_core_shared_EXPORTS) /** from core export */ 57 | # define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllexport) 58 | # elif defined(event_extra_shared_EXPORTS) || /** from extra import */ \ 59 | defined(EVENT_VISIBILITY_WANT_DLLIMPORT) 60 | # define EVENT2_CORE_EXPORT_SYMBOL __declspec(dllimport) 61 | # endif 62 | #endif /* _MSC_VER */ 63 | #if !defined(EVENT2_CORE_EXPORT_SYMBOL) 64 | # define EVENT2_CORE_EXPORT_SYMBOL EVENT2_EXPORT_SYMBOL 65 | #endif 66 | 67 | #endif /* EVENT2_VISIBILITY_H_INCLUDED_ */ 68 | -------------------------------------------------------------------------------- /include/evhttp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2000-2007 Niels Provos 3 | * Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVHTTP_H_INCLUDED_ 28 | #define EVENT1_EVHTTP_H_INCLUDED_ 29 | 30 | /** @file evhttp.h 31 | 32 | An http implementation subsystem for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVHTTP_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /include/evrpc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef EVENT1_EVRPC_H_INCLUDED_ 28 | #define EVENT1_EVRPC_H_INCLUDED_ 29 | 30 | /** @file evrpc.h 31 | 32 | An RPC system for Libevent. 33 | 34 | The header is deprecated in Libevent 2.0 and later; please 35 | use instead. Depending on what functionality you 36 | need, you may also want to include more of the other 37 | headers. 38 | */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* EVENT1_EVRPC_H_INCLUDED_ */ 46 | -------------------------------------------------------------------------------- /include/evutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef EVENT1_EVUTIL_H_INCLUDED_ 27 | #define EVENT1_EVUTIL_H_INCLUDED_ 28 | 29 | /** @file evutil.h 30 | 31 | Utility and compatibility functions for Libevent. 32 | 33 | The header is deprecated in Libevent 2.0 and later; please 34 | use instead. 35 | */ 36 | 37 | #include 38 | 39 | #endif /* EVENT1_EVUTIL_H_INCLUDED_ */ 40 | -------------------------------------------------------------------------------- /include/include.am: -------------------------------------------------------------------------------- 1 | # include/include.am for libevent 2 | # Copyright 2000-2007 Niels Provos 3 | # Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | # 5 | # See LICENSE for copying information. 6 | 7 | include_event2dir = $(includedir)/event2 8 | 9 | EVENT2_EXPORT = \ 10 | include/event2/buffer.h \ 11 | include/event2/buffer_compat.h \ 12 | include/event2/bufferevent.h \ 13 | include/event2/bufferevent_compat.h \ 14 | include/event2/bufferevent_struct.h \ 15 | include/event2/dns.h \ 16 | include/event2/dns_compat.h \ 17 | include/event2/dns_struct.h \ 18 | include/event2/event.h \ 19 | include/event2/event_compat.h \ 20 | include/event2/event_struct.h \ 21 | include/event2/http.h \ 22 | include/event2/http_compat.h \ 23 | include/event2/http_struct.h \ 24 | include/event2/keyvalq_struct.h \ 25 | include/event2/listener.h \ 26 | include/event2/rpc.h \ 27 | include/event2/rpc_compat.h \ 28 | include/event2/rpc_struct.h \ 29 | include/event2/tag.h \ 30 | include/event2/tag_compat.h \ 31 | include/event2/thread.h \ 32 | include/event2/util.h \ 33 | include/event2/visibility.h 34 | 35 | if OPENSSL 36 | EVENT2_EXPORT += include/event2/bufferevent_ssl.h 37 | endif 38 | 39 | ## Without the nobase_ prefixing, Automake would strip "include/event2/" from 40 | ## the source header filename to derive the installed header filename. 41 | ## With nobase_ the installed path is $(includedir)/include/event2/ev*.h. 42 | 43 | if INSTALL_LIBEVENT 44 | include_event2_HEADERS = $(EVENT2_EXPORT) 45 | nodist_include_event2_HEADERS = include/event2/event-config.h 46 | else 47 | noinst_HEADERS += $(EVENT2_EXPORT) 48 | nodist_noinst_HEADERS = include/event2/event-config.h 49 | endif 50 | -------------------------------------------------------------------------------- /ipv6-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* Internal use only: Fake IPv6 structures and values on platforms that 28 | * do not have them */ 29 | 30 | #ifndef IPV6_INTERNAL_H_INCLUDED_ 31 | #define IPV6_INTERNAL_H_INCLUDED_ 32 | 33 | #include "event2/event-config.h" 34 | #include "evconfig-private.h" 35 | 36 | #include 37 | #ifdef EVENT__HAVE_SYS_SOCKET_H 38 | #include 39 | #endif 40 | #include "event2/util.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @file ipv6-internal.h 47 | * 48 | * Replacement types and functions for platforms that don't support ipv6 49 | * properly. 50 | */ 51 | 52 | #ifndef EVENT__HAVE_STRUCT_IN6_ADDR 53 | struct in6_addr { 54 | ev_uint8_t s6_addr[16]; 55 | }; 56 | #endif 57 | 58 | #ifndef EVENT__HAVE_SA_FAMILY_T 59 | typedef int sa_family_t; 60 | #endif 61 | 62 | #ifndef EVENT__HAVE_STRUCT_SOCKADDR_IN6 63 | struct sockaddr_in6 { 64 | /* This will fail if we find a struct sockaddr that doesn't have 65 | * sa_family as the first element. */ 66 | sa_family_t sin6_family; 67 | ev_uint16_t sin6_port; 68 | struct in6_addr sin6_addr; 69 | }; 70 | #endif 71 | 72 | #ifndef AF_INET6 73 | #define AF_INET6 3333 74 | #endif 75 | #ifndef PF_INET6 76 | #define PF_INET6 AF_INET6 77 | #endif 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /kqueue-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef KQUEUE_INTERNAL_H_INCLUDED_ 27 | #define KQUEUE_INTERNAL_H_INCLUDED_ 28 | 29 | /** Notification function, used to tell an event base to wake up from another 30 | * thread. Only works when event_kq_add_notify_event_() has previously been 31 | * called successfully on that base. */ 32 | int event_kq_notify_base_(struct event_base *base); 33 | 34 | /** Prepare a kqueue-using event base to receive notifications via an internal 35 | * EVFILT_USER event. Return 0 on sucess, -1 on failure. 36 | */ 37 | int event_kq_add_notify_event_(struct event_base *base); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /libevent.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent 9 | Description: libevent is an asynchronous notification event loop library 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -levent 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} 16 | 17 | -------------------------------------------------------------------------------- /libevent_core.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_core 9 | Description: libevent_core 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -levent_core 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} 16 | 17 | -------------------------------------------------------------------------------- /libevent_extra.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_extra 9 | Description: libevent_extra 10 | Version: @VERSION@ 11 | Requires: 12 | Conflicts: 13 | Libs: -L${libdir} -levent_extra 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} 16 | 17 | -------------------------------------------------------------------------------- /libevent_openssl.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_openssl 9 | Description: libevent_openssl adds openssl-based TLS support to libevent 10 | Version: @VERSION@ 11 | Requires: libevent 12 | Conflicts: 13 | Libs: -L${libdir} -levent_openssl 14 | Libs.private: @LIBS@ @OPENSSL_LIBS@ 15 | Cflags: -I${includedir} @OPENSSL_INCS@ 16 | 17 | -------------------------------------------------------------------------------- /libevent_pthreads.pc.in: -------------------------------------------------------------------------------- 1 | #libevent pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libevent_pthreads 9 | Description: libevent_pthreads adds pthreads-based threading support to libevent 10 | Version: @VERSION@ 11 | Requires: libevent 12 | Conflicts: 13 | Libs: -L${libdir} -levent_pthreads 14 | Libs.private: @LIBS@ @PTHREAD_LIBS@ 15 | Cflags: -I${includedir} @PTHREAD_CFLAGS@ 16 | 17 | -------------------------------------------------------------------------------- /log-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef LOG_INTERNAL_H_INCLUDED_ 28 | #define LOG_INTERNAL_H_INCLUDED_ 29 | 30 | #include "event2/util.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifdef __GNUC__ 37 | #define EV_CHECK_FMT(a,b) __attribute__((format(printf, a, b))) 38 | #define EV_NORETURN __attribute__((noreturn)) 39 | #else 40 | #define EV_CHECK_FMT(a,b) 41 | #define EV_NORETURN 42 | #endif 43 | 44 | #define EVENT_ERR_ABORT_ ((int)0xdeaddead) 45 | 46 | #if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG) 47 | #define EVENT_DEBUG_LOGGING_ENABLED 48 | #endif 49 | 50 | #ifdef EVENT_DEBUG_LOGGING_ENABLED 51 | EVENT2_CORE_EXPORT_SYMBOL extern ev_uint32_t event_debug_logging_mask_; 52 | #define event_debug_get_logging_mask_() (event_debug_logging_mask_) 53 | #else 54 | #define event_debug_get_logging_mask_() (0) 55 | #endif 56 | 57 | EVENT2_EXPORT_SYMBOL 58 | void event_err(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN; 59 | EVENT2_EXPORT_SYMBOL 60 | void event_warn(const char *fmt, ...) EV_CHECK_FMT(1,2); 61 | EVENT2_EXPORT_SYMBOL 62 | void event_sock_err(int eval, evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(3,4) EV_NORETURN; 63 | EVENT2_EXPORT_SYMBOL 64 | void event_sock_warn(evutil_socket_t sock, const char *fmt, ...) EV_CHECK_FMT(2,3); 65 | EVENT2_EXPORT_SYMBOL 66 | void event_errx(int eval, const char *fmt, ...) EV_CHECK_FMT(2,3) EV_NORETURN; 67 | EVENT2_EXPORT_SYMBOL 68 | void event_warnx(const char *fmt, ...) EV_CHECK_FMT(1,2); 69 | EVENT2_EXPORT_SYMBOL 70 | void event_msgx(const char *fmt, ...) EV_CHECK_FMT(1,2); 71 | EVENT2_EXPORT_SYMBOL 72 | void event_debugx_(const char *fmt, ...) EV_CHECK_FMT(1,2); 73 | 74 | EVENT2_EXPORT_SYMBOL 75 | void event_logv_(int severity, const char *errstr, const char *fmt, va_list ap) 76 | EV_CHECK_FMT(3,0); 77 | 78 | #ifdef EVENT_DEBUG_LOGGING_ENABLED 79 | #define event_debug(x) do { \ 80 | if (event_debug_get_logging_mask_()) { \ 81 | event_debugx_ x; \ 82 | } \ 83 | } while (0) 84 | #else 85 | #define event_debug(x) ((void)0) 86 | #endif 87 | 88 | #undef EV_CHECK_FMT 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* LOG_INTERNAL_H_INCLUDED_ */ 95 | -------------------------------------------------------------------------------- /m4/ac_backport_259_ssizet.m4: -------------------------------------------------------------------------------- 1 | AN_IDENTIFIER([ssize_t], [AC_TYPE_SSIZE_T]) 2 | AC_DEFUN([AC_TYPE_SSIZE_T], [AC_CHECK_TYPE(ssize_t, int)]) 3 | 4 | -------------------------------------------------------------------------------- /m4/ax_check_funcs_ex.m4: -------------------------------------------------------------------------------- 1 | # Check if the function is available. 2 | # HAVE_XXX will be defined if yes. 3 | 4 | # $1: the name of function 5 | # $2: the headers in where the function declared 6 | AC_DEFUN([AX_CHECK_DECL_EX], [dnl 7 | AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])]) 8 | AS_VAR_PUSHDEF([have_func_var], [HAVE_[]m4_toupper($1)]) 9 | AC_CHECK_DECL([$1],dnl 10 | [AC_DEFINE([have_func_var], [1], [Define to 1 if you have the `$1' function.])],,dnl 11 | [$2]dnl 12 | ) 13 | AS_VAR_POPDEF([have_func_var])dnl 14 | ]) 15 | 16 | AC_DEFUN([AX_CHECK_DECLS_EX], [dnl 17 | AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])]) 18 | m4_foreach([decl],dnl 19 | m4_split(m4_normalize($1)),dnl 20 | [AX_CHECK_DECL_EX([decl], [$2])]dnl 21 | ) 22 | ]) 23 | -------------------------------------------------------------------------------- /m4/libevent_openssl.m4: -------------------------------------------------------------------------------- 1 | dnl ###################################################################### 2 | dnl OpenSSL support 3 | AC_DEFUN([LIBEVENT_OPENSSL], [ 4 | AC_REQUIRE([NTP_PKG_CONFIG])dnl 5 | 6 | case "$enable_openssl" in 7 | yes) 8 | have_openssl=no 9 | case "$PKG_CONFIG" in 10 | '') 11 | ;; 12 | *) 13 | OPENSSL_LIBS=`$PKG_CONFIG --libs openssl 2>/dev/null` 14 | case "$OPENSSL_LIBS" in 15 | '') ;; 16 | *) OPENSSL_LIBS="$OPENSSL_LIBS $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD" 17 | have_openssl=yes 18 | ;; 19 | esac 20 | OPENSSL_INCS=`$PKG_CONFIG --cflags openssl 2>/dev/null` 21 | ;; 22 | esac 23 | case "$have_openssl" in 24 | yes) ;; 25 | *) 26 | save_LIBS="$LIBS" 27 | LIBS="" 28 | OPENSSL_LIBS="" 29 | for lib in crypto eay32; do 30 | # clear cache 31 | unset ac_cv_search_SSL_new 32 | AC_SEARCH_LIBS([SSL_new], [ssl ssl32], 33 | [have_openssl=yes 34 | OPENSSL_LIBS="$LIBS -l$lib $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD"], 35 | [have_openssl=no], 36 | [-l$lib $EV_LIB_GDI $EV_LIB_WS32 $OPENSSL_LIBADD]) 37 | LIBS="$save_LIBS" 38 | test "$have_openssl" = "yes" && break 39 | done 40 | ;; 41 | esac 42 | CPPFLAGS_SAVE=$CPPFLAGS 43 | CPPFLAGS="$CPPFLAGS $OPENSSL_INCS" 44 | AC_CHECK_HEADERS([openssl/ssl.h], [], [have_openssl=no]) 45 | CPPFLAGS=$CPPFLAGS_SAVE 46 | AC_SUBST(OPENSSL_INCS) 47 | AC_SUBST(OPENSSL_LIBS) 48 | case "$have_openssl" in 49 | yes) AC_DEFINE(HAVE_OPENSSL, 1, [Define if the system has openssl]) ;; 50 | *) AC_MSG_ERROR([openssl is a must but can not be found. You should add the \ 51 | directory containing `openssl.pc' to the `PKG_CONFIG_PATH' environment variable, \ 52 | or set `CFLAGS' and `LDFLAGS' directly for openssl, or use `--disable-openssl' \ 53 | to disable support for openssl encryption]) 54 | ;; 55 | esac 56 | ;; 57 | esac 58 | 59 | # check if we have and should use openssl 60 | AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"]) 61 | ]) 62 | -------------------------------------------------------------------------------- /m4/ntp_pkg_config.m4: -------------------------------------------------------------------------------- 1 | dnl NTP_PKG_CONFIG -*- Autoconf -*- 2 | dnl 3 | dnl Look for pkg-config, which must be at least 4 | dnl $ntp_pkgconfig_min_version. 5 | dnl 6 | AC_DEFUN([NTP_PKG_CONFIG], [ 7 | 8 | dnl lower the minimum version if you find an earlier one works 9 | ntp_pkgconfig_min_version='0.15.0' 10 | AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) 11 | AS_UNSET([ac_cv_path_PKG_CONFIG]) 12 | AS_UNSET([ac_cv_path_ac_pt_PKG_CONFIG]) 13 | 14 | case "$PKG_CONFIG" in 15 | /*) 16 | AC_MSG_CHECKING([if pkg-config is at least version $ntp_pkgconfig_min_version]) 17 | if $PKG_CONFIG --atleast-pkgconfig-version $ntp_pkgconfig_min_version; then 18 | AC_MSG_RESULT([yes]) 19 | else 20 | AC_MSG_RESULT([no]) 21 | PKG_CONFIG="" 22 | fi 23 | ;; 24 | esac 25 | 26 | ]) dnl NTP_PKG_CONFIG 27 | 28 | -------------------------------------------------------------------------------- /make-event-config.sed: -------------------------------------------------------------------------------- 1 | # Sed script to postprocess config.h into event-config.h. 2 | 3 | 1i\ 4 | /* event2/event-config.h\ 5 | *\ 6 | * This file was generated by autoconf when libevent was built, and post-\ 7 | * processed by Libevent so that its macros would have a uniform prefix.\ 8 | *\ 9 | * DO NOT EDIT THIS FILE.\ 10 | *\ 11 | * Do not rely on macros in this file existing in later versions.\ 12 | */\ 13 | \ 14 | #ifndef EVENT2_EVENT_CONFIG_H_INCLUDED_\ 15 | #define EVENT2_EVENT_CONFIG_H_INCLUDED_\ 16 | 17 | $a\ 18 | \ 19 | #endif /* event2/event-config.h */ 20 | 21 | /#\( *\)undef STDC_HEADERS\>/b 22 | /#\( *\)define STDC_HEADERS\>/b 23 | 24 | # Only rewrite symbols starting with capitals 25 | s/#\( *\)define \([A-Z]\)/#\1define EVENT__\2/ 26 | s/#\( *\)undef \([A-Z]\)/#\1undef EVENT__\2/ 27 | s/#\( *\)if\(n*\)def \([A-Z]\)/#\1if\2def EVENT__\2/ 28 | -------------------------------------------------------------------------------- /make_epoll_table.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2 2 | 3 | def get(old,wc,rc,cc): 4 | if ('xxx' in (rc, wc, cc)): 5 | return "0",255 6 | 7 | if ('add' in (rc, wc, cc)): 8 | events = [] 9 | if rc == 'add' or (rc != 'del' and 'r' in old): 10 | events.append("EPOLLIN") 11 | if wc == 'add' or (wc != 'del' and 'w' in old): 12 | events.append("EPOLLOUT") 13 | if cc == 'add' or (cc != 'del' and 'c' in old): 14 | events.append("EPOLLRDHUP") 15 | 16 | if old == "0": 17 | op = "EPOLL_CTL_ADD" 18 | else: 19 | op = "EPOLL_CTL_MOD" 20 | return "|".join(events), op 21 | 22 | if ('del' in (rc, wc, cc)): 23 | delevents = [] 24 | modevents = [] 25 | op = "EPOLL_CTL_DEL" 26 | 27 | if 'r' in old: 28 | modevents.append("EPOLLIN") 29 | if 'w' in old: 30 | modevents.append("EPOLLOUT") 31 | if 'c' in old: 32 | modevents.append("EPOLLRDHUP") 33 | 34 | for item, event in [(rc,"EPOLLIN"), 35 | (wc,"EPOLLOUT"), 36 | (cc,"EPOLLRDHUP")]: 37 | if item == 'del': 38 | delevents.append(event) 39 | if event in modevents: 40 | modevents.remove(event) 41 | 42 | if modevents: 43 | return "|".join(modevents), "EPOLL_CTL_MOD" 44 | else: 45 | return "|".join(delevents), "EPOLL_CTL_DEL" 46 | 47 | return 0, 0 48 | 49 | 50 | def fmt(op, ev, old, wc, rc, cc): 51 | entry = "{ %s, %s },"%(op, ev) 52 | print "\t/* old=%3s, write:%3s, read:%3s, close:%3s */\n\t%s" % ( 53 | old, wc, rc, cc, entry) 54 | return len(entry) 55 | 56 | for old in ('0','r','w','rw','c','cr','cw','crw'): 57 | for wc in ('0', 'add', 'del', 'xxx'): 58 | for rc in ('0', 'add', 'del', 'xxx'): 59 | for cc in ('0', 'add', 'del', 'xxx'): 60 | 61 | op,ev = get(old,wc,rc,cc) 62 | 63 | fmt(op, ev, old, wc, rc, cc) 64 | -------------------------------------------------------------------------------- /mm-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef MM_INTERNAL_H_INCLUDED_ 27 | #define MM_INTERNAL_H_INCLUDED_ 28 | 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #ifndef EVENT__DISABLE_MM_REPLACEMENT 36 | /* Internal use only: Memory allocation functions. We give them nice short 37 | * mm_names for our own use, but make sure that the symbols have longer names 38 | * so they don't conflict with other libraries (like, say, libmm). */ 39 | 40 | /** Allocate uninitialized memory. 41 | * 42 | * @return On success, return a pointer to sz newly allocated bytes. 43 | * On failure, set errno to ENOMEM and return NULL. 44 | * If the argument sz is 0, simply return NULL. 45 | */ 46 | EVENT2_EXPORT_SYMBOL 47 | void *event_mm_malloc_(size_t sz); 48 | 49 | /** Allocate memory initialized to zero. 50 | * 51 | * @return On success, return a pointer to (count * size) newly allocated 52 | * bytes, initialized to zero. 53 | * On failure, or if the product would result in an integer overflow, 54 | * set errno to ENOMEM and return NULL. 55 | * If either arguments are 0, simply return NULL. 56 | */ 57 | EVENT2_EXPORT_SYMBOL 58 | void *event_mm_calloc_(size_t count, size_t size); 59 | 60 | /** Duplicate a string. 61 | * 62 | * @return On success, return a pointer to a newly allocated duplicate 63 | * of a string. 64 | * Set errno to ENOMEM and return NULL if a memory allocation error 65 | * occurs (or would occur) in the process. 66 | * If the argument str is NULL, set errno to EINVAL and return NULL. 67 | */ 68 | EVENT2_EXPORT_SYMBOL 69 | char *event_mm_strdup_(const char *str); 70 | 71 | EVENT2_EXPORT_SYMBOL 72 | void *event_mm_realloc_(void *p, size_t sz); 73 | EVENT2_EXPORT_SYMBOL 74 | void event_mm_free_(void *p); 75 | #define mm_malloc(sz) event_mm_malloc_(sz) 76 | #define mm_calloc(count, size) event_mm_calloc_((count), (size)) 77 | #define mm_strdup(s) event_mm_strdup_(s) 78 | #define mm_realloc(p, sz) event_mm_realloc_((p), (sz)) 79 | #define mm_free(p) event_mm_free_(p) 80 | #else 81 | #define mm_malloc(sz) malloc(sz) 82 | #define mm_calloc(n, sz) calloc((n), (sz)) 83 | #define mm_strdup(s) strdup(s) 84 | #define mm_realloc(p, sz) realloc((p), (sz)) 85 | #define mm_free(p) free(p) 86 | #endif 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /openssl-compat.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENSSL_COMPAT_H 2 | #define OPENSSL_COMPAT_H 3 | 4 | #include 5 | #include "util-internal.h" 6 | 7 | #if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ 8 | (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) 9 | 10 | static inline BIO_METHOD *BIO_meth_new(int type, const char *name) 11 | { 12 | BIO_METHOD *biom = calloc(1, sizeof(BIO_METHOD)); 13 | 14 | if (biom != NULL) { 15 | biom->type = type; 16 | biom->name = name; 17 | } 18 | return biom; 19 | } 20 | 21 | #define BIO_meth_set_write(b, f) (b)->bwrite = (f) 22 | #define BIO_meth_set_read(b, f) (b)->bread = (f) 23 | #define BIO_meth_set_puts(b, f) (b)->bputs = (f) 24 | #define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f) 25 | #define BIO_meth_set_create(b, f) (b)->create = (f) 26 | #define BIO_meth_set_destroy(b, f) (b)->destroy = (f) 27 | 28 | #define BIO_set_init(b, val) (b)->init = (val) 29 | #define BIO_set_data(b, val) (b)->ptr = (val) 30 | #define BIO_set_shutdown(b, val) (b)->shutdown = (val) 31 | #define BIO_get_init(b) (b)->init 32 | #define BIO_get_data(b) (b)->ptr 33 | #define BIO_get_shutdown(b) (b)->shutdown 34 | 35 | #define TLS_method SSLv23_method 36 | 37 | #define X509_getm_notBefore X509_get_notBefore 38 | #define X509_getm_notAfter X509_get_notAfter 39 | 40 | #endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ 41 | (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */ 42 | 43 | #if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L 44 | #define BIO_get_init(b) (b)->init 45 | #endif 46 | 47 | #endif /* OPENSSL_COMPAT_H */ 48 | -------------------------------------------------------------------------------- /ratelim-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef RATELIM_INTERNAL_H_INCLUDED_ 27 | #define RATELIM_INTERNAL_H_INCLUDED_ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include "event2/util.h" 34 | 35 | /** A token bucket is an internal structure that tracks how many bytes we are 36 | * currently willing to read or write on a given bufferevent or group of 37 | * bufferevents */ 38 | struct ev_token_bucket { 39 | /** How many bytes are we willing to read or write right now? These 40 | * values are signed so that we can do "defecit spending" */ 41 | ev_ssize_t read_limit, write_limit; 42 | /** When was this bucket last updated? Measured in abstract 'ticks' 43 | * relative to the token bucket configuration. */ 44 | ev_uint32_t last_updated; 45 | }; 46 | 47 | /** Configuration info for a token bucket or set of token buckets. */ 48 | struct ev_token_bucket_cfg { 49 | /** How many bytes are we willing to read on average per tick? */ 50 | size_t read_rate; 51 | /** How many bytes are we willing to read at most in any one tick? */ 52 | size_t read_maximum; 53 | /** How many bytes are we willing to write on average per tick? */ 54 | size_t write_rate; 55 | /** How many bytes are we willing to write at most in any one tick? */ 56 | size_t write_maximum; 57 | 58 | /* How long is a tick? Note that fractions of a millisecond are 59 | * ignored. */ 60 | struct timeval tick_timeout; 61 | 62 | /* How long is a tick, in milliseconds? Derived from tick_timeout. */ 63 | unsigned msec_per_tick; 64 | }; 65 | 66 | /** The current tick is 'current_tick': add bytes to 'bucket' as specified in 67 | * 'cfg'. */ 68 | int ev_token_bucket_update_(struct ev_token_bucket *bucket, 69 | const struct ev_token_bucket_cfg *cfg, 70 | ev_uint32_t current_tick); 71 | 72 | /** In which tick does 'tv' fall according to 'cfg'? Note that ticks can 73 | * overflow easily; your code needs to handle this. */ 74 | ev_uint32_t ev_token_bucket_get_tick_(const struct timeval *tv, 75 | const struct ev_token_bucket_cfg *cfg); 76 | 77 | /** Adjust 'bucket' to respect 'cfg', and note that it was last updated in 78 | * 'current_tick'. If 'reinitialize' is true, we are changing the 79 | * configuration of 'bucket'; otherwise, we are setting it up for the first 80 | * time. 81 | */ 82 | int ev_token_bucket_init_(struct ev_token_bucket *bucket, 83 | const struct ev_token_bucket_cfg *cfg, 84 | ev_uint32_t current_tick, 85 | int reinitialize); 86 | 87 | int bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, 88 | int unsuspend); 89 | 90 | /** Decrease the read limit of 'b' by 'n' bytes */ 91 | #define ev_token_bucket_decrement_read(b,n) \ 92 | do { \ 93 | (b)->read_limit -= (n); \ 94 | } while (0) 95 | /** Decrease the write limit of 'b' by 'n' bytes */ 96 | #define ev_token_bucket_decrement_write(b,n) \ 97 | do { \ 98 | (b)->write_limit -= (n); \ 99 | } while (0) 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /sample/event-read-fifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This sample code shows how to use Libevent to read from a named pipe. 3 | * XXX This code could make better use of the Libevent interfaces. 4 | * 5 | * XXX This does not work on Windows; ignore everything inside the _WIN32 block. 6 | * 7 | * On UNIX, compile with: 8 | * cc -I/usr/local/include -o event-read-fifo event-read-fifo.c \ 9 | * -L/usr/local/lib -levent 10 | */ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #ifndef _WIN32 17 | #include 18 | #include 19 | #include 20 | #include 21 | #else 22 | #include 23 | #include 24 | #endif 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | static void 34 | fifo_read(evutil_socket_t fd, short event, void *arg) 35 | { 36 | char buf[255]; 37 | int len; 38 | struct event *ev = arg; 39 | #ifdef _WIN32 40 | DWORD dwBytesRead; 41 | #endif 42 | 43 | fprintf(stderr, "fifo_read called with fd: %d, event: %d, arg: %p\n", 44 | (int)fd, event, arg); 45 | #ifdef _WIN32 46 | len = ReadFile((HANDLE)fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL); 47 | 48 | /* Check for end of file. */ 49 | if (len && dwBytesRead == 0) { 50 | fprintf(stderr, "End Of File"); 51 | event_del(ev); 52 | return; 53 | } 54 | 55 | buf[dwBytesRead] = '\0'; 56 | #else 57 | len = read(fd, buf, sizeof(buf) - 1); 58 | 59 | if (len <= 0) { 60 | if (len == -1) 61 | perror("read"); 62 | else if (len == 0) 63 | fprintf(stderr, "Connection closed\n"); 64 | event_del(ev); 65 | event_base_loopbreak(event_get_base(ev)); 66 | return; 67 | } 68 | 69 | buf[len] = '\0'; 70 | #endif 71 | fprintf(stdout, "Read: %s\n", buf); 72 | } 73 | 74 | /* On Unix, cleanup event.fifo if SIGINT is received. */ 75 | #ifndef _WIN32 76 | static void 77 | signal_cb(evutil_socket_t fd, short event, void *arg) 78 | { 79 | struct event_base *base = arg; 80 | event_base_loopbreak(base); 81 | } 82 | #endif 83 | 84 | int 85 | main(int argc, char **argv) 86 | { 87 | struct event *evfifo; 88 | struct event_base* base; 89 | #ifdef _WIN32 90 | HANDLE socket; 91 | /* Open a file. */ 92 | socket = CreateFileA("test.txt", /* open File */ 93 | GENERIC_READ, /* open for reading */ 94 | 0, /* do not share */ 95 | NULL, /* no security */ 96 | OPEN_EXISTING, /* existing file only */ 97 | FILE_ATTRIBUTE_NORMAL, /* normal file */ 98 | NULL); /* no attr. template */ 99 | 100 | if (socket == INVALID_HANDLE_VALUE) 101 | return 1; 102 | 103 | #else 104 | struct event *signal_int; 105 | struct stat st; 106 | const char *fifo = "event.fifo"; 107 | int socket; 108 | 109 | if (lstat(fifo, &st) == 0) { 110 | if ((st.st_mode & S_IFMT) == S_IFREG) { 111 | errno = EEXIST; 112 | perror("lstat"); 113 | exit(1); 114 | } 115 | } 116 | 117 | unlink(fifo); 118 | if (mkfifo(fifo, 0600) == -1) { 119 | perror("mkfifo"); 120 | exit(1); 121 | } 122 | 123 | socket = open(fifo, O_RDONLY | O_NONBLOCK, 0); 124 | 125 | if (socket == -1) { 126 | perror("open"); 127 | exit(1); 128 | } 129 | 130 | fprintf(stderr, "Write data to %s\n", fifo); 131 | #endif 132 | /* Initialize the event library */ 133 | base = event_base_new(); 134 | 135 | /* Initialize one event */ 136 | #ifdef _WIN32 137 | evfifo = event_new(base, (evutil_socket_t)socket, EV_READ|EV_PERSIST, fifo_read, 138 | event_self_cbarg()); 139 | #else 140 | /* catch SIGINT so that event.fifo can be cleaned up */ 141 | signal_int = evsignal_new(base, SIGINT, signal_cb, base); 142 | event_add(signal_int, NULL); 143 | 144 | evfifo = event_new(base, socket, EV_READ|EV_PERSIST, fifo_read, 145 | event_self_cbarg()); 146 | #endif 147 | 148 | /* Add it to the active events, without a timeout */ 149 | event_add(evfifo, NULL); 150 | 151 | event_base_dispatch(base); 152 | event_base_free(base); 153 | #ifdef _WIN32 154 | CloseHandle(socket); 155 | #else 156 | close(socket); 157 | unlink(fifo); 158 | #endif 159 | libevent_global_shutdown(); 160 | return (0); 161 | } 162 | 163 | -------------------------------------------------------------------------------- /sample/hello-world.c: -------------------------------------------------------------------------------- 1 | /* 2 | This example program provides a trivial server program that listens for TCP 3 | connections on port 9995. When they arrive, it writes a short message to 4 | each client connection, and closes each connection once it is flushed. 5 | 6 | Where possible, it exits cleanly in response to a SIGINT (ctrl-c). 7 | */ 8 | 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #ifndef _WIN32 15 | #include 16 | # ifdef _XOPEN_SOURCE_EXTENDED 17 | # include 18 | # endif 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | static const char MESSAGE[] = "Hello, World!\n"; 29 | 30 | static const int PORT = 9995; 31 | 32 | static void listener_cb(struct evconnlistener *, evutil_socket_t, 33 | struct sockaddr *, int socklen, void *); 34 | static void conn_writecb(struct bufferevent *, void *); 35 | static void conn_eventcb(struct bufferevent *, short, void *); 36 | static void signal_cb(evutil_socket_t, short, void *); 37 | 38 | int 39 | main(int argc, char **argv) 40 | { 41 | struct event_base *base; 42 | struct evconnlistener *listener; 43 | struct event *signal_event; 44 | 45 | struct sockaddr_in sin = {0}; 46 | #ifdef _WIN32 47 | WSADATA wsa_data; 48 | WSAStartup(0x0201, &wsa_data); 49 | #endif 50 | 51 | base = event_base_new(); 52 | if (!base) { 53 | fprintf(stderr, "Could not initialize libevent!\n"); 54 | return 1; 55 | } 56 | 57 | sin.sin_family = AF_INET; 58 | sin.sin_port = htons(PORT); 59 | 60 | listener = evconnlistener_new_bind(base, listener_cb, (void *)base, 61 | LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_FREE, -1, 62 | (struct sockaddr*)&sin, 63 | sizeof(sin)); 64 | 65 | if (!listener) { 66 | fprintf(stderr, "Could not create a listener!\n"); 67 | return 1; 68 | } 69 | 70 | signal_event = evsignal_new(base, SIGINT, signal_cb, (void *)base); 71 | 72 | if (!signal_event || event_add(signal_event, NULL)<0) { 73 | fprintf(stderr, "Could not create/add a signal event!\n"); 74 | return 1; 75 | } 76 | 77 | event_base_dispatch(base); 78 | 79 | evconnlistener_free(listener); 80 | event_free(signal_event); 81 | event_base_free(base); 82 | 83 | printf("done\n"); 84 | return 0; 85 | } 86 | 87 | static void 88 | listener_cb(struct evconnlistener *listener, evutil_socket_t fd, 89 | struct sockaddr *sa, int socklen, void *user_data) 90 | { 91 | struct event_base *base = user_data; 92 | struct bufferevent *bev; 93 | 94 | bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE); 95 | if (!bev) { 96 | fprintf(stderr, "Error constructing bufferevent!"); 97 | event_base_loopbreak(base); 98 | return; 99 | } 100 | bufferevent_setcb(bev, NULL, conn_writecb, conn_eventcb, NULL); 101 | bufferevent_enable(bev, EV_WRITE); 102 | bufferevent_disable(bev, EV_READ); 103 | 104 | bufferevent_write(bev, MESSAGE, strlen(MESSAGE)); 105 | } 106 | 107 | static void 108 | conn_writecb(struct bufferevent *bev, void *user_data) 109 | { 110 | struct evbuffer *output = bufferevent_get_output(bev); 111 | if (evbuffer_get_length(output) == 0) { 112 | printf("flushed answer\n"); 113 | bufferevent_free(bev); 114 | } 115 | } 116 | 117 | static void 118 | conn_eventcb(struct bufferevent *bev, short events, void *user_data) 119 | { 120 | if (events & BEV_EVENT_EOF) { 121 | printf("Connection closed.\n"); 122 | } else if (events & BEV_EVENT_ERROR) { 123 | printf("Got an error on the connection: %s\n", 124 | strerror(errno));/*XXX win32*/ 125 | } 126 | /* None of the other events can happen here, since we haven't enabled 127 | * timeouts */ 128 | bufferevent_free(bev); 129 | } 130 | 131 | static void 132 | signal_cb(evutil_socket_t sig, short events, void *user_data) 133 | { 134 | struct event_base *base = user_data; 135 | struct timeval delay = { 2, 0 }; 136 | 137 | printf("Caught an interrupt signal; exiting cleanly in two seconds.\n"); 138 | 139 | event_base_loopexit(base, &delay); 140 | } 141 | -------------------------------------------------------------------------------- /sample/hostcheck.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_CURL_HOSTCHECK_H 2 | #define HEADER_CURL_HOSTCHECK_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at http://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #define CURL_HOST_NOMATCH 0 26 | #define CURL_HOST_MATCH 1 27 | int Curl_cert_hostcheck(const char *match_pattern, const char *hostname); 28 | 29 | #endif /* HEADER_CURL_HOSTCHECK_H */ 30 | 31 | -------------------------------------------------------------------------------- /sample/http-connect.c: -------------------------------------------------------------------------------- 1 | #include "event2/event-config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define VERIFY(cond) do { \ 12 | if (!(cond)) { \ 13 | fprintf(stderr, "[error] %s\n", #cond); \ 14 | exit(EXIT_FAILURE); \ 15 | } \ 16 | } while (0); \ 17 | 18 | #define URL_MAX 4096 19 | 20 | struct connect_base 21 | { 22 | struct evhttp_connection *evcon; 23 | struct evhttp_uri *location; 24 | }; 25 | 26 | static struct evhttp_uri* uri_parse(const char *str) 27 | { 28 | struct evhttp_uri *uri; 29 | VERIFY(uri = evhttp_uri_parse(str)); 30 | VERIFY(evhttp_uri_get_host(uri)); 31 | VERIFY(evhttp_uri_get_port(uri) > 0); 32 | return uri; 33 | } 34 | static char* uri_path(struct evhttp_uri *uri, char buffer[URL_MAX]) 35 | { 36 | struct evhttp_uri *path; 37 | 38 | VERIFY(evhttp_uri_join(uri, buffer, URL_MAX)); 39 | 40 | path = evhttp_uri_parse(buffer); 41 | evhttp_uri_set_scheme(path, NULL); 42 | evhttp_uri_set_userinfo(path, 0); 43 | evhttp_uri_set_host(path, NULL); 44 | evhttp_uri_set_port(path, -1); 45 | VERIFY(evhttp_uri_join(path, buffer, URL_MAX)); 46 | return buffer; 47 | } 48 | static char* uri_hostport(struct evhttp_uri *uri, char buffer[URL_MAX]) 49 | { 50 | VERIFY(evhttp_uri_join(uri, buffer, URL_MAX)); 51 | VERIFY(evhttp_uri_get_host(uri)); 52 | VERIFY(evhttp_uri_get_port(uri) > 0); 53 | evutil_snprintf(buffer, URL_MAX, "%s:%d", 54 | evhttp_uri_get_host(uri), evhttp_uri_get_port(uri)); 55 | return buffer; 56 | } 57 | 58 | static void get_cb(struct evhttp_request *req, void *arg) 59 | { 60 | ev_ssize_t len; 61 | struct evbuffer *evbuf; 62 | 63 | VERIFY(req); 64 | 65 | evbuf = evhttp_request_get_input_buffer(req); 66 | len = evbuffer_get_length(evbuf); 67 | fwrite(evbuffer_pullup(evbuf, len), len, 1, stdout); 68 | evbuffer_drain(evbuf, len); 69 | } 70 | 71 | static void connect_cb(struct evhttp_request *proxy_req, void *arg) 72 | { 73 | struct connect_base *base = arg; 74 | struct evhttp_connection *evcon = base->evcon; 75 | struct evhttp_uri *location = base->location; 76 | struct evhttp_request *req; 77 | char buffer[URL_MAX]; 78 | 79 | VERIFY(proxy_req); 80 | VERIFY(evcon); 81 | 82 | req = evhttp_request_new(get_cb, NULL); 83 | evhttp_add_header(req->output_headers, "Connection", "close"); 84 | evhttp_add_header(req->output_headers, "Host", evhttp_uri_get_host(location)); 85 | VERIFY(!evhttp_make_request(evcon, req, EVHTTP_REQ_GET, 86 | uri_path(location, buffer))); 87 | } 88 | 89 | int main(int argc, const char **argv) 90 | { 91 | char hostport[URL_MAX]; 92 | 93 | struct evhttp_uri *location; 94 | struct evhttp_uri *proxy; 95 | 96 | struct event_base *base; 97 | struct evhttp_connection *evcon; 98 | struct evhttp_request *req; 99 | 100 | struct connect_base connect_base; 101 | 102 | if (argc != 3) { 103 | printf("Usage: %s proxy url\n", argv[0]); 104 | return 1; 105 | } 106 | 107 | proxy = uri_parse(argv[1]); 108 | location = uri_parse(argv[2]); 109 | 110 | VERIFY(base = event_base_new()); 111 | VERIFY(evcon = evhttp_connection_base_new(base, NULL, 112 | evhttp_uri_get_host(proxy), evhttp_uri_get_port(proxy))); 113 | connect_base.evcon = evcon; 114 | connect_base.location = location; 115 | VERIFY(req = evhttp_request_new(connect_cb, &connect_base)); 116 | 117 | uri_hostport(location, hostport); 118 | evhttp_add_header(req->output_headers, "Connection", "keep-alive"); 119 | evhttp_add_header(req->output_headers, "Proxy-Connection", "keep-alive"); 120 | evhttp_add_header(req->output_headers, "Host", hostport); 121 | evhttp_make_request(evcon, req, EVHTTP_REQ_CONNECT, hostport); 122 | 123 | event_base_dispatch(base); 124 | 125 | evhttp_connection_free(evcon); 126 | event_base_free(base); 127 | evhttp_uri_free(proxy); 128 | evhttp_uri_free(location); 129 | 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /sample/include.am: -------------------------------------------------------------------------------- 1 | # sample/include.am for libevent 2 | # Copyright 2000-2007 Niels Provos 3 | # Copyright 2007-2012 Niels Provos and Nick Mathewson 4 | # 5 | # See LICENSE for copying information. 6 | 7 | SAMPLES = \ 8 | sample/dns-example \ 9 | sample/event-read-fifo \ 10 | sample/hello-world \ 11 | sample/http-server \ 12 | sample/http-connect \ 13 | sample/signal-test \ 14 | sample/time-test 15 | 16 | if OPENSSL 17 | SAMPLES += sample/le-proxy 18 | sample_le_proxy_SOURCES = sample/le-proxy.c 19 | sample_le_proxy_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD) 20 | sample_le_proxy_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS) 21 | 22 | SAMPLES += sample/https-client 23 | sample_https_client_SOURCES = \ 24 | sample/https-client.c \ 25 | sample/hostcheck.c \ 26 | sample/openssl_hostname_validation.c 27 | sample_https_client_LDADD = libevent.la libevent_openssl.la $(OPENSSL_LIBS) $(OPENSSL_LIBADD) 28 | if BUILD_WIN32 29 | sample_https_client_LDADD += -lcrypt32 30 | endif 31 | sample_https_client_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS) 32 | noinst_HEADERS += \ 33 | sample/hostcheck.h \ 34 | sample/openssl_hostname_validation.h 35 | endif 36 | 37 | if BUILD_SAMPLES 38 | noinst_PROGRAMS += $(SAMPLES) 39 | endif 40 | 41 | $(SAMPLES) : libevent.la 42 | 43 | sample_event_read_fifo_SOURCES = sample/event-read-fifo.c 44 | sample_event_read_fifo_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 45 | sample_time_test_SOURCES = sample/time-test.c 46 | sample_time_test_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 47 | sample_signal_test_SOURCES = sample/signal-test.c 48 | sample_signal_test_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 49 | sample_dns_example_SOURCES = sample/dns-example.c 50 | sample_dns_example_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 51 | sample_hello_world_SOURCES = sample/hello-world.c 52 | sample_hello_world_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 53 | sample_http_server_SOURCES = sample/http-server.c 54 | sample_http_server_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 55 | sample_http_connect_SOURCES = sample/http-connect.c 56 | sample_http_connect_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 57 | -------------------------------------------------------------------------------- /sample/openssl_hostname_validation.h: -------------------------------------------------------------------------------- 1 | /* Obtained from: https://github.com/iSECPartners/ssl-conservatory */ 2 | 3 | /* 4 | Copyright (C) 2012, iSEC Partners. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is furnished to do 11 | so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | /* 26 | * Helper functions to perform basic hostname validation using OpenSSL. 27 | * 28 | * Please read "everything-you-wanted-to-know-about-openssl.pdf" before 29 | * attempting to use this code. This whitepaper describes how the code works, 30 | * how it should be used, and what its limitations are. 31 | * 32 | * Author: Alban Diquet 33 | * License: See LICENSE 34 | * 35 | */ 36 | 37 | typedef enum { 38 | MatchFound, 39 | MatchNotFound, 40 | NoSANPresent, 41 | MalformedCertificate, 42 | Error 43 | } HostnameValidationResult; 44 | 45 | /** 46 | * Validates the server's identity by looking for the expected hostname in the 47 | * server's certificate. As described in RFC 6125, it first tries to find a match 48 | * in the Subject Alternative Name extension. If the extension is not present in 49 | * the certificate, it checks the Common Name instead. 50 | * 51 | * Returns MatchFound if a match was found. 52 | * Returns MatchNotFound if no matches were found. 53 | * Returns MalformedCertificate if any of the hostnames had a NUL character embedded in it. 54 | * Returns Error if there was an error. 55 | */ 56 | HostnameValidationResult validate_hostname(const char *hostname, const X509 *server_cert); 57 | -------------------------------------------------------------------------------- /sample/signal-test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Compile with: 3 | * cc -I/usr/local/include -o signal-test \ 4 | * signal-test.c -L/usr/local/lib -levent 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #ifndef _WIN32 13 | #include 14 | #include 15 | #include 16 | #else 17 | #include 18 | #include 19 | #endif 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | int called = 0; 30 | 31 | static void 32 | signal_cb(evutil_socket_t fd, short event, void *arg) 33 | { 34 | struct event *signal = arg; 35 | 36 | printf("signal_cb: got signal %d\n", event_get_signal(signal)); 37 | 38 | if (called >= 2) 39 | event_del(signal); 40 | 41 | called++; 42 | } 43 | 44 | int 45 | main(int argc, char **argv) 46 | { 47 | struct event *signal_int = NULL; 48 | struct event_base* base; 49 | int ret = 0; 50 | #ifdef _WIN32 51 | WORD wVersionRequested; 52 | WSADATA wsaData; 53 | 54 | wVersionRequested = MAKEWORD(2, 2); 55 | 56 | (void) WSAStartup(wVersionRequested, &wsaData); 57 | #endif 58 | 59 | /* Initialize the event library */ 60 | base = event_base_new(); 61 | if (!base) { 62 | ret = 1; 63 | goto out; 64 | } 65 | 66 | /* Initialize one event */ 67 | signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg()); 68 | if (!signal_int) { 69 | ret = 2; 70 | goto out; 71 | } 72 | event_add(signal_int, NULL); 73 | 74 | event_base_dispatch(base); 75 | 76 | out: 77 | if (signal_int) 78 | event_free(signal_int); 79 | if (base) 80 | event_base_free(base); 81 | return ret; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /sample/time-test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * XXX This sample code was once meant to show how to use the basic Libevent 3 | * interfaces, but it never worked on non-Unix platforms, and some of the 4 | * interfaces have changed since it was first written. It should probably 5 | * be removed or replaced with something better. 6 | * 7 | * Compile with: 8 | * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent 9 | */ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #ifndef _WIN32 17 | #include 18 | #include 19 | #endif 20 | #include 21 | #ifdef EVENT__HAVE_SYS_TIME_H 22 | #include 23 | #endif 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef _WIN32 35 | #include 36 | #endif 37 | 38 | struct timeval lasttime; 39 | 40 | int event_is_persistent; 41 | 42 | static void 43 | timeout_cb(evutil_socket_t fd, short event, void *arg) 44 | { 45 | struct timeval newtime, difference; 46 | struct event *timeout = arg; 47 | double elapsed; 48 | 49 | evutil_gettimeofday(&newtime, NULL); 50 | evutil_timersub(&newtime, &lasttime, &difference); 51 | elapsed = difference.tv_sec + 52 | (difference.tv_usec / 1.0e6); 53 | 54 | printf("timeout_cb called at %d: %.3f seconds elapsed.\n", 55 | (int)newtime.tv_sec, elapsed); 56 | lasttime = newtime; 57 | 58 | if (! event_is_persistent) { 59 | struct timeval tv; 60 | evutil_timerclear(&tv); 61 | tv.tv_sec = 2; 62 | event_add(timeout, &tv); 63 | } 64 | } 65 | 66 | int 67 | main(int argc, char **argv) 68 | { 69 | struct event timeout; 70 | struct timeval tv; 71 | struct event_base *base; 72 | int flags; 73 | 74 | #ifdef _WIN32 75 | WORD wVersionRequested; 76 | WSADATA wsaData; 77 | 78 | wVersionRequested = MAKEWORD(2, 2); 79 | 80 | (void)WSAStartup(wVersionRequested, &wsaData); 81 | #endif 82 | 83 | if (argc == 2 && !strcmp(argv[1], "-p")) { 84 | event_is_persistent = 1; 85 | flags = EV_PERSIST; 86 | } else { 87 | event_is_persistent = 0; 88 | flags = 0; 89 | } 90 | 91 | /* Initialize the event library */ 92 | base = event_base_new(); 93 | 94 | /* Initialize one event */ 95 | event_assign(&timeout, base, -1, flags, timeout_cb, (void*) &timeout); 96 | 97 | evutil_timerclear(&tv); 98 | tv.tv_sec = 2; 99 | event_add(&timeout, &tv); 100 | 101 | evutil_gettimeofday(&lasttime, NULL); 102 | 103 | setbuf(stdout, NULL); 104 | setbuf(stderr, NULL); 105 | 106 | event_base_dispatch(base); 107 | 108 | return (0); 109 | } 110 | 111 | -------------------------------------------------------------------------------- /strlcpy-internal.h: -------------------------------------------------------------------------------- 1 | #ifndef STRLCPY_INTERNAL_H_INCLUDED_ 2 | #define STRLCPY_INTERNAL_H_INCLUDED_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "event2/event-config.h" 9 | #include "event2/visibility.h" 10 | #include "evconfig-private.h" 11 | 12 | #ifndef EVENT__HAVE_STRLCPY 13 | #include 14 | EVENT2_EXPORT_SYMBOL 15 | size_t event_strlcpy_(char *dst, const char *src, size_t siz); 16 | #define strlcpy event_strlcpy_ 17 | #endif 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #if defined(LIBC_SCCS) && !defined(lint) 31 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; 32 | #endif /* LIBC_SCCS and not lint */ 33 | 34 | #include "event2/event-config.h" 35 | #include "evconfig-private.h" 36 | 37 | #include 38 | 39 | #ifndef EVENT__HAVE_STRLCPY 40 | #include "strlcpy-internal.h" 41 | 42 | /* 43 | * Copy src to string dst of size siz. At most siz-1 characters 44 | * will be copied. Always NUL terminates (unless siz == 0). 45 | * Returns strlen(src); if retval >= siz, truncation occurred. 46 | */ 47 | size_t 48 | event_strlcpy_(dst, src, siz) 49 | char *dst; 50 | const char *src; 51 | size_t siz; 52 | { 53 | register char *d = dst; 54 | register const char *s = src; 55 | register size_t n = siz; 56 | 57 | /* Copy as many bytes as will fit */ 58 | if (n != 0 && --n != 0) { 59 | do { 60 | if ((*d++ = *s++) == 0) 61 | break; 62 | } while (--n != 0); 63 | } 64 | 65 | /* Not enough room in dst, add NUL and traverse rest of src */ 66 | if (n == 0) { 67 | if (siz != 0) 68 | *d = '\0'; /* NUL-terminate dst */ 69 | while (*s++) 70 | ; 71 | } 72 | 73 | return (s - src - 1); /* count does not include NUL */ 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /test-export/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1.2) 2 | if (POLICY CMP0074) 3 | cmake_policy(SET CMP0074 NEW) 4 | endif() 5 | project(verify) 6 | # set(CMAKE_VERBOSE_MAKEFILE 1) 7 | if(NOT ${EVENT__CODE_COMPONENT} STREQUAL "") 8 | string(TOUPPER ${EVENT__CODE_COMPONENT} _UPPER_COMPONENT) 9 | endif() 10 | find_package(Libevent 2.1.0 REQUIRED COMPONENTS ${EVENT__LINK_COMPONENT}) 11 | add_definitions(-DEVENT_EXPORT_TEST_COMPONENT_${_UPPER_COMPONENT}) 12 | add_executable(test-export test-export.c) 13 | target_link_libraries(test-export ${LIBEVENT_LIBRARIES}) 14 | enable_testing() 15 | add_test(test-export test-export) 16 | -------------------------------------------------------------------------------- /test-export/test-export.c: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined(EVENT_EXPORT_TEST_COMPONENT_EXTRA) 3 | #include "event2/http.h" 4 | #include "event2/rpc.h" 5 | #include 6 | #elif defined(EVENT_EXPORT_TEST_COMPONENT_PTHREADS) 7 | #include 8 | #elif defined(EVENT_EXPORT_TEST_COMPONENT_OPENSSL) 9 | #include 10 | #include 11 | #include 12 | #endif 13 | 14 | #if defined(EVENT_EXPORT_TEST_COMPONENT_EXTRA) 15 | static int 16 | test() 17 | { 18 | struct event_base *base = NULL; 19 | struct evhttp *http = NULL; 20 | struct evdns_base *dns_base = NULL; 21 | struct evrpc_base *rpc_base = NULL; 22 | 23 | base = event_base_new(); 24 | if (base) { 25 | http = evhttp_new(base); 26 | dns_base = evdns_base_new(base, 27 | EVDNS_BASE_DISABLE_WHEN_INACTIVE); 28 | } 29 | if (http) 30 | rpc_base = evrpc_init(http); 31 | 32 | if (base) 33 | event_base_free(base); 34 | if (http) 35 | evhttp_free(http); 36 | if (rpc_base) 37 | evrpc_free(rpc_base); 38 | if (dns_base) 39 | evdns_base_free(dns_base, 0); 40 | 41 | return 0; 42 | } 43 | #elif defined(EVENT_EXPORT_TEST_COMPONENT_PTHREADS) 44 | static int 45 | test() 46 | { 47 | return evthread_use_pthreads(); 48 | } 49 | #elif defined(EVENT_EXPORT_TEST_COMPONENT_OPENSSL) 50 | static int 51 | test() 52 | { 53 | struct event_base *base = NULL; 54 | SSL_CTX *ssl_ctx = NULL; 55 | SSL *ssl = NULL; 56 | struct bufferevent *bev; 57 | int r = 1; 58 | 59 | SSL_library_init(); 60 | ERR_load_crypto_strings(); 61 | SSL_load_error_strings(); 62 | OpenSSL_add_all_algorithms(); 63 | 64 | base = event_base_new(); 65 | if (!base) { 66 | goto error; 67 | } 68 | 69 | ssl_ctx = SSL_CTX_new(SSLv23_method()); 70 | if (!ssl_ctx) { 71 | goto error; 72 | } 73 | ssl = SSL_new(ssl_ctx); 74 | if (ssl == NULL) { 75 | goto error; 76 | } 77 | bev = bufferevent_openssl_socket_new(base, -1, ssl, 78 | BUFFEREVENT_SSL_CONNECTING, 79 | BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS); 80 | if (bev == NULL) { 81 | goto error; 82 | } 83 | r = 0; 84 | error: 85 | if (base) 86 | event_base_free(base); 87 | if (ssl_ctx) 88 | SSL_CTX_free(ssl_ctx); 89 | if (ssl) 90 | SSL_free(ssl); 91 | return r; 92 | } 93 | #else 94 | static int 95 | test() 96 | { 97 | struct event_base *base = NULL; 98 | 99 | base = event_base_new(); 100 | if (base) 101 | event_base_free(base); 102 | 103 | return 0; 104 | } 105 | #endif 106 | 107 | int 108 | main(int argc, char const *argv[]) 109 | { 110 | int r = 0; 111 | #ifdef _WIN32 112 | { 113 | WSADATA wsaData; 114 | WSAStartup(MAKEWORD(2, 2), &wsaData); 115 | } 116 | #endif 117 | r = test(); 118 | #ifdef _WIN32 119 | WSACleanup(); 120 | #endif 121 | return r; 122 | } 123 | -------------------------------------------------------------------------------- /test/Makefile.nmake: -------------------------------------------------------------------------------- 1 | # WATCH OUT! This makefile is a work in progress. -*- makefile -*- 2 | 3 | !IFDEF OPENSSL_DIR 4 | SSL_CFLAGS=/I$(OPENSSL_DIR)\include /DEVENT__HAVE_OPENSSL 5 | SSL_OBJS=regress_ssl.obj 6 | SSL_LIBS=..\libevent_openssl.lib $(OPENSSL_DIR)\lib\libeay32.lib $(OPENSSL_DIR)\lib\ssleay32.lib gdi32.lib User32.lib 7 | !ELSE 8 | SSL_CFLAGS= 9 | SSL_OBJS= 10 | SSL_LIBS= 11 | !ENDIF 12 | 13 | CFLAGS=/I.. /I../WIN32-Code /I../WIN32-Code/nmake /I../include /I../compat /DHAVE_CONFIG_H /DTINYTEST_LOCAL $(SSL_CFLAGS) 14 | 15 | CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo 16 | 17 | REGRESS_OBJS=regress.obj regress_buffer.obj regress_http.obj regress_dns.obj \ 18 | regress_testutils.obj \ 19 | regress_rpc.obj regress.gen.obj \ 20 | regress_et.obj regress_bufferevent.obj \ 21 | regress_listener.obj regress_util.obj tinytest.obj \ 22 | regress_main.obj regress_minheap.obj regress_iocp.obj \ 23 | regress_thread.obj regress_finalize.obj $(SSL_OBJS) 24 | 25 | OTHER_OBJS=test-init.obj test-eof.obj test-closed.obj test-weof.obj test-time.obj \ 26 | bench.obj bench_cascade.obj bench_http.obj bench_httpclient.obj \ 27 | test-changelist.obj \ 28 | print-winsock-errors.obj 29 | 30 | PROGRAMS=regress.exe \ 31 | test-init.exe test-eof.exe test-closed.exe test-weof.exe test-time.exe \ 32 | test-changelist.exe \ 33 | print-winsock-errors.exe 34 | 35 | # Disabled for now: 36 | # bench.exe bench_cascade.exe bench_http.exe bench_httpclient.exe 37 | 38 | 39 | LIBS=..\libevent.lib ws2_32.lib shell32.lib advapi32.lib 40 | 41 | all: $(PROGRAMS) 42 | 43 | regress.exe: $(REGRESS_OBJS) 44 | $(CC) $(CFLAGS) $(LIBS) $(SSL_LIBS) $(REGRESS_OBJS) 45 | 46 | test-init.exe: test-init.obj 47 | $(CC) $(CFLAGS) $(LIBS) test-init.obj 48 | test-eof.exe: test-eof.obj 49 | $(CC) $(CFLAGS) $(LIBS) test-eof.obj 50 | test-closed.exe: test-closed.obj 51 | $(CC) $(CFLAGS) $(LIBS) test-closed.obj 52 | test-changelist.exe: test-changelist.obj 53 | $(CC) $(CFLAGS) $(LIBS) test-changelist.obj 54 | test-weof.exe: test-weof.obj 55 | $(CC) $(CFLAGS) $(LIBS) test-weof.obj 56 | test-time.exe: test-time.obj 57 | $(CC) $(CFLAGS) $(LIBS) test-time.obj 58 | 59 | print-winsock-errors.exe: print-winsock-errors.obj 60 | $(CC) $(CFLAGS) $(LIBS) print-winsock-errors.obj 61 | 62 | bench.exe: bench.obj 63 | $(CC) $(CFLAGS) $(LIBS) bench.obj 64 | bench_cascade.exe: bench_cascade.obj 65 | $(CC) $(CFLAGS) $(LIBS) bench_cascade.obj 66 | bench_http.exe: bench_http.obj 67 | $(CC) $(CFLAGS) $(LIBS) bench_http.obj 68 | bench_httpclient.exe: bench_httpclient.obj 69 | $(CC) $(CFLAGS) $(LIBS) bench_httpclient.obj 70 | 71 | regress.gen.c regress.gen.h: regress.rpc ../event_rpcgen.py 72 | echo // > regress.gen.c 73 | echo #define NO_PYTHON_EXISTS > regress.gen.h 74 | -python ..\event_rpcgen.py regress.rpc 75 | 76 | clean: 77 | -del $(REGRESS_OBJS) 78 | -del $(OTHER_OBJS) 79 | -del $(PROGRAMS) 80 | -------------------------------------------------------------------------------- /test/check-dumpevents.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Post-process the output of test-dumpevents and check it for correctness. 4 | # 5 | 6 | import math 7 | import re 8 | import sys 9 | 10 | text = sys.stdin.readlines() 11 | 12 | try: 13 | expect_inserted_pos = text.index("Inserted:\n") 14 | expect_active_pos = text.index("Active:\n") 15 | got_inserted_pos = text.index("Inserted events:\n") 16 | got_active_pos = text.index("Active events:\n") 17 | except ValueError: 18 | sys.stderr.write("Missing expected dividing line in dumpevents output") 19 | sys.exit(1) 20 | 21 | if not (expect_inserted_pos < expect_active_pos < 22 | got_inserted_pos < got_active_pos): 23 | sys.stderr.write("Sections out of order in dumpevents output") 24 | sys.exit(1) 25 | 26 | now,T= text[1].split() 27 | T = float(T) 28 | 29 | want_inserted = set(text[expect_inserted_pos+1:expect_active_pos]) 30 | want_active = set(text[expect_active_pos+1:got_inserted_pos-1]) 31 | got_inserted = set(text[got_inserted_pos+1:got_active_pos]) 32 | got_active = set(text[got_active_pos+1:]) 33 | 34 | pat = re.compile(r'Timeout=([0-9\.]+)') 35 | def replace_time(m): 36 | t = float(m.group(1)) 37 | if .9 < abs(t-T) < 1.1: 38 | return "Timeout=T+1" 39 | elif 2.4 < abs(t-T) < 2.6: 40 | return "Timeout=T+2.5" 41 | else: 42 | return m.group(0) 43 | 44 | cleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted 45 | if "Internal" not in s) 46 | 47 | if cleaned_inserted != want_inserted: 48 | sys.stderr.write("Inserted event lists were not as expected!") 49 | sys.exit(1) 50 | 51 | if set(got_active) != set(want_active): 52 | sys.stderr.write("Active event lists were not as expected!") 53 | sys.exit(1) 54 | 55 | -------------------------------------------------------------------------------- /test/print-winsock-errors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "event2/event.h" 8 | #include "event2/util.h" 9 | #include "event2/thread.h" 10 | 11 | #define E(x) printf (#x " -> \"%s\"\n", evutil_socket_error_to_string (x)); 12 | 13 | int main (int argc, char **argv) 14 | { 15 | int i, j; 16 | const char *s1, *s2; 17 | 18 | #ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 19 | evthread_use_windows_threads (); 20 | #endif 21 | 22 | s1 = evutil_socket_error_to_string (WSAEINTR); 23 | 24 | for (i = 0; i < 3; i++) { 25 | printf ("\niteration %d:\n\n", i); 26 | E(WSAEINTR); 27 | E(WSAEACCES); 28 | E(WSAEFAULT); 29 | E(WSAEINVAL); 30 | E(WSAEMFILE); 31 | E(WSAEWOULDBLOCK); 32 | E(WSAEINPROGRESS); 33 | E(WSAEALREADY); 34 | E(WSAENOTSOCK); 35 | E(WSAEDESTADDRREQ); 36 | E(WSAEMSGSIZE); 37 | E(WSAEPROTOTYPE); 38 | E(WSAENOPROTOOPT); 39 | E(WSAEPROTONOSUPPORT); 40 | E(WSAESOCKTNOSUPPORT); 41 | E(WSAEOPNOTSUPP); 42 | E(WSAEPFNOSUPPORT); 43 | E(WSAEAFNOSUPPORT); 44 | E(WSAEADDRINUSE); 45 | E(WSAEADDRNOTAVAIL); 46 | E(WSAENETDOWN); 47 | E(WSAENETUNREACH); 48 | E(WSAENETRESET); 49 | E(WSAECONNABORTED); 50 | E(WSAECONNRESET); 51 | E(WSAENOBUFS); 52 | E(WSAEISCONN); 53 | E(WSAENOTCONN); 54 | E(WSAESHUTDOWN); 55 | E(WSAETIMEDOUT); 56 | E(WSAECONNREFUSED); 57 | E(WSAEHOSTDOWN); 58 | E(WSAEHOSTUNREACH); 59 | E(WSAEPROCLIM); 60 | E(WSASYSNOTREADY); 61 | E(WSAVERNOTSUPPORTED); 62 | E(WSANOTINITIALISED); 63 | E(WSAEDISCON); 64 | E(WSATYPE_NOT_FOUND); 65 | E(WSAHOST_NOT_FOUND); 66 | E(WSATRY_AGAIN); 67 | E(WSANO_RECOVERY); 68 | E(WSANO_DATA); 69 | E(0xdeadbeef); /* test the case where no message is available */ 70 | 71 | /* fill up the hash table a bit to make sure it grows properly */ 72 | for (j = 0; j < 50; j++) { 73 | int err; 74 | evutil_secure_rng_get_bytes(&err, sizeof(err)); 75 | evutil_socket_error_to_string(err); 76 | } 77 | } 78 | 79 | s2 = evutil_socket_error_to_string (WSAEINTR); 80 | if (s1 != s2) 81 | printf ("caching failed!\n"); 82 | 83 | libevent_global_shutdown (); 84 | 85 | return EXIT_SUCCESS; 86 | } 87 | -------------------------------------------------------------------------------- /test/regress.rpc: -------------------------------------------------------------------------------- 1 | /* tests data packing and unpacking */ 2 | 3 | struct msg { 4 | string /* sender */ from_name = 1; /* be verbose */ 5 | string to_name = 2; 6 | optional struct[kill] attack = 3; 7 | array struct[run] run = 4; 8 | } 9 | 10 | struct kill { 11 | string weapon = 0x10121; 12 | string action = 2; 13 | array int how_often = 3; 14 | } 15 | 16 | struct run { 17 | string how = 1; 18 | optional bytes some_bytes = 2; 19 | 20 | bytes fixed_bytes[24] = 3; 21 | array string notes = 4; 22 | 23 | optional int64 large_number = 5; 24 | array int other_numbers = 6; 25 | } 26 | -------------------------------------------------------------------------------- /test/regress_minheap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #include "../minheap-internal.h" 27 | 28 | #include 29 | #include "event2/event_struct.h" 30 | 31 | #include "tinytest.h" 32 | #include "tinytest_macros.h" 33 | #include "regress.h" 34 | 35 | static void 36 | set_random_timeout(struct event *ev) 37 | { 38 | ev->ev_timeout.tv_sec = test_weakrand(); 39 | ev->ev_timeout.tv_usec = test_weakrand() & 0xfffff; 40 | ev->ev_timeout_pos.min_heap_idx = -1; 41 | } 42 | 43 | static void 44 | check_heap(struct min_heap *heap) 45 | { 46 | unsigned i; 47 | for (i = 1; i < heap->n; ++i) { 48 | unsigned parent_idx = (i-1)/2; 49 | tt_want(evutil_timercmp(&heap->p[i]->ev_timeout, 50 | &heap->p[parent_idx]->ev_timeout, >=)); 51 | } 52 | } 53 | 54 | static void 55 | test_heap_randomized(void *ptr) 56 | { 57 | struct min_heap heap; 58 | struct event *inserted[1024]; 59 | struct event *e, *last_e; 60 | int i; 61 | 62 | min_heap_ctor_(&heap); 63 | 64 | for (i = 0; i < 1024; ++i) { 65 | inserted[i] = malloc(sizeof(struct event)); 66 | set_random_timeout(inserted[i]); 67 | min_heap_push_(&heap, inserted[i]); 68 | } 69 | check_heap(&heap); 70 | 71 | tt_assert(min_heap_size_(&heap) == 1024); 72 | 73 | for (i = 0; i < 512; ++i) { 74 | min_heap_erase_(&heap, inserted[i]); 75 | if (0 == (i % 32)) 76 | check_heap(&heap); 77 | } 78 | tt_assert(min_heap_size_(&heap) == 512); 79 | 80 | last_e = min_heap_pop_(&heap); 81 | while (1) { 82 | e = min_heap_pop_(&heap); 83 | if (!e) 84 | break; 85 | tt_want(evutil_timercmp(&last_e->ev_timeout, 86 | &e->ev_timeout, <=)); 87 | } 88 | tt_assert(min_heap_size_(&heap) == 0); 89 | end: 90 | for (i = 0; i < 1024; ++i) 91 | free(inserted[i]); 92 | 93 | min_heap_dtor_(&heap); 94 | } 95 | 96 | struct testcase_t minheap_testcases[] = { 97 | { "randomized", test_heap_randomized, 0, NULL, NULL }, 98 | END_OF_TESTCASES 99 | }; 100 | -------------------------------------------------------------------------------- /test/regress_testutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef REGRESS_TESTUTILS_H_INCLUDED_ 28 | #define REGRESS_TESTUTILS_H_INCLUDED_ 29 | 30 | #include "event2/dns.h" 31 | 32 | struct regress_dns_server_table { 33 | const char *q; 34 | const char *anstype; 35 | const char *ans; 36 | int seen; 37 | int lower; 38 | }; 39 | 40 | struct evdns_server_port * 41 | regress_get_dnsserver(struct event_base *base, 42 | ev_uint16_t *portnum, 43 | evutil_socket_t *psock, 44 | evdns_request_callback_fn_type cb, 45 | void *arg); 46 | 47 | /* Helper: return the port that a socket is bound on, in host order. */ 48 | int regress_get_socket_port(evutil_socket_t fd); 49 | 50 | /* used to look up pre-canned responses in a search table */ 51 | void regress_dns_server_cb( 52 | struct evdns_server_request *req, void *data); 53 | 54 | /* globally allocates a dns server that serves from a search table */ 55 | int regress_dnsserver(struct event_base *base, ev_uint16_t *port, 56 | struct regress_dns_server_table *seach_table); 57 | 58 | /* clean up the global dns server resources */ 59 | void regress_clean_dnsserver(void); 60 | 61 | struct evconnlistener; 62 | struct sockaddr; 63 | int regress_get_listener_addr(struct evconnlistener *lev, 64 | struct sockaddr *sa, ev_socklen_t *socklen); 65 | 66 | #endif /* REGRESS_TESTUTILS_H_INCLUDED_ */ 67 | 68 | -------------------------------------------------------------------------------- /test/regress_thread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. The name of the author may not be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef REGRESS_THREAD_H_INCLUDED_ 28 | #define REGRESS_THREAD_H_INCLUDED_ 29 | 30 | #if defined(_WIN32) /** _WIN32 */ 31 | #define THREAD_T void * /* HANDLE */ 32 | #define THREAD_FN unsigned __stdcall 33 | #define THREAD_RETURN() return (0) 34 | #define THREAD_SELF() GetCurrentThreadId() 35 | #define THREAD_START(threadvar, fn, arg) do { \ 36 | uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ 37 | (threadvar) = (THREAD_T)threadhandle; \ 38 | thread_setup(threadvar); \ 39 | } while (0) 40 | #define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) 41 | #else /* !_WIN32 */ 42 | #include 43 | #define THREAD_T pthread_t 44 | #define THREAD_FN void * 45 | #define THREAD_RETURN() return (NULL) 46 | #define THREAD_SELF() pthread_self() 47 | #define THREAD_START(threadvar, fn, arg) do { \ 48 | if (!pthread_create(&(threadvar), NULL, fn, arg)) \ 49 | thread_setup(threadvar); \ 50 | } while (0) 51 | #define THREAD_JOIN(th) pthread_join(th, NULL) 52 | #endif /* \!_WIN32 */ 53 | 54 | void thread_setup(THREAD_T pthread); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /test/rpcgen_wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # libevent rpcgen_wrapper.sh 3 | # Transforms event_rpcgen.py failure into success for make, only if 4 | # regress.gen.c and regress.gen.h already exist in $srcdir. This 5 | # is needed for "make distcheck" to pass the read-only $srcdir build, 6 | # as with read-only sources fresh from tarball, regress.gen.[ch] will 7 | # be correct in $srcdir but unwritable. This previously triggered 8 | # Makefile.am to create stub regress.gen.c and regress.gen.h in the 9 | # distcheck _build directory, which were then detected as leftover 10 | # files in the build tree after distclean, breaking distcheck. 11 | # Note that regress.gen.[ch] are not in fresh git clones, making 12 | # working Python a requirement for make distcheck of a git tree. 13 | 14 | exit_updated() { 15 | # echo "Updated ${srcdir}/regress.gen.c and ${srcdir}/regress.gen.h" 16 | exit 0 17 | } 18 | 19 | exit_reuse() { 20 | echo "event_rpcgen.py failed, ${srcdir}/regress.gen.\[ch\] will be reused." >&2 21 | exit 0 22 | } 23 | 24 | exit_failed() { 25 | echo "Could not generate regress.gen.\[ch\] using event_rpcgen.sh" >&2 26 | exit 1 27 | } 28 | srcdir=$1 29 | srcdir=${srcdir:-.} 30 | 31 | ${srcdir}/../event_rpcgen.py --quiet ${srcdir}/regress.rpc \ 32 | test/regress.gen.h test/regress.gen.c 33 | 34 | case "$?" in 35 | 0) 36 | exit_updated 37 | ;; 38 | *) 39 | test -r ${srcdir}/regress.gen.c -a -r ${srcdir}/regress.gen.h && \ 40 | exit_reuse 41 | exit_failed 42 | ;; 43 | esac 44 | -------------------------------------------------------------------------------- /test/test-closed.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Niels Provos 3 | * Copyright (c) 2007-2013 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "../util-internal.h" 28 | #include "event2/event-config.h" 29 | 30 | #ifdef _WIN32 31 | #include 32 | #else 33 | #include 34 | #endif 35 | #include 36 | #include 37 | #ifdef EVENT__HAVE_SYS_TIME_H 38 | #include 39 | #endif 40 | #ifdef EVENT__HAVE_SYS_SOCKET_H 41 | #include 42 | #endif 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | 52 | struct timeval timeout = {3, 0}; 53 | 54 | static void 55 | closed_cb(evutil_socket_t fd, short event, void *arg) 56 | { 57 | if (EV_TIMEOUT & event) { 58 | printf("%s: Timeout!\n", __func__); 59 | exit(1); 60 | } 61 | 62 | if (EV_CLOSED & event) { 63 | printf("%s: detected socket close with success\n", __func__); 64 | return; 65 | } 66 | 67 | printf("%s: unable to detect socket close\n", __func__); 68 | exit(1); 69 | } 70 | 71 | int 72 | main(int argc, char **argv) 73 | { 74 | struct event_base *base; 75 | struct event_config *cfg; 76 | struct event *ev; 77 | const char *test = "test string"; 78 | evutil_socket_t pair[2]; 79 | 80 | /* Initialize the library and check if the backend 81 | supports EV_FEATURE_EARLY_CLOSE 82 | */ 83 | cfg = event_config_new(); 84 | event_config_require_features(cfg, EV_FEATURE_EARLY_CLOSE); 85 | base = event_base_new_with_config(cfg); 86 | event_config_free(cfg); 87 | if (!base) { 88 | /* Backend doesn't support EV_FEATURE_EARLY_CLOSE */ 89 | return 0; 90 | } 91 | 92 | /* Create a pair of sockets */ 93 | if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) 94 | return (1); 95 | 96 | /* Send some data on socket 0 and immediately close it */ 97 | if (send(pair[0], test, (int)strlen(test)+1, 0) < 0) 98 | return (1); 99 | shutdown(pair[0], EVUTIL_SHUT_WR); 100 | 101 | /* Dispatch */ 102 | ev = event_new(base, pair[1], EV_CLOSED | EV_TIMEOUT, closed_cb, event_self_cbarg()); 103 | event_add(ev, &timeout); 104 | event_base_dispatch(base); 105 | 106 | /* Finalize library */ 107 | event_free(ev); 108 | event_base_free(base); 109 | return 0; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /test/test-eof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "../util-internal.h" 28 | #include "event2/event-config.h" 29 | 30 | #ifdef _WIN32 31 | #include 32 | #else 33 | #include 34 | #endif 35 | #include 36 | #include 37 | #ifdef EVENT__HAVE_SYS_TIME_H 38 | #include 39 | #endif 40 | #ifdef EVENT__HAVE_SYS_SOCKET_H 41 | #include 42 | #endif 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | 52 | int test_okay = 1; 53 | int called = 0; 54 | struct timeval timeout = {60, 0}; 55 | 56 | static void 57 | read_cb(evutil_socket_t fd, short event, void *arg) 58 | { 59 | char buf[256]; 60 | int len; 61 | 62 | if (EV_TIMEOUT & event) { 63 | printf("%s: Timeout!\n", __func__); 64 | exit(1); 65 | } 66 | 67 | len = recv(fd, buf, sizeof(buf), 0); 68 | 69 | printf("%s: read %d%s\n", __func__, 70 | len, len ? "" : " - means EOF"); 71 | 72 | if (len) { 73 | if (!called) 74 | event_add(arg, &timeout); 75 | } else if (called == 1) 76 | test_okay = 0; 77 | 78 | called++; 79 | } 80 | 81 | int 82 | main(int argc, char **argv) 83 | { 84 | struct event ev; 85 | const char *test = "test string"; 86 | evutil_socket_t pair[2]; 87 | 88 | #ifdef _WIN32 89 | WORD wVersionRequested; 90 | WSADATA wsaData; 91 | 92 | wVersionRequested = MAKEWORD(2, 2); 93 | 94 | (void) WSAStartup(wVersionRequested, &wsaData); 95 | #endif 96 | 97 | if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) 98 | return (1); 99 | 100 | 101 | if (send(pair[0], test, (int)strlen(test)+1, 0) < 0) 102 | return (1); 103 | shutdown(pair[0], EVUTIL_SHUT_WR); 104 | 105 | /* Initialize the event library */ 106 | event_init(); 107 | 108 | /* Initialize one event */ 109 | event_set(&ev, pair[1], EV_READ | EV_TIMEOUT, read_cb, &ev); 110 | 111 | event_add(&ev, &timeout); 112 | 113 | event_dispatch(); 114 | 115 | return (test_okay); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /test/test-init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "event2/event-config.h" 28 | 29 | #include 30 | #include 31 | #ifdef EVENT__HAVE_SYS_TIME_H 32 | #include 33 | #endif 34 | #ifdef EVENT__HAVE_SYS_SOCKET_H 35 | #include 36 | #endif 37 | #include 38 | #include 39 | #include 40 | #include 41 | #ifndef _WIN32 42 | #include 43 | #endif 44 | #include 45 | 46 | #include 47 | 48 | int 49 | main(int argc, char **argv) 50 | { 51 | #ifdef _WIN32 52 | WORD wVersionRequested; 53 | WSADATA wsaData; 54 | 55 | wVersionRequested = MAKEWORD(2, 2); 56 | 57 | (void) WSAStartup(wVersionRequested, &wsaData); 58 | #endif 59 | 60 | /* Initialize the event library */ 61 | event_init(); 62 | 63 | return (0); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /test/test-ratelim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | FAILED=no 4 | 5 | if test "x$TEST_OUTPUT_FILE" = "x" 6 | then 7 | TEST_OUTPUT_FILE=/dev/null 8 | fi 9 | 10 | # /bin/echo is a little more likely to support -n than sh's builtin echo. 11 | if test -x /bin/echo 12 | then 13 | ECHO=/bin/echo 14 | else 15 | ECHO=echo 16 | fi 17 | 18 | if test "$TEST_OUTPUT_FILE" != "/dev/null" 19 | then 20 | touch "$TEST_OUTPUT_FILE" || exit 1 21 | fi 22 | 23 | TEST_DIR=. 24 | 25 | T=`echo "$0" | sed -e 's/test-ratelim.sh$//'` 26 | if test -x "$T/test-ratelim" 27 | then 28 | TEST_DIR="$T" 29 | fi 30 | 31 | announce () { 32 | echo $@ 33 | echo $@ >>"$TEST_OUTPUT_FILE" 34 | } 35 | 36 | announce_n () { 37 | $ECHO -n $@ 38 | echo $@ >>"$TEST_OUTPUT_FILE" 39 | } 40 | 41 | 42 | run_tests () { 43 | announce_n " Group limits, no connection limit:" 44 | if $TEST_DIR/test-ratelim -g 30000 -n 30 -t 100 --check-grouplimit 1000 --check-stddev 100 >>"$TEST_OUTPUT_FILE" 45 | then 46 | announce OKAY 47 | else 48 | announce FAILED 49 | FAILED=yes 50 | fi 51 | 52 | announce_n " Connection limit, no group limit:" 53 | if $TEST_DIR/test-ratelim -c 1000 -n 30 -t 100 --check-connlimit 50 --check-stddev 50 >>"$TEST_OUTPUT_FILE" 54 | then 55 | announce OKAY ; 56 | else 57 | announce FAILED ; 58 | FAILED=yes 59 | fi 60 | 61 | announce_n " Connection limit and group limit:" 62 | if $TEST_DIR/test-ratelim -c 1000 -g 30000 -n 30 -t 100 --check-grouplimit 1000 --check-connlimit 50 --check-stddev 50 >>"$TEST_OUTPUT_FILE" 63 | then 64 | announce OKAY ; 65 | else 66 | announce FAILED ; 67 | FAILED=yes 68 | fi 69 | 70 | announce_n " Connection limit and group limit with independent drain:" 71 | if $TEST_DIR/test-ratelim -c 1000 -g 35000 -n 30 -t 100 -G 500 --check-grouplimit 1000 --check-connlimit 50 --check-stddev 50 >>"$TEST_OUTPUT_FILE" 72 | then 73 | announce OKAY ; 74 | else 75 | announce FAILED ; 76 | FAILED=yes 77 | fi 78 | 79 | 80 | } 81 | 82 | announce "Running rate-limiting tests:" 83 | 84 | run_tests 85 | 86 | if test "$FAILED" = "yes"; then 87 | exit 1 88 | fi 89 | -------------------------------------------------------------------------------- /test/test-time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "event2/event-config.h" 28 | #include "util-internal.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #ifndef _WIN32 37 | #include 38 | #include 39 | #endif 40 | #include 41 | 42 | #include "event2/event.h" 43 | #include "event2/event_compat.h" 44 | #include "event2/event_struct.h" 45 | 46 | int called = 0; 47 | 48 | #define NEVENT 20000 49 | 50 | struct event *ev[NEVENT]; 51 | 52 | struct evutil_weakrand_state weakrand_state; 53 | 54 | static int 55 | rand_int(int n) 56 | { 57 | return evutil_weakrand_(&weakrand_state) % n; 58 | } 59 | 60 | static void 61 | time_cb(evutil_socket_t fd, short event, void *arg) 62 | { 63 | struct timeval tv; 64 | int i, j; 65 | 66 | called++; 67 | 68 | if (called < 10*NEVENT) { 69 | for (i = 0; i < 10; i++) { 70 | j = rand_int(NEVENT); 71 | tv.tv_sec = 0; 72 | tv.tv_usec = rand_int(50000); 73 | if (tv.tv_usec % 2 || called < NEVENT) 74 | evtimer_add(ev[j], &tv); 75 | else 76 | evtimer_del(ev[j]); 77 | } 78 | } 79 | } 80 | 81 | int 82 | main(int argc, char **argv) 83 | { 84 | struct event_base *base; 85 | struct timeval tv; 86 | int i; 87 | 88 | #ifdef _WIN32 89 | WORD wVersionRequested; 90 | WSADATA wsaData; 91 | 92 | wVersionRequested = MAKEWORD(2, 2); 93 | 94 | (void) WSAStartup(wVersionRequested, &wsaData); 95 | #endif 96 | 97 | evutil_weakrand_seed_(&weakrand_state, 0); 98 | 99 | if (getenv("EVENT_DEBUG_LOGGING_ALL")) { 100 | event_enable_debug_logging(EVENT_DBG_ALL); 101 | } 102 | 103 | base = event_base_new(); 104 | 105 | for (i = 0; i < NEVENT; i++) { 106 | ev[i] = evtimer_new(base, time_cb, event_self_cbarg()); 107 | tv.tv_sec = 0; 108 | tv.tv_usec = rand_int(50000); 109 | evtimer_add(ev[i], &tv); 110 | } 111 | 112 | i = event_base_dispatch(base); 113 | 114 | printf("event_base_dispatch=%d, called=%d, EVENT=%d\n", 115 | i, called, NEVENT); 116 | 117 | if (i == 1 && called >= NEVENT) { 118 | return EXIT_SUCCESS; 119 | } else { 120 | return EXIT_FAILURE; 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /test/test-weof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "../util-internal.h" 28 | #include "event2/event-config.h" 29 | 30 | #ifdef _WIN32 31 | #include 32 | #else 33 | #include 34 | #endif 35 | #include 36 | #include 37 | #ifdef EVENT__HAVE_SYS_TIME_H 38 | #include 39 | #endif 40 | #ifdef EVENT__HAVE_SYS_SOCKET_H 41 | #include 42 | #endif 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include "event2/event.h" 51 | #include "event2/event_struct.h" 52 | #include "event2/event_compat.h" 53 | #include "event2/util.h" 54 | 55 | evutil_socket_t pair[2]; 56 | int test_okay = 1; 57 | int called = 0; 58 | 59 | static void 60 | write_cb(evutil_socket_t fd, short event, void *arg) 61 | { 62 | const char *test = "test string"; 63 | int len; 64 | 65 | len = send(fd, test, (int)strlen(test) + 1, 0); 66 | 67 | printf("%s: write %d%s\n", __func__, 68 | len, len ? "" : " - means EOF"); 69 | 70 | if (len > 0) { 71 | if (!called) 72 | event_add(arg, NULL); 73 | evutil_closesocket(pair[0]); 74 | } else if (called == 1) 75 | test_okay = 0; 76 | 77 | called++; 78 | } 79 | 80 | int 81 | main(int argc, char **argv) 82 | { 83 | struct event ev; 84 | 85 | #ifdef _WIN32 86 | WORD wVersionRequested; 87 | WSADATA wsaData; 88 | 89 | wVersionRequested = MAKEWORD(2, 2); 90 | 91 | (void) WSAStartup(wVersionRequested, &wsaData); 92 | #endif 93 | 94 | #ifndef _WIN32 95 | if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) 96 | return (1); 97 | #endif 98 | 99 | if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) 100 | return (1); 101 | 102 | /* Initialize the event library */ 103 | event_init(); 104 | 105 | /* Initialize one event */ 106 | event_set(&ev, pair[1], EV_WRITE, write_cb, &ev); 107 | 108 | event_add(&ev, NULL); 109 | 110 | event_dispatch(); 111 | 112 | return (test_okay); 113 | } 114 | 115 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | BACKENDS="EVPORT KQUEUE EPOLL DEVPOLL POLL SELECT WIN32" 4 | TESTS="test-eof test-closed test-weof test-time test-changelist test-fdleak" 5 | FAILED=no 6 | TEST_OUTPUT_FILE=${TEST_OUTPUT_FILE:-/dev/null} 7 | REGRESS_ARGS=${REGRESS_ARGS:-} 8 | 9 | # /bin/echo is a little more likely to support -n than sh's builtin echo, 10 | # printf is even more likely 11 | if test "`printf %s hello 2>&1`" = "hello" 12 | then 13 | ECHO_N="printf %s" 14 | else 15 | if test -x /bin/echo 16 | then 17 | ECHO_N="/bin/echo -n" 18 | else 19 | ECHO_N="echo -n" 20 | fi 21 | fi 22 | 23 | if test "$TEST_OUTPUT_FILE" != "/dev/null" 24 | then 25 | touch "$TEST_OUTPUT_FILE" || exit 1 26 | fi 27 | 28 | TEST_DIR=. 29 | TEST_SRC_DIR=. 30 | 31 | T=`echo "$0" | sed -e 's/test.sh$//'` 32 | if test -x "$T/test-init" 33 | then 34 | TEST_DIR="$T" 35 | elif test -x "./test/test-init" 36 | then 37 | TEST_DIR="./test" 38 | fi 39 | if test -f "$T/check-dumpevents.py" 40 | then 41 | TEST_SRC_DIR="$T" 42 | elif test -f "./test/check-dumpevents.py" 43 | then 44 | TEST_SRC_DIR="./test" 45 | fi 46 | 47 | setup () { 48 | for i in $BACKENDS; do 49 | eval "EVENT_NO$i=yes; export EVENT_NO$i" 50 | done 51 | unset EVENT_EPOLL_USE_CHANGELIST 52 | unset EVENT_PRECISE_TIMER 53 | } 54 | 55 | announce () { 56 | echo "$@" 57 | echo "$@" >>"$TEST_OUTPUT_FILE" 58 | } 59 | 60 | announce_n () { 61 | $ECHO_N "$@" 62 | echo "$@" >>"$TEST_OUTPUT_FILE" 63 | } 64 | 65 | 66 | run_tests () { 67 | if $TEST_DIR/test-init 2>>"$TEST_OUTPUT_FILE" ; 68 | then 69 | true 70 | else 71 | announce Skipping test 72 | return 73 | fi 74 | for i in $TESTS; do 75 | announce_n " $i: " 76 | if $TEST_DIR/$i >>"$TEST_OUTPUT_FILE" ; 77 | then 78 | announce OKAY ; 79 | else 80 | announce FAILED ; 81 | FAILED=yes 82 | fi 83 | done 84 | announce_n " test-dumpevents: " 85 | if python -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null && test -f $TEST_SRC_DIR/check-dumpevents.py; then 86 | if $TEST_DIR/test-dumpevents | $TEST_SRC_DIR/check-dumpevents.py >> "$TEST_OUTPUT_FILE" ; 87 | then 88 | announce OKAY ; 89 | else 90 | announce FAILED ; 91 | fi 92 | else 93 | # no python 94 | if $TEST_DIR/test-dumpevents >/dev/null; then 95 | announce "OKAY (output not checked)" ; 96 | else 97 | announce "FAILED (output not checked)" ; 98 | fi 99 | fi 100 | 101 | test -x $TEST_DIR/regress || return 102 | announce_n " regress: " 103 | if test "$TEST_OUTPUT_FILE" = "/dev/null" ; 104 | then 105 | $TEST_DIR/regress --quiet $REGRESS_ARGS 106 | else 107 | $TEST_DIR/regress $REGRESS_ARGS >>"$TEST_OUTPUT_FILE" 108 | fi 109 | if test "$?" = "0" ; 110 | then 111 | announce OKAY ; 112 | else 113 | announce FAILED ; 114 | FAILED=yes 115 | fi 116 | 117 | announce_n " regress_debug: " 118 | if test "$TEST_OUTPUT_FILE" = "/dev/null" ; 119 | then 120 | EVENT_DEBUG_MODE=1 $TEST_DIR/regress --quiet $REGRESS_ARGS 121 | else 122 | EVENT_DEBUG_MODE=1 $TEST_DIR/regress $REGRESS_ARGS >>"$TEST_OUTPUT_FILE" 123 | fi 124 | if test "$?" = "0" ; 125 | then 126 | announce OKAY ; 127 | else 128 | announce FAILED ; 129 | FAILED=yes 130 | fi 131 | } 132 | 133 | do_test() { 134 | setup 135 | announce "$1 $2" 136 | unset EVENT_NO$1 137 | if test "$2" = "(changelist)" ; then 138 | EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST 139 | elif test "$2" = "(timerfd)" ; then 140 | EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER 141 | elif test "$2" = "(timerfd+changelist)" ; then 142 | EVENT_EPOLL_USE_CHANGELIST=yes; export EVENT_EPOLL_USE_CHANGELIST 143 | EVENT_PRECISE_TIMER=1; export EVENT_PRECISE_TIMER 144 | fi 145 | 146 | run_tests 147 | } 148 | 149 | usage() 150 | { 151 | cat < 5 | #endif 6 | 7 | #include "event2/util.h" 8 | 9 | #ifdef snprintf 10 | #undef snprintf 11 | #endif 12 | #define snprintf evutil_snprintf 13 | -------------------------------------------------------------------------------- /time-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Niels Provos 3 | * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #ifndef TIME_INTERNAL_H_INCLUDED_ 28 | #define TIME_INTERNAL_H_INCLUDED_ 29 | 30 | #include "event2/event-config.h" 31 | #include "evconfig-private.h" 32 | 33 | #ifdef EVENT__HAVE_MACH_MACH_TIME_H 34 | /* For mach_timebase_info */ 35 | #include 36 | #endif 37 | 38 | #include 39 | 40 | #include "event2/util.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) 47 | #define HAVE_POSIX_MONOTONIC 48 | #elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) 49 | #define HAVE_MACH_MONOTONIC 50 | #elif defined(_WIN32) 51 | #define HAVE_WIN32_MONOTONIC 52 | #else 53 | #define HAVE_FALLBACK_MONOTONIC 54 | #endif 55 | 56 | long evutil_tv_to_msec_(const struct timeval *tv); 57 | EVENT2_EXPORT_SYMBOL 58 | void evutil_usleep_(const struct timeval *tv); 59 | 60 | #ifdef _WIN32 61 | typedef ULONGLONG (WINAPI *ev_GetTickCount_func)(void); 62 | #endif 63 | 64 | struct evutil_monotonic_timer { 65 | 66 | #ifdef HAVE_MACH_MONOTONIC 67 | struct mach_timebase_info mach_timebase_units; 68 | #endif 69 | 70 | #ifdef HAVE_POSIX_MONOTONIC 71 | int monotonic_clock; 72 | #endif 73 | 74 | #ifdef HAVE_WIN32_MONOTONIC 75 | ev_GetTickCount_func GetTickCount64_fn; 76 | ev_GetTickCount_func GetTickCount_fn; 77 | ev_uint64_t last_tick_count; 78 | ev_uint64_t adjust_tick_count; 79 | 80 | ev_uint64_t first_tick; 81 | ev_uint64_t first_counter; 82 | double usec_per_count; 83 | int use_performance_counter; 84 | #endif 85 | 86 | struct timeval adjust_monotonic_clock; 87 | struct timeval last_time; 88 | }; 89 | 90 | EVENT2_EXPORT_SYMBOL 91 | int evutil_configure_monotonic_time_(struct evutil_monotonic_timer *mt, 92 | int flags); 93 | EVENT2_EXPORT_SYMBOL 94 | int evutil_gettime_monotonic_(struct evutil_monotonic_timer *mt, struct timeval *tv); 95 | 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* EVENT_INTERNAL_H_INCLUDED_ */ 102 | --------------------------------------------------------------------------------