├── third_party ├── kcp │ ├── donation.png │ ├── .travis.yml │ ├── CMakeLists.txt │ ├── kcp.svg │ ├── LICENSE │ └── protocol.txt ├── WpdPack │ ├── Lib │ │ ├── wpcap.lib │ │ ├── Packet.lib │ │ ├── libpacket.a │ │ ├── libwpcap.a │ │ └── x64 │ │ │ ├── Packet.lib │ │ │ └── wpcap.lib │ └── Include │ │ ├── pcap │ │ ├── bluetooth.h │ │ ├── vlan.h │ │ ├── usb.h │ │ └── namedb.h │ │ ├── pcap-namedb.h │ │ ├── pcap.h │ │ ├── pcap-bpf.h │ │ └── pcap-stdinc.h └── libevent │ ├── m4 │ ├── ac_backport_259_ssizet.m4 │ ├── ntp_pkg_config.m4 │ └── libevent_openssl.m4 │ ├── .mailmap │ ├── WIN32-Code │ ├── nmake │ │ └── evconfig-private.h │ └── getopt.h │ ├── test │ ├── tinytest_local.h │ ├── regress.rpc │ ├── rpcgen_wrapper.sh │ ├── check-dumpevents.py │ ├── test-ratelim.sh │ ├── print-winsock-errors.c │ ├── regress_thread.h │ ├── test-init.c │ ├── Makefile.nmake │ ├── regress_testutils.h │ ├── regress_minheap.c │ ├── test-time.c │ ├── test-weof.c │ └── test-eof.c │ ├── libevent_core.pc.in │ ├── libevent_extra.pc.in │ ├── cmake │ ├── CheckFileOffsetBits.c │ ├── AddCompilerFlags.cmake │ ├── LibeventConfigVersion.cmake.in │ ├── CheckFunctionExistsEx.c │ ├── CheckFunctionKeywords.cmake │ ├── CheckPrototypeDefinition.c.in │ ├── LibeventConfigBuildTree.cmake.in │ ├── LibeventConfig.cmake.in │ ├── CheckConstExists.cmake │ ├── CheckWorkingKqueue.cmake │ ├── COPYING-CMAKE-SCRIPTS │ ├── FindGit.cmake │ ├── CheckFileOffsetBits.cmake │ ├── VersionViaGit.cmake │ ├── Copyright.txt │ └── CheckFunctionExistsEx.cmake │ ├── libevent.pc.in │ ├── libevent_openssl.pc.in │ ├── libevent_pthreads.pc.in │ ├── autogen.sh │ ├── strlcpy-internal.h │ ├── make-event-config.sed │ ├── CONTRIBUTING.md │ ├── evconfig-private.h.cmake │ ├── sample │ ├── hostcheck.h │ ├── signal-test.c │ ├── include.am │ ├── openssl_hostname_validation.h │ └── time-test.c │ ├── openssl-compat.h │ ├── evconfig-private.h.in │ ├── include │ ├── include.am │ ├── evutil.h │ ├── evrpc.h │ ├── evdns.h │ ├── evhttp.h │ ├── event2 │ │ ├── tag_compat.h │ │ ├── rpc_compat.h │ │ ├── dns_struct.h │ │ ├── keyvalq_struct.h │ │ ├── visibility.h │ │ └── http_compat.h │ └── event.h │ ├── .clang-format │ ├── make_epoll_table.py │ ├── kqueue-internal.h │ ├── epoll_sub.c │ ├── Makefile.nmake │ ├── .uncrustify │ ├── ipv6-internal.h │ ├── evsignal-internal.h │ ├── strlcpy.c │ ├── .gitignore │ ├── defer-internal.h │ ├── time-internal.h │ ├── log-internal.h │ ├── .travis.yml │ └── mm-internal.h ├── .gitignore ├── test └── CMakeLists.txt ├── .gitmodules ├── src ├── raw_packet.h ├── defines.h ├── utils.h ├── udp_layer.h ├── kcp.h ├── frame.h ├── configuration.h ├── sock_address.h ├── frame.cpp ├── trans_layer.h ├── stream.h ├── crypto.h ├── stream.cpp ├── kcp.cpp ├── CMakeLists.txt ├── session.h ├── tcp_layer.h └── sock_address.cpp ├── README.md ├── .travis.yml ├── appveyor.yml └── CMakeLists.txt /third_party/kcp/donation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/kcp/donation.png -------------------------------------------------------------------------------- /third_party/WpdPack/Lib/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/WpdPack/Lib/wpcap.lib -------------------------------------------------------------------------------- /third_party/WpdPack/Lib/Packet.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/WpdPack/Lib/Packet.lib -------------------------------------------------------------------------------- /third_party/WpdPack/Lib/libpacket.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/WpdPack/Lib/libpacket.a -------------------------------------------------------------------------------- /third_party/WpdPack/Lib/libwpcap.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/WpdPack/Lib/libwpcap.a -------------------------------------------------------------------------------- /third_party/WpdPack/Lib/x64/Packet.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/WpdPack/Lib/x64/Packet.lib -------------------------------------------------------------------------------- /third_party/WpdPack/Lib/x64/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stdcin/kcpp/HEAD/third_party/WpdPack/Lib/x64/wpcap.lib -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build 2 | build/ 3 | cmake-build-debug/ 4 | 5 | # Visual Studio 2017 6 | .vs 7 | 8 | # IntelliJ 9 | .idea 10 | *.iml -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/.mailmap: -------------------------------------------------------------------------------- 1 | # name -> email 2 | Azat Khuzhin 3 | 4 | # email -> email 5 | 6 | -------------------------------------------------------------------------------- /third_party/kcp/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | script: 6 | - $CC -O3 test.cpp -o test -lstdc++ 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(../src) 2 | 3 | add_executable(crypto_test ../src/crypto.cpp crypto_test.cpp) 4 | target_link_libraries(crypto_test gtest_main OpenSSL::Crypto) 5 | add_test(crypto_test crypto_test) 6 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/libtins"] 2 | path = third_party/libtins 3 | url = https://github.com/mfontanini/libtins.git 4 | [submodule "third_party/googletest"] 5 | path = third_party/googletest 6 | url = https://github.com/google/googletest.git 7 | -------------------------------------------------------------------------------- /third_party/kcp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | PROJECT(kcp) 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 3 | 4 | add_library(kcp STATIC ikcp.c) 5 | 6 | target_include_directories(kcp PUBLIC 7 | $ 8 | ) 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /third_party/libevent/test/tinytest_local.h: -------------------------------------------------------------------------------- 1 | 2 | #include "util-internal.h" 3 | #ifdef _WIN32 4 | #include 5 | #endif 6 | 7 | #include "event2/util.h" 8 | 9 | #ifdef snprintf 10 | #undef snprintf 11 | #endif 12 | #define snprintf evutil_snprintf 13 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/raw_packet.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_RAW_PACKET_H 2 | #define KCPP_RAW_PACKET_H 3 | 4 | #include 5 | #include 6 | #include "sock_address.h" 7 | 8 | class raw_packet { 9 | public: 10 | raw_packet(const sock_address &remote, const uint8_t *data, int len) : remote(remote), len(len), data() { 11 | this->data.insert(this->data.end(), data, data + len); 12 | } 13 | 14 | int len; 15 | std::vector data; 16 | sock_address remote; 17 | }; 18 | 19 | #endif //KCPP_RAW_PACKET_H 20 | -------------------------------------------------------------------------------- /src/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_DEFINES_H 2 | #define KCPP_DEFINES_H 3 | 4 | #include "zf_log.h" 5 | 6 | #define LOGV(...) ZF_LOGV(__VA_ARGS__) 7 | #define LOGD(...) ZF_LOGD(__VA_ARGS__) 8 | #define LOGI(...) ZF_LOGI(__VA_ARGS__) 9 | #define LOGW(...) ZF_LOGW(__VA_ARGS__) 10 | #define LOGE(...) ZF_LOGE(__VA_ARGS__) 11 | #define LOGF(...) do { \ 12 | ZF_LOGF(__VA_ARGS__); \ 13 | abort(); \ 14 | } while(0) 15 | 16 | 17 | #define LOCK_GUARD(o) std::lock_guard __lock(o) 18 | #define BUF_SIZE 8192 19 | 20 | #endif //KCPP_DEFINES_H 21 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/cmake/CheckFunctionExistsEx.c: -------------------------------------------------------------------------------- 1 | #ifdef CHECK_FUNCTION_EXISTS 2 | 3 | #ifdef __cplusplus 4 | extern "C" 5 | #endif 6 | char 7 | CHECK_FUNCTION_EXISTS(void); 8 | #ifdef __CLASSIC_C__ 9 | int main() 10 | { 11 | int ac; 12 | char* av[]; 13 | #else 14 | int main(int ac, char* av[]) 15 | { 16 | #endif 17 | CHECK_FUNCTION_EXISTS(); 18 | if (ac > 1000) { 19 | return *av[0]; 20 | } 21 | return 0; 22 | } 23 | 24 | #else /* CHECK_FUNCTION_EXISTS */ 25 | 26 | #error "CHECK_FUNCTION_EXISTS has to specify the function" 27 | 28 | #endif /* CHECK_FUNCTION_EXISTS */ 29 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Build (linux) [![Build Status](https://travis-ci.com/stdcin/kcpp.svg?branch=master)](https://travis-ci.com/stdcin/kcpp) 2 | ``` 3 | sudo apt-get update 4 | sudo apt-get install libevent-dev libpcap-dev libssl-dev 5 | 6 | git clone ... 7 | git submodule update --init 8 | mkdir build && cd build 9 | cmake .. 10 | make 11 | make install 12 | ``` 13 | 14 | 15 | ## Build (Windows) [![Build status](https://ci.appveyor.com/api/projects/status/se4vy0yi9g8lrtb1?svg=true)](https://ci.appveyor.com/project/vitamincpp/kcpp) 16 | 17 | ``` 18 | git clone ... 19 | git submodule update --init 20 | mkdir build 21 | cd build 22 | cmake .. 23 | cmake --build . 24 | ``` 25 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/kcp/kcp.svg: -------------------------------------------------------------------------------- 1 | KCPKCPPoweredPowered -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_UTILS_H 2 | #define KCPP_UTILS_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | size_t get_sockaddr_len(const sockaddr *addr); 11 | 12 | size_t get_sockaddr_len(const sockaddr_storage *addr); 13 | 14 | std::string sockaddr_tostring(const sockaddr *addr); 15 | 16 | std::string sockaddr_tostring(const sockaddr_storage *addr); 17 | 18 | bool parse_sockaddr_port(const char *str, sockaddr_storage *out); 19 | 20 | bool get_sockaddr(const char *host, const char *port, sockaddr_storage *storage); 21 | 22 | uint64_t unix_timestamp_ms(); 23 | 24 | uint32_t random_uint(uint32_t min, uint32_t max); 25 | 26 | #endif //KCPP_UTILS_H 27 | -------------------------------------------------------------------------------- /third_party/libevent/cmake/LibeventConfigBuildTree.cmake.in: -------------------------------------------------------------------------------- 1 | # - Config file for the Libevent package 2 | # It defines the following variables 3 | # LIBEVENT_INCLUDE_DIRS - include directories for FooBar 4 | # LIBEVENT_LIBRARIES - libraries to link against 5 | 6 | # Get the path of the current file. 7 | get_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 8 | 9 | # Set the include directories. 10 | set(LIBEVENT_INCLUDE_DIRS "@EVENT__INCLUDE_DIRS@") 11 | 12 | # Include the project Targets file, this contains definitions for IMPORTED targets. 13 | include(${LIBEVENT_CMAKE_DIR}/LibeventTargets.cmake) 14 | 15 | # IMPORTED targets from LibeventTargets.cmake 16 | set(LIBEVENT_LIBRARIES event event_core event_extra) 17 | 18 | -------------------------------------------------------------------------------- /src/udp_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_UDP_LAYER_H 2 | #define KCPP_UDP_LAYER_H 3 | 4 | #include "trans_layer.h" 5 | 6 | class udp_layer : public trans_layer { 7 | public: 8 | udp_layer(const sock_address &saddr, bool client); 9 | ~udp_layer() override; 10 | bool start() override; 11 | void stop() override; 12 | bool connect() override; 13 | int read_packets(std::vector &packets, bool block) override; 14 | void send_packet(raw_packet *packet) override; 15 | 16 | private: 17 | void read_packets_task() override; 18 | 19 | void send_packets_task() override; 20 | 21 | bool closed_; 22 | bool is_client_; 23 | int fd_; 24 | const sock_address &saddr_; 25 | queue_type snd_queue_; 26 | queue_type rcv_queue_; 27 | }; 28 | 29 | #endif //KCPP_UDP_LAYER_H 30 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: gcc 3 | 4 | matrix: 5 | include: 6 | - os: linux 7 | dist: xenial 8 | addons: 9 | apt: 10 | packages: 11 | - cmake 12 | - libevent-dev 13 | - libpcap-dev 14 | - libssl-dev 15 | 16 | # see https://docs.travis-ci.com/user/caching/ 17 | #cache: 18 | # - directories: 19 | # - $HOME/.cache 20 | 21 | install: 22 | # (fake) install dependencies (usually involves wget, configure, make, ...) 23 | # install into cache folder (build binaries+headers only, no sources and do NOT build there) 24 | - mkdir -p $HOME/.cache 25 | # - touch $HOME/.cache/mydependency.so 26 | 27 | before_script: 28 | - git submodule update --init 29 | - mkdir -p build 30 | - cd build 31 | - cmake .. -DKCPP__ENABLE_TESTS=ON 32 | 33 | script: 34 | - make 35 | - make test 36 | 37 | after_success: 38 | -------------------------------------------------------------------------------- /third_party/libevent/cmake/LibeventConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # - Config file for the Libevent package 2 | # It defines the following variables 3 | # LIBEVENT_INCLUDE_DIRS - include directories 4 | # LIBEVENT_STATIC_LIBRARIES - libraries to link against (archive/static) 5 | # LIBEVENT_SHARED_LIBRARIES - libraries to link against (shared) 6 | 7 | # Get the path of the current file. 8 | get_filename_component(LIBEVENT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 9 | 10 | # Set the include directories. 11 | set(LIBEVENT_INCLUDE_DIRS "@EVENT_INSTALL_INCLUDE_DIR@") 12 | 13 | # Include the project Targets file, this contains definitions for IMPORTED targets. 14 | include(${LIBEVENT_CMAKE_DIR}/LibeventTargets.cmake) 15 | 16 | # IMPORTED targets from LibeventTargets.cmake 17 | set(LIBEVENT_STATIC_LIBRARIES "@LIBEVENT_STATIC_LIBRARIES@") 18 | set(LIBEVENT_SHARED_LIBRARIES "@LIBEVENT_SHARED_LIBRARIES@") 19 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/kcp.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_KCP_H 2 | #define KCPP_KCP_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class kcp { 9 | public: 10 | typedef int (*output_t)(const char *buf, int len, struct IKCPCB *kcp, void *user); 11 | kcp(uint32_t convid, output_t output, void *user); 12 | ~kcp(); 13 | struct IKCPCB *raw_kcp() const; 14 | int recv(char *buffer, int len); 15 | int send(const char *buffer, int len); 16 | int peek_size(); 17 | uint32_t check(); 18 | bool writable(); 19 | int input(const uint8_t *data, size_t size); 20 | void update(); 21 | // void set_nodelay(int nodelay, int interval, int resend, int nc); 22 | // void set_wndsize(int sndwnd, int rcvwnd); 23 | 24 | private: 25 | uint32_t current_ts() const; 26 | std::mutex mutex_; 27 | struct IKCPCB *kcp_; 28 | }; 29 | 30 | #endif //KCPP_KCP_H 31 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/frame.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_FRAME_H 2 | #define KCPP_FRAME_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | // VERSION(1B) | CMD(1B) | LENGTH(2B) | STREAMID(4B) | DATA(LENGTH) 9 | struct frame { 10 | public: 11 | enum cmd_t { 12 | syn = 1 << 0, 13 | fin = 1 << 1, 14 | psh = 1 << 2, 15 | nop = 1 << 3 16 | }; 17 | static const int header_size = 1 + 1 + 2 + 4; 18 | static const uint8_t version = 1; 19 | 20 | 21 | frame(cmd_t cmd, uint32_t sid) 22 | : ver(version), cmd(cmd), sid(sid), len(0) { 23 | } 24 | 25 | frame() : frame(nop, 0) { 26 | } 27 | 28 | std::string to_string() const; 29 | static std::vector header_to_bytes(const frame &f); 30 | static void bytes_to_header(frame &f, const void *data); 31 | 32 | uint8_t ver; 33 | uint8_t cmd; 34 | uint16_t len; 35 | uint32_t sid; 36 | uint8_t *data = nullptr; 37 | }; 38 | 39 | #endif //KCPP_FRAME_H 40 | -------------------------------------------------------------------------------- /src/configuration.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_CONFIG_H 2 | #define KCPP_CONFIG_H 3 | 4 | #include 5 | #include 6 | 7 | struct configuration { 8 | std::string localaddr; 9 | std::string remoteaddr; 10 | std::string config; 11 | std::string key; 12 | std::string crypt; 13 | int keepalive; 14 | int sessionttl; 15 | int loglvl; // verbose=1, debug=2, info=3, warn=4, error=5, fatal=6 16 | int sockbuf; 17 | int rdbuf; //libevent read high-water mark, maximum receive buffer in bytes per stream 18 | bool tcp; 19 | std::string iface; //interface 20 | 21 | std::string mode; 22 | int mtu; 23 | int sndwnd; 24 | int rcvwnd; 25 | int nodelay; 26 | int interval; 27 | int resend; 28 | int nc; 29 | }; 30 | 31 | void default_local_config(configuration &config); 32 | bool parse_local_config(configuration &config, int argc, const char *const *argv); 33 | void default_server_config(configuration &config); 34 | bool parse_server_config(configuration &config, int argc, const char *const *argv); 35 | 36 | #endif //KCPP_CONFIG_H 37 | -------------------------------------------------------------------------------- /third_party/kcp/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Lin Wei (skywind3000 at gmail.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/evconfig-private.h.cmake: -------------------------------------------------------------------------------- 1 | 2 | #ifndef EVCONFIG_PRIVATE_H_INCLUDED_ 3 | #define EVCONFIG_PRIVATE_H_INCLUDED_ 4 | 5 | /* Enable extensions on AIX 3, Interix. */ 6 | #cmakedefine _ALL_SOURCE 7 | 8 | /* Enable GNU extensions on systems that have them. */ 9 | #cmakedefine _GNU_SOURCE 1 10 | 11 | /* Enable threading extensions on Solaris. */ 12 | #cmakedefine _POSIX_PTHREAD_SEMANTICS 1 13 | 14 | /* Enable extensions on HP NonStop. */ 15 | #cmakedefine _TANDEM_SOURCE 1 16 | 17 | /* Enable general extensions on Solaris. */ 18 | #cmakedefine __EXTENSIONS__ 19 | 20 | /* Number of bits in a file offset, on hosts where this is settable. */ 21 | #cmakedefine _FILE_OFFSET_BITS 1 22 | /* Define for large files, on AIX-style hosts. */ 23 | #cmakedefine _LARGE_FILES 1 24 | 25 | /* Define to 1 if on MINIX. */ 26 | #cmakedefine _MINIX 1 27 | 28 | /* Define to 2 if the system does not provide POSIX.1 features except with 29 | this defined. */ 30 | #cmakedefine _POSIX_1_SOURCE 1 31 | 32 | /* Define to 1 if you need to in order for `stat' and other things to work. */ 33 | #cmakedefine _POSIX_SOURCE 1 34 | 35 | /* Enable POSIX.2 extensions on QNX for getopt */ 36 | #ifdef __QNX__ 37 | #cmakedefine __EXT_POSIX2 1 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/sock_address.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_SOCK_ADDRESS_H 2 | #define KCPP_SOCK_ADDRESS_H 3 | 4 | #ifdef _WIN32 5 | #include 6 | #include 7 | #else 8 | #include 9 | #include 10 | #endif 11 | #include 12 | #include 13 | 14 | class sock_address { 15 | public: 16 | sock_address(); 17 | explicit sock_address(const sockaddr_storage &storage); 18 | /** 19 | * 20 | * @param ipv4 ipv4 address 21 | * @param port port 22 | */ 23 | explicit sock_address(uint32_t ipv4, uint16_t port); 24 | bool operator<(const sock_address &rhs) const; 25 | bool operator==(const sock_address &rhs) const; 26 | bool operator!=(const sock_address &rhs) const; 27 | bool is_ipv4() const; 28 | bool is_ipv6() const; 29 | int family() const; 30 | int len() const; 31 | uint16_t port() const; 32 | std::string to_string() const; 33 | std::string ip_string() const; 34 | const sockaddr_storage &storage() const; 35 | sockaddr_storage &storage(); 36 | private: 37 | sockaddr_storage storage_; 38 | }; 39 | 40 | namespace std { 41 | template<> 42 | struct hash { 43 | size_t operator()(const sock_address &k) const; 44 | }; 45 | } 46 | 47 | #endif //KCPP_SOCK_ADDRESS_H 48 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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. -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '1.0.{build}' 2 | 3 | image: 4 | - Visual Studio 2017 5 | 6 | #platform: 7 | # - x86 8 | # - x64 9 | 10 | configuration: 11 | - Release 12 | - Debug 13 | 14 | before_build: 15 | - cmd: |- 16 | git submodule update --init 17 | if not exist "build" mkdir "build" 18 | cd build 19 | cmake --version 20 | cmake .. -G "Visual Studio 15 2017" -DKCPP__ENABLE_TESTS=OFF 21 | 22 | build: 23 | project: build/kcpp.sln 24 | parallel: true 25 | verbosity: minimal 26 | 27 | test_script: 28 | - ctest 29 | 30 | cache: 31 | - C:/projects/kcpp/build 32 | 33 | skip_commits: 34 | message: /Update documentation.*/ 35 | 36 | 37 | after_build: 38 | - xcopy C:\OpenSSL-Win32\bin\libeay32.dll bin\%Configuration% /y 39 | - 7z a kcpp-windows-x86-%Configuration%.zip bin\%Configuration% 40 | 41 | artifacts: 42 | - path: build/kcpp-windows-x86-%Configuration%.zip 43 | name: kcpp 44 | type: zip 45 | 46 | 47 | # https://www.appveyor.com/docs/deployment/github/#promoting-selected-tag-to-github-release 48 | #deploy: 49 | # provider: GitHub 50 | # auth_token: 51 | # secure: OGsDOhVHdeWq7ejDbd8R+tj+xxZbkJ6oi9XQJ4RY6WAJHmg+5scgeyEIsrGhXkJ+ 52 | # artifact: kcpp 53 | # draft: false 54 | # prerelease: false 55 | # on: 56 | # branch: master # release from master branch only 57 | # APPVEYOR_REPO_TAG: true # deploy on tag push only -------------------------------------------------------------------------------- /src/frame.cpp: -------------------------------------------------------------------------------- 1 | #include "frame.h" 2 | 3 | std::string frame::to_string() const { 4 | const char *name = "unk"; 5 | switch (cmd) { 6 | case frame::syn: 7 | name = "syn"; 8 | break; 9 | case frame::psh: 10 | name = "psh"; 11 | break; 12 | case frame::fin: 13 | name = "fin"; 14 | break; 15 | case frame::nop: 16 | name = "nop"; 17 | break; 18 | } 19 | 20 | char buf[128]; 21 | sprintf(buf, "ver=%d, cmd=%s, len=%d, sid=%u", ver, name, len, sid); 22 | return buf; 23 | } 24 | 25 | 26 | void frame::bytes_to_header(frame &f, const void *data) { 27 | uint8_t *p = (uint8_t *) data; 28 | uint8_t ver = *p; 29 | p++; 30 | uint8_t cmd = *p; 31 | p++; 32 | uint16_t len = *(uint16_t *) p; //todo: little endian 33 | p += 2; 34 | uint32_t sid = *(uint32_t *) p; 35 | 36 | f.ver = ver; 37 | f.cmd = cmd; 38 | f.len = len; 39 | f.sid = sid; 40 | f.data = nullptr; 41 | } 42 | 43 | std::vector frame::header_to_bytes(const frame &f) { 44 | std::vector ret(header_size); 45 | char *p = (char *) ret.data(); 46 | *(uint8_t *) p = f.ver; 47 | p++; 48 | *(uint8_t *) p = f.cmd; 49 | p++; 50 | *(uint16_t *) p = f.len; //todo: little endian 51 | p += 2; 52 | *(uint32_t *) p = f.sid; 53 | return ret; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /src/trans_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_TRANS_LAYER_H 2 | #define KCPP_TRANS_LAYER_H 3 | 4 | #include 5 | #include "moodycamel/blockingconcurrentqueue.h" 6 | #include "raw_packet.h" 7 | 8 | class crypto; 9 | struct configuration; 10 | class trans_layer { 11 | public: 12 | typedef moodycamel::BlockingConcurrentQueue queue_type; 13 | trans_layer(); 14 | virtual ~trans_layer(); 15 | virtual bool start() = 0; 16 | virtual void stop() = 0; 17 | virtual bool connect() = 0; 18 | virtual int read_packets(std::vector &packets, bool block) = 0; 19 | virtual void send_packet(raw_packet *packet) = 0; 20 | void config(const configuration &cfg); 21 | const configuration &config() const { return *config_; } 22 | constexpr static int header_size() { return 4 + 4; } 23 | 24 | protected: 25 | /** 26 | * 收包循环 27 | */ 28 | virtual void read_packets_task() = 0; 29 | 30 | /** 31 | * 发包循环 32 | */ 33 | virtual void send_packets_task() = 0; 34 | 35 | int process_output_packet(const raw_packet &packet, uint8_t *plaintext, uint8_t *out) const; 36 | raw_packet *process_input_packet(const sock_address &from, const uint8_t *data, size_t n, uint8_t *out) const; 37 | 38 | const int mtu_max_size = 1500; 39 | const size_t crypto_buf_size = 2048; 40 | const configuration *config_; 41 | crypto *crypto_; 42 | }; 43 | 44 | #endif //KCPP_TRANS_LAYER_H 45 | -------------------------------------------------------------------------------- /third_party/libevent/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 | #endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ 38 | (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */ 39 | 40 | #if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L 41 | #define BIO_get_init(b) (b)->init 42 | #endif 43 | 44 | #endif /* OPENSSL_COMPAT_H */ 45 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/stream.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_STREAM_H 2 | #define KCPP_STREAM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class stream { 11 | public: 12 | enum stream_state { 13 | shut_read = 1 << 0, 14 | shut_write = 1 << 1, 15 | }; 16 | 17 | typedef std::chrono::time_point time_point_type; 18 | typedef std::chrono::milliseconds time_duration_type; 19 | 20 | stream(uint32_t sid, bufferevent *bev, time_duration_type ttl); 21 | uint32_t sid() const { return sid_; } 22 | const std::atomic &state() const { return state_; } 23 | const std::atomic &is_fin_sent() const { return fin_sent_; } 24 | void set_fin_sent() { fin_sent_ = true; } 25 | bufferevent *bev() const { return bev_; } 26 | evbuffer *in() const; 27 | evbuffer *out() const; 28 | const time_point_type deadline(); 29 | void shutdown_read(); 30 | void shutdown_write(); 31 | 32 | /** 33 | * release bufferevent 34 | */ 35 | void close(); 36 | 37 | /** 38 | * set stream deadline 39 | * @param sec 40 | */ 41 | void die_after(time_duration_type sec); 42 | 43 | private: 44 | uint32_t sid_; 45 | bufferevent *bev_; 46 | std::mutex mutex_; 47 | const time_duration_type ttl_; 48 | 49 | std::atomic closed_ = {false}; 50 | std::atomic fin_sent_ = {false}; 51 | std::atomic state_ = {0}; 52 | time_point_type deadline_; 53 | }; 54 | 55 | #endif //KCPP_STREAM_H 56 | -------------------------------------------------------------------------------- /src/crypto.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_CRYPTO_H 2 | #define KCPP_CRYPTO_H 3 | #include 4 | #include 5 | #include 6 | 7 | struct evp_cipher_st; 8 | class crypto { 9 | public: 10 | typedef std::vector key_type; 11 | 12 | bool password(std::string password); 13 | const key_type &key() const { return key_; } 14 | int block_size() const { return block_size_; } 15 | int key_size() const { return key_size_; } 16 | bool encrypt(const uint8_t *plaintext, size_t plaintext_len, uint8_t *out, size_t &out_len) const; 17 | bool decrypt(const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *out, size_t &out_len) const; 18 | protected: 19 | crypto(int key_size, int block_size); 20 | int key_size_; 21 | int block_size_; 22 | evp_cipher_st *cipher_; 23 | key_type key_; 24 | }; 25 | 26 | // cbc 27 | class crypto_aes128_cbc : public crypto { 28 | public: 29 | crypto_aes128_cbc(); 30 | }; 31 | class crypto_aes192_cbc : public crypto { 32 | public: 33 | crypto_aes192_cbc(); 34 | }; 35 | class crypto_aes256_cbc : public crypto { 36 | public: 37 | crypto_aes256_cbc(); 38 | }; 39 | 40 | // cfb 41 | class crypto_aes128_cfb : public crypto { 42 | public: 43 | crypto_aes128_cfb(); 44 | }; 45 | class crypto_aes192_cfb : public crypto { 46 | public: 47 | crypto_aes192_cfb(); 48 | }; 49 | class crypto_aes256_cfb : public crypto { 50 | public: 51 | crypto_aes256_cfb(); 52 | }; 53 | 54 | void crypto_random_bytes(uint8_t *buf, int n); 55 | uint32_t crypto_crc32(const uint8_t *data, size_t n); 56 | 57 | #endif //KCPP_CRYPTO_H 58 | -------------------------------------------------------------------------------- /src/stream.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stream.h" 3 | #include "defines.h" 4 | #include "session.h" 5 | #include "utils.h" 6 | 7 | stream::stream(uint32_t sid, bufferevent *bev, time_duration_type ttl) 8 | : sid_(sid), bev_(bev), ttl_(ttl), closed_(false) { 9 | 10 | die_after(ttl_); 11 | } 12 | 13 | evbuffer *stream::in() const { 14 | return bufferevent_get_input(bev_); 15 | } 16 | 17 | evbuffer *stream::out() const { 18 | return bufferevent_get_output(bev_); 19 | } 20 | 21 | void stream::close() { 22 | LOCK_GUARD(mutex_); 23 | assert(bev_); 24 | if (!closed_) { 25 | bufferevent_free(bev_); 26 | bev_ = nullptr; 27 | closed_ = true; 28 | } 29 | } 30 | 31 | void stream::shutdown_read() { 32 | LOCK_GUARD(mutex_); 33 | evutil_socket_t fd = bufferevent_getfd(bev_); 34 | if (fd != -1) { 35 | #ifdef _WIN32 36 | int n = shutdown(fd, SD_RECEIVE); 37 | if (n != 0) { 38 | LOGD("shutdown(SD_RECEIVE) err: %d", WSAGetLastError()); 39 | } 40 | #else 41 | shutdown(fd, SHUT_RD); 42 | #endif 43 | } 44 | 45 | state_ |= shut_read; 46 | } 47 | 48 | void stream::shutdown_write() { 49 | LOCK_GUARD(mutex_); 50 | if (!fin_sent_) { 51 | state_ |= shut_write; 52 | } 53 | } 54 | 55 | void stream::die_after(time_duration_type sec) { 56 | LOCK_GUARD(mutex_); 57 | deadline_ = std::chrono::system_clock::now() + sec; 58 | } 59 | 60 | const stream::time_point_type stream::deadline() { 61 | LOCK_GUARD(mutex_); 62 | return deadline_; 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /third_party/libevent/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; 48 | struct event_base* base; 49 | #ifdef _WIN32 50 | WORD wVersionRequested; 51 | WSADATA wsaData; 52 | 53 | wVersionRequested = MAKEWORD(2, 2); 54 | 55 | (void) WSAStartup(wVersionRequested, &wsaData); 56 | #endif 57 | 58 | /* Initalize the event library */ 59 | base = event_base_new(); 60 | 61 | /* Initalize one event */ 62 | signal_int = evsignal_new(base, SIGINT, signal_cb, event_self_cbarg()); 63 | 64 | event_add(signal_int, NULL); 65 | 66 | event_base_dispatch(base); 67 | event_free(signal_int); 68 | event_base_free(base); 69 | 70 | return (0); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /third_party/libevent/evconfig-private.h.in: -------------------------------------------------------------------------------- 1 | /* evconfig-private.h template - see "Configuration Header Templates" */ 2 | /* in AC manual. Kevin Bowling /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+=$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 | esac 51 | ;; 52 | esac 53 | 54 | # check if we have and should use openssl 55 | AM_CONDITIONAL(OPENSSL, [test "$enable_openssl" != "no" && test "$have_openssl" = "yes"]) 56 | ]) 57 | -------------------------------------------------------------------------------- /src/kcp.cpp: -------------------------------------------------------------------------------- 1 | #include "kcp.h" 2 | #include 3 | #include "defines.h" 4 | #include "utils.h" 5 | #include "ikcp.h" 6 | 7 | kcp::kcp(uint32_t convid, kcp::output_t output, void *user) { 8 | kcp_ = ikcp_create(convid, user); 9 | kcp_->stream = 1; 10 | kcp_->output = output; 11 | } 12 | 13 | kcp::~kcp() { 14 | ikcp_release(kcp_); 15 | } 16 | 17 | struct IKCPCB *kcp::raw_kcp() const { 18 | return kcp_; 19 | } 20 | 21 | int kcp::recv(char *buffer, int len) { 22 | LOCK_GUARD(mutex_); 23 | int n = ikcp_recv(kcp_, buffer, len); 24 | return n; 25 | } 26 | 27 | int kcp::send(const char *buffer, int len) { 28 | LOCK_GUARD(mutex_); 29 | int n = ikcp_send(kcp_, buffer, len); 30 | return n; 31 | } 32 | 33 | int kcp::peek_size() { 34 | LOCK_GUARD(mutex_); 35 | int n = ikcp_peeksize(kcp_); 36 | return n; 37 | } 38 | 39 | uint32_t kcp::check() { 40 | LOCK_GUARD(mutex_); 41 | return ikcp_check(kcp_, current_ts()); 42 | } 43 | 44 | bool kcp::writable() { 45 | LOCK_GUARD(mutex_); 46 | 47 | IUINT32 cwnd = std::min(kcp_->snd_wnd, kcp_->rmt_wnd); 48 | if (kcp_->nocwnd == 0) { 49 | cwnd = std::min(kcp_->cwnd, cwnd); 50 | } 51 | bool b = ikcp_waitsnd(kcp_) < cwnd; 52 | // bool b = ikcp_waitsnd(kcp_) < 2 * kcp_->snd_wnd; 53 | return b; 54 | } 55 | 56 | int kcp::input(const uint8_t *data, size_t size) { 57 | LOCK_GUARD(mutex_); 58 | int n = ikcp_input(kcp_, (const char *) data, size); 59 | return n; 60 | } 61 | 62 | void kcp::update() { 63 | LOCK_GUARD(mutex_); 64 | ikcp_update(kcp_, current_ts()); 65 | } 66 | 67 | uint32_t kcp::current_ts() const { 68 | uint32_t current = static_cast(unix_timestamp_ms() & 0xfffffffful); 69 | return current; 70 | } 71 | 72 | 73 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/.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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE(TestBigEndian) 2 | TEST_BIG_ENDIAN(IS_BIG_ENDIAN) 3 | 4 | set(SOURCES kcp.cpp zf_log.c utils.cpp stream.cpp 5 | sock_address.cpp session.cpp crypto.cpp 6 | udp_layer.cpp trans_layer.cpp 7 | frame.cpp configuration.cpp) 8 | if (NOT KCPP__DISABLE_TCP) 9 | set(SOURCES ${SOURCES} tcp_layer.cpp) 10 | endif () 11 | 12 | add_executable(kcpp_server ${SOURCES} server.cpp) 13 | add_executable(kcpp_local ${SOURCES} local.cpp) 14 | 15 | # zf_log mesage ctx 16 | add_definitions("-DZF_LOG_MESSAGE_CTX_FORMAT=(HOUR, S(\":\"), MINUTE, S(\":\"), SECOND, S(\".\"), MILLISECOND, S(ZF_LOG_DEF_DELIMITER), LEVEL, S(ZF_LOG_DEF_DELIMITER))") 17 | # zf_log source location format 18 | add_definitions("-DZF_LOG_MESSAGE_SRC_FORMAT=(FILENAME, S(\":\"), FILELINE, S(\" > \"))") 19 | 20 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/include) 21 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/libtins/include) 22 | include_directories(${PCAP_INCLUDE_DIR}) 23 | 24 | set_property(TARGET kcpp_server PROPERTY C_STANDARD 11) 25 | set_property(TARGET kcpp_local PROPERTY C_STANDARD 11) 26 | 27 | if (UNIX) 28 | set(DEP_LIBS kcp event pthread event_pthreads OpenSSL::Crypto) 29 | if (NOT KCPP__DISABLE_TCP) 30 | set(DEP_LIBS ${DEP_LIBS} tins) 31 | endif () 32 | elseif (WIN32) 33 | include_directories(${LIBEVENT_INCLUDE_DIRS}) 34 | add_definitions(-DNOMINMAX) 35 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 36 | 37 | if (NOT (MSVC_VERSION LESS 1900)) 38 | # https://github.com/pocoproject/poco/commit/50ae257a52065c222e0e57e19dad3eadb2333389 39 | endif () 40 | 41 | set(DEP_LIBS kcp event_core OpenSSL::Crypto) 42 | if (NOT KCPP__DISABLE_TCP) 43 | set(DEP_LIBS ${DEP_LIBS} tins) 44 | endif () 45 | endif () 46 | 47 | target_link_libraries(kcpp_server ${DEP_LIBS}) 48 | target_link_libraries(kcpp_local ${DEP_LIBS}) 49 | 50 | install (TARGETS kcpp_server kcpp_local DESTINATION bin) -------------------------------------------------------------------------------- /third_party/libevent/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 | sample_https_client_CPPFLAGS = $(AM_CPPFLAGS) $(OPENSSL_INCS) 29 | noinst_HEADERS += \ 30 | sample/hostcheck.h \ 31 | sample/openssl_hostname_validation.h 32 | endif 33 | 34 | if BUILD_SAMPLES 35 | noinst_PROGRAMS += $(SAMPLES) 36 | endif 37 | 38 | $(SAMPLES) : libevent.la 39 | 40 | sample_event_read_fifo_SOURCES = sample/event-read-fifo.c 41 | sample_event_read_fifo_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 42 | sample_time_test_SOURCES = sample/time-test.c 43 | sample_time_test_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 44 | sample_signal_test_SOURCES = sample/signal-test.c 45 | sample_signal_test_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 46 | sample_dns_example_SOURCES = sample/dns-example.c 47 | sample_dns_example_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 48 | sample_hello_world_SOURCES = sample/hello-world.c 49 | sample_hello_world_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 50 | sample_http_server_SOURCES = sample/http-server.c 51 | sample_http_server_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 52 | sample_http_connect_SOURCES = sample/http-connect.c 53 | sample_http_connect_LDADD = $(LIBEVENT_GC_SECTIONS) libevent.la 54 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) 2 | 3 | project(kcpp) 4 | set(CMAKE_CXX_STANDARD 11) 5 | 6 | option(KCPP__DISABLE_TCP "disable tcp feature" OFF) 7 | option(KCPP__BUILD_LIBTINS "build custom libtins" ON) 8 | option(KCPP__BUILD_LIBTINS_STATIC "libtins static build" OFF) 9 | option(KCPP__ENABLE_TESTS "build tests" OFF) 10 | 11 | if (WIN32) 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 13 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 14 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) 15 | 16 | # libevent 17 | set(EVENT__DISABLE_OPENSSL ON CACHE BOOL "disable libevent:openssl" FORCE) 18 | set(EVENT__DISABLE_BENCHMARK ON CACHE BOOL "disable libevent:benchmark" FORCE) 19 | set(EVENT__DISABLE_TESTS ON CACHE BOOL "disable libevent:tests" FORCE) 20 | set(EVENT__DISABLE_REGRESS ON CACHE BOOL "disable libevent:regress" FORCE) 21 | set(EVENT__DISABLE_SAMPLES ON CACHE BOOL "disable libevent:samples" FORCE) 22 | add_subdirectory(third_party/libevent) 23 | 24 | # winpcap 25 | if (NOT KCPP__DISABLE_TCP) 26 | set(PCAP_ROOT_DIR ${CMAKE_SOURCE_DIR}/third_party/WpdPack) 27 | endif () 28 | 29 | # openssl 30 | set(OPENSSL_USE_STATIC_LIBS FALSE) 31 | endif () 32 | 33 | find_package(OpenSSL REQUIRED) 34 | 35 | if (KCPP__DISABLE_TCP) 36 | add_definitions(-DKCPP_DISABLE_TCP) 37 | endif () 38 | if ((WIN32 OR KCPP__BUILD_LIBTINS) AND NOT KCPP__DISABLE_TCP) 39 | set(LIBTINS_BUILD_EXAMPLES OFF CACHE BOOL "disable LIBTINS_BUILD_EXAMPLES" FORCE) 40 | set(LIBTINS_BUILD_TESTS OFF CACHE BOOL "disable LIBTINS_BUILD_TESTS" FORCE) 41 | if (KCPP__BUILD_LIBTINS_STATIC) 42 | set(LIBTINS_BUILD_SHARED OFF CACHE BOOL "libtins static build" FORCE) 43 | endif () 44 | set(LIBTINS_ENABLE_WPA2 OFF CACHE BOOL "disable WPA2" FORCE) 45 | add_subdirectory(third_party/libtins) 46 | endif () 47 | 48 | if (KCPP__ENABLE_TESTS) 49 | enable_testing() 50 | add_subdirectory(test) 51 | add_subdirectory(third_party/googletest) 52 | endif () 53 | 54 | add_subdirectory(third_party/kcp) 55 | add_subdirectory(src) 56 | 57 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Paolo Abeni (Italy) 3 | * All rights reserved. 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 | * 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 15 | * products derived from this software without specific prior written 16 | * permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * 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 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * bluetooth data struct 31 | * By Paolo Abeni 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007/09/22 02:10:17 guy Exp $ 34 | */ 35 | 36 | #ifndef _PCAP_BLUETOOTH_STRUCTS_H__ 37 | #define _PCAP_BLUETOOTH_STRUCTS_H__ 38 | 39 | /* 40 | * Header prepended libpcap to each bluetooth h:4 frame. 41 | * fields are in network byte order 42 | */ 43 | typedef struct _pcap_bluetooth_h4_header { 44 | u_int32_t direction; /* if first bit is set direction is incoming */ 45 | } pcap_bluetooth_h4_header; 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 10) 27 | set(EVENT_GIT___VERSION_STAGE "beta") 28 | 29 | find_package(Git) 30 | 31 | if (GIT_FOUND) 32 | execute_process( 33 | COMMAND 34 | ${GIT_EXECUTABLE} describe --abbrev=0 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 | list(LENGTH VERSION_LIST VERSION_LIST_LENGTH) 46 | 47 | if ((GITRET EQUAL 0) AND (VERSION_LIST_LENGTH EQUAL 5)) 48 | list(GET VERSION_LIST 1 _MAJOR) 49 | list(GET VERSION_LIST 2 _MINOR) 50 | list(GET VERSION_LIST 3 _PATCH) 51 | list(GET VERSION_LIST 4 _STAGE) 52 | 53 | set(_DEFAULT_VERSION "${EVENT_GIT___VERSION_MAJOR}.${EVENT_GIT___VERSION_MINOR}.${EVENT_GIT___VERSION_PATCH}-${EVENT_GIT___VERSION_STAGE}") 54 | set(_GIT_VERSION "${_MAJOR}.${_MINOR}.${_PATCH}-${_STAGE}") 55 | 56 | if (${_DEFAULT_VERSION} VERSION_LESS ${_GIT_VERSION}) 57 | set(EVENT_GIT___VERSION_MAJOR ${_MAJOR}) 58 | set(EVENT_GIT___VERSION_MINOR ${_MINOR}) 59 | set(EVENT_GIT___VERSION_PATCH ${_PATCH}) 60 | set(EVENT_GIT___VERSION_STAGE ${_STAGE}) 61 | endif() 62 | endif() 63 | endif() 64 | endmacro() 65 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap-namedb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1996 3 | * The Regents of the University of California. All rights reserved. 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. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.13 2006/10/04 18:13:32 guy Exp $ (LBL) 34 | */ 35 | 36 | /* 37 | * For backwards compatibility. 38 | * 39 | * Note to OS vendors: do NOT get rid of this file! Some applications 40 | * might expect to be able to include . 41 | */ 42 | #include 43 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap/vlan.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 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. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/vlan.h,v 1.1.2.2 2008-08-06 07:45:59 guy Exp $ 34 | */ 35 | 36 | #ifndef lib_pcap_vlan_h 37 | #define lib_pcap_vlan_h 38 | 39 | struct vlan_tag { 40 | u_int16_t vlan_tpid; /* ETH_P_8021Q */ 41 | u_int16_t vlan_tci; /* VLAN TCI */ 42 | }; 43 | 44 | #define VLAN_TAG_LEN 4 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /third_party/kcp/protocol.txt: -------------------------------------------------------------------------------- 1 | KCP PROTOCOL SPECIFICATION 2 | 3 | 4 | 1. Packet (aka. segment) Structure 5 | 6 | KCP has only one kind of segment: both the data and control messages are 7 | encoded into the same structure and share the same header. 8 | 9 | The KCP packet (aka. segment) structure is as following: 10 | 11 | 0 4 5 6 8 (BYTE) 12 | +---------------+---+---+-------+ 13 | | conv |cmd|frg| wnd | 14 | +---------------+---+---+-------+ 8 15 | | ts | sn | 16 | +---------------+---------------+ 16 17 | | una | len | 18 | +---------------+---------------+ 24 19 | | | 20 | | DATA (optional) | 21 | | | 22 | +-------------------------------+ 23 | 24 | 25 | - conv: conversation id (32 bits integer) 26 | 27 | The conversation id is used to identify each connection, which will not change 28 | during the connection life-time. 29 | 30 | It is represented by a 32 bits integer which is given at the moment the KCP 31 | control block (aka. struct ikcpcb, or kcp object) has been created. Each 32 | packet sent out will carry the conversation id in the first 4 bytes and a 33 | packet from remote endpoint will not be accepted if it has a different 34 | conversation id. 35 | 36 | The value can be any random number, but in practice, both side between a 37 | connection will have many KCP objects (or control block) storing in the 38 | containers like a map or an array. A index is used as the key to look up one 39 | KCP object from the container. 40 | 41 | So, the higher 16 bits of conversation id can be used as caller's index while 42 | the lower 16 bits can be used as callee's index. KCP will not handle 43 | handshake, and the index in both side can be decided and exchanged after 44 | connection establish. 45 | 46 | When you receive and accept a remote packet, the local index can be extracted 47 | from the conversation id and the kcp object which is in charge of this 48 | connection can be find out from your map or array. 49 | 50 | 51 | - cmd: command 52 | 53 | - frg: fragment count 54 | 55 | - wnd: window size 56 | 57 | - ts: timestamp 58 | 59 | - sn: serial number 60 | 61 | - una: un-acknowledged serial number 62 | 63 | 64 | # vim: set ts=4 sw=4 tw=0 noet cc=78 wrap textwidth=78 : 65 | 66 | -------------------------------------------------------------------------------- /src/session.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_SESSION_H 2 | #define KCPP_SESSION_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "message_buffer.h" 11 | #include "sock_address.h" 12 | #include "stream.h" 13 | 14 | struct configuration; 15 | class frame; 16 | class kcp; 17 | class trans_layer; 18 | class session { 19 | public: 20 | typedef std::chrono::time_point time_point_type; 21 | typedef std::chrono::milliseconds time_duration_type; 22 | 23 | explicit session(uint32_t convid, const configuration &config, 24 | trans_layer &trans, const sock_address &epaddr); 25 | ~session(); 26 | // set session target address 27 | void session_target(const sock_address &target_addr, event_base *base); 28 | stream *open_stream(bufferevent *buffer); 29 | void update(); 30 | void kcp_input(const uint8_t *data, size_t size); 31 | bool closed() const { return closed_; } 32 | const configuration &get_config() const { return config_; } 33 | static session *dial(const configuration &config, trans_layer &trans, const sock_address &raddr); 34 | 35 | private: 36 | void write_frame(const frame &frame); 37 | bool read_frame_header(); 38 | bool read_frame_data(); 39 | bool process_frame(); 40 | /** 41 | * set session deadline 42 | * @param sec 43 | */ 44 | void die_after(time_duration_type sec); 45 | static int kcp_output(const char *buf, int len, struct IKCPCB *kcp, void *user); 46 | static void listener_event_cb(bufferevent *bev, short events, void *ctx); 47 | 48 | bool client_; 49 | std::atomic closed_ = {false}; 50 | const configuration &config_; 51 | event_base *base_; 52 | std::unordered_map streams_; 53 | std::mutex streams_mutex_; 54 | uint32_t next_stream_id_; 55 | kcp *kcp_; 56 | char *kcp_buf_; 57 | trans_layer &trans_layer_; 58 | sock_address endpoint_addr_; 59 | sock_address target_addr_; //target server 60 | time_point_type keep_alive_time_point_; 61 | time_point_type deadline_; 62 | 63 | MessageBuffer frame_header_buffer_; 64 | MessageBuffer frame_data_buffer_; 65 | evbuffer *input_buffer_; 66 | }; 67 | #endif //KCPP_SESSION_H 68 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | #ifdef EVENT__HAVE_PTHREADS 31 | #include 32 | #define THREAD_T pthread_t 33 | #define THREAD_FN void * 34 | #define THREAD_RETURN() return (NULL) 35 | #define THREAD_START(threadvar, fn, arg) \ 36 | pthread_create(&(threadvar), NULL, fn, arg) 37 | #define THREAD_JOIN(th) pthread_join(th, NULL) 38 | #else 39 | #define THREAD_T HANDLE 40 | #define THREAD_FN unsigned __stdcall 41 | #define THREAD_RETURN() return (0) 42 | #define THREAD_START(threadvar, fn, arg) do { \ 43 | uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ 44 | (threadvar) = (HANDLE) threadhandle; \ 45 | } while (0) 46 | #define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /third_party/libevent/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 | /* Initalize the event library */ 61 | event_init(); 62 | 63 | return (0); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 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. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.59 2006/10/04 18:09:22 guy Exp $ (LBL) 34 | */ 35 | 36 | /* 37 | * For backwards compatibility. 38 | * 39 | * Note to OS vendors: do NOT get rid of this file! Many applications 40 | * expect to be able to include , and at least some of them 41 | * go through contortions in their configure scripts to try to detect 42 | * OSes that have "helpfully" moved pcap.h to without 43 | * leaving behind a file. 44 | */ 45 | #include 46 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap-bpf.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from the Stanford/CMU enet packet filter, 6 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 | * Berkeley Laboratory. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by the University of 21 | * California, Berkeley and its contributors. 22 | * 4. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.50 2007/04/01 21:43:55 guy Exp $ (LBL) 39 | */ 40 | 41 | /* 42 | * For backwards compatibility. 43 | * 44 | * Note to OS vendors: do NOT get rid of this file! Some applications 45 | * might expect to be able to include . 46 | */ 47 | #include 48 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/tcp_layer.h: -------------------------------------------------------------------------------- 1 | #ifndef KCPP_TCP_LAYER_H 2 | #define KCPP_TCP_LAYER_H 3 | 4 | #include "trans_layer.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "sock_address.h" 12 | 13 | struct tcp_stream { 14 | typedef std::chrono::system_clock::time_point time_point_type; 15 | typedef std::chrono::milliseconds time_duration_type; 16 | void die_after(time_duration_type t); 17 | 18 | uint16_t src_port; 19 | uint16_t dst_port; 20 | Tins::IPv4Address src_ip; 21 | Tins::IPv4Address dst_ip; 22 | uint16_t ip_id; 23 | uint32_t seq_number; 24 | uint32_t ack_number; 25 | std::atomic established; 26 | time_point_type deadline; 27 | }; 28 | 29 | class tcp_layer : public trans_layer { 30 | public: 31 | typedef tcp_stream::time_point_type time_point_type; 32 | typedef tcp_stream::time_duration_type time_duration_type; 33 | 34 | tcp_layer(const sock_address &saddr, const std::string &iface, bool client); 35 | ~tcp_layer() override; 36 | bool start() override; 37 | void stop() override; 38 | bool connect() override; 39 | int read_packets(std::vector &packets, bool block) override; 40 | void send_packet(raw_packet *packet) override; 41 | 42 | private: 43 | void read_packets_task() override; 44 | void send_packets_task() override; 45 | // remove expired tcp_streams 46 | void expire_streams_task(); 47 | bool handle_dummy_packet(const Tins::PDU &pdu); 48 | bool handle_packet(const Tins::PDU &pdu); 49 | bool process_packet(const Tins::IP &ip, const Tins::TCP &tcp); 50 | bool update_firewall_rules(); 51 | void send_tcp_packet(tcp_stream &s, const uint8_t *data, size_t len, uint32_t flags); 52 | void send_tcp_packet(tcp_stream &s, uint32_t flags); 53 | 54 | bool closed_; 55 | bool is_client_; 56 | queue_type snd_queue_; 57 | queue_type rcv_queue_; 58 | moodycamel::BlockingConcurrentQueue pdu_queue_; 59 | std::thread loop_thread_; 60 | std::string interface_; 61 | Tins::PacketSender *sender_; 62 | Tins::Sniffer *sniffer_; 63 | const sock_address &saddr_; 64 | Tins::IPv4Address *server_ip_addr_; 65 | Tins::IPv4Address *dns_ip_addr_; 66 | Tins::IPv4Address *src_ip_addr_; 67 | uint16_t server_port_; 68 | Tins::EthernetII *eth_; 69 | std::atomic initialized_ = {false}; 70 | 71 | std::mutex streams_mutex_; 72 | std::unordered_map tcp_streams_; 73 | std::atomic client_src_port_; 74 | uint8_t *plaintext_buf_; 75 | }; 76 | 77 | #endif //KCPP_TCP_LAYER_H 78 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | /* Initalize the event library */ 92 | base = event_base_new(); 93 | 94 | /* Initalize 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 | -------------------------------------------------------------------------------- /third_party/libevent/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. -------------------------------------------------------------------------------- /third_party/libevent/.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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/evsignal-internal.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 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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/.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 | /doxygen 70 | /config.cache 71 | /config.guess 72 | /config.log 73 | /config.status 74 | /config.sub 75 | /configure 76 | /configure.lineno 77 | /depcomp 78 | /config.h 79 | /config.h.in 80 | /install-sh 81 | /libtool 82 | /ltmain.sh 83 | /missing 84 | /stamp-h1 85 | /stamp-h2 86 | 87 | /sample/dns-example 88 | /sample/event-read-fifo 89 | /sample/hello-world 90 | /sample/http-server 91 | /sample/http-connect 92 | /sample/le-proxy 93 | /sample/https-client 94 | /sample/signal-test 95 | /sample/time-test 96 | /sample/event-test 97 | 98 | /test-driver 99 | /test/bench 100 | /test/bench_cascade 101 | /test/bench_http 102 | /test/bench_httpclient 103 | /test/regress 104 | /test/regress.gen.c 105 | /test/regress.gen.h 106 | /test/rpcgen-attempted 107 | /test/test-dumpevents 108 | /test/test-eof 109 | /test/test-closed 110 | /test/test-init 111 | /test/test-ratelim 112 | /test/test-script.sh 113 | /test/test-time 114 | /test/test-weof 115 | /test/test-changelist 116 | /test/test-fdleak 117 | 118 | **/include/event2/event-config.h 119 | **/include/evconfig-private.h 120 | /evconfig-private.h 121 | 122 | # Files generated by cmake 123 | CMakeCache.txt 124 | CMakeFiles/ 125 | CTestTestfile.cmake 126 | DartConfiguration.tcl 127 | LibeventConfig.cmake 128 | LibeventConfigVersion.cmake 129 | LibeventTargets.cmake 130 | bin/ 131 | cmake_install.cmake 132 | lib/ 133 | tmp/ 134 | verify_tests.sh 135 | verify_tests.bat 136 | event.dir 137 | event_core.dir 138 | event_extra.dir 139 | *.vcxproj 140 | *.sln 141 | *.filters 142 | 143 | # ninja 144 | build.ninja 145 | rules.ninja 146 | .ninja_deps 147 | .ninja_log 148 | 149 | # make dist 150 | /COPYING 151 | /INSTALL 152 | /*.tar.gz 153 | 154 | /.vagrant 155 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap-stdinc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy) 3 | * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California) 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 | * 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 name of the Politecnico di Torino 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 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10.2.1 2008-10-06 15:38:39 gianluca Exp $ (LBL) 32 | */ 33 | 34 | #define SIZEOF_CHAR 1 35 | #define SIZEOF_SHORT 2 36 | #define SIZEOF_INT 4 37 | #ifndef _MSC_EXTENSIONS 38 | #define SIZEOF_LONG_LONG 8 39 | #endif 40 | 41 | /* 42 | * Avoids a compiler warning in case this was already defined 43 | * (someone defined _WINSOCKAPI_ when including 'windows.h', in order 44 | * to prevent it from including 'winsock.h') 45 | */ 46 | #ifdef _WINSOCKAPI_ 47 | #undef _WINSOCKAPI_ 48 | #endif 49 | #include 50 | 51 | #include 52 | 53 | #include "bittypes.h" 54 | #include 55 | #include 56 | 57 | #ifndef __MINGW32__ 58 | #include "IP6_misc.h" 59 | #endif 60 | 61 | #define caddr_t char* 62 | 63 | #if _MSC_VER < 1500 64 | #define snprintf _snprintf 65 | #define vsnprintf _vsnprintf 66 | #define strdup _strdup 67 | #endif 68 | 69 | #define inline __inline 70 | 71 | #ifdef __MINGW32__ 72 | #include 73 | #else /*__MINGW32__*/ 74 | /* MSVC compiler */ 75 | #ifndef _UINTPTR_T_DEFINED 76 | #ifdef _WIN64 77 | typedef unsigned __int64 uintptr_t; 78 | #else 79 | typedef _W64 unsigned int uintptr_t; 80 | #endif 81 | #define _UINTPTR_T_DEFINED 82 | #endif 83 | 84 | #ifndef _INTPTR_T_DEFINED 85 | #ifdef _WIN64 86 | typedef __int64 intptr_t; 87 | #else 88 | typedef _W64 int intptr_t; 89 | #endif 90 | #define _INTPTR_T_DEFINED 91 | #endif 92 | 93 | #endif /*__MINGW32__*/ 94 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Paolo Abeni (Italy) 3 | * All rights reserved. 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 | * 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 15 | * products derived from this software without specific prior written 16 | * permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * 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 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * Basic USB data struct 31 | * By Paolo Abeni 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/usb.h,v 1.6 2007/09/22 02:06:08 guy Exp $ 34 | */ 35 | 36 | #ifndef _PCAP_USB_STRUCTS_H__ 37 | #define _PCAP_USB_STRUCTS_H__ 38 | 39 | /* 40 | * possible transfer mode 41 | */ 42 | #define URB_TRANSFER_IN 0x80 43 | #define URB_ISOCHRONOUS 0x0 44 | #define URB_INTERRUPT 0x1 45 | #define URB_CONTROL 0x2 46 | #define URB_BULK 0x3 47 | 48 | /* 49 | * possible event type 50 | */ 51 | #define URB_SUBMIT 'S' 52 | #define URB_COMPLETE 'C' 53 | #define URB_ERROR 'E' 54 | 55 | /* 56 | * USB setup header as defined in USB specification. 57 | * Appears at the front of each packet in DLT_USB captures. 58 | */ 59 | typedef struct _usb_setup { 60 | u_int8_t bmRequestType; 61 | u_int8_t bRequest; 62 | u_int16_t wValue; 63 | u_int16_t wIndex; 64 | u_int16_t wLength; 65 | } pcap_usb_setup; 66 | 67 | 68 | /* 69 | * Header prepended by linux kernel to each event. 70 | * Appears at the front of each packet in DLT_USB_LINUX captures. 71 | */ 72 | typedef struct _usb_header { 73 | u_int64_t id; 74 | u_int8_t event_type; 75 | u_int8_t transfer_type; 76 | u_int8_t endpoint_number; 77 | u_int8_t device_address; 78 | u_int16_t bus_id; 79 | char setup_flag;/*if !=0 the urb setup header is not present*/ 80 | char data_flag; /*if !=0 no urb data is present*/ 81 | int64_t ts_sec; 82 | int32_t ts_usec; 83 | int32_t status; 84 | u_int32_t urb_len; 85 | u_int32_t data_len; /* amount of urb data really present in this event*/ 86 | pcap_usb_setup setup; 87 | } pcap_usb_header; 88 | 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /third_party/libevent/cmake/CheckFunctionExistsEx.cmake: -------------------------------------------------------------------------------- 1 | # - Check if a C function can be linked 2 | # CHECK_FUNCTION_EXISTS( ) 3 | # 4 | # Check that the is provided by libraries on the system and 5 | # store the result in a . This does not verify that any 6 | # system header file declares the function, only that it can be found 7 | # at link time (considure using CheckSymbolExists). 8 | # 9 | # The following variables may be set before calling this macro to 10 | # modify the way the check is run: 11 | # 12 | # CMAKE_REQUIRED_FLAGS = string of compile command line flags 13 | # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) 14 | # CMAKE_REQUIRED_INCLUDES = list of include directories 15 | # CMAKE_REQUIRED_LIBRARIES = list of libraries to link 16 | 17 | #============================================================================= 18 | # Copyright 2002-2011 Kitware, Inc. 19 | # 20 | # Distributed under the OSI-approved BSD License (the "License"); 21 | # see accompanying file Copyright.txt for details. 22 | # 23 | # This software is distributed WITHOUT ANY WARRANTY; without even the 24 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | # See the License for more information. 26 | #============================================================================= 27 | # (To distribute this file outside of CMake, substitute the full 28 | # License text for the above reference.) 29 | 30 | MACRO(CHECK_FUNCTION_EXISTS_EX FUNCTION VARIABLE) 31 | IF(${VARIABLE} MATCHES "^${VARIABLE}$") 32 | SET(MACRO_CHECK_FUNCTION_DEFINITIONS 33 | "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") 34 | MESSAGE(STATUS "Looking for ${FUNCTION}") 35 | IF(CMAKE_REQUIRED_LIBRARIES) 36 | SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES 37 | "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") 38 | ELSE(CMAKE_REQUIRED_LIBRARIES) 39 | SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) 40 | ENDIF(CMAKE_REQUIRED_LIBRARIES) 41 | IF(CMAKE_REQUIRED_INCLUDES) 42 | SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES 43 | "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") 44 | ELSE(CMAKE_REQUIRED_INCLUDES) 45 | SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES) 46 | ENDIF(CMAKE_REQUIRED_INCLUDES) 47 | TRY_COMPILE(${VARIABLE} 48 | ${CMAKE_BINARY_DIR} 49 | ${PROJECT_SOURCE_DIR}/cmake/CheckFunctionExistsEx.c 50 | COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} 51 | CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} 52 | "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" 53 | "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}" 54 | OUTPUT_VARIABLE OUTPUT) 55 | IF(${VARIABLE}) 56 | SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}") 57 | MESSAGE(STATUS "Looking for ${FUNCTION} - found") 58 | FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 59 | "Determining if the function ${FUNCTION} exists passed with the following output:\n" 60 | "${OUTPUT}\n\n") 61 | ELSE(${VARIABLE}) 62 | MESSAGE(STATUS "Looking for ${FUNCTION} - not found") 63 | SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}") 64 | FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 65 | "Determining if the function ${FUNCTION} exists failed with the following output:\n" 66 | "${OUTPUT}\n\n") 67 | ENDIF(${VARIABLE}) 68 | ENDIF() 69 | ENDMACRO(CHECK_FUNCTION_EXISTS_EX) 70 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /src/sock_address.cpp: -------------------------------------------------------------------------------- 1 | #include "sock_address.h" 2 | #ifdef __unix__ 3 | #include 4 | #endif 5 | #include 6 | #include "utils.h" 7 | 8 | #ifndef INET_ADDRSTRLEN 9 | #define INET_ADDRSTRLEN 16 10 | #endif 11 | #ifndef INET6_ADDRSTRLEN 12 | #define INET6_ADDRSTRLEN 46 13 | #endif 14 | 15 | sock_address::sock_address() { 16 | memset(&storage_, 0, sizeof(storage_)); 17 | } 18 | sock_address::sock_address(const sockaddr_storage &storage) 19 | : storage_(storage) { 20 | } 21 | 22 | sock_address::sock_address(uint32_t ipv4, uint16_t port) { 23 | memset(&storage_, 0, sizeof(storage_)); 24 | sockaddr_in *addr = reinterpret_cast(&storage_); 25 | addr->sin_family = AF_INET; 26 | addr->sin_port = htons(port); 27 | addr->sin_addr.s_addr = ipv4; 28 | } 29 | 30 | bool sock_address::operator<(const sock_address &rhs) const { 31 | return memcmp(&storage_, &rhs.storage(), sizeof storage_) < 0; 32 | } 33 | 34 | bool sock_address::operator==(const sock_address &rhs) const { 35 | return memcmp(&storage_, &rhs.storage(), sizeof storage_) == 0; 36 | } 37 | 38 | bool sock_address::operator!=(const sock_address &rhs) const { 39 | return !(rhs == *this); 40 | } 41 | 42 | bool sock_address::is_ipv4() const { 43 | return storage_.ss_family == AF_INET; 44 | } 45 | 46 | bool sock_address::is_ipv6() const { 47 | return storage_.ss_family == AF_INET6; 48 | } 49 | 50 | int sock_address::family() const { 51 | return storage_.ss_family; 52 | } 53 | 54 | int sock_address::len() const { 55 | return get_sockaddr_len(&storage_); 56 | } 57 | 58 | uint16_t sock_address::port() const { 59 | if (is_ipv4()) { 60 | const sockaddr_in *in = (const sockaddr_in *) &storage_; 61 | return ntohs(in->sin_port); 62 | } else if (is_ipv6()) { 63 | const sockaddr_in6 *in6 = (const sockaddr_in6 *) &storage_; 64 | return ntohs(in6->sin6_port); 65 | } else { 66 | return 0; 67 | } 68 | } 69 | 70 | std::string sock_address::to_string() const { 71 | return sockaddr_tostring(&storage_); 72 | } 73 | 74 | std::string sock_address::ip_string() const { 75 | if (is_ipv4()) { 76 | char ip[INET_ADDRSTRLEN]; 77 | sockaddr_in *in = (sockaddr_in *) &storage_; 78 | inet_ntop(AF_INET, &in->sin_addr, ip, sizeof ip); 79 | return ip; 80 | } else if (is_ipv6()) { 81 | char ip[INET6_ADDRSTRLEN]; 82 | sockaddr_in6 *in6 = (sockaddr_in6 *) &storage_; 83 | inet_ntop(AF_INET, &in6->sin6_addr, ip, sizeof ip); 84 | return ip; 85 | } 86 | return std::string(); 87 | } 88 | 89 | const sockaddr_storage &sock_address::storage() const { 90 | return storage_; 91 | } 92 | 93 | sockaddr_storage &sock_address::storage() { 94 | return storage_; 95 | } 96 | 97 | // http://ctips.pbworks.com/w/page/7277591/FNV%20Hash 98 | static uint32_t fnv32(const void *buf, size_t len) { 99 | #define FNV_PRIME_32 16777619 100 | #define FNV_OFFSET_32 2166136261U 101 | uint32_t hash = FNV_OFFSET_32; 102 | const char *p = static_cast(buf); 103 | for (int i = 0; i < len; i++) { 104 | hash = hash ^ (p[i]); // xor next byte into the bottom of the hash 105 | hash = hash * FNV_PRIME_32; // Multiply by prime number found to work well 106 | } 107 | return hash; 108 | } 109 | 110 | size_t std::hash::operator()(const sock_address &k) const { 111 | return fnv32(&k.storage(), sizeof k.storage()); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/WpdPack/Include/pcap/namedb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1996 3 | * The Regents of the University of California. All rights reserved. 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. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/namedb.h,v 1.1 2006/10/04 18:09:22 guy Exp $ (LBL) 34 | */ 35 | 36 | #ifndef lib_pcap_namedb_h 37 | #define lib_pcap_namedb_h 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* 44 | * As returned by the pcap_next_etherent() 45 | * XXX this stuff doesn't belong in this interface, but this 46 | * library already must do name to address translation, so 47 | * on systems that don't have support for /etc/ethers, we 48 | * export these hooks since they'll 49 | */ 50 | struct pcap_etherent { 51 | u_char addr[6]; 52 | char name[122]; 53 | }; 54 | #ifndef PCAP_ETHERS_FILE 55 | #define PCAP_ETHERS_FILE "/etc/ethers" 56 | #endif 57 | struct pcap_etherent *pcap_next_etherent(FILE *); 58 | u_char *pcap_ether_hostton(const char*); 59 | u_char *pcap_ether_aton(const char *); 60 | 61 | bpf_u_int32 **pcap_nametoaddr(const char *); 62 | #ifdef INET6 63 | struct addrinfo *pcap_nametoaddrinfo(const char *); 64 | #endif 65 | bpf_u_int32 pcap_nametonetaddr(const char *); 66 | 67 | int pcap_nametoport(const char *, int *, int *); 68 | int pcap_nametoportrange(const char *, int *, int *, int *); 69 | int pcap_nametoproto(const char *); 70 | int pcap_nametoeproto(const char *); 71 | int pcap_nametollc(const char *); 72 | /* 73 | * If a protocol is unknown, PROTO_UNDEF is returned. 74 | * Also, pcap_nametoport() returns the protocol along with the port number. 75 | * If there are ambiguous entried in /etc/services (i.e. domain 76 | * can be either tcp or udp) PROTO_UNDEF is returned. 77 | */ 78 | #define PROTO_UNDEF -1 79 | 80 | /* XXX move these to pcap-int.h? */ 81 | int __pcap_atodn(const char *, bpf_u_int32 *); 82 | int __pcap_atoin(const char *, bpf_u_int32 *); 83 | u_short __pcap_nametodnaddr(const char *); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /third_party/libevent/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 timeval tv; 85 | int i; 86 | #ifdef _WIN32 87 | WORD wVersionRequested; 88 | WSADATA wsaData; 89 | 90 | wVersionRequested = MAKEWORD(2, 2); 91 | 92 | (void) WSAStartup(wVersionRequested, &wsaData); 93 | #endif 94 | 95 | evutil_weakrand_seed_(&weakrand_state, 0); 96 | 97 | /* Initalize the event library */ 98 | event_init(); 99 | 100 | for (i = 0; i < NEVENT; i++) { 101 | ev[i] = malloc(sizeof(struct event)); 102 | 103 | /* Initalize one event */ 104 | evtimer_set(ev[i], time_cb, ev[i]); 105 | tv.tv_sec = 0; 106 | tv.tv_usec = rand_int(50000); 107 | evtimer_add(ev[i], &tv); 108 | } 109 | 110 | event_dispatch(); 111 | 112 | 113 | printf("%d, %d\n", called, NEVENT); 114 | return (called < NEVENT); 115 | } 116 | 117 | -------------------------------------------------------------------------------- /third_party/libevent/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 | /* Initalize the event library */ 103 | event_init(); 104 | 105 | /* Initalize 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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | /* Initalize the event library */ 106 | event_init(); 107 | 108 | /* Initalize 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 | -------------------------------------------------------------------------------- /third_party/libevent/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 | -------------------------------------------------------------------------------- /third_party/libevent/.travis.yml: -------------------------------------------------------------------------------- 1 | os: 2 | - linux 3 | - osx 4 | sudo: false 5 | dist: trusty 6 | osx_image: xcode10.1 7 | 8 | branches: 9 | except: 10 | - /.*appveyor.*/ 11 | - /.*win.*/ 12 | - /.*mingw.*/ 13 | - /.*freebsd.*/ 14 | - /.*bitrise.*/ 15 | 16 | git: 17 | quiet: true 18 | 19 | env: 20 | matrix: 21 | - EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="-DEVENT__COVERAGE=ON -DCMAKE_BUILD_TYPE=debug" COVERALLS=yes 22 | - EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="" 23 | - EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="-DEVENT__DISABLE_OPENSSL=ON" 24 | - EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="-DEVENT__DISABLE_THREAD_SUPPORT=ON" 25 | - EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="-DEVENT__DISABLE_DEBUG_MODE=ON" 26 | - EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="-DEVENT__DISABLE_MM_REPLACEMENT=ON" 27 | - EVENT_BUILD_METHOD=autotools EVENT_CONFIGURE_OPTIONS="" 28 | - EVENT_BUILD_METHOD=autotools EVENT_CONFIGURE_OPTIONS="--disable-openssl" 29 | - EVENT_BUILD_METHOD=autotools EVENT_CONFIGURE_OPTIONS="--disable-thread-support" 30 | - EVENT_BUILD_METHOD=autotools EVENT_CONFIGURE_OPTIONS="--disable-debug-mode" 31 | - EVENT_BUILD_METHOD=autotools EVENT_CONFIGURE_OPTIONS="--disable-malloc-replacement" 32 | 33 | matrix: 34 | exclude: 35 | - os: osx 36 | env: EVENT_BUILD_METHOD=cmake EVENT_CMAKE_OPTIONS="-DEVENT__COVERAGE=ON -DCMAKE_BUILD_TYPE=debug" COVERALLS=yes 37 | allow_failures: 38 | - os: osx 39 | fast_finish: true 40 | 41 | language: c 42 | compiler: 43 | - gcc 44 | - clang 45 | 46 | before_install: 47 | # do not run with clang, since it fails (SIGSEGV) 48 | - if [ "$CC" = "clang" ]; then 49 | unset COVERALLS; 50 | fi 51 | - if [ -n "$COVERALLS" ]; then 52 | pip install --user cpp-coveralls; 53 | fi 54 | - export JOBS=20 55 | - export TIMEOUT=50 56 | - if [ "$TRAVIS_OS_NAME" == "osx" ]; then 57 | if [ "$CC" == "gcc" ]; then 58 | export CC=$(ls /usr/local/Cellar/gcc/*/bin/gcc-?); 59 | fi 60 | 61 | export OPENSSL_ROOT=$(echo /usr/local/Cellar/openssl/*); 62 | export 63 | CMAKE_INCLUDE_PATH=$OPENSSL_ROOT/include 64 | CMAKE_LIBRARY_PATH=$OPENSSL_ROOT/lib; 65 | export 66 | CFLAGS=-I$CMAKE_INCLUDE_PATH 67 | LDFLAGS=-L$CMAKE_LIBRARY_PATH; 68 | 69 | export JOBS=1; 70 | fi 71 | 72 | addons: 73 | apt: 74 | sources: 75 | - xenial 76 | - sourceline: 'deb http://archive.ubuntu.com/ubuntu xenial main' 77 | packages: 78 | - zlib1g-dev 79 | - libssl-dev 80 | - build-essential 81 | - automake 82 | - autoconf 83 | - cmake 84 | - lcov 85 | homebrew: 86 | packages: 87 | - openssl 88 | - lcov 89 | - libtool 90 | - gcc 91 | 92 | 93 | script: 94 | - if [ "$EVENT_BUILD_METHOD" = "autotools" ]; then 95 | ./autogen.sh && 96 | ./configure $EVENT_CONFIGURE_OPTIONS && 97 | make && 98 | travis_wait $TIMEOUT make -j $JOBS verify; 99 | fi 100 | - if [ "$EVENT_BUILD_METHOD" = "cmake" ]; then 101 | export 102 | CTEST_PARALLEL_LEVEL=$JOBS 103 | CTEST_OUTPUT_ON_FAILURE=1; 104 | 105 | mkdir build && 106 | cd build && 107 | cmake .. $EVENT_CMAKE_OPTIONS && 108 | travis_wait $TIMEOUT 109 | cmake --build . --target verify; 110 | fi 111 | 112 | after_script: 113 | - if [ -n "$COVERALLS" ]; then 114 | coveralls 115 | --build-root . 116 | --root .. 117 | --exclude test 118 | --exclude sample 119 | --exclude cmake 120 | --exclude build/CMakeFiles/CheckTypeSize 121 | --exclude build/CMakeFiles/CompilerIdC 122 | --gcov-options '\-lp'; 123 | fi 124 | -------------------------------------------------------------------------------- /third_party/libevent/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 | --------------------------------------------------------------------------------