mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-16 15:12:30 +00:00
* Added "http_ca{path/cert}" options. Patch by Johan Gunnarsson,
public domain. * Minor bugfixes to SCgi. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@907 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+11
-3
@@ -55,12 +55,19 @@ SCgi::~SCgi() {
|
||||
if (!get_fd().is_valid())
|
||||
return;
|
||||
|
||||
for (SCgiTask* itr = m_task, *last = m_task + max_tasks; itr != last; ++itr)
|
||||
if (itr->is_open())
|
||||
itr->close();
|
||||
|
||||
control->poll()->remove_read(this);
|
||||
control->poll()->remove_error(this);
|
||||
control->poll()->close(this);
|
||||
|
||||
get_fd().close();
|
||||
get_fd().clear();
|
||||
|
||||
if (!m_path.empty())
|
||||
::unlink(m_path.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -90,6 +97,7 @@ SCgi::open_named(const std::string& filename) {
|
||||
throw torrent::resource_error("Could not open socket for listening.");
|
||||
|
||||
open(sa, offsetof(struct sockaddr_un, sun_path) + filename.size() + 1);
|
||||
m_path = filename;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -98,7 +106,7 @@ SCgi::open(void* sa, unsigned int length) {
|
||||
if (!get_fd().set_nonblock() ||
|
||||
!get_fd().set_reuse_address(true) ||
|
||||
!get_fd().bind(*reinterpret_cast<rak::socket_address*>(sa), length) ||
|
||||
!get_fd().listen(10))
|
||||
!get_fd().listen(max_tasks))
|
||||
throw torrent::resource_error("Could not prepare socket for listening.");
|
||||
|
||||
torrent::connection_manager()->inc_socket_count();
|
||||
@@ -121,9 +129,9 @@ SCgi::event_read() {
|
||||
utils::SocketFd fd;
|
||||
|
||||
while ((fd = get_fd().accept(&sa)).is_valid()) {
|
||||
SCgiTask* task = std::find_if(m_task, m_task + 10, std::mem_fun_ref(&SCgiTask::is_available));
|
||||
SCgiTask* task = std::find_if(m_task, m_task + max_tasks, std::mem_fun_ref(&SCgiTask::is_available));
|
||||
|
||||
if (task == task + 10) {
|
||||
if (task == task + max_tasks) {
|
||||
// Ergh... just closing for now.
|
||||
fd.close();
|
||||
continue;
|
||||
|
||||
+5
-3
@@ -54,9 +54,13 @@ public:
|
||||
typedef rak::function2<bool, const char*, uint32_t> slot_write;
|
||||
typedef rak::function3<bool, const char*, uint32_t, slot_write> slot_process;
|
||||
|
||||
static const int max_tasks = 10;
|
||||
|
||||
SCgi() {}
|
||||
virtual ~SCgi();
|
||||
|
||||
void open(void* sa, unsigned int length);
|
||||
|
||||
void open_port(uint16_t port);
|
||||
void open_named(const std::string& filename);
|
||||
|
||||
@@ -73,11 +77,9 @@ public:
|
||||
utils::SocketFd& get_fd() { return *reinterpret_cast<utils::SocketFd*>(&m_fileDesc); }
|
||||
|
||||
private:
|
||||
void open(void* sa, unsigned int length);
|
||||
|
||||
std::string m_path;
|
||||
slot_process m_slotProcess;
|
||||
SCgiTask m_task[10];
|
||||
SCgiTask m_task[max_tasks];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+19
-7
@@ -48,6 +48,12 @@
|
||||
#include "globals.h"
|
||||
#include "scgi.h"
|
||||
|
||||
// Test:
|
||||
// #include "core/manager.h"
|
||||
// #include <rak/timer.h>
|
||||
|
||||
// static rak::timer scgiTimer;
|
||||
|
||||
namespace rpc {
|
||||
|
||||
void
|
||||
@@ -60,6 +66,8 @@ SCgiTask::open(SCgi* parent, int fd) {
|
||||
control->poll()->open(this);
|
||||
control->poll()->insert_read(this);
|
||||
control->poll()->insert_error(this);
|
||||
|
||||
scgiTimer = rak::timer::current();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -77,6 +85,11 @@ SCgiTask::close() {
|
||||
|
||||
delete [] m_buffer;
|
||||
m_buffer = NULL;
|
||||
|
||||
// Test
|
||||
// char buffer[512];
|
||||
// sprintf(buffer, "SCgi system call processed: %i", (int)(rak::timer::current() - scgiTimer).usec());
|
||||
// control->core()->push_log(std::string(buffer));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -162,19 +175,18 @@ SCgiTask::event_error() {
|
||||
|
||||
bool
|
||||
SCgiTask::receive_write(const char* buffer, uint32_t length) {
|
||||
if (length + 44 > m_bufferSize) {
|
||||
if (length + 256 > m_bufferSize) {
|
||||
delete [] m_buffer;
|
||||
m_buffer = new char[length + 44];
|
||||
m_buffer = new char[length + 256];
|
||||
}
|
||||
|
||||
// Try writing as much as possible from here, before copying
|
||||
// anything.
|
||||
// Who ever bothers to check the return value?
|
||||
int headerSize = sprintf(m_buffer, "Status: 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %i\r\n\r\n", length);
|
||||
|
||||
m_position = m_buffer;
|
||||
m_bufferSize = length + 44;
|
||||
m_bufferSize = length + headerSize;
|
||||
|
||||
std::memcpy(m_buffer, "Status: 200 OK\r\nContent-Type: text/plain\r\n\r\n", 44);
|
||||
std::memcpy(m_buffer + 44, buffer, length);
|
||||
std::memcpy(m_buffer + headerSize, buffer, length);
|
||||
|
||||
event_write();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user