mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-07 10:42:31 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49625ab5e5 | |||
| cc15e9308a | |||
| a5a96236df | |||
| f1cfe8ad72 | |||
| d0fc48cf7b | |||
| 5725eb3773 | |||
| ca706c21c0 | |||
| 14edd68653 | |||
| 50a609ade9 | |||
| 2cf8f2351b | |||
| add305f90c | |||
| 880510073a | |||
| 0989b2218d | |||
| 3d7e6cb077 | |||
| 64881317c6 | |||
| a5ecd89a54 | |||
| 84229a85be | |||
| e03ab27cf0 | |||
| e41b066555 | |||
| 8318133c79 |
@@ -14,7 +14,7 @@ jobs:
|
||||
permissions:
|
||||
pull-requests: write
|
||||
# OPTIONAL: auto-closing conversations requires the `contents` permission
|
||||
contents: write
|
||||
contents: read
|
||||
steps:
|
||||
- name: Sleep for 30 seconds
|
||||
run: sleep 30s
|
||||
|
||||
@@ -4,9 +4,8 @@ on: pull_request
|
||||
|
||||
jobs:
|
||||
|
||||
unit-tests:
|
||||
ubuntu-base:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: Update Packages
|
||||
run: |
|
||||
@@ -23,43 +22,80 @@ jobs:
|
||||
- name: Build libtorrent
|
||||
run: |
|
||||
cd libtorrent
|
||||
libtoolize
|
||||
aclocal -I scripts
|
||||
autoconf -i
|
||||
autoheader
|
||||
automake --add-missing
|
||||
autoreconf -fiv
|
||||
./configure
|
||||
make
|
||||
sudo make install
|
||||
cd ..
|
||||
rm -rf libtorrent
|
||||
- uses: actions/checkout@v4
|
||||
sudo make install DESTDIR=$GITHUB_WORKSPACE/libtorrent-dist
|
||||
- name: Upload Build Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
- name: Fetch base branch
|
||||
name: installed-libtorrent
|
||||
path: libtorrent-dist/
|
||||
|
||||
|
||||
unit-tests-default:
|
||||
runs-on: ubuntu-22.04
|
||||
needs: ubuntu-base
|
||||
steps:
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
git remote add upstream "https://github.com/${{ github.event.pull_request.base.repo.full_name }}"
|
||||
git fetch --no-tags --no-recurse-submodules upstream "${{ github.event.pull_request.base.ref }}"
|
||||
sudo apt-get install -y \
|
||||
libcppunit-dev \
|
||||
zlib1g-dev \
|
||||
libcurl4-openssl-dev
|
||||
- name: Download Libtorrent Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: installed-libtorrent
|
||||
path: ./libtorrent-dist
|
||||
- name: Move Artifacts to System Path
|
||||
run: |
|
||||
# Elevate permissions with sudo to safely place the files
|
||||
sudo cp -r ./libtorrent-dist/usr/local/* /usr/local/
|
||||
rm -rf ./libtorrent-dist
|
||||
- uses: actions/checkout@v4
|
||||
- name: Configure Project
|
||||
run: |
|
||||
libtoolize
|
||||
aclocal -I scripts
|
||||
autoconf -i
|
||||
autoheader
|
||||
automake --add-missing
|
||||
autoreconf -fiv
|
||||
./configure
|
||||
- name: Build Project
|
||||
run: |
|
||||
make
|
||||
- name: Run Unit Tests
|
||||
run: |
|
||||
ls /usr/local/lib/
|
||||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
|
||||
make check
|
||||
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" make check
|
||||
- name: Archive test/test-suite.log
|
||||
if: success() || failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: test-suite.log
|
||||
path: test/test-suite.log
|
||||
|
||||
unit-tests-variants:
|
||||
runs-on: ubuntu-22.04
|
||||
needs: unit-tests-default
|
||||
strategy:
|
||||
matrix:
|
||||
config_flag: ["--with-xmlrpc-c", "--with-xmlrpc-tinyxml2"]
|
||||
steps:
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
sudo apt-get install -y \
|
||||
libcppunit-dev \
|
||||
zlib1g-dev \
|
||||
libcurl4-openssl-dev \
|
||||
libxmlrpc-c++8-dev
|
||||
- name: Download Libtorrent Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: installed-libtorrent
|
||||
path: ./libtorrent-dist
|
||||
- name: Move Artifacts to System Path
|
||||
run: |
|
||||
sudo cp -r ./libtorrent-dist/usr/local/* /usr/local/
|
||||
rm -rf ./libtorrent-dist
|
||||
- uses: actions/checkout@v4
|
||||
- name: Configure Project
|
||||
run: |
|
||||
autoreconf -fiv
|
||||
./configure ${{ matrix.config_flag }}
|
||||
make
|
||||
ls /usr/local/lib/
|
||||
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" make check
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
.libs
|
||||
Makefile
|
||||
aclocal.m4
|
||||
actmp.*
|
||||
ar-lib
|
||||
autom4te.cache
|
||||
compile
|
||||
@@ -69,4 +70,5 @@ TAGS
|
||||
###########################
|
||||
src/rtorrent
|
||||
test/rtorrent_Test*
|
||||
test/test-suite.log.tmp
|
||||
test-driver
|
||||
|
||||
+17
-8
@@ -1,6 +1,6 @@
|
||||
m4_pattern_allow([PKG_CHECK_EXISTS])
|
||||
|
||||
AC_INIT([rtorrent],[0.16.12],[sundell.software@gmail.com])
|
||||
AC_INIT([rtorrent],[0.16.13],[sundell.software@gmail.com])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIRS([scripts])
|
||||
@@ -11,12 +11,12 @@ LT_INIT
|
||||
|
||||
AC_PROG_CXX
|
||||
|
||||
AC_DEFINE([API_VERSION], [20], [api version])
|
||||
AC_DEFINE([API_VERSION], [21], [api version])
|
||||
|
||||
# Filter out unwanted flags added by autoconf on some systems, e.g. MacOS.
|
||||
TORRENT_REMOVE_UNWANTED(CXX, $CXX, -std=c++11 -std=gnu++11)
|
||||
|
||||
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
|
||||
AX_CXX_COMPILE_STDCXX(20, noext, mandatory)
|
||||
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
@@ -41,20 +41,28 @@ AC_ARG_ENABLE(execinfo,
|
||||
])
|
||||
|
||||
AX_PTHREAD([], AC_MSG_ERROR([requires pthread]))
|
||||
AX_WITH_CURSES
|
||||
|
||||
if test "x$ax_cv_ncursesw" != xyes && test "x$ax_cv_ncurses" != xyes; then
|
||||
AC_MSG_ERROR([requires either NcursesW or Ncurses library])
|
||||
TORRENT_WITHOUT_NCURSES
|
||||
|
||||
if test "x$with_ncurses" != xno; then
|
||||
AX_WITH_CURSES
|
||||
|
||||
if test "x$ax_cv_ncursesw" != xyes && test "x$ax_cv_ncurses" != xyes; then
|
||||
AC_MSG_ERROR([requires either NcursesW or Ncurses library])
|
||||
fi
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES([CPPUNIT], [cppunit],, [no_cppunit="yes"])
|
||||
PKG_CHECK_MODULES([ZLIB], [zlib])
|
||||
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.12])
|
||||
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.13])
|
||||
|
||||
AC_LANG_PUSH(C++)
|
||||
TORRENT_WITH_XMLRPC_C
|
||||
AC_LANG_POP(C++)
|
||||
|
||||
dnl We don't have LuaJIT support, and the script breaks if not disabled.
|
||||
AM_CONDITIONAL([LUAJIT], [false])
|
||||
|
||||
TORRENT_WITH_LUA
|
||||
TORRENT_WITH_TINYXML2
|
||||
TORRENT_WITH_SYSTEMD
|
||||
@@ -71,7 +79,8 @@ LIBS="$PTHREAD_LIBS $CURSES_LIB $CURSES_LIBS $ZLIB_LIBS $DEPENDENCIES_LIBS $LIBS
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS $CURSES_CFLAGS $ZLIB_CFLAGS $DEPENDENCIES_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS $CURSES_CFLAGS $ZLIB_CFLAGS $DEPENDENCIES_CFLAGS"
|
||||
|
||||
TORRENT_CHECK_POPCOUNT()
|
||||
TORRENT_CHECK_CACHELINE
|
||||
TORRENT_CHECK_POPCOUNT
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
|
||||
+5
-1
@@ -46,8 +46,12 @@
|
||||
#session.path.set = ./session
|
||||
|
||||
# Watch a directory for new torrents, and stop those that have been
|
||||
# deleted.
|
||||
# deleted. Use directory.watch.ready for network shares or other watch
|
||||
# directories where files may be copied or written directly into place.
|
||||
# Do not mix directory.watch.ready and directory.watch.added on the same
|
||||
# watch directory.
|
||||
#
|
||||
#directory.watch.ready = ./watch, load.start
|
||||
#schedule2 = watch_directory,5,5,load.start=./watch/*.torrent
|
||||
|
||||
# Close torrents when disk-space is low.
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#
|
||||
# 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).
|
||||
# CXXCPP to enable support. VERSION may be '11', '14', '17', '20', or
|
||||
# '23' for the respective C++ standard version.
|
||||
#
|
||||
# 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.
|
||||
@@ -36,13 +36,15 @@
|
||||
# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
|
||||
# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
|
||||
# Copyright (c) 2020 Jason Merrill <jason@redhat.com>
|
||||
# Copyright (c) 2021, 2024 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
|
||||
# Copyright (c) 2015, 2022, 2023, 2024 Olly Betts
|
||||
#
|
||||
# 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 12
|
||||
#serial 25
|
||||
|
||||
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
|
||||
dnl (serial version number 13).
|
||||
@@ -51,6 +53,8 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
|
||||
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
|
||||
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
|
||||
[$1], [17], [ax_cxx_compile_alternatives="17 1z"],
|
||||
[$1], [20], [ax_cxx_compile_alternatives="20"],
|
||||
[$1], [23], [ax_cxx_compile_alternatives="23"],
|
||||
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
|
||||
m4_if([$2], [], [],
|
||||
[$2], [ext], [],
|
||||
@@ -102,9 +106,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
|
||||
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"
|
||||
dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
|
||||
for alternative in ${ax_cxx_compile_alternatives}; do
|
||||
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
|
||||
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
|
||||
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
|
||||
if test x"$switch" = xMSVC; then
|
||||
dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
|
||||
dnl with -std=c++17. We suffix the cache variable name with _MSVC to
|
||||
dnl avoid this.
|
||||
switch=-std:c++${alternative}
|
||||
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC])
|
||||
else
|
||||
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
|
||||
fi
|
||||
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
|
||||
$cachevar,
|
||||
[ac_save_CXX="$CXX"
|
||||
@@ -148,23 +161,44 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
|
||||
dnl Test body for checking C++11 support
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_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
|
||||
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14]
|
||||
)
|
||||
|
||||
dnl Test body for checking C++17 support
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
|
||||
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17]
|
||||
)
|
||||
|
||||
dnl Test body for checking C++20 support
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20],
|
||||
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_20]
|
||||
)
|
||||
|
||||
dnl Test body for checking C++23 support
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_23],
|
||||
[_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_20
|
||||
_AX_CXX_COMPILE_STDCXX_testbody_new_in_23]
|
||||
)
|
||||
|
||||
|
||||
dnl Tests for new features in C++11
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
|
||||
@@ -176,7 +210,21 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
|
||||
|
||||
#error "This is not a C++ compiler"
|
||||
|
||||
#elif __cplusplus < 201103L
|
||||
// MSVC always sets __cplusplus to 199711L in older versions; newer versions
|
||||
// only set it correctly if /Zc:__cplusplus is specified as well as a
|
||||
// /std:c++NN switch:
|
||||
//
|
||||
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
|
||||
//
|
||||
// The value __cplusplus ought to have is available in _MSVC_LANG since
|
||||
// Visual Studio 2015 Update 3:
|
||||
//
|
||||
// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
|
||||
//
|
||||
// This was also the first MSVC version to support C++14 so we can't use the
|
||||
// value of either __cplusplus or _MSVC_LANG to quickly rule out MSVC having
|
||||
// C++11 or C++14 support, but we can check _MSVC_LANG for C++17 and later.
|
||||
#elif __cplusplus < 201103L && !defined _MSC_VER
|
||||
|
||||
#error "This is not a C++11 compiler"
|
||||
|
||||
@@ -467,7 +515,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
|
||||
|
||||
#error "This is not a C++ compiler"
|
||||
|
||||
#elif __cplusplus < 201402L
|
||||
#elif __cplusplus < 201402L && !defined _MSC_VER
|
||||
|
||||
#error "This is not a C++14 compiler"
|
||||
|
||||
@@ -591,7 +639,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
|
||||
|
||||
#error "This is not a C++ compiler"
|
||||
|
||||
#elif __cplusplus < 201703L
|
||||
#elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 201703L
|
||||
|
||||
#error "This is not a C++17 compiler"
|
||||
|
||||
@@ -957,6 +1005,66 @@ namespace cxx17
|
||||
|
||||
} // namespace cxx17
|
||||
|
||||
#endif // __cplusplus < 201703L
|
||||
#endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 201703L
|
||||
|
||||
]])
|
||||
|
||||
|
||||
dnl Tests for new features in C++20
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#error "This is not a C++ compiler"
|
||||
|
||||
#elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202002L
|
||||
|
||||
#error "This is not a C++20 compiler"
|
||||
|
||||
#else
|
||||
|
||||
#include <version>
|
||||
|
||||
namespace cxx20
|
||||
{
|
||||
|
||||
// As C++20 supports feature test macros in the standard, there is no
|
||||
// immediate need to actually test for feature availability on the
|
||||
// Autoconf side.
|
||||
|
||||
} // namespace cxx20
|
||||
|
||||
#endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202002L
|
||||
|
||||
]])
|
||||
|
||||
|
||||
dnl Tests for new features in C++23
|
||||
|
||||
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_23], [[
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#error "This is not a C++ compiler"
|
||||
|
||||
#elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202302L
|
||||
|
||||
#error "This is not a C++23 compiler"
|
||||
|
||||
#else
|
||||
|
||||
#include <version>
|
||||
|
||||
namespace cxx23
|
||||
{
|
||||
|
||||
// As C++23 supports feature test macros in the standard, there is no
|
||||
// immediate need to actually test for feature availability on the
|
||||
// Autoconf side.
|
||||
|
||||
} // namespace cxx23
|
||||
|
||||
#endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202302L
|
||||
|
||||
]])
|
||||
|
||||
+83
-34
@@ -19,7 +19,7 @@
|
||||
# header is checked to match the Lua interpreter version exactly. When
|
||||
# searching for Lua libraries, the version number is used as a suffix.
|
||||
# This is done with the goal of supporting multiple Lua installs (5.1,
|
||||
# 5.2, and 5.3 side-by-side).
|
||||
# 5.2, 5.3, and 5.4 side-by-side).
|
||||
#
|
||||
# A note on compatibility with previous versions: This file has been
|
||||
# mostly rewritten for serial 18. Most developers should be able to use
|
||||
@@ -49,6 +49,14 @@
|
||||
# interpreter. If LUA is blank, the user's path is searched for an
|
||||
# suitable interpreter.
|
||||
#
|
||||
# Optionally a LUAJIT option may be set ahead of time to look for and
|
||||
# validate a LuaJIT install instead of PUC Lua. Usage might look like:
|
||||
#
|
||||
# AC_ARG_WITH(luajit, [AS_HELP_STRING([--with-luajit],
|
||||
# [Prefer LuaJIT over PUC Lua, even if the latter is newer. Default: no])
|
||||
# ])
|
||||
# AM_CONDITIONAL([LUAJIT], [test "x$with_luajit" != 'xno'])
|
||||
#
|
||||
# If MINIMUM-VERSION is supplied, then only Lua interpreters with a
|
||||
# version number greater or equal to MINIMUM-VERSION will be accepted. If
|
||||
# TOO-BIG-VERSION is also supplied, then only Lua interpreters with a
|
||||
@@ -82,7 +90,7 @@
|
||||
# appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
|
||||
#
|
||||
# If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
|
||||
# performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
|
||||
# performed, otherwise ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-
|
||||
# FOUND is blank, then it will default to printing an error. To prevent
|
||||
# the default behavior, give ':' as an action.
|
||||
#
|
||||
@@ -152,6 +160,7 @@
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2023 Caleb Maclennan <caleb@alerque.com>
|
||||
# Copyright (c) 2015 Reuben Thomas <rrt@sc3d.org>
|
||||
# Copyright (c) 2014 Tim Perkins <tprk77@gmail.com>
|
||||
#
|
||||
@@ -181,7 +190,7 @@
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 42
|
||||
#serial 47
|
||||
|
||||
dnl =========================================================================
|
||||
dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
|
||||
@@ -197,13 +206,14 @@ AC_DEFUN([AX_PROG_LUA],
|
||||
AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
|
||||
|
||||
dnl Find a Lua interpreter.
|
||||
m4_define_default([_AX_LUA_INTERPRETER_LIST],
|
||||
[lua lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua50])
|
||||
AM_COND_IF([LUAJIT],
|
||||
[_ax_lua_interpreter_list='luajit luajit-2.1.0-beta3 luajit-2.0.5 luajit-2.0.4 luajit-2.0.3'],
|
||||
[_ax_lua_interpreter_list='lua lua5.4 lua54 lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua5.0 lua50'])
|
||||
|
||||
m4_if([$1], [],
|
||||
[ dnl No version check is needed. Find any Lua interpreter.
|
||||
AS_IF([test "x$LUA" = 'x'],
|
||||
[AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
|
||||
[AC_PATH_PROGS([LUA], [$_ax_lua_interpreter_list], [:])])
|
||||
ax_display_LUA='lua'
|
||||
|
||||
AS_IF([test "x$LUA" != 'x:'],
|
||||
@@ -242,7 +252,7 @@ AC_DEFUN([AX_PROG_LUA],
|
||||
[_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
|
||||
AC_CACHE_CHECK([$_ax_check_text],
|
||||
[ax_cv_pathless_LUA],
|
||||
[ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
|
||||
[ for ax_cv_pathless_LUA in $_ax_lua_interpreter_list none; do
|
||||
test "x$ax_cv_pathless_LUA" = 'xnone' && break
|
||||
_AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
|
||||
_AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
|
||||
@@ -268,13 +278,25 @@ AC_DEFUN([AX_PROG_LUA],
|
||||
ax_cv_lua_version=[`$LUA -e '
|
||||
-- return a version number in X.Y format
|
||||
local _, _, ver = string.find(_VERSION, "^Lua (%d+%.%d+)")
|
||||
print(ver)'`]
|
||||
print(ver or "")'`]
|
||||
])
|
||||
AS_IF([test "x$ax_cv_lua_version" = 'x'],
|
||||
[AC_MSG_ERROR([invalid Lua version number])])
|
||||
AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
|
||||
AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | $SED 's|\.||'`])
|
||||
|
||||
AM_COND_IF([LUAJIT], [
|
||||
AC_CACHE_CHECK([for $ax_display_LUA jit version], [ax_cv_luajit_version],
|
||||
[ ax_cv_luajit_version=[`$LUA -e '
|
||||
local _, _, ver = string.find(jit and jit.version, "(%d+%..+)")
|
||||
print(ver or "")'`]
|
||||
])
|
||||
AS_IF([test "x$ax_cv_luajit_version" = 'x'],
|
||||
[AC_MSG_ERROR([invalid Lua jit version number])])
|
||||
AC_SUBST([LUAJIT_VERSION], [$ax_cv_luajit_version])
|
||||
AC_SUBST([LUAJIT_SHORT_VERSION], [$(echo "$LUAJIT_VERSION" | $SED 's|\.|§|;s|\..*||;s|§|.|')])
|
||||
])
|
||||
|
||||
dnl The following check is not supported:
|
||||
dnl At times (like when building shared libraries) you may want to know
|
||||
dnl which OS platform Lua thinks this is.
|
||||
@@ -464,33 +486,50 @@ AC_DEFUN([AX_LUA_HEADERS],
|
||||
AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
|
||||
])
|
||||
|
||||
AM_COND_IF([LUAJIT],[
|
||||
dnl Check for LUAJIT_VERSION.
|
||||
AC_MSG_CHECKING([if LUAJIT_VERSION is defined])
|
||||
AS_IF([test "x$LUAJIT_VERSION" != 'x'],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot check Lua jit headers without knowing LUAJIT_VERSION])
|
||||
])
|
||||
])
|
||||
|
||||
dnl Make LUA_INCLUDE a precious variable.
|
||||
AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
|
||||
|
||||
dnl Some default directories to search.
|
||||
LUA_SHORT_VERSION=`echo "$LUA_VERSION" | $SED 's|\.||'`
|
||||
m4_define_default([_AX_LUA_INCLUDE_LIST],
|
||||
[ /usr/include/lua$LUA_VERSION \
|
||||
/usr/include/lua-$LUA_VERSION \
|
||||
/usr/include/lua/$LUA_VERSION \
|
||||
/usr/include/lua$LUA_SHORT_VERSION \
|
||||
/usr/local/include/lua$LUA_VERSION \
|
||||
/usr/local/include/lua-$LUA_VERSION \
|
||||
/usr/local/include/lua/$LUA_VERSION \
|
||||
/usr/local/include/lua$LUA_SHORT_VERSION \
|
||||
])
|
||||
dnl Some default directories to search.
|
||||
AM_COND_IF([LUAJIT],
|
||||
[_ax_lua_include_list="
|
||||
/usr/include/luajit-$LUAJIT_VERSION
|
||||
/usr/include/luajit-$LUAJIT_SHORT_VERSION
|
||||
/usr/local/include/luajit-$LUAJIT_VERSION
|
||||
/usr/local/include/luajit-$LUAJIT_SHORT_VERSION"],
|
||||
[_ax_lua_include_list="
|
||||
/usr/include/lua$LUA_VERSION
|
||||
/usr/include/lua-$LUA_VERSION
|
||||
/usr/include/lua/$LUA_VERSION
|
||||
/usr/include/lua$LUA_SHORT_VERSION
|
||||
/usr/local/include/lua$LUA_VERSION
|
||||
/usr/local/include/lua-$LUA_VERSION
|
||||
/usr/local/include/lua/$LUA_VERSION
|
||||
/usr/local/include/lua$LUA_SHORT_VERSION"])
|
||||
|
||||
dnl Try to find the headers.
|
||||
_ax_lua_saved_cppflags=$CPPFLAGS
|
||||
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
|
||||
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
|
||||
AM_COND_IF([LUAJIT], [AC_CHECK_HEADERS([luajit.h])])
|
||||
CPPFLAGS=$_ax_lua_saved_cppflags
|
||||
|
||||
dnl Try some other directories if LUA_INCLUDE was not set.
|
||||
AS_IF([test "x$LUA_INCLUDE" = 'x' &&
|
||||
test "x$ac_cv_header_lua_h" != 'xyes'],
|
||||
test "x$ac_cv_header_lua_h" != 'xyes' ||
|
||||
test "x$with_luajit" != 'xno' &&
|
||||
test "x$ac_cv_header_luajit_h" != 'xyes'],
|
||||
[ dnl Try some common include paths.
|
||||
for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
|
||||
for _ax_include_path in $_ax_lua_include_list; do
|
||||
test ! -d "$_ax_include_path" && continue
|
||||
|
||||
AC_MSG_CHECKING([for Lua headers in])
|
||||
@@ -500,10 +539,12 @@ AC_DEFUN([AX_LUA_HEADERS],
|
||||
AS_UNSET([ac_cv_header_lualib_h])
|
||||
AS_UNSET([ac_cv_header_lauxlib_h])
|
||||
AS_UNSET([ac_cv_header_luaconf_h])
|
||||
AS_UNSET([ac_cv_header_luajit_h])
|
||||
|
||||
_ax_lua_saved_cppflags=$CPPFLAGS
|
||||
CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
|
||||
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
|
||||
AM_COND_IF([LUAJIT], [AC_CHECK_HEADERS([luajit.h])])
|
||||
CPPFLAGS=$_ax_lua_saved_cppflags
|
||||
|
||||
AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
|
||||
@@ -621,18 +662,26 @@ AC_DEFUN([AX_LUA_LIBS],
|
||||
dnl Try to find the Lua libs.
|
||||
_ax_lua_saved_libs=$LIBS
|
||||
LIBS="$LIBS $LUA_LIB"
|
||||
AC_SEARCH_LIBS([lua_load],
|
||||
[ lua$LUA_VERSION \
|
||||
lua$LUA_SHORT_VERSION \
|
||||
lua-$LUA_VERSION \
|
||||
lua-$LUA_SHORT_VERSION \
|
||||
:liblua-$LUA_VERSION.so.0 \
|
||||
:liblua-$LUA_SHORT_VERSION.so.0 \
|
||||
lua \
|
||||
],
|
||||
[_ax_found_lua_libs='yes'],
|
||||
[_ax_found_lua_libs='no'],
|
||||
[$_ax_lua_extra_libs])
|
||||
AM_COND_IF([LUAJIT],
|
||||
[AC_SEARCH_LIBS([lua_load],
|
||||
[ luajit$LUA_VERSION \
|
||||
luajit$LUA_SHORT_VERSION \
|
||||
luajit-$LUA_VERSION \
|
||||
luajit-$LUA_SHORT_VERSION \
|
||||
luajit],
|
||||
[_ax_found_lua_libs='yes'],
|
||||
[_ax_found_lua_libs='no'],
|
||||
[$_ax_lua_extra_libs])],
|
||||
[AC_SEARCH_LIBS([lua_load],
|
||||
[ lua$LUA_VERSION \
|
||||
lua$LUA_SHORT_VERSION \
|
||||
lua-$LUA_VERSION \
|
||||
lua-$LUA_SHORT_VERSION \
|
||||
lua \
|
||||
],
|
||||
[_ax_found_lua_libs='yes'],
|
||||
[_ax_found_lua_libs='no'],
|
||||
[$_ax_lua_extra_libs])])
|
||||
LIBS=$_ax_lua_saved_libs
|
||||
|
||||
AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
|
||||
|
||||
+158
-10
@@ -54,6 +54,8 @@ AC_DEFUN([TORRENT_CHECK_EPOLL], [
|
||||
}
|
||||
])],
|
||||
[
|
||||
use_epoll=yes
|
||||
|
||||
AC_DEFINE(USE_EPOLL, 1, Use epoll.)
|
||||
AC_MSG_RESULT(yes)
|
||||
], [
|
||||
@@ -86,6 +88,8 @@ AC_DEFUN([TORRENT_CHECK_KQUEUE], [
|
||||
}
|
||||
])],
|
||||
[
|
||||
use_kqueue=yes
|
||||
|
||||
AC_DEFINE(USE_KQUEUE, 1, Use kqueue.)
|
||||
AC_MSG_RESULT(yes)
|
||||
], [
|
||||
@@ -125,7 +129,7 @@ AC_DEFUN([TORRENT_CHECK_FALLOCATE], [
|
||||
#include <fcntl.h>
|
||||
]], [[ fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 0); return 0;
|
||||
]])],[
|
||||
AC_DEFINE(HAVE_FALLOCATE, 1, Linux's fallocate supported.)
|
||||
AC_DEFINE(USE_FALLOCATE, 1, Linux's fallocate supported.)
|
||||
AC_MSG_RESULT(yes)
|
||||
],[
|
||||
AC_MSG_RESULT(no)
|
||||
@@ -157,6 +161,116 @@ AC_DEFUN([TORRENT_WITH_POSIX_FALLOCATE], [
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_CHECK_STATVFS], [
|
||||
AC_CHECK_HEADERS(sys/vfs.h sys/statvfs.h sys/statfs.h)
|
||||
|
||||
AC_MSG_CHECKING(for statvfs)
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||
#if HAVE_SYS_VFS_H
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
#if HAVE_SYS_STATVFS_H
|
||||
#include <sys/statvfs.h>
|
||||
#endif
|
||||
#if HAVE_SYS_STATFS_H
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
]], [[
|
||||
struct statvfs s; fsblkcnt_t c;
|
||||
statvfs("", &s);
|
||||
fstatvfs(0, &s);
|
||||
]])],[
|
||||
AC_DEFINE(FS_STAT_FD, [fstatvfs(fd, &m_stat) == 0], Function to determine filesystem stats from fd)
|
||||
AC_DEFINE(FS_STAT_FN, [statvfs(fn, &m_stat) == 0], Function to determine filesystem stats from filename)
|
||||
AC_DEFINE(FS_STAT_STRUCT, [struct statvfs], Type of second argument to statfs function)
|
||||
AC_DEFINE(FS_STAT_SIZE_TYPE, [unsigned long], Type of block size member in stat struct)
|
||||
AC_DEFINE(FS_STAT_COUNT_TYPE, [fsblkcnt_t], Type of block count member in stat struct)
|
||||
AC_DEFINE(FS_STAT_BLOCK_SIZE, [(m_stat.f_frsize)], Determine the block size)
|
||||
AC_MSG_RESULT(ok)
|
||||
have_stat_vfs=yes
|
||||
],[
|
||||
AC_MSG_RESULT(no)
|
||||
have_stat_vfs=no
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_CHECK_STATFS], [
|
||||
AC_CHECK_HEADERS(sys/statfs.h)
|
||||
|
||||
AC_MSG_CHECKING(for statfs)
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||
#if HAVE_SYS_STATFS_H
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
]], [[
|
||||
struct statfs s;
|
||||
statfs("", &s);
|
||||
fstatfs(0, &s);
|
||||
]])],[
|
||||
AC_DEFINE(FS_STAT_FD, [fstatfs(fd, &m_stat) == 0], Function to determine filesystem stats from fd)
|
||||
AC_DEFINE(FS_STAT_FN, [statfs(fn, &m_stat) == 0], Function to determine filesystem stats from filename)
|
||||
AC_DEFINE(FS_STAT_STRUCT, [struct statfs], Type of second argument to statfs function)
|
||||
AC_DEFINE(FS_STAT_SIZE_TYPE, [long], Type of block size member in stat struct)
|
||||
AC_DEFINE(FS_STAT_COUNT_TYPE, [long], Type of block count member in stat struct)
|
||||
AC_DEFINE(FS_STAT_BLOCK_SIZE, [(m_stat.f_bsize)], Determine the block size)
|
||||
AC_MSG_RESULT(ok)
|
||||
have_stat_vfs=yes
|
||||
],[
|
||||
AC_MSG_RESULT(no)
|
||||
have_stat_vfs=no
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_DISABLED_STATFS], [
|
||||
AC_DEFINE(FS_STAT_FD, [(errno = ENOSYS) == 0], Function to determine filesystem stats from fd)
|
||||
AC_DEFINE(FS_STAT_FN, [(errno = ENOSYS) == 0], Function to determine filesystem stats from filename)
|
||||
AC_DEFINE(FS_STAT_STRUCT, [struct {blocksize_type f_bsize; blockcount_type f_bavail;}], Type of second argument to statfs function)
|
||||
AC_DEFINE(FS_STAT_SIZE_TYPE, [int], Type of block size member in stat struct)
|
||||
AC_DEFINE(FS_STAT_COUNT_TYPE, [int], Type of block count member in stat struct)
|
||||
AC_DEFINE(FS_STAT_BLOCK_SIZE, [(4096)], Determine the block size)
|
||||
AC_MSG_RESULT(No filesystem stats available)
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_WITHOUT_STATVFS], [
|
||||
AC_ARG_WITH(statvfs,
|
||||
AS_HELP_STRING([--without-statvfs],[don't try to use statvfs to find free diskspace]),
|
||||
[
|
||||
if test "$withval" = "yes"; then
|
||||
TORRENT_CHECK_STATVFS
|
||||
else
|
||||
have_stat_vfs=no
|
||||
fi
|
||||
],
|
||||
[
|
||||
TORRENT_CHECK_STATVFS
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_WITHOUT_STATFS], [
|
||||
AC_ARG_WITH(statfs,
|
||||
AS_HELP_STRING([--without-statfs],[don't try to use statfs to find free diskspace]),
|
||||
[
|
||||
if test "$have_stat_vfs" = "no"; then
|
||||
if test "$withval" = "yes"; then
|
||||
TORRENT_CHECK_STATFS
|
||||
else
|
||||
TORRENT_DISABLED_STATFS
|
||||
fi
|
||||
fi
|
||||
],
|
||||
[
|
||||
if test "$have_stat_vfs" = "no"; then
|
||||
TORRENT_CHECK_STATFS
|
||||
if test "$have_stat_vfs" = "no"; then
|
||||
TORRENT_DISABLED_STATFS
|
||||
fi
|
||||
fi
|
||||
])
|
||||
])
|
||||
|
||||
|
||||
AC_DEFUN([TORRENT_WITH_ADDRESS_SPACE], [
|
||||
AC_ARG_WITH(address-space,
|
||||
AS_HELP_STRING([--with-address-space=MB],[change the default address space size [[default=1024mb]]]),
|
||||
@@ -189,7 +303,7 @@ AC_DEFUN([TORRENT_WITH_FASTCGI], [
|
||||
|
||||
elif test "$withval" = "yes"; then
|
||||
CXXFLAGS="$CXXFLAGS"
|
||||
LIBS="$LIBS -lfcgi"
|
||||
LIBS="$LIBS -lfcgi"
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <fcgiapp.h>
|
||||
]], [[ FCGX_Init(); ]])],[
|
||||
@@ -281,29 +395,45 @@ AC_DEFUN([TORRENT_WITH_LUA], [
|
||||
AC_MSG_RESULT(no)
|
||||
else
|
||||
AX_PROG_LUA
|
||||
AX_LUA_LIBS
|
||||
AX_LUA_HEADERS
|
||||
AC_DEFINE(HAVE_LUA, 1, Use LUA.)
|
||||
AC_DEFINE(LUA_DATADIR, [PACKAGE_DATADIR "/lua"], [LUA data directory])
|
||||
LIBS="$LIBS $LUA_LIB"
|
||||
CXXFLAGS="$CXXFLAGS $LUA_INCLUDE"
|
||||
|
||||
# 1. Override AX_LUA_LIBS default crash behavior
|
||||
AX_LUA_LIBS([have_lua_libs=yes], [have_lua_libs=no])
|
||||
|
||||
# 2. Override AX_LUA_HEADERS default crash behavior
|
||||
AX_LUA_HEADERS([have_lua_headers=yes], [have_lua_headers=no])
|
||||
|
||||
# 3. Only inject if both checks completely pass
|
||||
if test "x$have_lua_libs" = "xyes" && test "x$have_lua_headers" = "xyes"; then
|
||||
AC_DEFINE(HAVE_LUA, 1, Use LUA.)
|
||||
AC_DEFINE(LUA_DATADIR, [PACKAGE_DATADIR "/lua"], [LUA data directory])
|
||||
LIBS="$LIBS $LUA_LIB"
|
||||
CXXFLAGS="$CXXFLAGS $LUA_INCLUDE"
|
||||
else
|
||||
# Throw fatal error ONLY if user strictly ran --with-lua=yes
|
||||
if test "$withval" = "yes"; then
|
||||
AC_MSG_ERROR([Lua support explicitly requested, but compatible Lua 5.3 libs/headers were not found.])
|
||||
else
|
||||
AC_MSG_WARN([Lua 5.3 libs or headers missing. Proceeding without Lua support.])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
],[
|
||||
AC_MSG_RESULT(ignored)
|
||||
])
|
||||
])
|
||||
|
||||
|
||||
AC_DEFUN([TORRENT_WITH_INOTIFY], [
|
||||
AC_LANG_PUSH(C++)
|
||||
|
||||
AC_CHECK_HEADERS([sys/inotify.h mcheck.h])
|
||||
AC_CHECK_HEADERS([sys/inotify.h])
|
||||
AC_MSG_CHECKING([whether sys/inotify.h actually works])
|
||||
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <sys/inotify.h>
|
||||
int main(int,const char**) { return (-1 == inotify_init()); }])
|
||||
],[
|
||||
AC_DEFINE(HAVE_INOTIFY, 1, [sys/inotify.h exists and works correctly])
|
||||
AC_DEFINE(USE_INOTIFY, 1, [sys/inotify.h exists and works correctly])
|
||||
AC_MSG_RESULT(yes)],
|
||||
[AC_MSG_RESULT(failed)]
|
||||
)
|
||||
@@ -317,6 +447,7 @@ AC_DEFUN([TORRENT_CHECK_PTHREAD_SETNAME_NP], [
|
||||
AC_MSG_CHECKING(for pthread_setname_np type)
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||
#define _GNU_SOURCE
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
]], [[
|
||||
@@ -375,3 +506,20 @@ AC_DEFUN([TORRENT_WITH_SYSTEMD], [
|
||||
fi
|
||||
])
|
||||
])
|
||||
|
||||
|
||||
AC_DEFUN([TORRENT_WITHOUT_NCURSES], [
|
||||
AC_ARG_WITH([ncurses],
|
||||
[AS_HELP_STRING([--without-ncurses], [build without ncurses (daemon-only mode)])],
|
||||
[with_ncurses=$withval],
|
||||
[with_ncurses=yes])
|
||||
|
||||
if test "x$with_ncurses" = xno; then
|
||||
AC_DEFINE([HAVE_NO_NCURSES], [1], [Define to 1 if building without ncurses])
|
||||
CURSES_LIBS=""
|
||||
CURSES_CFLAGS=""
|
||||
CURSES_LIB=""
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL([NO_NCURSES], [test "x$with_ncurses" = xno])
|
||||
])
|
||||
|
||||
+64
-15
@@ -159,23 +159,72 @@ AC_DEFUN([TORRENT_CHECK_POPCOUNT], [
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_CHECK_CACHELINE], [
|
||||
AC_MSG_CHECKING(for cacheline)
|
||||
AC_REQUIRE([AC_CANONICAL_HOST])
|
||||
AC_MSG_CHECKING([for target cacheline size])
|
||||
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <stdlib.h>
|
||||
#include <linux/cache.h>
|
||||
void* vptr __cacheline_aligned;
|
||||
void f() { posix_memalign(&vptr, SMP_CACHE_BYTES, 42); }
|
||||
])],
|
||||
[
|
||||
AC_MSG_RESULT(found builtin)
|
||||
dnl Need to fix this so that it uses the stuff defined by the system.
|
||||
case "$host_os" in
|
||||
linux*)
|
||||
# REGION: Linux Kernel Extraction Loop
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
|
||||
#include <stdlib.h>
|
||||
#include <linux/cache.h>
|
||||
void* vptr;
|
||||
void f() {
|
||||
int res = posix_memalign(&vptr, SMP_CACHE_BYTES, 42);
|
||||
(void)res;
|
||||
}
|
||||
]])],[
|
||||
# We need an explicit variable fallback condition inside AC_COMPUTE_INT
|
||||
AC_COMPUTE_INT([torrent_cv_cacheline_size], [SMP_CACHE_BYTES], [#include <linux/cache.h>], [torrent_cv_cacheline_size=0])
|
||||
|
||||
AC_DEFINE(LT_SMP_CACHE_BYTES, 128, Largest L1 cache size we know of should work on all archs.)
|
||||
], [
|
||||
AC_MSG_RESULT(using default 128 bytes)
|
||||
AC_DEFINE(LT_SMP_CACHE_BYTES, 128, Largest L1 cache size we know of should work on all archs.)
|
||||
])
|
||||
if test "$torrent_cv_cacheline_size" -gt 0; then
|
||||
AC_MSG_RESULT([linux builtin ($torrent_cv_cacheline_size bytes)])
|
||||
AC_DEFINE_UNQUOTED([LT_SMP_CACHE_BYTES], [$torrent_cv_cacheline_size], [System-defined Linux L1 SMP cacheline size.])
|
||||
else
|
||||
# Handle scenarios where macro maps to a complex runtime expression or fails
|
||||
AC_MSG_RESULT([failed to parse SMP_CACHE_BYTES value])
|
||||
AC_MSG_FAILURE([Linux kernel headers found, but cacheline constant could not be computed at compile-time.])
|
||||
fi
|
||||
],[
|
||||
# Explicitly validate the CPU type even on Linux if the header check fails
|
||||
case "$host_cpu" in
|
||||
x86_64*|amd64*|i386*|i486*|i586*|i686*)
|
||||
AC_MSG_RESULT([linux fallback x86 64 bytes])
|
||||
AC_DEFINE([LT_SMP_CACHE_BYTES], 64, [Fallback 64-byte alignment for Linux x86 hardware.])
|
||||
;;
|
||||
arm*|aarch64*|powerpc*|ppc*|s390x*)
|
||||
AC_MSG_RESULT([linux fallback enterprise 128 bytes])
|
||||
AC_DEFINE([LT_SMP_CACHE_BYTES], 128, [Fallback 128-byte alignment for Linux enterprise hardware.])
|
||||
;;
|
||||
*)
|
||||
AC_MSG_RESULT([unrecognized CPU arch on Linux header fallback])
|
||||
AC_MSG_FAILURE([Unrecognized CPU architecture ($host_cpu) on Linux fallback path. Aborting build.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
;;
|
||||
|
||||
*)
|
||||
# REGION: Cross-Platform Strict Hardware Mapping (macOS, FreeBSD, OpenBSD, NetBSD)
|
||||
case "$host_cpu" in
|
||||
x86_64*|amd64*|i386*|i486*|i586*|i686*)
|
||||
# Explicit x86 desktop hardware baseline block
|
||||
AC_MSG_RESULT([$host_os ($host_cpu) standard x86 64 bytes])
|
||||
AC_DEFINE([LT_SMP_CACHE_BYTES], 64, [Standard 64-byte alignment for stable x86 hardware layout.])
|
||||
;;
|
||||
arm*|aarch64*|powerpc*|ppc*|s390x*)
|
||||
# Explicit modern enterprise and Apple Silicon hardware baseline block
|
||||
AC_MSG_RESULT([$host_os ($host_cpu) stable enterprise 128 bytes])
|
||||
AC_DEFINE([LT_SMP_CACHE_BYTES], 128, [Optimized 128-byte alignment for newer high-performance chipsets.])
|
||||
;;
|
||||
*)
|
||||
# STRICT ENFORCEMENT: Fail the build immediately if the CPU isn't explicitly known
|
||||
AC_MSG_RESULT([unrecognized architecture])
|
||||
AC_MSG_FAILURE([The target CPU architecture ($host_cpu) is unrecognized. Aborting configuration to prevent fatal runtime false-sharing or memory misalignment errors.])
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
||||
AC_DEFUN([TORRENT_CHECK_ALIGNED], [
|
||||
|
||||
@@ -174,6 +174,8 @@ libsub_root_a_SOURCES = \
|
||||
utils/list_focus.h \
|
||||
utils/lockfile.cc \
|
||||
utils/lockfile.h \
|
||||
utils/watch_ready_queue.cc \
|
||||
utils/watch_ready_queue.h \
|
||||
\
|
||||
command_download.cc \
|
||||
command_dynamic.cc \
|
||||
@@ -203,4 +205,8 @@ libsub_root_a_SOURCES = \
|
||||
signal_handler.h
|
||||
|
||||
|
||||
if NO_NCURSES
|
||||
libsub_root_a_SOURCES += display/curses_stub.cc display/curses_stub.h
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS = -I$(srcdir) -I$(top_srcdir) -DPACKAGE_DATADIR=\"$(pkgdatadir)\"
|
||||
|
||||
+80
-48
@@ -18,6 +18,7 @@
|
||||
#include <torrent/net/types.h>
|
||||
#include <torrent/peer/connection_list.h>
|
||||
#include <torrent/peer/peer_list.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/utils/file_stat.h>
|
||||
#include <torrent/utils/log.h>
|
||||
#include <torrent/utils/option_strings.h>
|
||||
@@ -32,31 +33,34 @@
|
||||
#include "control.h"
|
||||
#include "command_helpers.h"
|
||||
|
||||
std::string
|
||||
torrent::string_utf8
|
||||
retrieve_d_base_path(core::Download* download) {
|
||||
if (download->file_list()->is_multi_file())
|
||||
return download->file_list()->frozen_root_dir();
|
||||
else
|
||||
return download->file_list()->empty() ? std::string() : download->file_list()->at(0)->frozen_path();
|
||||
|
||||
if (download->file_list()->empty())
|
||||
return {};
|
||||
|
||||
return download->file_list()->at(0)->frozen_path();
|
||||
}
|
||||
|
||||
std::string
|
||||
torrent::string_utf8
|
||||
retrieve_d_base_filename(core::Download* download) {
|
||||
const std::string* base;
|
||||
torrent::string_utf8 base_path;
|
||||
|
||||
if (download->file_list()->is_multi_file())
|
||||
base = &download->file_list()->frozen_root_dir();
|
||||
else if (download->file_list()->empty())
|
||||
return std::string();
|
||||
base_path = download->file_list()->frozen_root_dir();
|
||||
else if (!download->file_list()->empty())
|
||||
base_path = download->file_list()->at(0)->frozen_path();
|
||||
else
|
||||
base = &download->file_list()->at(0)->frozen_path();
|
||||
return {};
|
||||
|
||||
std::string::size_type split = base->rfind('/');
|
||||
auto split = base_path.str().rfind('/');
|
||||
|
||||
if (split == std::string::npos)
|
||||
return *base;
|
||||
else
|
||||
return base->substr(split + 1);
|
||||
return base_path;
|
||||
|
||||
return torrent::string_utf8::from_string(base_path.str().substr(split + 1));
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
@@ -144,9 +148,9 @@ apply_d_directory(core::Download* download, const std::string& name) {
|
||||
if (!download->file_list()->is_multi_file())
|
||||
download->set_root_directory(name);
|
||||
else if (name.empty() || *name.rbegin() == '/')
|
||||
download->set_root_directory(name + download->info()->name());
|
||||
download->set_root_directory(name + download->info()->name().str());
|
||||
else
|
||||
download->set_root_directory(name + "/" + download->info()->name());
|
||||
download->set_root_directory(name + "/" + download->info()->name().str());
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
@@ -271,16 +275,6 @@ retrieve_d_custom_map(core::Download* download, bool keys_only, const torrent::O
|
||||
return result;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
retrieve_d_bitfield(core::Download* download) {
|
||||
const torrent::Bitfield* bitField = download->download()->file_list()->bitfield();
|
||||
|
||||
if (bitField->empty())
|
||||
return torrent::Object("");
|
||||
|
||||
return torrent::Object(torrent::utils::transform_to_hex_str(*bitField));
|
||||
}
|
||||
|
||||
void
|
||||
apply_d_add_peer(core::Download* download, const std::string& arg) {
|
||||
int port, ret;
|
||||
@@ -305,8 +299,10 @@ apply_d_add_peer(core::Download* download, const std::string& arg) {
|
||||
|
||||
assert(std::this_thread::get_id() == torrent::main_thread::thread_id());
|
||||
|
||||
auto callback_id = torrent::system::make_callback_id();
|
||||
|
||||
// Currently discarding SOCK_STREAM.
|
||||
torrent::this_thread::resolver()->resolve_preferred(NULL, host, AF_UNSPEC, AF_INET, [download, port](torrent::c_sa_shared_ptr sa, int err) {
|
||||
torrent::this_thread::resolver()->resolve_preferred(callback_id, host, AF_UNSPEC, AF_INET, [download, port](torrent::c_sa_shared_ptr sa, int err) {
|
||||
if (sa == nullptr) {
|
||||
lt_log_print(torrent::LOG_TORRENT_WARN, "could not resolve hostname for added peer: %s", gai_strerror(err));
|
||||
return;
|
||||
@@ -648,30 +644,48 @@ void cg_d_group_set(core::Download* download, const torrent::Objec
|
||||
|
||||
void
|
||||
initialize_command_download() {
|
||||
CMD2_DL("d.hash", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->hash()); });
|
||||
CMD2_DL("d.local_id", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->local_id()); });
|
||||
CMD2_DL("d.local_id_html", [](auto* download, auto) { return torrent::utils::copy_escape_html_str(download->info()->local_id()); });
|
||||
CMD2_DL("d.bitfield", std::bind(&retrieve_d_bitfield, std::placeholders::_1));
|
||||
CMD2_DL("d.base_path", std::bind(&retrieve_d_base_path, std::placeholders::_1));
|
||||
CMD2_DL("d.base_filename", std::bind(&retrieve_d_base_filename, std::placeholders::_1));
|
||||
CMD2_DL("d.hash", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->hash()); });
|
||||
CMD2_DL("d.local_id", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->local_id()); });
|
||||
CMD2_DL("d.local_id_html", [](auto* download, auto) { return torrent::utils::copy_escape_html_str(download->info()->local_id()); });
|
||||
CMD2_DL("d.bitfield", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(*download->download()->file_list()->bitfield()); });
|
||||
CMD2_DL("d.base_path", [](auto* download, auto) { return retrieve_d_base_path(download).str(); });
|
||||
CMD2_DL("d.base_path.hex", [](auto* download, auto) { return retrieve_d_base_path(download).object_hex(); });
|
||||
CMD2_DL("d.base_path.base64", [](auto* download, auto) { return retrieve_d_base_path(download).object_base64(); });
|
||||
CMD2_DL("d.base_path.base64_as_binary", [](auto* download, auto) { return retrieve_d_base_path(download).object_base64_as_binary(); });
|
||||
CMD2_DL("d.base_path.as_binary", [](auto* download, auto) { return retrieve_d_base_path(download).object_as_binary(); });
|
||||
CMD2_DL("d.base_path.or_base64", [](auto* download, auto) { return retrieve_d_base_path(download).object_utf8_or_base64(); });
|
||||
CMD2_DL("d.base_path.or_as_binary", [](auto* download, auto) { return retrieve_d_base_path(download).object_utf8_or_as_binary(); });
|
||||
CMD2_DL("d.base_filename", [](auto* download, auto) { return retrieve_d_base_filename(download).str(); });
|
||||
CMD2_DL("d.base_filename.hex", [](auto* download, auto) { return retrieve_d_base_filename(download).object_hex(); });
|
||||
CMD2_DL("d.base_filename.base64", [](auto* download, auto) { return retrieve_d_base_filename(download).object_base64(); });
|
||||
CMD2_DL("d.base_filename.base64_as_binary", [](auto* download, auto) { return retrieve_d_base_filename(download).object_base64_as_binary(); });
|
||||
CMD2_DL("d.base_filename.as_binary", [](auto* download, auto) { return retrieve_d_base_filename(download).object_as_binary(); });
|
||||
CMD2_DL("d.base_filename.or_base64", [](auto* download, auto) { return retrieve_d_base_filename(download).object_utf8_or_base64(); });
|
||||
CMD2_DL("d.base_filename.or_as_binary", [](auto* download, auto) { return retrieve_d_base_filename(download).object_utf8_or_as_binary(); });
|
||||
|
||||
CMD2_DL("d.name", CMD2_ON_INFO(name));
|
||||
CMD2_DL("d.creation_date", CMD2_ON_INFO(creation_date));
|
||||
CMD2_DL("d.load_date", CMD2_ON_INFO(load_date));
|
||||
CMD2_DL("d.name", [](auto* download, auto) { return download->info()->name().str(); });
|
||||
CMD2_DL("d.name.hex", [](auto* download, auto) { return download->info()->name().object_hex(); });
|
||||
CMD2_DL("d.name.base64", [](auto* download, auto) { return download->info()->name().object_base64(); });
|
||||
CMD2_DL("d.name.base64_as_binary", [](auto* download, auto) { return download->info()->name().object_base64_as_binary(); });
|
||||
CMD2_DL("d.name.as_binary", [](auto* download, auto) { return download->info()->name().object_as_binary(); });
|
||||
CMD2_DL("d.name.or_base64", [](auto* download, auto) { return download->info()->name().object_utf8_or_base64(); });
|
||||
CMD2_DL("d.name.or_as_binary", [](auto* download, auto) { return download->info()->name().object_utf8_or_as_binary(); });
|
||||
CMD2_DL("d.creation_date", [](auto* download, auto) { return download->info()->creation_date(); });
|
||||
CMD2_DL("d.load_date", [](auto* download, auto) { return download->info()->load_date(); });
|
||||
|
||||
//
|
||||
// Network related:
|
||||
//
|
||||
|
||||
CMD2_DL ("d.up.rate", std::bind(&torrent::Rate::rate, CMD2_ON_INFO(up_rate)));
|
||||
CMD2_DL ("d.up.total", std::bind(&torrent::Rate::total, CMD2_ON_INFO(up_rate)));
|
||||
CMD2_DL ("d.down.rate", std::bind(&torrent::Rate::rate, CMD2_ON_INFO(down_rate)));
|
||||
CMD2_DL ("d.down.total", std::bind(&torrent::Rate::total, CMD2_ON_INFO(down_rate)));
|
||||
CMD2_DL ("d.skip.rate", std::bind(&torrent::Rate::rate, CMD2_ON_INFO(skip_rate)));
|
||||
CMD2_DL ("d.skip.total", std::bind(&torrent::Rate::total, CMD2_ON_INFO(skip_rate)));
|
||||
CMD2_DL ("d.up.rate", [](auto* download, auto) { return download->info()->up_rate()->rate(); });
|
||||
CMD2_DL ("d.up.total", [](auto* download, auto) { return download->info()->up_rate()->total(); });
|
||||
CMD2_DL ("d.down.rate", [](auto* download, auto) { return download->info()->down_rate()->rate(); });
|
||||
CMD2_DL ("d.down.total", [](auto* download, auto) { return download->info()->down_rate()->total(); });
|
||||
CMD2_DL ("d.skip.rate", [](auto* download, auto) { return download->info()->skip_rate()->rate(); });
|
||||
CMD2_DL ("d.skip.total", [](auto* download, auto) { return download->info()->skip_rate()->total(); });
|
||||
|
||||
CMD2_DL ("d.peer_exchange", CMD2_ON_INFO(is_pex_enabled));
|
||||
CMD2_DL_VALUE_V ("d.peer_exchange.set", std::bind(&torrent::Download::set_pex_enabled, CMD2_BIND_DL, std::placeholders::_2));
|
||||
CMD2_DL ("d.peer_exchange", [](auto* download, auto) { return download->info()->is_pex_enabled(); });
|
||||
CMD2_DL_VALUE_V ("d.peer_exchange.set", [](auto* download, auto value) { download->download()->set_pex_enabled(value); });
|
||||
|
||||
CMD2_DL_LIST ("d.create_link", std::bind(&apply_d_change_link, std::placeholders::_1, std::placeholders::_2, 0));
|
||||
CMD2_DL_LIST ("d.delete_link", std::bind(&apply_d_change_link, std::placeholders::_1, std::placeholders::_2, 1));
|
||||
@@ -687,16 +701,16 @@ initialize_command_download() {
|
||||
// Control functinos:
|
||||
//
|
||||
|
||||
CMD2_DL ("d.is_open", CMD2_ON_INFO(is_open));
|
||||
CMD2_DL ("d.is_active", CMD2_ON_INFO(is_active));
|
||||
CMD2_DL ("d.is_open", [](auto* download, auto) { return download->info()->is_open(); });
|
||||
CMD2_DL ("d.is_active", [](auto* download, auto) { return download->info()->is_active(); });
|
||||
CMD2_DL ("d.is_hash_checked", std::bind(&torrent::Download::is_hash_checked, CMD2_BIND_DL));
|
||||
CMD2_DL ("d.is_hash_checking", std::bind(&torrent::Download::is_hash_checking, CMD2_BIND_DL));
|
||||
CMD2_DL ("d.is_multi_file", std::bind(&torrent::FileList::is_multi_file, CMD2_BIND_FL));
|
||||
CMD2_DL ("d.is_private", CMD2_ON_INFO(is_private));
|
||||
CMD2_DL ("d.is_pex_active", CMD2_ON_INFO(is_pex_active));
|
||||
CMD2_DL ("d.is_private", [](auto* download, auto) { return download->info()->is_private(); });
|
||||
CMD2_DL ("d.is_pex_active", [](auto* download, auto) { return download->info()->is_pex_active(); });
|
||||
CMD2_DL ("d.is_partially_done", CMD2_ON_DATA(is_partially_done));
|
||||
CMD2_DL ("d.is_not_partially_done", CMD2_ON_DATA(is_not_partially_done));
|
||||
CMD2_DL ("d.is_meta", CMD2_ON_INFO(is_meta_download));
|
||||
CMD2_DL ("d.is_meta", [](auto* download, auto) { return download->info()->is_meta_download(); });
|
||||
|
||||
CMD2_DL_V ("d.resume", std::bind(&core::DownloadList::resume_default, control->core()->download_list(), std::placeholders::_1));
|
||||
CMD2_DL_V ("d.pause", std::bind(&core::DownloadList::pause_default, control->core()->download_list(), std::placeholders::_1));
|
||||
@@ -898,8 +912,26 @@ initialize_command_download() {
|
||||
rpc::rpc.mark_safe("d.local_id_html");
|
||||
rpc::rpc.mark_safe("d.bitfield");
|
||||
rpc::rpc.mark_safe("d.base_path");
|
||||
rpc::rpc.mark_safe("d.base_path.hex");
|
||||
rpc::rpc.mark_safe("d.base_path.base64");
|
||||
rpc::rpc.mark_safe("d.base_path.base64_as_binary");
|
||||
rpc::rpc.mark_safe("d.base_path.as_binary");
|
||||
rpc::rpc.mark_safe("d.base_path.or_base64");
|
||||
rpc::rpc.mark_safe("d.base_path.or_as_binary");
|
||||
rpc::rpc.mark_safe("d.base_filename");
|
||||
rpc::rpc.mark_safe("d.base_filename.hex");
|
||||
rpc::rpc.mark_safe("d.base_filename.base64");
|
||||
rpc::rpc.mark_safe("d.base_filename.base64_as_binary");
|
||||
rpc::rpc.mark_safe("d.base_filename.as_binary");
|
||||
rpc::rpc.mark_safe("d.base_filename.or_base64");
|
||||
rpc::rpc.mark_safe("d.base_filename.or_as_binary");
|
||||
rpc::rpc.mark_safe("d.name");
|
||||
rpc::rpc.mark_safe("d.name.hex");
|
||||
rpc::rpc.mark_safe("d.name.base64");
|
||||
rpc::rpc.mark_safe("d.name.base64_as_binary");
|
||||
rpc::rpc.mark_safe("d.name.as_binary");
|
||||
rpc::rpc.mark_safe("d.name.or_base64");
|
||||
rpc::rpc.mark_safe("d.name.or_as_binary");
|
||||
rpc::rpc.mark_safe("d.directory");
|
||||
rpc::rpc.mark_safe("d.directory_base");
|
||||
rpc::rpc.mark_safe("d.creation_date");
|
||||
|
||||
+25
-4
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <functional>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/hash_string.h>
|
||||
#include <torrent/utils/log.h>
|
||||
@@ -19,6 +21,7 @@
|
||||
#include "rpc/command_scheduler.h"
|
||||
#include "rpc/parse.h"
|
||||
#include "rpc/parse_commands.h"
|
||||
#include "utils/watch_ready_queue.h"
|
||||
|
||||
torrent::Object
|
||||
apply_on_ratio(const torrent::Object& rawArgs) {
|
||||
@@ -291,22 +294,39 @@ call_watch_command(const std::string& command, const std::string& path) {
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
directory_watch_added(const torrent::Object::list_type& args) {
|
||||
directory_watch(const torrent::Object::list_type& args, int flags) {
|
||||
if (args.size() != 2)
|
||||
throw torrent::input_error("Too few arguments.");
|
||||
|
||||
auto& path = args.front().as_string();
|
||||
auto& command = args.back().as_string();
|
||||
std::string expanded_path = expand_path(path);
|
||||
|
||||
if (!control->directory_events()->open())
|
||||
throw torrent::input_error("Could not open inotify:" + std::string(std::strerror(errno)));
|
||||
|
||||
control->directory_events()->notify_on(path.c_str(),
|
||||
torrent::directory_events::flag_on_added | torrent::directory_events::flag_on_updated,
|
||||
std::bind(&call_watch_command, command, std::placeholders::_1));
|
||||
torrent::watch_descriptor::slot_string slot =
|
||||
flags == torrent::directory_events::flag_on_ready ?
|
||||
torrent::watch_descriptor::slot_string([command](const auto& arg) { control->watch_ready_queue()->push(command, arg); }) :
|
||||
torrent::watch_descriptor::slot_string(std::bind(&call_watch_command, command, std::placeholders::_1));
|
||||
|
||||
control->directory_events()->notify_on(expanded_path.c_str(), flags, slot);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
directory_watch_added(const torrent::Object::list_type& args) {
|
||||
return directory_watch(args,
|
||||
torrent::directory_events::flag_on_added |
|
||||
torrent::directory_events::flag_on_updated);
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
directory_watch_ready(const torrent::Object::list_type& args) {
|
||||
return directory_watch(args,
|
||||
torrent::directory_events::flag_on_ready);
|
||||
}
|
||||
|
||||
void
|
||||
initialize_command_events() {
|
||||
CMD2_ANY_STRING ("on_ratio", std::bind(&apply_on_ratio, std::placeholders::_2));
|
||||
@@ -344,6 +364,7 @@ initialize_command_events() {
|
||||
CMD2_ANY_LIST ("d.multicall.filtered", std::bind(&d_multicall_filtered, std::placeholders::_2));
|
||||
|
||||
CMD2_ANY_LIST ("directory.watch.added", std::bind(&directory_watch_added, std::placeholders::_2));
|
||||
CMD2_ANY_LIST ("directory.watch.ready", std::bind(&directory_watch_ready, std::placeholders::_2));
|
||||
|
||||
rpc::rpc.mark_safe("start_tied");
|
||||
rpc::rpc.mark_safe("stop_untied");
|
||||
|
||||
+50
-23
@@ -24,24 +24,34 @@ apply_f_path(torrent::File* file) {
|
||||
if (file->path()->empty())
|
||||
return std::string();
|
||||
|
||||
torrent::Object resultRaw(*file->path()->begin());
|
||||
torrent::Object::string_type& result = resultRaw.as_string();
|
||||
torrent::Object result_raw(file->path()->begin()->str());
|
||||
auto& result = result_raw.as_string();
|
||||
|
||||
for (torrent::Path::const_iterator itr = ++file->path()->begin(), last = file->path()->end(); itr != last; itr++)
|
||||
result += '/' + *itr;
|
||||
result += '/' + itr->str();
|
||||
|
||||
return resultRaw;
|
||||
return result_raw;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_f_path_components(torrent::File* file) {
|
||||
torrent::Object resultRaw = torrent::Object::create_list();
|
||||
torrent::Object::list_type& result = resultRaw.as_list();
|
||||
apply_f_path_components(torrent::File* file, int output_type) {
|
||||
auto result_raw = torrent::Object::create_list();
|
||||
auto& result = result_raw.as_list();
|
||||
|
||||
for (const auto& itr : *file->path())
|
||||
result.push_back(itr);
|
||||
for (const auto& itr : *file->path()) {
|
||||
switch (output_type) {
|
||||
case 0: result.push_back(itr.str()); break;
|
||||
case 1: result.push_back(itr.object_hex()); break;
|
||||
case 2: result.push_back(itr.object_base64()); break;
|
||||
case 3: result.push_back(itr.object_base64_as_binary()); break;
|
||||
case 4: result.push_back(itr.object_as_binary()); break;
|
||||
case 5: result.push_back(itr.object_utf8_or_base64()); break;
|
||||
case 6: result.push_back(itr.object_utf8_or_as_binary()); break;
|
||||
default: throw torrent::input_error("apply_f_path_components(): invalid output type");
|
||||
};
|
||||
}
|
||||
|
||||
return resultRaw;
|
||||
return result_raw;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
@@ -57,7 +67,7 @@ apply_fi_filename_last(torrent::FileListIterator* itr) {
|
||||
if (itr->depth() >= itr->file()->path()->size())
|
||||
return "ERROR";
|
||||
|
||||
return itr->file()->path()->at(itr->depth());
|
||||
return itr->file()->path()->at(itr->depth()).str();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -80,21 +90,32 @@ initialize_command_file() {
|
||||
CMD2_FILE_V("f.prioritize_last.enable", std::bind(&torrent::File::set_flags, std::placeholders::_1, torrent::File::flag_prioritize_last));
|
||||
CMD2_FILE_V("f.prioritize_last.disable", std::bind(&torrent::File::unset_flags, std::placeholders::_1, torrent::File::flag_prioritize_last));
|
||||
|
||||
CMD2_FILE("f.size_bytes", std::bind(&torrent::File::size_bytes, std::placeholders::_1));
|
||||
CMD2_FILE("f.size_chunks", std::bind(&torrent::File::size_chunks, std::placeholders::_1));
|
||||
CMD2_FILE("f.completed_chunks", std::bind(&torrent::File::completed_chunks, std::placeholders::_1));
|
||||
CMD2_FILE("f.size_bytes", [](auto* file, auto) { return file->size_bytes(); });
|
||||
CMD2_FILE("f.size_chunks", [](auto* file, auto) { return file->size_chunks(); });
|
||||
CMD2_FILE("f.completed_chunks", [](auto* file, auto) { return file->completed_chunks(); });
|
||||
|
||||
CMD2_FILE("f.offset", std::bind(&torrent::File::offset, std::placeholders::_1));
|
||||
CMD2_FILE("f.range_first", std::bind(&torrent::File::range_first, std::placeholders::_1));
|
||||
CMD2_FILE("f.range_second", std::bind(&torrent::File::range_second, std::placeholders::_1));
|
||||
CMD2_FILE("f.offset", [](auto* file, auto) { return file->offset(); });
|
||||
CMD2_FILE("f.range_first", [](auto* file, auto) { return file->range_first(); });
|
||||
CMD2_FILE("f.range_second", [](auto* file, auto) { return file->range_second(); });
|
||||
|
||||
CMD2_FILE("f.priority", std::bind(&torrent::File::priority, std::placeholders::_1));
|
||||
CMD2_FILE_VALUE_V("f.priority.set", std::bind(&apply_f_set_priority, std::placeholders::_1, std::placeholders::_2));
|
||||
CMD2_FILE("f.priority", [](auto* file, auto) { return file->priority(); });
|
||||
CMD2_FILE_VALUE_V("f.priority.set", [](auto* file, auto v) { apply_f_set_priority(file, v); });
|
||||
|
||||
CMD2_FILE("f.path", std::bind(&apply_f_path, std::placeholders::_1));
|
||||
CMD2_FILE("f.path_components", std::bind(&apply_f_path_components, std::placeholders::_1));
|
||||
CMD2_FILE("f.path_depth", std::bind(&apply_f_path_depth, std::placeholders::_1));
|
||||
CMD2_FILE("f.frozen_path", std::bind(&torrent::File::frozen_path, std::placeholders::_1));
|
||||
CMD2_FILE("f.path", [](auto* file, auto) { return apply_f_path(file); });
|
||||
CMD2_FILE("f.path_components", [](auto* file, auto) { return apply_f_path_components(file, 0); });
|
||||
CMD2_FILE("f.path_components.hex", [](auto* file, auto) { return apply_f_path_components(file, 1); });
|
||||
CMD2_FILE("f.path_components.base64", [](auto* file, auto) { return apply_f_path_components(file, 2); });
|
||||
CMD2_FILE("f.path_components.base64_as_binary", [](auto* file, auto) { return apply_f_path_components(file, 3); });
|
||||
CMD2_FILE("f.path_components.as_binary", [](auto* file, auto) { return apply_f_path_components(file, 4); });
|
||||
CMD2_FILE("f.path_components.or_base64", [](auto* file, auto) { return apply_f_path_components(file, 5); });
|
||||
CMD2_FILE("f.path_components.or_as_binary", [](auto* file, auto) { return apply_f_path_components(file, 6); });
|
||||
CMD2_FILE("f.path_depth", [](auto* file, auto) { return apply_f_path_depth(file); });
|
||||
CMD2_FILE("f.frozen_path", [](auto* file, auto) { return file->frozen_path().str(); });
|
||||
CMD2_FILE("f.frozen_path.hex", [](auto* file, auto) { return file->frozen_path().object_hex(); });
|
||||
CMD2_FILE("f.frozen_path.base64", [](auto* file, auto) { return file->frozen_path().object_base64(); });
|
||||
CMD2_FILE("f.frozen_path.as_binary", [](auto* file, auto) { return file->frozen_path().object_as_binary(); });
|
||||
CMD2_FILE("f.frozen_path.or_base64", [](auto* file, auto) { return file->frozen_path().object_utf8_or_base64(); });
|
||||
CMD2_FILE("f.frozen_path.or_as_binary", [](auto* file, auto) { return file->frozen_path().object_utf8_or_as_binary(); });
|
||||
|
||||
CMD2_FILE("f.match_depth_prev", std::bind(&torrent::File::match_depth_prev, std::placeholders::_1));
|
||||
CMD2_FILE("f.match_depth_next", std::bind(&torrent::File::match_depth_next, std::placeholders::_1));
|
||||
@@ -108,6 +129,12 @@ initialize_command_file() {
|
||||
rpc::rpc.mark_safe("f.path_components");
|
||||
rpc::rpc.mark_safe("f.path_depth");
|
||||
rpc::rpc.mark_safe("f.frozen_path");
|
||||
rpc::rpc.mark_safe("f.frozen_path.hex");
|
||||
rpc::rpc.mark_safe("f.frozen_path.base64");
|
||||
rpc::rpc.mark_safe("f.frozen_path.base64_as_binary");
|
||||
rpc::rpc.mark_safe("f.frozen_path.as_binary");
|
||||
rpc::rpc.mark_safe("f.frozen_path.or_base64");
|
||||
rpc::rpc.mark_safe("f.frozen_path.or_as_binary");
|
||||
rpc::rpc.mark_safe("f.offset");
|
||||
rpc::rpc.mark_safe("f.size_bytes");
|
||||
rpc::rpc.mark_safe("f.size_chunks");
|
||||
|
||||
@@ -292,7 +292,7 @@ initialize_command_network() {
|
||||
CMD2_ANY ("network.total_handshakes", [](auto, auto) { return torrent::runtime::total_handshakes(); });
|
||||
CMD2_ANY ("network.open_sockets", [](auto, auto) { return torrent::runtime::socket_manager()->size(); });
|
||||
CMD2_ANY ("network.max_open_sockets", [](auto, auto) { return torrent::runtime::socket_manager()->max_size(); });
|
||||
CMD2_ANY_VALUE_V ("network.max_open_sockets.set", [](auto, auto& value) { return torrent::runtime::socket_manager()->set_max_size(value); });
|
||||
CMD2_ANY_VALUE_V ("network.max_open_sockets.set", [](auto, auto& value) { return torrent::runtime::socket_manager()->set_max_size_and_adjust(value); });
|
||||
|
||||
CMD2_ANY_STRING ("network.scgi.open_port", std::bind(&apply_scgi, std::placeholders::_2, 1));
|
||||
CMD2_ANY_STRING ("network.scgi.open_local", std::bind(&apply_scgi, std::placeholders::_2, 2));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <torrent/net/resolver.h>
|
||||
#include <torrent/runtime/network_config.h>
|
||||
#include <torrent/runtime/network_manager.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/tracker/dht_controller.h>
|
||||
#include <torrent/tracker/tracker.h>
|
||||
#include <torrent/utils/log.h>
|
||||
@@ -48,8 +49,10 @@ apply_dht_add_node(const std::string& arg) {
|
||||
|
||||
// TODO: Move this lookup to DhtController.
|
||||
|
||||
auto callback_id = torrent::system::make_callback_id();
|
||||
|
||||
// Currently discarding SOCK_STREAM.
|
||||
torrent::this_thread::resolver()->resolve_specific(nullptr, host_str, PF_INET, [host_str, port](torrent::c_sa_shared_ptr sa, int err) {
|
||||
torrent::this_thread::resolver()->resolve_specific(callback_id, host_str, PF_INET, [host_str, port](torrent::c_sa_shared_ptr sa, int err) {
|
||||
if (sa == nullptr) {
|
||||
lt_log_print(torrent::LOG_DHT_ERROR, "dht.add_node : could not resolve host : %s (%s)", gai_strerror(err), host_str.c_str());
|
||||
return;
|
||||
@@ -78,10 +81,10 @@ apply_enable_trackers(int64_t arg) {
|
||||
|
||||
void
|
||||
initialize_command_tracker() {
|
||||
CMD2_TRACKER ("t.is_busy", std::bind(&torrent::tracker::Tracker::is_busy, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_busy", std::bind(&torrent::tracker::Tracker::is_requesting, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_enabled", std::bind(&torrent::tracker::Tracker::is_enabled, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_extra_tracker", std::bind(&torrent::tracker::Tracker::is_extra_tracker, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_open", std::bind(&torrent::tracker::Tracker::is_busy, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_open", std::bind(&torrent::tracker::Tracker::is_requesting, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_scrapable", std::bind(&torrent::tracker::Tracker::is_scrapable, std::placeholders::_1));
|
||||
CMD2_TRACKER ("t.is_usable", std::bind(&torrent::tracker::Tracker::is_usable, std::placeholders::_1));
|
||||
|
||||
|
||||
+5
-2
@@ -27,6 +27,7 @@
|
||||
#include "rpc/object_storage.h"
|
||||
#include "session/session_manager.h"
|
||||
#include "ui/root.h"
|
||||
#include "utils/watch_ready_queue.h"
|
||||
|
||||
Control::Control()
|
||||
: m_ui(new ui::Root()),
|
||||
@@ -36,7 +37,8 @@ Control::Control()
|
||||
m_commandScheduler(new rpc::CommandScheduler()),
|
||||
m_objectStorage(new rpc::object_storage()),
|
||||
m_lua_engine(new rpc::LuaEngine()),
|
||||
m_directory_events(new torrent::directory_events()) {
|
||||
m_directory_events(new torrent::directory_events()),
|
||||
m_watch_ready_queue(new utils::WatchReadyQueue()) {
|
||||
|
||||
m_core = std::make_unique<core::Manager>();
|
||||
m_view_manager = std::make_unique<core::ViewManager>();
|
||||
@@ -126,6 +128,8 @@ Control::is_shutdown_completed() {
|
||||
|
||||
void
|
||||
Control::handle_shutdown() {
|
||||
m_watch_ready_queue->shutdown();
|
||||
|
||||
rpc::commands.call_catch("event.system.shutdown", rpc::make_target(), "shutdown", "System shutdown event action failed: ");
|
||||
|
||||
if (scgi_thread::thread()->is_active())
|
||||
@@ -147,4 +151,3 @@ Control::handle_shutdown() {
|
||||
m_shutdownQuick = true;
|
||||
m_shutdownReceived = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ namespace torrent {
|
||||
class directory_events;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
class WatchReadyQueue;
|
||||
}
|
||||
|
||||
class Control {
|
||||
public:
|
||||
Control();
|
||||
@@ -70,6 +74,7 @@ public:
|
||||
rpc::LuaEngine* lua_engine() { return m_lua_engine.get(); }
|
||||
|
||||
torrent::directory_events* directory_events() { return m_directory_events.get(); }
|
||||
utils::WatchReadyQueue* watch_ready_queue() { return m_watch_ready_queue.get(); }
|
||||
|
||||
uint64_t tick() const { return m_tick; }
|
||||
void inc_tick() { m_tick++; }
|
||||
@@ -94,6 +99,7 @@ private:
|
||||
std::unique_ptr<rpc::object_storage> m_objectStorage;
|
||||
std::unique_ptr<rpc::LuaEngine> m_lua_engine;
|
||||
std::unique_ptr<torrent::directory_events> m_directory_events;
|
||||
std::unique_ptr<utils::WatchReadyQueue> m_watch_ready_queue;
|
||||
|
||||
uint64_t m_tick{};
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ Download::set_root_directory(const std::string& path) {
|
||||
|
||||
(file_list->is_multi_file() ?
|
||||
!file_list->is_root_dir_created() :
|
||||
!file_stat.update(file_list->front()->frozen_path()))) {
|
||||
!file_stat.update(file_list->front()->frozen_path().str()))) {
|
||||
|
||||
set_message("Cannot change the directory of an open download after the files have been moved.");
|
||||
rpc::call_command("d.state.set", (int64_t)0, rpc::make_target(this));
|
||||
|
||||
@@ -109,8 +109,8 @@ DownloadFactory::receive_load() {
|
||||
|
||||
HttpQueue::iterator itr = m_manager->http_queue()->insert(m_uri, m_stream);
|
||||
|
||||
itr->add_done_slot([this]() { receive_loaded(); });
|
||||
itr->add_failed_slot([this](const std::string& error) { receive_failed(error); });
|
||||
itr->add_done_slot(torrent::this_thread::thread(), [this]() { receive_loaded(); });
|
||||
itr->add_failed_slot(torrent::this_thread::thread(), [this](const std::string& error) { receive_failed(error); });
|
||||
|
||||
m_variables["tied_to_file"] = (int64_t)false;
|
||||
|
||||
|
||||
@@ -683,8 +683,10 @@ DownloadList::process_meta_download(Download* download) {
|
||||
rpc::call_command("d.stop", torrent::Object(), rpc::make_target(download));
|
||||
rpc::call_command("d.close", torrent::Object(), rpc::make_target(download));
|
||||
|
||||
std::string metafile = (*download->file_list()->begin())->frozen_path();
|
||||
std::string metafile = (*download->file_list()->begin())->frozen_path().str();
|
||||
|
||||
std::fstream file(metafile.c_str(), std::ios::in | std::ios::binary);
|
||||
|
||||
if (!file.is_open()) {
|
||||
lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not read download metadata.");
|
||||
return;
|
||||
@@ -692,11 +694,13 @@ DownloadList::process_meta_download(Download* download) {
|
||||
|
||||
torrent::Object* bencode = new torrent::Object(torrent::Object::create_map());
|
||||
file >> bencode->insert_key("info", torrent::Object());
|
||||
|
||||
if (file.fail()) {
|
||||
delete bencode;
|
||||
lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download, the input is not a valid torrent.");
|
||||
return;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
// Steal the keys we still need. The old download has no use for them.
|
||||
@@ -707,6 +711,7 @@ DownloadList::process_meta_download(Download* download) {
|
||||
bencode->insert_key("announce-list", torrent::Object()).swap(download->bencode()->get_key("announce-list"));
|
||||
|
||||
erase_ptr(download);
|
||||
|
||||
control->core()->try_create_download_from_meta_download(bencode, metafile);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ HttpQueue::insert(const std::string& url, std::shared_ptr<std::ostream> stream)
|
||||
for (auto& slot : m_signal_insert)
|
||||
slot(*itr);
|
||||
|
||||
itr->add_done_slot([this, itr]() { erase(itr); });
|
||||
itr->add_failed_slot([this, itr](auto) { erase(itr); });
|
||||
itr->add_done_slot(torrent::this_thread::thread(), [this, itr]() { erase(itr); });
|
||||
itr->add_failed_slot(torrent::this_thread::thread(), [this, itr](auto) { erase(itr); });
|
||||
|
||||
// TODO: Downloading http torrents doesn't seem to work.
|
||||
// TODO: Quitting no longer works.
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if defined(HAVE_NCURSESW_CURSES_H)
|
||||
#if defined(HAVE_NO_NCURSES)
|
||||
#include "curses_stub.h"
|
||||
#elif defined(HAVE_NCURSESW_CURSES_H)
|
||||
#include <ncursesw/curses.h>
|
||||
#elif defined(HAVE_NCURSESW_H)
|
||||
#include <ncursesw.h>
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
#include <array>
|
||||
#include <map>
|
||||
|
||||
#if defined(HAVE_NO_NCURSES)
|
||||
#include "curses_stub.h"
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif
|
||||
|
||||
namespace display {
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Dummy ncurses stub: provides the stdscr symbol expected by the codebase.
|
||||
|
||||
#include "curses_stub.h"
|
||||
|
||||
// Define stdscr as a null pointer; all ncurses calls are no-ops in this stub.
|
||||
WINDOW* stdscr = nullptr;
|
||||
@@ -0,0 +1,108 @@
|
||||
// Dummy ncurses stub header for building rtorrent without ncurses.
|
||||
// Provides types, macros, and no-op function stubs so the codebase
|
||||
// compiles without a real curses library. All display functions become
|
||||
// no-ops; use with system.daemon.set = true.
|
||||
|
||||
#ifndef RTORRENT_DISPLAY_CURSES_STUB_H
|
||||
#define RTORRENT_DISPLAY_CURSES_STUB_H
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
|
||||
// Opaque window type
|
||||
typedef void* WINDOW;
|
||||
|
||||
// Character type used by curses
|
||||
typedef unsigned int chtype;
|
||||
typedef unsigned int attr_t;
|
||||
|
||||
// The standard screen
|
||||
extern WINDOW* stdscr;
|
||||
|
||||
// Boolean constants and return codes
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef ERR
|
||||
#define ERR (-1)
|
||||
#endif
|
||||
|
||||
// Attribute constants
|
||||
#define A_NORMAL 0
|
||||
#define A_STANDOUT (1U << 8)
|
||||
#define A_UNDERLINE (1U << 9)
|
||||
#define A_REVERSE (1U << 10)
|
||||
#define A_BLINK (1U << 11)
|
||||
#define A_DIM (1U << 12)
|
||||
#define A_BOLD (1U << 13)
|
||||
|
||||
// Color support
|
||||
#define COLORS 0
|
||||
#define COLOR_BLACK 0
|
||||
#define COLOR_RED 1
|
||||
#define COLOR_GREEN 2
|
||||
#define COLOR_YELLOW 3
|
||||
#define COLOR_BLUE 4
|
||||
#define COLOR_MAGENTA 5
|
||||
#define COLOR_CYAN 6
|
||||
#define COLOR_WHITE 7
|
||||
|
||||
#define COLOR_PAIR(n) 0
|
||||
|
||||
// Key constants
|
||||
#define KEY_DOWN 0x102
|
||||
#define KEY_UP 0x103
|
||||
#define KEY_LEFT 0x104
|
||||
#define KEY_RIGHT 0x105
|
||||
#define KEY_HOME 0x106
|
||||
#define KEY_BACKSPACE 0x107
|
||||
#define KEY_DC 0x14a
|
||||
#define KEY_ENTER 0x157
|
||||
#define KEY_NPAGE 0x152
|
||||
#define KEY_PPAGE 0x153
|
||||
#define KEY_END 0x168
|
||||
#define KEY_MOUSE 0x199
|
||||
#define KEY_RESIZE 0x19a
|
||||
|
||||
// Stubbed functions
|
||||
inline WINDOW* initscr() { return nullptr; }
|
||||
inline int endwin() { return 0; }
|
||||
inline WINDOW* newwin(int, int, int, int) { return nullptr; }
|
||||
inline int delwin(WINDOW*) { return 0; }
|
||||
inline int wresize(WINDOW*, int, int) { return 0; }
|
||||
inline int mvwin(WINDOW*, int, int) { return 0; }
|
||||
inline int wnoutrefresh(WINDOW*) { return 0; }
|
||||
inline int redrawwin(WINDOW*) { return 0; }
|
||||
inline int werase(WINDOW*) { return 0; }
|
||||
inline int wmove(WINDOW*, int, int) { return 0; }
|
||||
inline int vw_printw(WINDOW*, char*, va_list) { return 0; }
|
||||
inline int waddch(WINDOW*, const chtype) { return 0; }
|
||||
inline int mvwaddch(WINDOW*, int, int, const chtype) { return 0; }
|
||||
inline int mvwchgat(WINDOW*, int, int, int, attr_t, short, const void*) { return 0; }
|
||||
inline int wattrset(WINDOW*, int) { return 0; }
|
||||
inline int wattr_get(WINDOW*, attr_t*, short*, void*) { return 0; }
|
||||
inline int wattr_set(WINDOW*, attr_t, short, void*) { return 0; }
|
||||
inline int doupdate() { return 0; }
|
||||
inline int start_color() { return 0; }
|
||||
inline int use_default_colors() { return 0; }
|
||||
inline int raw() { return 0; }
|
||||
inline int noraw() { return 0; }
|
||||
inline int noecho() { return 0; }
|
||||
inline int nodelay(WINDOW*, bool) { return 0; }
|
||||
inline int keypad(WINDOW*, bool) { return 0; }
|
||||
inline int curs_set(int) { return 0; }
|
||||
inline int init_pair(short, short, short) { return 0; }
|
||||
inline int pair_content(short, short*, short*) { return 0; }
|
||||
inline int resizeterm(int, int) { return 0; }
|
||||
inline int getch() { return ERR; }
|
||||
inline int set_escdelay(int) { return 0; }
|
||||
|
||||
// getyx / getmaxyx are macros in real ncurses; stub them as no-ops
|
||||
#define getyx(w, y, x) do { (y) = 0; (x) = 0; } while (0)
|
||||
#define getmaxyx(w, y, x) do { (y) = 24; (x) = 80; } while (0)
|
||||
|
||||
#endif // RTORRENT_DISPLAY_CURSES_STUB_H
|
||||
@@ -155,7 +155,7 @@ print_download_status(char* first, char* last, core::Download* d) {
|
||||
|
||||
} else if (d->tracker_controller().has_active_trackers_not_scrape()) {
|
||||
auto tracker = d->tracker_controller().find_if([](const auto& t) {
|
||||
return t.is_busy_not_scrape();
|
||||
return t.is_requesting_not_scrape();
|
||||
});
|
||||
|
||||
if (tracker.is_valid()) {
|
||||
|
||||
@@ -135,8 +135,11 @@ WindowFileList::redraw() {
|
||||
m_canvas->print(0, pos, "%*c%-*s", 16, ' ', filenameWidth, "EMPTY");
|
||||
|
||||
} else if (itr.is_entering()) {
|
||||
m_canvas->print(0, pos, "%*c %ls", 16 + itr.depth(), '\\',
|
||||
itr.depth() < itr.file()->path()->size() ? wstring_width(itr.file()->path()->at(itr.depth()), filenameWidth - itr.depth() - 1).c_str() : L"UNKNOWN");
|
||||
if (itr.depth() < itr.file()->path()->size())
|
||||
m_canvas->print(0, pos, "%*c %ls", 16 + itr.depth(), '\\',
|
||||
wstring_width(itr.file()->path()->at(itr.depth()).str(), filenameWidth - itr.depth() - 1).c_str());
|
||||
else
|
||||
m_canvas->print(0, pos, "%*c %ls", 16 + itr.depth(), '\\', L"UNKNOWN");
|
||||
|
||||
} else if (itr.is_leaving()) {
|
||||
m_canvas->print(0, pos, "%*c %-*s", 16 + (itr.depth() - 1), '/', filenameWidth - (itr.depth() - 1), "");
|
||||
@@ -166,8 +169,12 @@ WindowFileList::redraw() {
|
||||
else
|
||||
m_canvas->print(8, pos, "%5.1f T", (double)val / (int64_t(1) << 40));
|
||||
|
||||
m_canvas->print(15, pos, "%*c %ls", 1 + itr.depth(), '|',
|
||||
itr.depth() < itr.file()->path()->size() ? wstring_width(itr.file()->path()->at(itr.depth()), filenameWidth - itr.depth() - 1).c_str() : L"UNKNOWN");
|
||||
if (itr.depth() < itr.file()->path()->size())
|
||||
m_canvas->print(15, pos, "%*c %ls", 1 + itr.depth(), '|',
|
||||
wstring_width(itr.file()->path()->at(itr.depth()).str(), filenameWidth - itr.depth() - 1).c_str());
|
||||
else
|
||||
m_canvas->print(15, pos, "%*c %ls", 1 + itr.depth(), '|', L"UNKNOWN");
|
||||
|
||||
|
||||
} else {
|
||||
m_canvas->print(0, pos, "BORK BORK");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <ctime>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/system/thread.h>
|
||||
|
||||
#include "canvas.h"
|
||||
@@ -14,13 +15,14 @@ WindowLog::WindowLog(torrent::log_buffer* l) :
|
||||
Window(new Canvas, 0, 0, 0, extent_full, extent_static),
|
||||
m_log(l) {
|
||||
|
||||
m_task_update.slot() = std::bind(&WindowLog::receive_update, this);
|
||||
m_task_update.slot() = [this]() { receive_update(); };
|
||||
|
||||
unsigned int signal_index = torrent::main_thread::thread()->signal_bitfield()->add_signal(std::bind(&WindowLog::receive_update, this));
|
||||
m_log->lock_and_set_update_slot([this]() {
|
||||
if (m_log_updating.exchange(true) == true)
|
||||
return;
|
||||
|
||||
m_log->lock_and_set_update_slot([signal_index]() {
|
||||
torrent::main_thread::thread()->send_event_signal(signal_index, false);
|
||||
});
|
||||
torrent::main_thread::callback([this]() { receive_update(); });
|
||||
});
|
||||
}
|
||||
|
||||
WindowLog::~WindowLog() {
|
||||
@@ -52,11 +54,13 @@ WindowLog::redraw() {
|
||||
// gets updated.
|
||||
void
|
||||
WindowLog::receive_update() {
|
||||
m_log_updating = false;
|
||||
|
||||
if (!is_active())
|
||||
return;
|
||||
|
||||
iterator itr = find_older();
|
||||
extent_type height = std::min(std::distance(itr, (iterator)m_log->end()), (std::iterator_traits<iterator>::difference_type)10);
|
||||
auto itr = find_older();
|
||||
auto height = std::min(std::distance(itr, (iterator)m_log->end()), (std::iterator_traits<iterator>::difference_type)10);
|
||||
|
||||
if (height != m_max_height) {
|
||||
m_min_height = height != 0 ? 1 : 0;
|
||||
|
||||
@@ -24,6 +24,8 @@ private:
|
||||
|
||||
torrent::log_buffer* m_log;
|
||||
torrent::utils::SchedulerEntry m_task_update;
|
||||
|
||||
align_cacheline std::atomic<bool> m_log_updating{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ WindowTrackerList::redraw() {
|
||||
if (pos < m_canvas->height()) {
|
||||
const char* state;
|
||||
|
||||
if (tracker.is_busy_not_scrape())
|
||||
if (tracker.is_requesting_not_scrape())
|
||||
state = "req ";
|
||||
else if (tracker.is_busy())
|
||||
else if (tracker.is_requesting())
|
||||
state = "scr ";
|
||||
else
|
||||
state = " ";
|
||||
@@ -79,7 +79,7 @@ WindowTrackerList::redraw() {
|
||||
m_canvas->set_attr(4, pos - 1, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0));
|
||||
}
|
||||
|
||||
if (tracker.is_busy()) {
|
||||
if (tracker.is_requesting()) {
|
||||
m_canvas->set_attr(0, pos - 2, 4, A_REVERSE, COLOR_PAIR(0));
|
||||
m_canvas->set_attr(0, pos - 1, 4, A_REVERSE, COLOR_PAIR(0));
|
||||
}
|
||||
|
||||
+7
-9
@@ -25,13 +25,11 @@ namespace scgi_thread {
|
||||
torrent::system::Thread* thread();
|
||||
std::thread::id thread_id();
|
||||
|
||||
void callback(void* target, std::function<void ()>&& fn);
|
||||
void cancel_callback(void* target);
|
||||
void cancel_callback_and_wait(void* target);
|
||||
void callback_interrupt(torrent::system::callback_id& id, std::function<void ()>&& fn);
|
||||
|
||||
rpc::SCgi* scgi();
|
||||
void set_scgi(rpc::SCgi* scgi);
|
||||
void set_rpc_log(const std::string& filename);
|
||||
rpc::SCgi* scgi();
|
||||
void set_scgi(rpc::SCgi* scgi);
|
||||
void set_rpc_log(const std::string& filename);
|
||||
|
||||
} // namespace torrent::scgi_thread
|
||||
|
||||
@@ -41,9 +39,9 @@ namespace session_thread {
|
||||
torrent::system::Thread* thread();
|
||||
std::thread::id thread_id();
|
||||
|
||||
void callback(void* target, std::function<void ()>&& fn);
|
||||
void cancel_callback(void* target);
|
||||
void cancel_callback_and_wait(void* target);
|
||||
void callback(std::function<void ()>&& fn);
|
||||
void callback(torrent::system::callback_id& id, std::function<void ()>&& fn);
|
||||
void cancel_callback(torrent::system::callback_id& id);
|
||||
|
||||
session::SessionManager* manager();
|
||||
std::string session_path();
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
namespace input {
|
||||
|
||||
void
|
||||
InputEvent::insert(torrent::net::Poll* p) {
|
||||
InputEvent::insert(torrent::system::Poll* p) {
|
||||
p->open(this);
|
||||
p->insert_read(this);
|
||||
}
|
||||
|
||||
void
|
||||
InputEvent::remove(torrent::net::Poll* p) {
|
||||
InputEvent::remove(torrent::system::Poll* p) {
|
||||
p->remove_read(this);
|
||||
p->close(this);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <functional>
|
||||
|
||||
#include <torrent/event.h>
|
||||
#include <torrent/net/poll.h>
|
||||
#include <torrent/system/poll.h>
|
||||
|
||||
namespace input {
|
||||
|
||||
@@ -16,8 +16,8 @@ public:
|
||||
|
||||
const char* type_name() const override { return "input"; }
|
||||
|
||||
void insert(torrent::net::Poll* p);
|
||||
void remove(torrent::net::Poll* p);
|
||||
void insert(torrent::system::Poll* p);
|
||||
void remove(torrent::system::Poll* p);
|
||||
|
||||
void event_read() override;
|
||||
void event_write() override;
|
||||
|
||||
+1
-10
@@ -112,6 +112,7 @@ main(int argc, char** argv) {
|
||||
// TODO: Create a fake thread object for initializing other processes and enabling logging.
|
||||
torrent::initialize_main_thread();
|
||||
|
||||
// All signal handlers must restore errno if they return.
|
||||
SignalHandler::set_ignore(SIGPIPE);
|
||||
SignalHandler::set_handler(SIGSEGV, std::bind(&do_panic, SIGSEGV));
|
||||
SignalHandler::set_handler(SIGILL, std::bind(&do_panic, SIGILL));
|
||||
@@ -140,16 +141,6 @@ main(int argc, char** argv) {
|
||||
|
||||
SignalHandler::set_sigaction_handler(SIGBUS, &handle_sigbus);
|
||||
|
||||
// SIGUSR1 is used for interrupting polling, forcing the target
|
||||
// thread to process new non-socket events.
|
||||
//
|
||||
// LibTorrent uses sockets for this purpose on Solaris and other
|
||||
// platforms that do not properly pass signals to the target
|
||||
// threads. Use '--enable-interrupt-socket' when configuring
|
||||
// LibTorrent to enable this workaround.
|
||||
if (torrent::system::Thread::should_handle_sigusr1())
|
||||
SignalHandler::set_handler(SIGUSR1, []() {});
|
||||
|
||||
torrent::log_add_group_output(torrent::LOG_NOTICE, "important");
|
||||
torrent::log_add_group_output(torrent::LOG_DHT_ERROR, "important");
|
||||
|
||||
|
||||
+34
-5
@@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
#include <torrent/common.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/utils/string_manip.h>
|
||||
|
||||
#include "rpc/rpc_manager.h"
|
||||
#include "rpc/command.h"
|
||||
@@ -33,24 +34,29 @@ json_to_object(const json& value) {
|
||||
case json::value_t::number_unsigned:
|
||||
case json::value_t::number_integer:
|
||||
return torrent::Object(value.get<int64_t>());
|
||||
|
||||
case json::value_t::boolean:
|
||||
return value.get<bool>() ? torrent::Object(int64_t(1)) : torrent::Object(int64_t(0));
|
||||
|
||||
case json::value_t::string:
|
||||
return torrent::Object(value.get<std::string>());
|
||||
|
||||
case json::value_t::array: {
|
||||
auto array_raw = torrent::Object::create_list();
|
||||
auto& array = array_raw.as_list();
|
||||
for (const auto& entry : value) {
|
||||
|
||||
for (const auto& entry : value)
|
||||
array.push_back(json_to_object(entry));
|
||||
}
|
||||
|
||||
return array_raw;
|
||||
}
|
||||
case json::value_t::object: {
|
||||
auto map_raw = torrent::Object::create_map();
|
||||
auto& map = map_raw.as_map();
|
||||
for (const auto& entry : value.items()) {
|
||||
|
||||
for (const auto& entry : value.items())
|
||||
map[entry.key()] = json_to_object(entry.value());
|
||||
}
|
||||
|
||||
return map_raw;
|
||||
}
|
||||
case json::value_t::number_float:
|
||||
@@ -61,17 +67,38 @@ json_to_object(const json& value) {
|
||||
}
|
||||
}
|
||||
|
||||
// Note: Only throw rpc_errors here.
|
||||
|
||||
json
|
||||
object_to_json(const torrent::Object& object) noexcept {
|
||||
object_to_json(const torrent::Object& object) {
|
||||
switch (object.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
return object.as_value();
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
if (object.flags() & torrent::Object::flag_as_binary) {
|
||||
|
||||
// We should optimize our imported json library to support copying base64 strings directly.
|
||||
if (object.flags() & torrent::Object::flag_base64) {
|
||||
auto binary_data = torrent::utils::transform_from_base64_unsafe(object.as_string());
|
||||
|
||||
if (!binary_data.has_value())
|
||||
throw rpc_error(JSONRPC_INTERNAL_ERROR, "invalid base64 string in base64-as-binary object");
|
||||
|
||||
return json::binary(*binary_data);
|
||||
}
|
||||
|
||||
return json::binary({object.as_string().begin(), object.as_string().end()});
|
||||
}
|
||||
|
||||
return object.as_string();
|
||||
|
||||
case torrent::Object::TYPE_LIST: {
|
||||
json result = json::array();
|
||||
|
||||
for (const auto& obj : object.as_list())
|
||||
result.push_back(object_to_json(obj));
|
||||
|
||||
return result;
|
||||
}
|
||||
case torrent::Object::TYPE_MAP: {
|
||||
@@ -135,7 +162,9 @@ jsonrpc_call_command(const std::string& method, const json& params) {
|
||||
|
||||
try {
|
||||
const auto& result = rpc::commands.call_command(itr, params_object, target);
|
||||
|
||||
return object_to_json(result);
|
||||
|
||||
} catch (untrusted_error& e) {
|
||||
throw rpc_error(JSONRPC_METHOD_NOT_FOUND_ERROR, e.what());
|
||||
}
|
||||
|
||||
+1
-1
@@ -211,7 +211,7 @@ object_to_target(const torrent::Object& obj, int call_flags, rpc::target_type* t
|
||||
auto tracker = new torrent::tracker::Tracker(rpc.slot_find_tracker()(download, std::stoi(std::string(index))));
|
||||
|
||||
*deleter = [tracker]() { delete tracker; };
|
||||
*target = rpc::make_target(command_base::target_tracker, target);
|
||||
*target = rpc::make_target(command_base::target_tracker, tracker);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace rpc {
|
||||
|
||||
struct object_storage_node {
|
||||
torrent::Object object;
|
||||
char flags;
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<fixed_key_type<64>, object_storage_node, hash_fixed_key_type> object_storage_base_type;
|
||||
|
||||
+6
-6
@@ -8,8 +8,8 @@
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/net/fd.h>
|
||||
#include <torrent/net/poll.h>
|
||||
#include <torrent/net/socket_address.h>
|
||||
#include <torrent/system/poll.h>
|
||||
#include <torrent/runtime/socket_manager.h>
|
||||
|
||||
#include "control.h"
|
||||
@@ -48,12 +48,12 @@ SCgi::open_port(sockaddr* sa, unsigned int length, bool dont_route) {
|
||||
|
||||
open(reinterpret_cast<sockaddr*>(sa), length);
|
||||
|
||||
torrent::runtime::socket_manager()->register_event_or_throw(this, []() {});
|
||||
torrent::runtime::socket_manager()->register_event_or_throw(this, torrent::runtime::category_scgi, []() {});
|
||||
}
|
||||
|
||||
void
|
||||
SCgi::open_named(const std::string& filename) {
|
||||
if (filename.empty() || filename.size() > 4096)
|
||||
if (filename.empty() || filename.size() >= sizeof(sockaddr_un::sun_path))
|
||||
throw torrent::resource_error("Invalid filename length.");
|
||||
|
||||
auto buffer = std::make_unique<char[]>(sizeof(sockaddr_un) + filename.size() + 1);
|
||||
@@ -72,7 +72,7 @@ SCgi::open_named(const std::string& filename) {
|
||||
|
||||
open(reinterpret_cast<sockaddr*>(sa), offsetof(struct sockaddr_un, sun_path) + filename.size() + 1);
|
||||
|
||||
torrent::runtime::socket_manager()->register_event_or_throw(this, []() {});
|
||||
torrent::runtime::socket_manager()->register_event_or_throw(this, torrent::runtime::category_scgi, []() {});
|
||||
|
||||
m_path = filename;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ SCgi::open_fd(int fd) {
|
||||
|
||||
// fd is already bound and listening; no bind()/listen() needed.
|
||||
|
||||
torrent::runtime::socket_manager()->register_event_or_throw(this, []() {});
|
||||
torrent::runtime::socket_manager()->register_event_or_throw(this, torrent::runtime::category_scgi, []() {});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -183,7 +183,7 @@ SCgi::event_read() {
|
||||
task->cancel_open();
|
||||
};
|
||||
|
||||
bool result = torrent::runtime::socket_manager()->open_event_or_cleanup(m_current->get(), open_func, cleanup_func);
|
||||
bool result = torrent::runtime::socket_manager()->open_event_or_cleanup(m_current->get(), torrent::runtime::category_scgi, open_func, cleanup_func);
|
||||
|
||||
if (!result)
|
||||
break;
|
||||
|
||||
+16
-11
@@ -11,10 +11,10 @@
|
||||
#include <sys/socket.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/net/fd.h>
|
||||
#include <torrent/net/poll.h>
|
||||
#include <torrent/runtime/socket_manager.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/system/poll.h>
|
||||
#include <torrent/utils/log.h>
|
||||
#include <torrent/system/thread.h>
|
||||
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
@@ -24,6 +24,12 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
SCgiTask::SCgiTask()
|
||||
: m_callback_id(torrent::system::make_callback_id()) {
|
||||
|
||||
set_file_descriptor(-1);
|
||||
}
|
||||
|
||||
void
|
||||
SCgiTask::open(SCgi* parent, int fd) {
|
||||
set_file_descriptor(fd);
|
||||
@@ -67,8 +73,7 @@ SCgiTask::close() {
|
||||
if (!is_open())
|
||||
return;
|
||||
|
||||
torrent::main_thread::thread()->cancel_callback_and_wait(this);
|
||||
torrent::system::Thread::self()->cancel_callback(this);
|
||||
torrent::system::cancel_callback_and_wait(m_callback_id, scgi_thread::thread(), torrent::main_thread::thread());
|
||||
|
||||
torrent::runtime::socket_manager()->close_event_or_throw(this, [this]() {
|
||||
torrent::this_thread::poll()->remove_and_close(this);
|
||||
@@ -86,13 +91,13 @@ SCgiTask::close() {
|
||||
void
|
||||
SCgiTask::event_read() {
|
||||
int read_length = m_buffer.size() - m_position;
|
||||
|
||||
|
||||
if (m_content_length == 0)
|
||||
read_length--;
|
||||
|
||||
if (read_length <= 0)
|
||||
throw torrent::internal_error("SCgiTask::event_read() no space in buffer for event_read.");
|
||||
|
||||
|
||||
int bytes = ::recv(m_fileDesc, m_buffer.data() + m_position, read_length, 0);
|
||||
|
||||
if (bytes <= 0) {
|
||||
@@ -179,7 +184,7 @@ SCgiTask::event_write() {
|
||||
int bytes = ::send(m_fileDesc, m_buffer.data() + m_position, m_buffer.size() - m_position, 0);
|
||||
|
||||
if (bytes == -1) {
|
||||
if (!(errno == EAGAIN || errno == EINTR || errno == EPIPE))
|
||||
if (!(errno == EAGAIN || errno == EINTR))
|
||||
close();
|
||||
|
||||
return;
|
||||
@@ -321,7 +326,7 @@ SCgiTask::detect_content_type(const std::string& content_type) {
|
||||
|
||||
void
|
||||
SCgiTask::receive_call(const char* buffer, uint32_t length) {
|
||||
assert(torrent::system::Thread::self() == scgi_thread::thread());
|
||||
assert(torrent::this_thread::thread() == scgi_thread::thread());
|
||||
|
||||
RpcManager::RPCType rpc_type;
|
||||
|
||||
@@ -348,7 +353,7 @@ SCgiTask::receive_call(const char* buffer, uint32_t length) {
|
||||
m_result_mutex.lock();
|
||||
m_result_mutex.unlock();
|
||||
|
||||
scgi_thread::thread()->callback_interrupt_polling(this, [this]() {
|
||||
scgi_thread::callback_interrupt(m_callback_id, [this]() {
|
||||
if (!is_open())
|
||||
return;
|
||||
|
||||
@@ -368,7 +373,7 @@ SCgiTask::receive_call(const char* buffer, uint32_t length) {
|
||||
m_result_mutex.lock();
|
||||
m_result_mutex.unlock();
|
||||
|
||||
torrent::main_thread::thread()->callback_interrupt_polling(this, [this, rpc_type, buffer, length, result_callback]() {
|
||||
torrent::main_thread::callback_interrupt(m_callback_id, [this, rpc_type, buffer, length, result_callback]() {
|
||||
// Memory barrier for the input data.
|
||||
// std::atomic_thread_fence(std::memory_order_acquire);
|
||||
m_result_mutex.lock();
|
||||
@@ -383,7 +388,7 @@ SCgiTask::receive_call(const char* buffer, uint32_t length) {
|
||||
|
||||
void
|
||||
SCgiTask::receive_write(const char* buffer, uint32_t length) {
|
||||
assert(torrent::system::Thread::self() == torrent::main_thread::thread());
|
||||
assert(torrent::this_thread::thread() == torrent::main_thread::thread());
|
||||
|
||||
if (buffer == nullptr || length > (100 << 20))
|
||||
throw torrent::internal_error("SCgiTask::receive_write(...) received bad input.");
|
||||
|
||||
+3
-2
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
enum ContentType { XML, JSON };
|
||||
|
||||
SCgiTask() { m_fileDesc = -1; }
|
||||
SCgiTask();
|
||||
|
||||
const char* type_name() const override { return "scgi-task"; }
|
||||
|
||||
@@ -54,7 +54,8 @@ private:
|
||||
void plaintext_response(const char* buffer, uint32_t content_length);
|
||||
void gzip_response(const char* buffer, uint32_t content_length);
|
||||
|
||||
SCgi* m_parent{};
|
||||
SCgi* m_parent{};
|
||||
torrent::system::callback_id m_callback_id;
|
||||
|
||||
std::mutex m_result_mutex;
|
||||
|
||||
|
||||
+7
-6
@@ -9,20 +9,21 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
std::vector<std::unique_ptr<const char>> XmlRpc::m_command_names;
|
||||
std::vector<std::string> XmlRpc::m_command_names;
|
||||
|
||||
const char*
|
||||
XmlRpc::store_command_name(const char* name) {
|
||||
if (::strnlen(name, 8192) == 8192)
|
||||
if (::strnlen(name, 1024 + 1) > 1024)
|
||||
throw torrent::input_error("XMLRPC command name too long, limit is 8192 characters.");
|
||||
|
||||
for (const auto& itr : m_command_names) {
|
||||
if (::strcmp(itr.get(), name) == 0)
|
||||
return itr.get();
|
||||
if (itr == name)
|
||||
return itr.c_str();
|
||||
}
|
||||
|
||||
m_command_names.push_back(std::unique_ptr<const char>(::strdup(name)));
|
||||
return m_command_names.back().get();
|
||||
m_command_names.push_back(name);
|
||||
|
||||
return m_command_names.back().c_str();
|
||||
}
|
||||
|
||||
#ifndef HAVE_XMLRPC_C
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ public:
|
||||
private:
|
||||
static const char* store_command_name(const char* name);
|
||||
|
||||
static std::vector<std::unique_ptr<const char>> m_command_names;
|
||||
static std::vector<std::string> m_command_names;
|
||||
|
||||
slot_download m_slotFindDownload;
|
||||
slot_file m_slotFindFile;
|
||||
|
||||
+17
-2
@@ -272,12 +272,27 @@ object_to_xmlrpc(xmlrpc_env* env, const torrent::Object& object) {
|
||||
#ifdef XMLRPC_HAVE_I8
|
||||
if (rpc.dialect() != XmlRpc::dialect_generic)
|
||||
return xmlrpc_i8_new(env, object.as_value());
|
||||
#else
|
||||
return xmlrpc_int_new(env, object.as_value());
|
||||
#endif
|
||||
|
||||
return xmlrpc_int_new(env, object.as_value());
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
if (object.flags() & torrent::Object::flag_as_binary) {
|
||||
|
||||
// This causes decode-and-reencode for base64, as XMLRPC-C doesn't allow us to pass base64 strings.
|
||||
if (object.flags() & torrent::Object::flag_base64) {
|
||||
auto binary_data = torrent::utils::transform_from_base64_unsafe(object.as_string());
|
||||
|
||||
if (!binary_data.has_value())
|
||||
throw torrent::input_error("invalid base64 string in base64-as-binary object");
|
||||
|
||||
return xmlrpc_base64_new(env, binary_data->size(), reinterpret_cast<const unsigned char*>(binary_data->data()));
|
||||
}
|
||||
|
||||
return xmlrpc_base64_new(env, object.as_string().size(), reinterpret_cast<const unsigned char*>(object.as_string().c_str()));
|
||||
}
|
||||
|
||||
#ifdef XMLRPC_HAVE_I8
|
||||
// The versions that support I8 do implicit utf-8 validation.
|
||||
xmlrpc_value* result = xmlrpc_string_new(env, object.as_string().c_str());
|
||||
|
||||
+59
-12
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/utils/string_manip.h>
|
||||
|
||||
#include "parse_commands.h"
|
||||
#include "rpc/tinyxml2/tinyxml2.h"
|
||||
@@ -66,56 +67,85 @@ xml_value_to_object(const tinyxml2::XMLNode* elem) {
|
||||
if (elem == nullptr) {
|
||||
throw rpc_error(XMLRPC_INTERNAL_ERROR, "received null element to convert");
|
||||
}
|
||||
|
||||
if (std::strncmp(elem->Value(), "value", sizeof("value")) != 0) {
|
||||
throw rpc_error(XMLRPC_INTERNAL_ERROR, "received non-value element to convert");
|
||||
}
|
||||
|
||||
auto root_element = elem->FirstChild();
|
||||
|
||||
if (root_element == nullptr)
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "empty value element");
|
||||
|
||||
auto root_type = root_element->Value();
|
||||
|
||||
if (std::strncmp(root_type, "string", sizeof("string")) == 0) {
|
||||
auto child_element = root_element->FirstChild();
|
||||
if (child_element == nullptr) {
|
||||
|
||||
if (child_element == nullptr)
|
||||
return torrent::Object("");
|
||||
}
|
||||
|
||||
return torrent::Object(child_element->ToText()->Value());
|
||||
|
||||
} else if (std::strncmp(root_type, "int", sizeof("int")) == 0 ||
|
||||
std::strncmp(root_type, "i4", sizeof("i4")) == 0 ||
|
||||
std::strncmp(root_type, "i8", sizeof("i8")) == 0) {
|
||||
return torrent::Object(element_to_int(root_element));
|
||||
|
||||
} else if (std::strncmp(root_type, "boolean", sizeof("boolean")) == 0) {
|
||||
auto boolean_text = std::string(root_element->FirstChild()->ToText()->Value());
|
||||
if (boolean_text == "1") {
|
||||
auto child_element = root_element->FirstChild();
|
||||
|
||||
if (child_element == nullptr)
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "empty boolean element");
|
||||
|
||||
auto boolean_text = std::string(child_element->ToText()->Value());
|
||||
|
||||
if (boolean_text == "1")
|
||||
return torrent::Object((int64_t)1);
|
||||
} else if (boolean_text == "0") {
|
||||
else if (boolean_text == "0")
|
||||
return torrent::Object((int64_t)0);
|
||||
}
|
||||
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "unknown boolean value: " + boolean_text);
|
||||
|
||||
} else if (std::strncmp(root_type, "array", sizeof("array")) == 0) {
|
||||
auto array_raw = torrent::Object::create_list();
|
||||
auto& array = array_raw.as_list();
|
||||
auto data_element = root_element->ToElement()->FirstChildElement("data");
|
||||
|
||||
if (data_element == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "could not find expected data element in array");
|
||||
for (auto child = data_element->FirstChildElement("value"); child; child = child->NextSiblingElement("value")) {
|
||||
|
||||
for (auto child = data_element->FirstChildElement("value"); child; child = child->NextSiblingElement("value"))
|
||||
array.push_back(xml_value_to_object(child));
|
||||
}
|
||||
|
||||
return array_raw;
|
||||
} else if (std::strncmp(root_type, "struct", sizeof("struct")) == 0) {
|
||||
auto map_raw = torrent::Object::create_map();
|
||||
auto& map = map_raw.as_map();
|
||||
|
||||
for (auto child = root_element->FirstChildElement("member"); child; child = child->NextSiblingElement("member")) {
|
||||
auto key = child->FirstChildElement("name")->GetText();
|
||||
map[key] = std::move(xml_value_to_object(child->FirstChildElement("value")));
|
||||
auto name_element = child->FirstChildElement("name");
|
||||
|
||||
if (name_element == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "struct member missing name element");
|
||||
|
||||
map[name_element->GetText()] = std::move(xml_value_to_object(child->FirstChildElement("value")));
|
||||
}
|
||||
|
||||
return map_raw;
|
||||
|
||||
} else if (std::strncmp(root_type, "base64", sizeof("base64")) == 0) {
|
||||
auto child_element = root_element->FirstChild();
|
||||
if (child_element == nullptr) {
|
||||
|
||||
if (child_element == nullptr)
|
||||
return torrent::Object("");
|
||||
}
|
||||
|
||||
return torrent::Object(utils::decode_base64(utils::remove_newlines(child_element->ToText()->Value())));
|
||||
|
||||
} else {
|
||||
throw rpc_error(XMLRPC_INTERNAL_ERROR, "received unsupported value type: " + std::string(root_type));
|
||||
}
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
@@ -123,15 +153,32 @@ void
|
||||
print_object_xml(const torrent::Object& obj, tinyxml2::XMLPrinter* printer) {
|
||||
switch (obj.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
if (obj.flags() & torrent::Object::flag_as_binary) {
|
||||
// It is optimal for tinyxml2 to pass base64 strings directly from torrent::string_utf8 sources.
|
||||
if (obj.flags() & torrent::Object::flag_base64) {
|
||||
printer->OpenElement("base64", true);
|
||||
printer->PushText(obj.as_string().c_str());
|
||||
printer->CloseElement(true);
|
||||
break;
|
||||
}
|
||||
|
||||
printer->OpenElement("base64", true);
|
||||
printer->PushText(torrent::utils::transform_to_base64(obj.as_string()).c_str());
|
||||
printer->CloseElement(true);
|
||||
break;
|
||||
}
|
||||
|
||||
printer->OpenElement("string", true);
|
||||
printer->PushText(obj.as_string().c_str());
|
||||
printer->CloseElement(true);
|
||||
break;
|
||||
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
printer->OpenElement("i8", true);
|
||||
printer->PushText(std::to_string(obj.as_value()).c_str());
|
||||
printer->CloseElement(true);
|
||||
break;
|
||||
|
||||
case torrent::Object::TYPE_LIST:
|
||||
printer->OpenElement("array", true);
|
||||
printer->OpenElement("data", true);
|
||||
|
||||
+8
-15
@@ -12,11 +12,6 @@
|
||||
|
||||
namespace scgi {
|
||||
|
||||
class ThreadScgiInternal {
|
||||
public:
|
||||
static ThreadScgi* thread_scgi() { return ThreadScgi::internal_thread_scgi(); }
|
||||
};
|
||||
|
||||
ThreadScgi* ThreadScgi::m_thread_scgi{};
|
||||
|
||||
void
|
||||
@@ -60,7 +55,7 @@ ThreadScgi::set_scgi(rpc::SCgi* scgi) {
|
||||
|
||||
change_rpc_log();
|
||||
|
||||
callback(nullptr, [this]() {
|
||||
callback([this]() {
|
||||
if (m_scgi == nullptr)
|
||||
throw torrent::internal_error("Tried to start SCGI but object was not present.");
|
||||
|
||||
@@ -72,7 +67,7 @@ ThreadScgi::set_scgi(rpc::SCgi* scgi) {
|
||||
|
||||
void
|
||||
ThreadScgi::set_rpc_log(const std::string& filename) {
|
||||
callback(nullptr, [this, filename]() {
|
||||
callback([this, filename]() {
|
||||
m_rpc_log_filename = filename;
|
||||
change_rpc_log();
|
||||
});
|
||||
@@ -127,15 +122,13 @@ ThreadScgi::next_timeout() {
|
||||
|
||||
namespace scgi_thread {
|
||||
|
||||
torrent::system::Thread* thread() { return scgi::ThreadScgiInternal::thread_scgi(); }
|
||||
std::thread::id thread_id() { return scgi::ThreadScgiInternal::thread_scgi()->thread_id(); }
|
||||
torrent::system::Thread* thread() { return scgi::ThreadScgi::thread_scgi(); }
|
||||
std::thread::id thread_id() { return scgi::ThreadScgi::thread_scgi()->thread_id(); }
|
||||
|
||||
void callback(void* target, std::function<void ()>&& fn) { scgi::ThreadScgiInternal::thread_scgi()->callback(target, std::move(fn)); }
|
||||
void cancel_callback(void* target) { scgi::ThreadScgiInternal::thread_scgi()->cancel_callback(target); }
|
||||
void cancel_callback_and_wait(void* target) { scgi::ThreadScgiInternal::thread_scgi()->cancel_callback_and_wait(target); }
|
||||
void callback_interrupt(torrent::system::callback_id& id, std::function<void ()>&& fn) { scgi::ThreadScgi::thread_scgi()->callback_interrupt(id, std::move(fn)); }
|
||||
|
||||
rpc::SCgi* scgi() { return scgi::ThreadScgiInternal::thread_scgi()->scgi(); }
|
||||
void set_scgi(rpc::SCgi* scgi) { scgi::ThreadScgiInternal::thread_scgi()->set_scgi(scgi); }
|
||||
void set_rpc_log(const std::string& filename) { scgi::ThreadScgiInternal::thread_scgi()->set_rpc_log(filename); }
|
||||
rpc::SCgi* scgi() { return scgi::ThreadScgi::thread_scgi()->scgi(); }
|
||||
void set_scgi(rpc::SCgi* scgi) { scgi::ThreadScgi::thread_scgi()->set_scgi(scgi); }
|
||||
void set_rpc_log(const std::string& filename) { scgi::ThreadScgi::thread_scgi()->set_rpc_log(filename); }
|
||||
|
||||
} // namespace scgi_thread
|
||||
|
||||
@@ -11,8 +11,6 @@ class SCgi;
|
||||
|
||||
namespace scgi {
|
||||
|
||||
class ThreadScgiInternal;
|
||||
|
||||
class ThreadScgi : public torrent::system::Thread {
|
||||
public:
|
||||
|
||||
@@ -28,8 +26,6 @@ public:
|
||||
void set_rpc_log(const std::string& filename);
|
||||
|
||||
protected:
|
||||
friend class ThreadScgiInternal;
|
||||
|
||||
ThreadScgi() = default;
|
||||
|
||||
static auto internal_thread_scgi() { return m_thread_scgi; }
|
||||
@@ -43,9 +39,9 @@ private:
|
||||
void task_touch_log();
|
||||
void change_rpc_log();
|
||||
|
||||
static ThreadScgi* m_thread_scgi;
|
||||
static ThreadScgi* m_thread_scgi;
|
||||
|
||||
std::atomic<rpc::SCgi*> m_scgi{nullptr};
|
||||
std::atomic<rpc::SCgi*> m_scgi{};
|
||||
std::string m_rpc_log_filename;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
#include "globals.h"
|
||||
@@ -23,6 +24,7 @@ namespace session {
|
||||
|
||||
SessionManager::SessionManager(torrent::system::Thread* thread)
|
||||
: m_thread(thread),
|
||||
m_callback_id(torrent::system::make_callback_id()),
|
||||
m_lockfile(std::make_unique<utils::Lockfile>()) {
|
||||
}
|
||||
|
||||
@@ -221,8 +223,7 @@ SessionManager::cleanup() {
|
||||
|
||||
LT_LOG("session manager cleaned up", 0);
|
||||
|
||||
session_thread::cancel_callback(this);
|
||||
torrent::main_thread::cancel_callback(this);
|
||||
torrent::system::cancel_callback_and_wait(m_callback_id, session_thread::thread(), torrent::main_thread::thread());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -233,7 +234,9 @@ SessionManager::callback_pending_builds() {
|
||||
if (m_callback_scheduled_process_pending_builds.exchange(true))
|
||||
return;
|
||||
|
||||
torrent::main_thread::callback(this, [this]() { process_pending_builds(false); });
|
||||
torrent::main_thread::callback(m_callback_id, [this]() {
|
||||
process_pending_builds(false);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -247,7 +250,9 @@ SessionManager::callback_save_request() {
|
||||
if (m_callback_scheduled_process_saves_request.exchange(true))
|
||||
return;
|
||||
|
||||
session_thread::callback(this, [this]() { process_save_request(); });
|
||||
session_thread::callback(m_callback_id, [this]() {
|
||||
process_save_request();
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -255,7 +260,9 @@ SessionManager::callback_finished_saves() {
|
||||
if (m_callback_scheduled_process_finished_saves.exchange(true))
|
||||
return;
|
||||
|
||||
session_thread::callback(this, [this]() { process_finished_saves(); });
|
||||
session_thread::callback(m_callback_id, [this]() {
|
||||
process_finished_saves();
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -89,37 +89,39 @@ private:
|
||||
bool replace_save_request_unsafe(SaveRequest& download);
|
||||
bool remove_completely_unsafe(core::Download* download, std::unique_lock<std::mutex>& lock);
|
||||
|
||||
torrent::system::Thread* m_thread;
|
||||
using ProcessingSave = std::pair<std::future<void>, SaveRequest>;
|
||||
|
||||
bool m_freeze_info{};
|
||||
std::string m_path;
|
||||
bool m_use_fsyncdisk{true};
|
||||
bool m_use_lock{true};
|
||||
torrent::system::Thread* m_thread;
|
||||
torrent::system::callback_id m_callback_id;
|
||||
|
||||
std::mutex m_mutex;
|
||||
bool m_active{};
|
||||
bool m_freeze_info{};
|
||||
std::string m_path;
|
||||
bool m_use_fsyncdisk{true};
|
||||
bool m_use_lock{true};
|
||||
|
||||
typedef std::pair<std::future<void>, SaveRequest> ProcessingSave;
|
||||
align_cacheline std::mutex m_mutex;
|
||||
|
||||
std::deque<SaveRequest> m_save_requests;
|
||||
std::atomic<size_t> m_save_request_counter{};
|
||||
std::list<ProcessingSave> m_processing_saves;
|
||||
std::atomic<size_t> m_processing_save_counter{};
|
||||
std::condition_variable m_finished_condition;
|
||||
std::vector<ProcessingSave> m_finished_saves;
|
||||
bool m_active{};
|
||||
|
||||
std::atomic<bool> m_callback_scheduled_process_pending_builds{};
|
||||
std::atomic<bool> m_callback_scheduled_process_saves_request{};
|
||||
std::atomic<bool> m_callback_scheduled_process_finished_saves{};
|
||||
std::deque<SaveRequest> m_save_requests;
|
||||
std::atomic<size_t> m_save_request_counter{};
|
||||
std::list<ProcessingSave> m_processing_saves;
|
||||
std::atomic<size_t> m_processing_save_counter{};
|
||||
std::condition_variable m_finished_condition;
|
||||
std::vector<ProcessingSave> m_finished_saves;
|
||||
|
||||
std::atomic<bool> m_callback_scheduled_process_pending_builds{};
|
||||
std::atomic<bool> m_callback_scheduled_process_saves_request{};
|
||||
std::atomic<bool> m_callback_scheduled_process_finished_saves{};
|
||||
|
||||
std::unique_ptr<utils::Lockfile> m_lockfile;
|
||||
|
||||
std::chrono::microseconds m_last_storage_error_message{};
|
||||
unsigned int m_ignored_storage_error_count{};
|
||||
std::chrono::microseconds m_last_storage_error_message{};
|
||||
unsigned int m_ignored_storage_error_count{};
|
||||
|
||||
// Pending builds are only ever locked by main thread.
|
||||
std::mutex m_pending_builds_mutex;
|
||||
std::deque<core::Download*> m_pending_builds;
|
||||
std::mutex m_pending_builds_mutex;
|
||||
std::deque<core::Download*> m_pending_builds;
|
||||
};
|
||||
|
||||
inline bool SessionManager::is_used() const { return !m_path.empty(); }
|
||||
|
||||
@@ -4,15 +4,11 @@
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "session/session_manager.h"
|
||||
|
||||
namespace session {
|
||||
|
||||
class ThreadSessionInternal {
|
||||
public:
|
||||
static ThreadSession* thread_session() { return ThreadSession::internal_thread_session(); }
|
||||
};
|
||||
|
||||
ThreadSession* ThreadSession::m_thread_session{nullptr};
|
||||
|
||||
void
|
||||
@@ -74,14 +70,14 @@ ThreadSession::next_timeout() {
|
||||
|
||||
namespace session_thread {
|
||||
|
||||
torrent::system::Thread* thread() { return session::ThreadSessionInternal::thread_session(); }
|
||||
std::thread::id thread_id() { return session::ThreadSessionInternal::thread_session()->thread_id(); }
|
||||
torrent::system::Thread* thread() { return session::ThreadSession::thread_session(); }
|
||||
std::thread::id thread_id() { return thread()->thread_id(); }
|
||||
|
||||
void callback(void* target, std::function<void ()>&& fn) { session::ThreadSessionInternal::thread_session()->callback(target, std::move(fn)); }
|
||||
void cancel_callback(void* target) { session::ThreadSessionInternal::thread_session()->cancel_callback(target); }
|
||||
void cancel_callback_and_wait(void* target) { session::ThreadSessionInternal::thread_session()->cancel_callback_and_wait(target); }
|
||||
void callback(std::function<void()>&& fn) { thread()->callback(std::move(fn)); }
|
||||
void callback(torrent::system::callback_id& id, std::function<void()>&& fn) { thread()->callback(id, std::move(fn)); }
|
||||
void cancel_callback(torrent::system::callback_id& id) { thread()->cancel_callback(id); }
|
||||
|
||||
session::SessionManager* manager() { return session::ThreadSessionInternal::thread_session()->manager(); }
|
||||
std::string session_path() { return session::ThreadSessionInternal::thread_session()->manager()->path(); }
|
||||
session::SessionManager* manager() { return session::ThreadSession::thread_session()->manager(); }
|
||||
std::string session_path() { return manager()->path(); }
|
||||
|
||||
} // namespace session_thread
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ Download::activate_display(Display displayType, bool focusDisplay) {
|
||||
// Set title.
|
||||
switch (displayType) {
|
||||
case DISPLAY_MAX_SIZE: break;
|
||||
default: control->ui()->window_title()->set_title(m_download->info()->name()); break;
|
||||
default: control->ui()->window_title()->set_title(m_download->info()->name().str()); break;
|
||||
}
|
||||
|
||||
control->display()->adjust_layout();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/system/thread.h>
|
||||
|
||||
#include "display/frame.h"
|
||||
@@ -17,11 +18,12 @@ namespace ui {
|
||||
ElementLogComplete::ElementLogComplete(torrent::log_buffer* l) :
|
||||
m_log(l) {
|
||||
|
||||
unsigned int signal_index = torrent::main_thread::thread()->signal_bitfield()->add_signal(std::bind(&ElementLogComplete::received_update, this));
|
||||
m_log->lock_and_set_update_slot([this]() {
|
||||
if (m_log_updating.exchange(true) == true)
|
||||
return;
|
||||
|
||||
m_log->lock_and_set_update_slot([signal_index]() {
|
||||
torrent::main_thread::thread()->send_event_signal(signal_index, false);
|
||||
});
|
||||
torrent::main_thread::callback([this]() { received_update(); });
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -59,6 +61,8 @@ ElementLogComplete::window() {
|
||||
|
||||
void
|
||||
ElementLogComplete::received_update() {
|
||||
m_log_updating = false;
|
||||
|
||||
if (m_window != NULL)
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ private:
|
||||
WLogComplete* m_window{};
|
||||
|
||||
torrent::log_buffer* m_log;
|
||||
|
||||
align_cacheline std::atomic<bool> m_log_updating{};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -70,4 +70,5 @@ decode_base64(const std::string& input) {
|
||||
}
|
||||
return decodedBytes;
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
+3
-1
@@ -1,12 +1,14 @@
|
||||
#ifndef RTORRENT_UTILS_BASE64_H
|
||||
#define RTORRENT_UTILS_BASE64_H
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include <vector>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
// TODO: Deprecate.
|
||||
std::string remove_newlines(const std::string& str);
|
||||
std::string decode_base64(const std::string& input);
|
||||
|
||||
|
||||
@@ -21,13 +21,16 @@ FileStatusCache::insert(const std::string& path) {
|
||||
|
||||
std::pair<iterator, bool> result = base_type::insert(value_type(path, file_status()));
|
||||
|
||||
// Return false if the file hasn't been modified since last time. We
|
||||
// use 'equal to' instead of 'greater than' since the file might
|
||||
// have been replaced by another file, and thus should be re-tried.
|
||||
if (!result.second && result.first->second.m_mtime == (uint32_t)fs.modified_time())
|
||||
// Return false if the file hasn't changed since last time. We use
|
||||
// 'equal to' instead of 'greater than' since the file might have
|
||||
// been replaced by another file, and thus should be re-tried.
|
||||
if (!result.second &&
|
||||
result.first->second.m_mtime == (uint32_t)fs.modified_time() &&
|
||||
result.first->second.m_size == (int64_t)fs.size())
|
||||
return false;
|
||||
|
||||
result.first->second.m_flags = 0;
|
||||
result.first->second.m_size = (int64_t)fs.size();
|
||||
result.first->second.m_mtime = fs.modified_time();
|
||||
|
||||
return true;
|
||||
@@ -41,7 +44,9 @@ FileStatusCache::prune() {
|
||||
torrent::utils::FileStat fs;
|
||||
iterator tmp = itr++;
|
||||
|
||||
if (!fs.update(expand_path(tmp->first)) || tmp->second.m_mtime != (uint32_t)fs.modified_time())
|
||||
if (!fs.update(expand_path(tmp->first)) ||
|
||||
tmp->second.m_mtime != (uint32_t)fs.modified_time() ||
|
||||
tmp->second.m_size != (int64_t)fs.size())
|
||||
base_type::erase(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace utils {
|
||||
|
||||
struct file_status {
|
||||
int m_flags;
|
||||
int64_t m_size;
|
||||
uint32_t m_mtime;
|
||||
};
|
||||
|
||||
@@ -32,14 +33,14 @@ public:
|
||||
|
||||
using base_type::erase;
|
||||
|
||||
// Insert and return true if the entry does not exist or the new
|
||||
// file's mtime is more recent.
|
||||
// Insert and return true if the entry does not exist or the file's
|
||||
// status has changed.
|
||||
bool insert(const std::string& path);
|
||||
|
||||
// Add a function for pruning a sorted list of paths.
|
||||
|
||||
// Function for pruning entries that no longer points to a file, or
|
||||
// has a different mtime.
|
||||
// has different status.
|
||||
void prune();
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "utils/watch_ready_queue.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <torrent/utils/file_stat.h>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "rpc/rpc_manager.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
namespace {
|
||||
|
||||
auto compare_next_time = [](const auto* lhs, const auto* rhs) {
|
||||
return lhs->next_time > rhs->next_time;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
WatchReadyQueue::WatchReadyQueue() {
|
||||
m_task_process.slot() = [this]() { process(); };
|
||||
}
|
||||
|
||||
WatchReadyQueue::~WatchReadyQueue() {
|
||||
torrent::this_thread::scheduler()->erase(&m_task_process);
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::push(const std::string& command, const std::string& path) {
|
||||
if (!m_active)
|
||||
return;
|
||||
|
||||
auto result = m_entries.emplace(path, Entry());
|
||||
auto& entry = result.first->second;
|
||||
|
||||
if (result.second) {
|
||||
entry.path = path;
|
||||
entry.first_seen = torrent::this_thread::cached_time();
|
||||
}
|
||||
|
||||
entry.command = command;
|
||||
entry.last_changed = torrent::this_thread::cached_time();
|
||||
update_status(&entry);
|
||||
|
||||
if (result.second) {
|
||||
update_next_time(&entry);
|
||||
push_entry(&entry);
|
||||
} else {
|
||||
update_entry(&entry);
|
||||
}
|
||||
|
||||
schedule();
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::shutdown() {
|
||||
m_active = false;
|
||||
m_entries.clear();
|
||||
m_entry_queue.clear();
|
||||
torrent::this_thread::scheduler()->erase(&m_task_process);
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::push_entry(Entry* entry) {
|
||||
m_entry_queue.push_back(entry);
|
||||
std::push_heap(m_entry_queue.begin(), m_entry_queue.end(), compare_next_time);
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::update_entry(Entry* entry) {
|
||||
update_next_time(entry);
|
||||
std::make_heap(m_entry_queue.begin(), m_entry_queue.end(), compare_next_time);
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::update_next_time(Entry* entry) {
|
||||
if (entry->regular && entry->size > 0) {
|
||||
entry->next_time = entry->last_changed + quiet_time;
|
||||
return;
|
||||
}
|
||||
|
||||
entry->next_time = std::min(torrent::this_thread::cached_time() + retry_time,
|
||||
entry->first_seen + stale_time);
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::update_status(Entry* entry) {
|
||||
torrent::utils::FileStat fs;
|
||||
bool regular = false;
|
||||
int64_t size = -1;
|
||||
time_t mtime = 0;
|
||||
|
||||
if (fs.update(expand_path(entry->path))) {
|
||||
regular = fs.is_regular();
|
||||
size = fs.size();
|
||||
mtime = fs.modified_time();
|
||||
}
|
||||
|
||||
if (entry->regular != regular || entry->size != size || entry->mtime != mtime) {
|
||||
entry->regular = regular;
|
||||
entry->size = size;
|
||||
entry->mtime = mtime;
|
||||
entry->last_changed = torrent::this_thread::cached_time();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::process() {
|
||||
ready_list ready;
|
||||
|
||||
while (!m_entry_queue.empty() && m_entry_queue.front()->next_time <= torrent::this_thread::cached_time()) {
|
||||
std::pop_heap(m_entry_queue.begin(), m_entry_queue.end(), compare_next_time);
|
||||
Entry* entry = m_entry_queue.back();
|
||||
m_entry_queue.pop_back();
|
||||
|
||||
update_status(entry);
|
||||
|
||||
bool unchanged_entry = torrent::this_thread::cached_time() - entry->last_changed >= quiet_time;
|
||||
bool stale_entry = torrent::this_thread::cached_time() - entry->first_seen >= stale_time;
|
||||
bool nonempty_regular = entry->regular && entry->size > 0;
|
||||
|
||||
if (nonempty_regular && unchanged_entry) {
|
||||
ready.emplace_back(entry->command, entry->path);
|
||||
std::string path = entry->path;
|
||||
m_entries.erase(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!nonempty_regular && stale_entry) {
|
||||
std::string path = entry->path;
|
||||
lt_log_print(torrent::LOG_SYSTEM, "system: Dropped unready watch file after timeout: \"%s\"", path.c_str());
|
||||
m_entries.erase(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
update_next_time(entry);
|
||||
push_entry(entry);
|
||||
}
|
||||
|
||||
schedule();
|
||||
|
||||
for (const auto& item : ready)
|
||||
rpc::commands.call_catch(item.first.c_str(), rpc::make_target(), item.second);
|
||||
}
|
||||
|
||||
void
|
||||
WatchReadyQueue::schedule() {
|
||||
if (m_entry_queue.empty()) {
|
||||
torrent::this_thread::scheduler()->erase(&m_task_process);
|
||||
return;
|
||||
}
|
||||
|
||||
torrent::this_thread::scheduler()->update_wait_until(&m_task_process, m_entry_queue.front()->next_time);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef RTORRENT_UTILS_WATCH_READY_QUEUE_H
|
||||
#define RTORRENT_UTILS_WATCH_READY_QUEUE_H
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <torrent/utils/scheduler.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
class WatchReadyQueue {
|
||||
public:
|
||||
WatchReadyQueue();
|
||||
~WatchReadyQueue();
|
||||
|
||||
void push(const std::string& command, const std::string& path);
|
||||
void shutdown();
|
||||
bool empty() const { return m_entries.empty(); }
|
||||
|
||||
private:
|
||||
using time_type = std::chrono::microseconds;
|
||||
|
||||
static constexpr auto quiet_time = std::chrono::milliseconds(500);
|
||||
static constexpr auto retry_time = std::chrono::milliseconds(250);
|
||||
static constexpr auto stale_time = std::chrono::seconds(10);
|
||||
|
||||
using ready_list = std::vector<std::pair<std::string, std::string>>;
|
||||
|
||||
struct Entry {
|
||||
std::string command;
|
||||
std::string path;
|
||||
bool regular{};
|
||||
int64_t size{-1};
|
||||
time_t mtime{};
|
||||
time_type first_seen{};
|
||||
time_type last_changed{};
|
||||
time_type next_time{};
|
||||
};
|
||||
|
||||
void process();
|
||||
void push_entry(Entry* entry);
|
||||
void update_entry(Entry* entry);
|
||||
void update_next_time(Entry* entry);
|
||||
void update_status(Entry* entry);
|
||||
void schedule();
|
||||
|
||||
std::map<std::string, Entry> m_entries;
|
||||
std::vector<Entry*> m_entry_queue;
|
||||
torrent::utils::SchedulerEntry m_task_process;
|
||||
bool m_active{true};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+3
-1
@@ -48,7 +48,9 @@ rtorrent_Test_Rpc_SOURCES = $(rtorrent_Test_Common) \
|
||||
|
||||
rtorrent_Test_Src_SOURCES = $(rtorrent_Test_Common) \
|
||||
src/test_command_dynamic.cc \
|
||||
src/test_command_dynamic.h
|
||||
src/test_command_dynamic.h \
|
||||
src/test_watch_ready_queue.cc \
|
||||
src/test_watch_ready_queue.h
|
||||
|
||||
rtorrent_Test_Rpc_CXXFLAGS = $(CPPUNIT_CFLAGS)
|
||||
rtorrent_Test_Rpc_LDFLAGS = $(CPPUNIT_LIBS) -ldl
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "test/helpers/mock_function.h"
|
||||
#include "torrent/exceptions.h"
|
||||
#include "torrent/net/poll.h"
|
||||
#include "torrent/system/poll.h"
|
||||
|
||||
const int test_thread::test_flag_pre_stop;
|
||||
const int test_thread::test_flag_long_timeout;
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "test/src/test_watch_ready_queue.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "command_helpers.h"
|
||||
#include "rpc/command_map.h"
|
||||
#include "utils/watch_ready_queue.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestWatchReadyQueue);
|
||||
|
||||
namespace {
|
||||
|
||||
const char* test_load_command = "test.watch_ready.load";
|
||||
std::vector<std::string> loaded_paths;
|
||||
|
||||
torrent::Object
|
||||
cmd_watch_ready_load([[maybe_unused]] rpc::target_type target, const std::string& path) {
|
||||
loaded_paths.push_back(path);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
std::string
|
||||
temporary_path() {
|
||||
char path[] = "/tmp/rtorrent-watch-ready-XXXXXX";
|
||||
int fd = ::mkstemp(path);
|
||||
|
||||
CPPUNIT_ASSERT(fd != -1);
|
||||
CPPUNIT_ASSERT(::close(fd) == 0);
|
||||
CPPUNIT_ASSERT(::unlink(path) == 0);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void
|
||||
write_file(const std::string& path, const std::string& contents) {
|
||||
int fd = ::open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
||||
|
||||
CPPUNIT_ASSERT(fd != -1);
|
||||
CPPUNIT_ASSERT(::write(fd, contents.data(), contents.size()) == static_cast<ssize_t>(contents.size()));
|
||||
CPPUNIT_ASSERT(::close(fd) == 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::setUp() {
|
||||
TestFixtureWithMainThread::setUp();
|
||||
|
||||
loaded_paths.clear();
|
||||
m_main_thread->test_set_cached_time(std::chrono::seconds(0));
|
||||
|
||||
if (!rpc::commands.has(test_load_command))
|
||||
CMD2_ANY_STRING(test_load_command, &cmd_watch_ready_load);
|
||||
}
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::tearDown() {
|
||||
loaded_paths.clear();
|
||||
|
||||
TestFixtureWithMainThread::tearDown();
|
||||
}
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::test_repeated_events_reset_quiet_time() {
|
||||
auto path = temporary_path();
|
||||
write_file(path, "torrent");
|
||||
|
||||
utils::WatchReadyQueue queue;
|
||||
queue.push(test_load_command, path);
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(300));
|
||||
queue.push(test_load_command, path);
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(300));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.empty());
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(201));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.size() == 1);
|
||||
CPPUNIT_ASSERT(loaded_paths.front() == path);
|
||||
|
||||
CPPUNIT_ASSERT(::unlink(path.c_str()) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::test_retry_restats_zero_length_file_without_new_event() {
|
||||
auto path = temporary_path();
|
||||
write_file(path, "");
|
||||
|
||||
utils::WatchReadyQueue queue;
|
||||
queue.push(test_load_command, path);
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(251));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.empty());
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(10));
|
||||
// No second queue event: retry processing must re-stat the same pending path.
|
||||
write_file(path, "torrent");
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(240));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.empty());
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(500));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.size() == 1);
|
||||
CPPUNIT_ASSERT(loaded_paths.front() == path);
|
||||
|
||||
CPPUNIT_ASSERT(::unlink(path.c_str()) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::test_unrelated_events_do_not_delay_missing_retry() {
|
||||
auto path = temporary_path();
|
||||
auto unrelated_path = temporary_path();
|
||||
|
||||
utils::WatchReadyQueue queue;
|
||||
queue.push(test_load_command, path);
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(100));
|
||||
queue.push(test_load_command, unrelated_path);
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(160));
|
||||
write_file(path, "torrent");
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.empty());
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::milliseconds(501));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
CPPUNIT_ASSERT(loaded_paths.size() == 1);
|
||||
CPPUNIT_ASSERT(loaded_paths.front() == path);
|
||||
|
||||
CPPUNIT_ASSERT(::unlink(path.c_str()) == 0);
|
||||
}
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::test_missing_paths_expire_without_dispatch() {
|
||||
auto path = temporary_path();
|
||||
|
||||
utils::WatchReadyQueue queue;
|
||||
queue.push(test_load_command, path);
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::seconds(10) + std::chrono::milliseconds(1));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
|
||||
CPPUNIT_ASSERT(loaded_paths.empty());
|
||||
CPPUNIT_ASSERT(queue.empty());
|
||||
}
|
||||
|
||||
void
|
||||
TestWatchReadyQueue::test_shutdown_discards_pending_loads() {
|
||||
auto path = temporary_path();
|
||||
write_file(path, "torrent");
|
||||
|
||||
utils::WatchReadyQueue queue;
|
||||
queue.push(test_load_command, path);
|
||||
queue.shutdown();
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::seconds(1));
|
||||
m_main_thread->test_process_events_without_cached_time();
|
||||
|
||||
CPPUNIT_ASSERT(loaded_paths.empty());
|
||||
CPPUNIT_ASSERT(queue.empty());
|
||||
|
||||
CPPUNIT_ASSERT(::unlink(path.c_str()) == 0);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "test/helpers/test_main_thread.h"
|
||||
|
||||
class TestWatchReadyQueue : public TestFixtureWithMainThread {
|
||||
CPPUNIT_TEST_SUITE(TestWatchReadyQueue);
|
||||
|
||||
CPPUNIT_TEST(test_repeated_events_reset_quiet_time);
|
||||
CPPUNIT_TEST(test_retry_restats_zero_length_file_without_new_event);
|
||||
CPPUNIT_TEST(test_unrelated_events_do_not_delay_missing_retry);
|
||||
CPPUNIT_TEST(test_missing_paths_expire_without_dispatch);
|
||||
CPPUNIT_TEST(test_shutdown_discards_pending_loads);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void test_repeated_events_reset_quiet_time();
|
||||
void test_retry_restats_zero_length_file_without_new_event();
|
||||
void test_unrelated_events_do_not_delay_missing_retry();
|
||||
void test_missing_paths_expire_without_dispatch();
|
||||
void test_shutdown_discards_pending_loads();
|
||||
};
|
||||
Reference in New Issue
Block a user