Compare commits

...

2 Commits

Author SHA1 Message Date
rakshasa 39f186e523 Tagged release 0.16.8. 2026-03-15 15:43:32 +01:00
Jari Sundell 70e6964823 Fixed various SCGI issues. 2026-03-10 23:25:28 +09:00
4 changed files with 42 additions and 16 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
m4_pattern_allow([PKG_CHECK_EXISTS])
AC_INIT([rtorrent],[0.16.7],[sundell.software@gmail.com])
AC_INIT([rtorrent],[0.16.8],[sundell.software@gmail.com])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIRS([scripts])
@@ -48,7 +48,7 @@ if test "x$ax_cv_ncursesw" != xyes && test "x$ax_cv_ncurses" != xyes; then
fi
PKG_CHECK_MODULES([CPPUNIT], [cppunit],, [no_cppunit="yes"])
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.7])
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.8])
AC_LANG_PUSH(C++)
TORRENT_WITH_XMLRPC_C
+29 -8
View File
@@ -1,5 +1,6 @@
#include "config.h"
#include <algorithm>
#include <cassert>
#include <unistd.h>
#include <sys/un.h>
@@ -20,6 +21,12 @@
namespace rpc {
SCgi::SCgi() {
std::generate(m_tasks.begin(), m_tasks.end(), []() { return std::make_unique<SCgiTask>(); });
m_current = m_tasks.begin();
}
SCgi::~SCgi() {
assert(!is_open() && "SCgi::~SCgi() called while open");
}
@@ -106,9 +113,10 @@ SCgi::stop() {
if (!is_open())
return;
for (SCgiTask* itr = m_task, *last = m_task + max_tasks; itr != last; ++itr)
for (auto& itr : m_tasks) {
if (itr->is_open())
itr->close();
}
torrent::runtime::socket_manager()->close_event_or_throw(this, [this]() {
torrent::this_thread::poll()->remove_and_close(this);
@@ -125,10 +133,19 @@ SCgi::stop() {
void
SCgi::event_read() {
while (true) {
auto* task = std::find_if(m_task, m_task + max_tasks, std::mem_fn(&SCgiTask::is_available));
if (m_current < m_tasks.begin() || m_current >= m_tasks.end())
throw torrent::internal_error("SCgi::event_read() m_current is out of bounds");
if (task == m_task + max_tasks) {
while (true) {
// TODO: Optimize this by keeping track of count.
auto prev = m_current;
m_current = std::find_if(m_current + 1, m_tasks.end(), [](const auto& task) { return !task->is_open(); });
if (m_current == m_tasks.end())
m_current = std::find_if(m_tasks.begin(), prev, [](const auto& task) { return !task->is_open(); });
if (m_current == prev) {
// TODO: Currently just close, although we should remove ourselves from read.
int fd = torrent::fd_accept(file_descriptor());
@@ -138,11 +155,15 @@ SCgi::event_read() {
continue;
}
auto open_func = [this, task]() {
auto open_func = [this, task = m_current->get()]() {
int fd = torrent::fd_accept(file_descriptor());
if (fd == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
return;
// Force a new event_read() call just to be sure we don't enter an infinite loop.
if (errno == ECONNABORTED)
return;
throw torrent::resource_error("Listener port accept() failed: " + std::string(std::strerror(errno)));
@@ -151,11 +172,11 @@ SCgi::event_read() {
task->open(this, fd);
};
auto cleanup_func = [task]() {
auto cleanup_func = [task = m_current->get()]() {
task->cancel_open();
};
bool result = torrent::runtime::socket_manager()->open_event_or_cleanup(task, open_func, cleanup_func);
bool result = torrent::runtime::socket_manager()->open_event_or_cleanup(m_current->get(), open_func, cleanup_func);
if (!result)
break;
+8 -1
View File
@@ -1,7 +1,9 @@
#ifndef RTORRENT_RPC_SCGI_H
#define RTORRENT_RPC_SCGI_H
#include <array>
#include <functional>
#include <memory>
#include <torrent/event.h>
#include "rpc/scgi_task.h"
@@ -12,6 +14,7 @@ class SCgi : public torrent::Event {
public:
static const int max_tasks = 100;
SCgi();
~SCgi() override;
const char* type_name() const override { return "scgi"; }
@@ -33,11 +36,15 @@ public:
void event_error() override;
private:
using task_list = std::array<std::unique_ptr<SCgiTask>, max_tasks>;
void open(sockaddr* sa, unsigned int length);
std::string m_path;
int m_logFd{-1};
SCgiTask m_task[max_tasks];
task_list m_tasks;
task_list::iterator m_current;
};
}
+3 -5
View File
@@ -43,12 +43,10 @@ SCgiTask::cancel_open() {
if (!is_open())
return;
torrent::runtime::socket_manager()->close_event_or_throw(this, [this]() {
torrent::this_thread::poll()->remove_and_close(this);
torrent::this_thread::poll()->remove_and_close(this);
torrent::fd_close(file_descriptor());
set_file_descriptor(-1);
});
torrent::fd_close(file_descriptor());
set_file_descriptor(-1);
};
void