|
|
@ -1,16 +1,16 @@
|
|
|
|
#include "csoap/http_request_handler.h"
|
|
|
|
#include "webcc/http_request_handler.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "csoap/common.h"
|
|
|
|
#include "webcc/common.h"
|
|
|
|
#include "csoap/http_request.h"
|
|
|
|
#include "webcc/http_request.h"
|
|
|
|
#include "csoap/http_response.h"
|
|
|
|
#include "webcc/http_response.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace csoap {
|
|
|
|
namespace webcc {
|
|
|
|
|
|
|
|
|
|
|
|
void HttpRequestHandler::Enqueue(HttpSessionPtr session) {
|
|
|
|
void HttpRequestHandler::Enqueue(HttpSessionPtr session) {
|
|
|
|
queue_.Push(session);
|
|
|
|
queue_.Push(session);
|
|
|
@ -20,25 +20,25 @@ void HttpRequestHandler::Start(std::size_t count) {
|
|
|
|
assert(count > 0 && workers_.size() == 0);
|
|
|
|
assert(count > 0 && workers_.size() == 0);
|
|
|
|
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < count; ++i) {
|
|
|
|
for (std::size_t i = 0; i < count; ++i) {
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
boost::thread* worker =
|
|
|
|
boost::thread* worker =
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
workers_.create_thread(std::bind(&HttpRequestHandler::WorkerRoutine, this));
|
|
|
|
workers_.create_thread(std::bind(&HttpRequestHandler::WorkerRoutine, this));
|
|
|
|
|
|
|
|
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
std::cout << "Worker is running (thread: " << worker->get_id() << ")\n";
|
|
|
|
std::cout << "Worker is running (thread: " << worker->get_id() << ")\n";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HttpRequestHandler::Stop() {
|
|
|
|
void HttpRequestHandler::Stop() {
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
std::cout << "Stopping workers...\n";
|
|
|
|
std::cout << "Stopping workers...\n";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Close pending sessions.
|
|
|
|
// Close pending sessions.
|
|
|
|
for (HttpSessionPtr conn = queue_.Pop(); conn; conn = queue_.Pop()) {
|
|
|
|
for (HttpSessionPtr conn = queue_.Pop(); conn; conn = queue_.Pop()) {
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
std::cout << "Closing pending session...\n";
|
|
|
|
std::cout << "Closing pending session...\n";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
conn->Stop();
|
|
|
|
conn->Stop();
|
|
|
@ -49,13 +49,13 @@ void HttpRequestHandler::Stop() {
|
|
|
|
|
|
|
|
|
|
|
|
workers_.join_all();
|
|
|
|
workers_.join_all();
|
|
|
|
|
|
|
|
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
std::cout << "All workers have been stopped.\n";
|
|
|
|
std::cout << "All workers have been stopped.\n";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HttpRequestHandler::WorkerRoutine() {
|
|
|
|
void HttpRequestHandler::WorkerRoutine() {
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
boost::thread::id thread_id = boost::this_thread::get_id();
|
|
|
|
boost::thread::id thread_id = boost::this_thread::get_id();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +63,7 @@ void HttpRequestHandler::WorkerRoutine() {
|
|
|
|
HttpSessionPtr session = queue_.PopOrWait();
|
|
|
|
HttpSessionPtr session = queue_.PopOrWait();
|
|
|
|
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
if (!session) {
|
|
|
|
#if CSOAP_DEBUG_OUTPUT
|
|
|
|
#if WEBCC_DEBUG_OUTPUT
|
|
|
|
std::cout << "Worker is going to stop (thread: " << thread_id << ")\n";
|
|
|
|
std::cout << "Worker is going to stop (thread: " << thread_id << ")\n";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
// For stopping next worker.
|
|
|
|
// For stopping next worker.
|
|
|
@ -77,4 +77,4 @@ void HttpRequestHandler::WorkerRoutine() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace csoap
|
|
|
|
} // namespace webcc
|