mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-18 15:16:17 +00:00
Compare commits
3 Commits
v0.16.16
...
a07f57a703
| Author | SHA1 | Date | |
|---|---|---|---|
| a07f57a703 | |||
| 0494ce70c8 | |||
| cfad36bf12 |
@@ -118,6 +118,10 @@ AC_DEFUN([TORRENT_CHECK_CACHELINE], [
|
|||||||
AC_MSG_RESULT([linux fallback enterprise 128 bytes])
|
AC_MSG_RESULT([linux fallback enterprise 128 bytes])
|
||||||
AC_DEFINE([LT_SMP_CACHE_BYTES], 128, [Fallback 128-byte alignment for Linux enterprise hardware.])
|
AC_DEFINE([LT_SMP_CACHE_BYTES], 128, [Fallback 128-byte alignment for Linux enterprise hardware.])
|
||||||
;;
|
;;
|
||||||
|
riscv32*|riscv64*)
|
||||||
|
AC_MSG_RESULT([linux fallback RISC-V 64 bytes])
|
||||||
|
AC_DEFINE([LT_SMP_CACHE_BYTES], 64, [Fallback 64-byte alignment for Linux RISC-V hardware.])
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
AC_MSG_RESULT([unrecognized CPU arch on Linux header fallback])
|
AC_MSG_RESULT([unrecognized CPU arch on Linux header fallback])
|
||||||
AC_MSG_FAILURE([Unrecognized CPU architecture ($host_cpu) on Linux fallback path. Aborting build.])
|
AC_MSG_FAILURE([Unrecognized CPU architecture ($host_cpu) on Linux fallback path. Aborting build.])
|
||||||
|
|||||||
@@ -107,10 +107,10 @@ DownloadFactory::receive_load() {
|
|||||||
// Http handling here.
|
// Http handling here.
|
||||||
m_stream.reset(new std::stringstream);
|
m_stream.reset(new std::stringstream);
|
||||||
|
|
||||||
HttpQueue::iterator itr = m_manager->http_queue()->insert(m_uri, m_stream);
|
m_manager->http_queue()->insert(m_uri, m_stream,
|
||||||
|
[this]() { receive_loaded(); },
|
||||||
itr->add_done_slot(torrent::this_thread::thread(), [this]() { receive_loaded(); });
|
[this](const std::string& error) { receive_failed(error); }
|
||||||
itr->add_failed_slot(torrent::this_thread::thread(), [this](const std::string& error) { receive_failed(error); });
|
);
|
||||||
|
|
||||||
m_variables["tied_to_file"] = (int64_t)false;
|
m_variables["tied_to_file"] = (int64_t)false;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
HttpQueue::iterator
|
HttpQueue::iterator
|
||||||
HttpQueue::insert(const std::string& url, std::shared_ptr<std::ostream> stream) {
|
HttpQueue::insert(const std::string& url, std::shared_ptr<std::ostream> stream,
|
||||||
|
std::function<void()> done_fn, std::function<void(const std::string&)> failed_fn) {
|
||||||
auto itr = base_type::insert(end(), torrent::net::HttpGet(url, stream));
|
auto itr = base_type::insert(end(), torrent::net::HttpGet(url, stream));
|
||||||
|
|
||||||
itr->set_max_file_size(15 << 20);
|
itr->set_max_file_size(15 << 20);
|
||||||
@@ -18,9 +19,12 @@ HttpQueue::insert(const std::string& url, std::shared_ptr<std::ostream> stream)
|
|||||||
for (auto& slot : m_signal_insert)
|
for (auto& slot : m_signal_insert)
|
||||||
slot(*itr);
|
slot(*itr);
|
||||||
|
|
||||||
itr->add_done_slot(torrent::this_thread::thread(), [this, itr]() { 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); });
|
itr->add_failed_slot(torrent::this_thread::thread(), [this, itr](auto) { erase(itr); });
|
||||||
|
|
||||||
|
itr->add_done_slot(torrent::this_thread::thread(), std::move(done_fn));
|
||||||
|
itr->add_failed_slot(torrent::this_thread::thread(), std::move(failed_fn));
|
||||||
|
|
||||||
// TODO: Downloading http torrents doesn't seem to work.
|
// TODO: Downloading http torrents doesn't seem to work.
|
||||||
// TODO: Quitting no longer works.
|
// TODO: Quitting no longer works.
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public:
|
|||||||
//
|
//
|
||||||
// Consider adding a flag to indicate whetever HttpQueue should
|
// Consider adding a flag to indicate whetever HttpQueue should
|
||||||
// delete the stream.
|
// delete the stream.
|
||||||
iterator insert(const std::string& url, std::shared_ptr<std::ostream> stream);
|
iterator insert(const std::string& url, std::shared_ptr<std::ostream> stream,
|
||||||
|
std::function<void()> done_fn, std::function<void(const std::string&)> failed_fn);
|
||||||
void erase(iterator itr);
|
void erase(iterator itr);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
+26
-24
@@ -8,6 +8,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <torrent/net/fd.h>
|
||||||
|
#include <torrent/system/system.h>
|
||||||
#include <torrent/system/thread.h>
|
#include <torrent/system/thread.h>
|
||||||
|
|
||||||
#include "exec_file.h"
|
#include "exec_file.h"
|
||||||
@@ -46,19 +48,11 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
|||||||
posix_spawnattr_t attr;
|
posix_spawnattr_t attr;
|
||||||
posix_spawnattr_init(&attr);
|
posix_spawnattr_init(&attr);
|
||||||
|
|
||||||
short spawn_flags = 0;
|
|
||||||
|
|
||||||
// Try to avoid leaking open fds to the spawned process. Prefer POSIX_SPAWN_CLOEXEC_DEFAULT
|
// Try to avoid leaking open fds to the spawned process. Prefer POSIX_SPAWN_CLOEXEC_DEFAULT
|
||||||
// (macOS-only) or posix_spawn_file_actions_addclosefrom_np (glibc >= 2.34, FreeBSD >= 13.1).
|
// (macOS-only) or posix_spawn_file_actions_addclosefrom_np (glibc >= 2.34, FreeBSD >= 13.1).
|
||||||
//
|
//
|
||||||
// Other platforms like musl libc, OpenBSD and NetBSD must rely on explicit O_CLOEXEC.
|
// Other platforms like musl libc, OpenBSD and NetBSD must rely on explicit O_CLOEXEC.
|
||||||
|
|
||||||
#if defined(POSIX_SPAWN_CLOEXEC_DEFAULT)
|
|
||||||
spawn_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
|
|
||||||
#elif defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP)
|
|
||||||
posix_spawn_file_actions_addclosefrom_np(&actions, 3);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Handle standard input redirection (/dev/null), posix_spawn_file_actions_addopen handles opening
|
// Handle standard input redirection (/dev/null), posix_spawn_file_actions_addopen handles opening
|
||||||
// and dup2 natively
|
// and dup2 natively
|
||||||
if (posix_spawn_file_actions_addopen(&actions, 0, "/dev/null", O_RDWR, 0) != 0) {
|
if (posix_spawn_file_actions_addopen(&actions, 0, "/dev/null", O_RDWR, 0) != 0) {
|
||||||
@@ -66,18 +60,18 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
|||||||
posix_spawn_file_actions_addclose(&actions, 0);
|
posix_spawn_file_actions_addclose(&actions, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int pipe_fd[2] = {-1, -1};
|
int pipe_0 = -1;
|
||||||
|
int pipe_1 = -1;
|
||||||
if ((flags & flag_capture) && pipe(pipe_fd))
|
|
||||||
throw torrent::input_error("ExecFile::execute(...) Pipe creation failed.");
|
|
||||||
|
|
||||||
// Handle standard output redirection
|
// Handle standard output redirection
|
||||||
if (flags & flag_capture) {
|
if (flags & flag_capture) {
|
||||||
posix_spawn_file_actions_adddup2(&actions, pipe_fd[1], 1);
|
torrent::fd_open_pipe(pipe_0, pipe_1);
|
||||||
|
|
||||||
|
posix_spawn_file_actions_adddup2(&actions, pipe_1, 1);
|
||||||
|
|
||||||
// Ensure the write end of the pipe is closed in the child after duplicating.
|
// Ensure the write end of the pipe is closed in the child after duplicating.
|
||||||
posix_spawn_file_actions_addclose(&actions, pipe_fd[1]);
|
posix_spawn_file_actions_addclose(&actions, pipe_0);
|
||||||
posix_spawn_file_actions_addclose(&actions, pipe_fd[0]);
|
posix_spawn_file_actions_addclose(&actions, pipe_1);
|
||||||
|
|
||||||
} else if (m_log_fd != -1) {
|
} else if (m_log_fd != -1) {
|
||||||
posix_spawn_file_actions_adddup2(&actions, m_log_fd, 1);
|
posix_spawn_file_actions_adddup2(&actions, m_log_fd, 1);
|
||||||
@@ -92,6 +86,14 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
|||||||
posix_spawn_file_actions_addopen(&actions, 2, "/dev/null", O_RDWR, 0);
|
posix_spawn_file_actions_addopen(&actions, 2, "/dev/null", O_RDWR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short spawn_flags = 0;
|
||||||
|
|
||||||
|
#if defined(POSIX_SPAWN_CLOEXEC_DEFAULT)
|
||||||
|
spawn_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
|
||||||
|
#elif defined(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSEFROM_NP)
|
||||||
|
posix_spawn_file_actions_addclosefrom_np(&actions, 3);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (flags & flag_background) {
|
if (flags & flag_background) {
|
||||||
#ifdef POSIX_SPAWN_SETSID
|
#ifdef POSIX_SPAWN_SETSID
|
||||||
spawn_flags |= POSIX_SPAWN_SETSID;
|
spawn_flags |= POSIX_SPAWN_SETSID;
|
||||||
@@ -110,31 +112,31 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
|||||||
posix_spawnattr_destroy(&attr);
|
posix_spawnattr_destroy(&attr);
|
||||||
|
|
||||||
if (spawn_status != 0) {
|
if (spawn_status != 0) {
|
||||||
if (pipe_fd[0] != -1)
|
if (pipe_0 != -1)
|
||||||
::close(pipe_fd[0]);
|
torrent::fd_close(pipe_0);
|
||||||
|
|
||||||
if (pipe_fd[1] != -1)
|
if (pipe_1 != -1)
|
||||||
::close(pipe_fd[1]);
|
torrent::fd_close(pipe_1);
|
||||||
|
|
||||||
throw torrent::input_error("ExecFile::execute(...) posix_spawn failed: " + std::string(std::strerror(spawn_status)));
|
throw torrent::input_error("ExecFile::execute() posix_spawn failed: " + torrent::system::errno_enum_str(spawn_status));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & flag_capture) {
|
if (flags & flag_capture) {
|
||||||
m_capture = std::string();
|
m_capture = std::string();
|
||||||
::close(pipe_fd[1]);
|
torrent::fd_close(pipe_1);
|
||||||
|
|
||||||
char buffer[4096];
|
char buffer[4096];
|
||||||
ssize_t length;
|
ssize_t length;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
length = read(pipe_fd[0], buffer, sizeof(buffer));
|
length = read(pipe_0, buffer, sizeof(buffer));
|
||||||
|
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
m_capture += std::string(buffer, length);
|
m_capture += std::string(buffer, length);
|
||||||
|
|
||||||
} while (length > 0);
|
} while (length > 0);
|
||||||
|
|
||||||
::close(pipe_fd[0]);
|
torrent::fd_close(pipe_0);
|
||||||
|
|
||||||
if (m_log_fd != -1) {
|
if (m_log_fd != -1) {
|
||||||
result = write(m_log_fd, "Captured output:\n", sizeof("Captured output:\n"));
|
result = write(m_log_fd, "Captured output:\n", sizeof("Captured output:\n"));
|
||||||
@@ -151,7 +153,7 @@ ExecFile::execute(const char* file, char* const* argv, int flags) {
|
|||||||
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
while (waitpid(child_pid, &status, 0) == -1) {
|
while (::waitpid(child_pid, &status, 0) == -1) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user