mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-10 04:02:30 +00:00
* Threaded XMLRPC support. Sponsored by Xirvik.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1123 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+13
-7
@@ -49,6 +49,7 @@
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
#include "scgi.h"
|
||||
#include "parse_commands.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
@@ -118,16 +119,16 @@ SCgi::open(void* sa, unsigned int length) {
|
||||
|
||||
void
|
||||
SCgi::activate() {
|
||||
main_thread->poll()->open(this);
|
||||
main_thread->poll()->insert_read(this);
|
||||
main_thread->poll()->insert_error(this);
|
||||
worker_thread->poll()->open(this);
|
||||
worker_thread->poll()->insert_read(this);
|
||||
worker_thread->poll()->insert_error(this);
|
||||
}
|
||||
|
||||
void
|
||||
SCgi::deactivate() {
|
||||
main_thread->poll()->remove_read(this);
|
||||
main_thread->poll()->remove_error(this);
|
||||
main_thread->poll()->close(this);
|
||||
worker_thread->poll()->remove_read(this);
|
||||
worker_thread->poll()->remove_error(this);
|
||||
worker_thread->poll()->close(this);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -163,7 +164,12 @@ SCgi::receive_call(SCgiTask* task, const char* buffer, uint32_t length) {
|
||||
slot_write slotWrite;
|
||||
slotWrite.set(rak::mem_fn(task, &SCgiTask::receive_write));
|
||||
|
||||
return m_slotProcess(buffer, length, slotWrite);
|
||||
ThreadBase::acquire_global_lock();
|
||||
// bool result = m_slotProcess(buffer, length, slotWrite);
|
||||
bool result = xmlrpc.process(buffer, length, slotWrite);
|
||||
ThreadBase::release_global_lock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-4
@@ -49,13 +49,14 @@ namespace utils {
|
||||
|
||||
namespace rpc {
|
||||
|
||||
class SCgi : public torrent::Event {
|
||||
class lt_cacheline_aligned SCgi : public torrent::Event {
|
||||
public:
|
||||
typedef rak::function2<bool, const char*, uint32_t> slot_write;
|
||||
typedef rak::function3<bool, const char*, uint32_t, slot_write> slot_process;
|
||||
// typedef rak::function3<bool, const char*, uint32_t, slot_write> slot_process;
|
||||
|
||||
static const int max_tasks = 10;
|
||||
|
||||
// Global lock:
|
||||
SCgi() : m_logFd(-1) {}
|
||||
virtual ~SCgi();
|
||||
|
||||
@@ -67,11 +68,12 @@ public:
|
||||
|
||||
const std::string& path() const { return m_path; }
|
||||
|
||||
void set_slot_process(slot_process::base_type* s) { m_slotProcess.set(s); }
|
||||
// void set_slot_process(slot_process::base_type* s) { m_slotProcess.set(s); }
|
||||
|
||||
int log_fd() const { return m_logFd; }
|
||||
void set_log_fd(int fd) { m_logFd = fd; }
|
||||
|
||||
// Thread local:
|
||||
virtual void event_read();
|
||||
virtual void event_write();
|
||||
virtual void event_error();
|
||||
@@ -85,7 +87,7 @@ private:
|
||||
|
||||
std::string m_path;
|
||||
int m_logFd;
|
||||
slot_process m_slotProcess;
|
||||
// slot_process m_slotProcess;
|
||||
SCgiTask m_task[max_tasks];
|
||||
};
|
||||
|
||||
|
||||
+12
-11
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <rak/allocators.h>
|
||||
#include <rak/error_number.h>
|
||||
#include <cstdio>
|
||||
#include <sys/types.h>
|
||||
@@ -60,7 +61,7 @@ namespace rpc {
|
||||
// If bufferSize is zero then memcpy won't do anything.
|
||||
inline void
|
||||
SCgiTask::realloc_buffer(uint32_t size, const char* buffer, uint32_t bufferSize) {
|
||||
char* tmp = new char[size];
|
||||
char* tmp = rak::cacheline_allocator<char>::alloc_size(size);
|
||||
|
||||
std::memcpy(tmp, buffer, bufferSize);
|
||||
delete [] m_buffer;
|
||||
@@ -71,13 +72,13 @@ void
|
||||
SCgiTask::open(SCgi* parent, int fd) {
|
||||
m_parent = parent;
|
||||
m_fileDesc = fd;
|
||||
m_buffer = new char[(m_bufferSize = default_buffer_size) + 1];
|
||||
m_buffer = rak::cacheline_allocator<char>::alloc_size((m_bufferSize = default_buffer_size) + 1);
|
||||
m_position = m_buffer;
|
||||
m_body = NULL;
|
||||
|
||||
main_thread->poll()->open(this);
|
||||
main_thread->poll()->insert_read(this);
|
||||
main_thread->poll()->insert_error(this);
|
||||
worker_thread->poll()->open(this);
|
||||
worker_thread->poll()->insert_read(this);
|
||||
worker_thread->poll()->insert_error(this);
|
||||
|
||||
// scgiTimer = rak::timer::current();
|
||||
}
|
||||
@@ -87,10 +88,10 @@ SCgiTask::close() {
|
||||
if (!get_fd().is_valid())
|
||||
return;
|
||||
|
||||
main_thread->poll()->remove_read(this);
|
||||
main_thread->poll()->remove_write(this);
|
||||
main_thread->poll()->remove_error(this);
|
||||
main_thread->poll()->close(this);
|
||||
worker_thread->poll()->remove_read(this);
|
||||
worker_thread->poll()->remove_write(this);
|
||||
worker_thread->poll()->remove_error(this);
|
||||
worker_thread->poll()->close(this);
|
||||
|
||||
get_fd().close();
|
||||
get_fd().clear();
|
||||
@@ -171,8 +172,8 @@ SCgiTask::event_read() {
|
||||
if ((unsigned int)std::distance(m_buffer, m_position) != m_bufferSize)
|
||||
return;
|
||||
|
||||
main_thread->poll()->remove_read(this);
|
||||
main_thread->poll()->insert_write(this);
|
||||
worker_thread->poll()->remove_read(this);
|
||||
worker_thread->poll()->insert_write(this);
|
||||
|
||||
if (m_parent->log_fd() >= 0) {
|
||||
// Clean up logging, this is just plain ugly...
|
||||
|
||||
Reference in New Issue
Block a user