aboutsummaryrefslogtreecommitdiffstats
path: root/apps/http-proxy/src
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-04-03 17:02:21 +0200
committerMauro Sardara <msardara@cisco.com>2019-04-03 18:27:00 +0200
commitf22d37b98032b94fc5b63daff296017a7b611fa8 (patch)
tree15ac6601a44061fa418048c985cb936a97c352a3 /apps/http-proxy/src
parentfc938965a323d0865faf1fc93e375cdfbb66aa7b (diff)
[HICN-165] Http proxy: segment headers and payload in 2 different steps.
Change-Id: Ic4f6d1bc693d1170df02b470e8b384b51567acf3 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'apps/http-proxy/src')
-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
3 files changed, 22 insertions, 24 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();
}