aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn/transport/interfaces/socket_producer.cc
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-07-08 15:00:58 +0200
committerMauro Sardara <msardara@cisco.com>2019-07-08 16:45:04 +0200
commit63422dfdcb1cd6827e76440cc147c9eac415952a (patch)
treeaeafaffb0e1f7a68c823611609e21983f51f5d0e /libtransport/src/hicn/transport/interfaces/socket_producer.cc
parent87cd4b4d22a08f1b56cd067770a29bcb05ebb845 (diff)
[HICN-242] Perform only one allocation for the whole buffer passed to produce()
Change-Id: Ib4628d0a7711e2d7175b3dbb5c152dd22616ff32 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/interfaces/socket_producer.cc')
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.cc27
1 files changed, 18 insertions, 9 deletions
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.cc b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
index c85b8af32..9ca004c41 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.cc
+++ b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
@@ -22,6 +22,8 @@ namespace transport {
namespace interface {
+namespace details {}
+
typedef std::chrono::time_point<std::chrono::steady_clock> Time;
typedef std::chrono::microseconds TimeDuration;
@@ -133,13 +135,15 @@ void ProducerSocket::produce(ContentObject &content_object) {
portal_->sendContentObject(content_object);
}
-uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
- size_t buffer_size, bool is_last,
- uint32_t start_offset) {
- if (TRANSPORT_EXPECT_FALSE(buffer_size == 0)) {
+uint32_t ProducerSocket::produce(Name content_name,
+ std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last, uint32_t start_offset) {
+ if (TRANSPORT_EXPECT_FALSE(buffer->length() == 0)) {
return 0;
}
+ auto buffer_size = buffer->length();
+
const std::size_t hash_size = 32;
int bytes_segmented = 0;
@@ -198,6 +202,8 @@ uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
number_of_segments++;
}
+ // TODO allocate space for all the headers
+
if (making_manifest_) {
auto segment_in_manifest = static_cast<float>(
std::floor(double(data_packet_size_ - manifest_header_size -
@@ -267,9 +273,11 @@ uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
content_name.setSuffix(current_segment), format);
content_object->setLifetime(content_object_expiry_time_);
- if (packaged_segments == number_of_segments - 1) {
- content_object->appendPayload(&buf[bytes_segmented],
- buffer_size - bytes_segmented);
+ auto b = buffer->cloneOne();
+ b->trimStart(free_space_for_content * packaged_segments);
+ b->trimEnd(b->length());
+ if (TRANSPORT_EXPECT_FALSE(packaged_segments == number_of_segments - 1)) {
+ b->append(buffer_size - bytes_segmented);
bytes_segmented += (int)(buffer_size - bytes_segmented);
if (is_last && making_manifest_) {
@@ -279,11 +287,12 @@ uint32_t ProducerSocket::produce(Name content_name, const uint8_t *buf,
}
} else {
- content_object->appendPayload(&buf[bytes_segmented],
- free_space_for_content);
+ b->append(free_space_for_content);
bytes_segmented += (int)(free_space_for_content);
}
+ content_object->appendPayload(std::move(b));
+
if (making_manifest_) {
using namespace std::chrono_literals;
utils::CryptoHash hash = content_object->computeDigest(hash_algorithm_);