From 5b230694e55283b800bea330e9a2a0983f2b75c3 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 2 Aug 2016 00:46:15 -0400 Subject: [PATCH] check autotools on travis (#973) build and run tests with autotools on travis, and fix configure issues. --- .travis.yml | 39 +-- configure.ac | 11 +- docs/storage.png | Bin 4773 -> 0 bytes examples/Makefile.am | 2 +- m4/ax_cxx_compile_stdcxx.m4 | 562 +++++++++++++++++++++++++++++++++ m4/ax_cxx_compile_stdcxx_11.m4 | 39 +++ src/utp_stream.cpp | 13 +- test/Makefile.am | 1 + test/main.cpp | 2 +- test/test_dht.cpp | 2 +- 10 files changed, 625 insertions(+), 46 deletions(-) delete mode 100644 docs/storage.png create mode 100644 m4/ax_cxx_compile_stdcxx.m4 create mode 100644 m4/ax_cxx_compile_stdcxx_11.m4 diff --git a/.travis.yml b/.travis.yml index 2a81f7ab6..97b0c5777 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ matrix: - env: variant=test_release coverage=1 toolset=gcc-coverage - env: variant=test_debug sim=1 ssl=openssl crypto=libcrypto toolset=gcc - env: variant=test_barebones toolset=gcc - - env: analyze=1 autotools=1 toolset=gcc + - env: autotools=1 toolset=gcc - os: osx osx_image: xcode6.4 env: variant=test_release docs=1 toolset=darwin @@ -44,7 +44,6 @@ addons: - libboost1.55-tools-dev - python2.7-dev - g++-5 - - cppcheck before_install: @@ -159,39 +158,13 @@ script: fi' - cd .. -# run through autotools and ./confiture to make sure it works +# run through autotools and ./configure to make sure it works +# TODO: --enable-python-bindings - 'if [[ "$autotools" == "1" ]]; then ./autotool.sh && - ./configure; - fi' - -# run cppcheck if enabled - - 'if [[ "$analyze" == "1" ]]; then - cppcheck --version && - find src test examples tools -type f | grep ".*\.cpp$" >cppcheck.files && - find simulation -maxdepth 1 -type f | grep ".*\.cpp$" >>cppcheck.files && - cppcheck -DTORRENT_USE_IPV6="1" -DTORRENT_USE_I2P="1" - -DTORRENT_USE_OPENSSL="1" -DTORRENT_USE_INVARIANT_CHECKS="1" - -DTORRENT_EXPENSIVE_INVARIANT_CHECKS="1" -DTORRENT_USE_ASSERTS="1" - -UTORRENT_DISABLE_MUTABLE_TORRENTS -UTORRENT_DISABLE_LOGGING - -UTORRENT_DEBUG_BUFFERS -UTORRENT_EXPORT_EXTRA - --suppress=preprocessorErrorDirective - --suppress=uninitVar - --suppress=arrayIndexOutOfBounds - --suppress=unusedStructMember - --suppress=operatorEqVarError - --suppress=noConstructor - --suppress=syntaxError - --enable=style - --template "{file}({line}): {severity} ({id}): {message}" - --inline-suppr --force --std=c++11 -j2 -I include -I /usr/local/include - -I test -I simulation/libsimulator/include - --file-list=cppcheck.files 2> cppcheck.txt && - if [ -s cppcheck.txt ]; then - echo " ======= CPPCHECK ERRORS ====="; - cat cppcheck.txt; - exit 1; - fi; + export CXX=g++-5 && + ./configure --enable-debug --enable-encryption --enable-examples --enable-tests && + make -j2 check; fi' - 'if [[ "$variant" != "" ]]; then ccache --show-stats; fi' diff --git a/configure.ac b/configure.ac index 1c5f3623c..b113f86d2 100644 --- a/configure.ac +++ b/configure.ac @@ -99,7 +99,7 @@ AX_PTHREAD() LIBS="$PTHREAD_LIBS $LIBS" CFLAGS="$PTHREAD_CFLAGS $CFLAGS" CC="$PTHREAD_CC" -CXXFLAGS="$CXXFLAGS -ftemplate-depth=120" +CXXFLAGS="$CXXFLAGS -ftemplate-depth=128" AS_ECHO "Checking for visibility support:" AC_CACHE_CHECK([for __attribute__((visibility("hidden")))], @@ -119,6 +119,8 @@ AS_ECHO "Checking for boost libraries:" AX_BOOST_BASE([1.54]) +AX_CXX_COMPILE_STDCXX_11([noext], [mandatory]) + AX_BOOST_SYSTEM() AS_IF([test -z "$BOOST_SYSTEM_LIB"], [AC_MSG_ERROR(Boost.System library not found. Try using --with-boost-system=lib)]) @@ -313,7 +315,7 @@ AS_CASE(["$ARG_ENABLE_DEBUG"], ["yes"], [ AC_MSG_RESULT([yes]) AC_DEFINE([TORRENT_USE_ASSERTS],[1],[Define to enable debug code.]) - COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_DEBUG " + COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_USE_ASSERTS" DEBUGFLAGS="-g" ], ["no"], [ @@ -407,11 +409,6 @@ AS_CASE(["$ARG_ENABLE_DHT"], AC_DEFINE([TORRENT_DISABLE_DHT],[1],[Define to disable the DHT support.]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_DISABLE_DHT " ], - ["logging"], [ - AC_MSG_RESULT([logging]) - AC_DEFINE([TORRENT_DHT_VERBOSE_LOGGING],[1],[Define to enable DHT support with verbose logging.]) - COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DTORRENT_DHT_VERBOSE_LOGGING " - ], [AC_MSG_RESULT([$ARG_ENABLE_DHT]) AC_MSG_ERROR([Unknown option "$ARG_ENABLE_DHT". Use either "yes", "no" or "logging".])] ) diff --git a/docs/storage.png b/docs/storage.png deleted file mode 100644 index 14f79370a45e15d0a1fcdbc2e54a3fc9e65d30ea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4773 zcmb7|c{r5q+sE&r2H7etQcF_ONfYJY$1jj!%y`*&+mDU<9XlXc>lc5`@F8}{NsCmug`hiyJT)8xI=6Q004r< z7Yr-_fJ+YmK+3#aTM_sR`6mFd+sD}8tmVy&*`fX1@Ns>9KpFrdc$EPC-7Y}P4;ZUyczC$FliNKnLR5+gTOmEz z=d|%Gnpfp0*Ult>`^Yg6SnmRt0Os-H*+WbA;k_vfQrS@2SLyLioY5DRhsRMJFUnhl z(W4+x)-fkR{Ofe`@O%#x-Ay0|W}u`)9uIO&^1``0z^4m!-S?LJj3M#4aBXw>3)sWu zkQ7=ulbtC}u)61i+5wm(db=RFl7nBU@PWH=ff@Mg#7OJqS=%5&!<--Jxts+i{sL0T z_Iu=MVV#1|;(NsoK)M!`;xt==Hx;=y-8j4%UgQUwSxl)UnV}C3C5q6T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1~Ce>VOp;;bxY$eoYKB(v&* z-#o8WiadjLbMAHszZ+edODq3W0)%wLy7<(mzVLfH_t93uro+YBwufGk*JF_dD-=F4 zaCE>1+rYYN-C-h}6dWC&p+^7g4+TzZin-JcZ&zNj7hKZJ;rkdYMB&WY@Rw=GtUv9m z^Q2ag8$c7GMi|FEV8Z2t{nJDBh*JVC?riRvzz5D7bv}NA9&Mxfc2GD-(POd0az0G2hRTeHnV2nj=K!(y!}>TOYHxy?w_;t|7&vo hNB{hV&(uxO{a9WzeHXQut>-7e*wEadMBnB1e*m+T@a+Hq diff --git a/examples/Makefile.am b/examples/Makefile.am index ad0daad8a..f511ffd1a 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -30,5 +30,5 @@ LDADD = $(top_builddir)/src/libtorrent-rasterbar.la AM_CPPFLAGS = -ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ -AM_LDFLAGS = @BOOST_SYSTEM_LIB@ @BOOST_RANDOM_LIB@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@ +AM_LDFLAGS = @BOOST_SYSTEM_LIB@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@ diff --git a/m4/ax_cxx_compile_stdcxx.m4 b/m4/ax_cxx_compile_stdcxx.m4 new file mode 100644 index 000000000..2c18e49c5 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx.m4 @@ -0,0 +1,562 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXX and +# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) +# or '14' (for the C++14 standard). +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 4 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [], + [$1], [14], [], + [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, + ax_cv_cxx_compile_cxx$1, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [ax_cv_cxx_compile_cxx$1=yes], + [ax_cv_cxx_compile_cxx$1=no])]) + if test x$ax_cv_cxx_compile_cxx$1 = xyes; then + ac_success=yes + fi + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for switch in -std=gnu++$1 -std=gnu++0x; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + fi + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + AC_SUBST(HAVE_CXX$1) +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_seperators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) diff --git a/m4/ax_cxx_compile_stdcxx_11.m4 b/m4/ax_cxx_compile_stdcxx_11.m4 new file mode 100644 index 000000000..0aadeafe7 --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_11.m4 @@ -0,0 +1,39 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXX and CXXCPP to enable +# support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++11. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 17 + +AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])]) diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 31e7abf66..78a6b9f17 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -3570,9 +3570,16 @@ void utp_socket_impl::tick(time_point now) // TIMEOUT! // set cwnd to 1 MSS - m_sm->inc_stats_counter(counters::utp_timeout); - - if (m_outbuf.size()) ++m_num_timeouts; + // the close_reason here is a bit of a hack. When it's set, it indicates + // that the upper layer intends to close the socket. However, it has been + // observed that the SSL shutdown sometimes can hang in a state where + // there's no outstanding data, and it won't receive any more from the + // other end. This catches that case and let the socket time out. + if (m_outbuf.size() || m_close_reason != 0) + { + ++m_num_timeouts; + m_sm->inc_stats_counter(counters::utp_timeout); + } UTP_LOGV("%8p: timeout num-timeouts: %d max-resends: %d confirmed: %d " " acked-seq-num: %d mtu-seq: %d\n" diff --git a/test/Makefile.am b/test/Makefile.am index 3cf655fb4..f6d88bd6b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -200,6 +200,7 @@ test_receive_buffer_SOURCES = test_receive_buffer.cpp test_storage_SOURCES = test_storage.cpp test_time_critical_SOURCES = test_time_critical.cpp test_resume_SOURCES = test_resume.cpp +test_read_resume_SOURCES = test_read_resume.cpp test_ssl_SOURCES = test_ssl.cpp test_torrent_SOURCES = test_torrent.cpp test_tracker_SOURCES = test_tracker.cpp diff --git a/test/main.cpp b/test/main.cpp index 8d796bc86..c5cde7148 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -322,7 +322,7 @@ EXPORT int main(int argc, char const* argv[]) #else chdir(dir); #endif - std::fprintf(stderr, "cwd = \"%s\"\n", test_dir.c_str()); + std::fprintf(stderr, "test: %s\ncwd = \"%s\"\n", executable, test_dir.c_str()); int total_failures = 0; diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 6bd5ed0cc..c39d5aabb 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -2580,7 +2580,7 @@ TORRENT_TEST(routing_table_uniform) // i.e. no more than 5 levels TEST_EQUAL(tbl.num_active_buckets(), 5); -#if defined TORRENT_DHT_VERBOSE_LOGGING +#ifndef TORRENT_DISABLE_LOGGING tbl.print_state(std::cerr); #endif }