From 53fbb7acf328179d6cfa98ee719048af77ba2321 Mon Sep 17 00:00:00 2001 From: void Date: Mon, 23 Nov 2009 12:13:51 +0100 Subject: [PATCH] Fixed the keep alive issue --- source/client.cpp | 18 +++++++++++++----- source/module_manager.cpp | 6 +++--- source/request.cpp | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/source/client.cpp b/source/client.cpp index 3aca03b..7fa1fa0 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -35,12 +35,13 @@ void http_server_client::initialise() void http_server_client::read() { std::cout << "Reading" << std::endl; + socket.async_read_some(boost::asio::buffer(read_buffer, read_buffer_size), boost::bind(&http_server_client::read_event, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } void http_server_client::write(std::string const & data) { - std::cout << "Writing:" << std::endl << data << std::endl; + //std::cout << "Writing:" << std::endl << data << std::endl; char * write_buffer = new char[data.size()]; std::memcpy(write_buffer, data.c_str(), data.size()); @@ -60,10 +61,11 @@ void http_server_client::terminate() void http_server_client::read_event(boost::system::error_code const & error, std::size_t bytes_in_buffer) { - std::cout << "Read event" << std::endl; + //std::cout << "Read event" << std::endl; + if(!error) { - std::cout << "Read " << bytes_in_buffer << " bytes:" << std::endl; + std::cout << "Read " << bytes_in_buffer << " bytes" << std::endl; bytes_read += bytes_in_buffer; if(bytes_read > maximal_request_size) @@ -79,7 +81,7 @@ void http_server_client::read_event(boost::system::error_code const & error, std { extended_buffer += new_data; - std::cout << extended_buffer << std::endl; + //std::cout << extended_buffer << std::endl; if(!got_header) { @@ -132,7 +134,7 @@ void http_server_client::read_event(boost::system::error_code const & error, std if(got_header) { std::size_t expected_byte_count = current_request.header_size + current_request.content_length; - std::cout << "Expected byte count: " << current_request.header_size << " + " << current_request.content_length << " = " << expected_byte_count << std::endl; + //std::cout << "Expected byte count: " << current_request.header_size << " + " << current_request.content_length << " = " << expected_byte_count << std::endl; if(bytes_read > expected_byte_count) { std::cout << "Received too many bytes from a client: " << bytes_read << " > " << expected_byte_count << std::endl; @@ -172,7 +174,10 @@ void http_server_client::read_event(boost::system::error_code const & error, std read(); } else + { + std::cout << "Read error" << std::endl; terminate(); + } } void http_server_client::write_event(boost::system::error_code const & error, char * write_buffer) @@ -201,7 +206,10 @@ void http_server_client::write_event(boost::system::error_code const & error, ch } } else + { + std::cout << "Write error" << std::endl; terminate(); + } } bool http_server_client::generate_content(http_request & request, module_result & result, std::string & content) diff --git a/source/module_manager.cpp b/source/module_manager.cpp index 3c4a949..3ec4c2d 100644 --- a/source/module_manager.cpp +++ b/source/module_manager.cpp @@ -52,11 +52,11 @@ bool module_manager::load_modules(std::string const & directory) bool module_manager::process_request(http_request & request, module_result & result) { - std::cout << "module_manager::process_request" << std::endl; + //std::cout << "module_manager::process_request" << std::endl; BOOST_FOREACH(module_entry & entry, module_entries) { - std::cout << entry.name << ":" << std::endl; + //std::cout << entry.name << ": " << std::endl; entry.handler(request, result); @@ -69,7 +69,7 @@ bool module_manager::process_request(http_request & request, module_result & res break; case request_handler_result::success: - std::cout << "Success!" << std::endl; + //std::cout << "Success!" << std::endl; output = true; break; diff --git a/source/request.cpp b/source/request.cpp index 5c1a717..504702b 100644 --- a/source/request.cpp +++ b/source/request.cpp @@ -229,8 +229,8 @@ process_header_result::type process_header(std::string const & input, http_reque string_vector argument_tokens = ail::tokenise(argument, ","); BOOST_FOREACH(std::string token, argument_tokens) { - token = ail::trim(token); - if(token == "Keep-Alive") + token = ail::to_lower(ail::trim(token)); + if(token == "keep-alive") output.keep_alive = true; } } -- 2.11.4.GIT