aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-04-04 07:49:39 +0000
committerGerrit Code Review <gerrit@fd.io>2019-04-04 07:49:39 +0000
commit805cfe7b075b4f906a4646211b5aa29a993cb16f (patch)
tree48e1c785490e9f48b0b0d7af4decdab3cebcc13a
parent41878be65785063472c3a69139347efe3952492a (diff)
parentf22d37b98032b94fc5b63daff296017a7b611fa8 (diff)
Merge "[HICN-165] Http proxy: segment headers and payload in 2 different steps."
-rw-r--r--apps/http-proxy/src/ATSConnector.cc42
-rw-r--r--apps/http-proxy/src/ATSConnector.h3
-rw-r--r--apps/http-proxy/src/IcnReceiver.cc1
-rw-r--r--libtransport/src/hicn/transport/http/response.cc2
4 files changed, 23 insertions, 25 deletions
diff --git a/apps/http-proxy/src/ATSConnector.cc b/apps/http-proxy/src/ATSConnector.cc
index 2a2f73c3e..cc41ca219 100644
--- a/apps/http-proxy/src/ATSConnector.cc
+++ b/apps/http-proxy/src/ATSConnector.cc
@@ -35,7 +35,7 @@ ATSConnector::ATSConnector(asio::io_service &io_service,
data_available_(false),
receive_callback_(receive_callback),
on_reconnect_callback_(on_reconnect_callback) {
- header_input_buffer_.prepare(2048);
+ input_buffer_.prepare(buffer_size + 2048);
state_ = ConnectorState::CONNECTING;
doConnect();
}
@@ -99,56 +99,54 @@ void ATSConnector::doWrite() {
void ATSConnector::handleRead(std::error_code ec, std::size_t length,
std::size_t size) {
if (TRANSPORT_EXPECT_TRUE(!ec)) {
- std::size_t bytes_in_buffer = length;
- size -= bytes_in_buffer;
- receive_callback_(input_buffer_, bytes_in_buffer, !size, false);
+ size -= length;
+ const uint8_t *buffer =
+ asio::buffer_cast<const uint8_t *>(input_buffer_.data());
+ receive_callback_(buffer, input_buffer_.size(), !size, false);
+ input_buffer_.consume(input_buffer_.size());
if (!size) {
doReadHeader();
} else {
auto to_read = size >= buffer_size ? buffer_size : size;
asio::async_read(
- socket_, asio::buffer(input_buffer_, to_read),
+ socket_, input_buffer_, asio::transfer_exactly(to_read),
std::bind(&ATSConnector::handleRead, this, std::placeholders::_1,
std::placeholders::_2, size));
}
} else if (ec == asio::error::eof) {
+ input_buffer_.consume(input_buffer_.size());
tryReconnection();
}
}
void ATSConnector::doReadBody(std::size_t size) {
- auto to_read = size >= buffer_size ? buffer_size : size;
+ auto to_read =
+ size >= buffer_size ? (buffer_size - input_buffer_.size()) : size;
asio::async_read(
- socket_, asio::buffer(input_buffer_, to_read),
+ socket_, input_buffer_, asio::transfer_exactly(to_read),
std::bind(&ATSConnector::handleRead, this, std::placeholders::_1,
std::placeholders::_2, size));
}
void ATSConnector::doReadHeader() {
asio::async_read_until(
- socket_, header_input_buffer_, "\r\n\r\n",
+ socket_, input_buffer_, "\r\n\r\n",
[this](std::error_code ec, std::size_t length) {
if (TRANSPORT_EXPECT_TRUE(!ec)) {
- // TRANSPORT_LOGD("Headers received");
-
const uint8_t *buffer =
- asio::buffer_cast<const uint8_t *>(header_input_buffer_.data());
+ asio::buffer_cast<const uint8_t *>(input_buffer_.data());
std::size_t size = HTTPMessageFastParser::hasBody(buffer, length);
- auto additional_bytes = header_input_buffer_.size() - length;
+ auto additional_bytes = input_buffer_.size() - length;
auto bytes_to_read = size - additional_bytes;
- receive_callback_(buffer, header_input_buffer_.size(), !bytes_to_read,
- true);
- header_input_buffer_.consume(header_input_buffer_.size());
-
- if (bytes_to_read) {
- doReadBody(bytes_to_read);
- } else {
- doReadHeader();
- }
+
+ receive_callback_(buffer, length, !size, true);
+ input_buffer_.consume(length);
+
+ doReadBody(bytes_to_read);
} else {
- header_input_buffer_.consume(header_input_buffer_.size());
+ input_buffer_.consume(input_buffer_.size());
tryReconnection();
}
});
diff --git a/apps/http-proxy/src/ATSConnector.h b/apps/http-proxy/src/ATSConnector.h
index be5c2c8d5..aa5662e24 100644
--- a/apps/http-proxy/src/ATSConnector.h
+++ b/apps/http-proxy/src/ATSConnector.h
@@ -83,8 +83,7 @@ class ATSConnector {
BufferQueue write_msgs_;
- asio::streambuf header_input_buffer_;
- uint8_t input_buffer_[buffer_size];
+ asio::streambuf input_buffer_;
bool is_reconnection_;
bool data_available_;
diff --git a/apps/http-proxy/src/IcnReceiver.cc b/apps/http-proxy/src/IcnReceiver.cc
index 76e2bd10b..4ad616168 100644
--- a/apps/http-proxy/src/IcnReceiver.cc
+++ b/apps/http-proxy/src/IcnReceiver.cc
@@ -141,6 +141,7 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data,
uint32_t start_suffix = 0;
if (response_name_queue_.empty()) {
+ std::cerr << "Aborting due tue empty request queue" << std::endl;
abort();
}
diff --git a/libtransport/src/hicn/transport/http/response.cc b/libtransport/src/hicn/transport/http/response.cc
index 0aa9affe8..db7306cca 100644
--- a/libtransport/src/hicn/transport/http/response.cc
+++ b/libtransport/src/hicn/transport/http/response.cc
@@ -49,7 +49,7 @@ bool HTTPResponse::parseHeaders() {
if (it != end()) {
std::stringstream ss;
- ss.str(std::string(begin(), it));
+ ss.str(std::string(begin(), it + 1));
std::string line;
getline(ss, line);