From 6d7704c1b497341fd6dd3c27e3f64d0db062ccc2 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Mon, 4 Feb 2019 11:06:18 +0100 Subject: [HICN-11] Rework on transport protocols improving components modularity Change-Id: I6683ec5b494238dc93591c103d25275e89b9f267 Signed-off-by: Mauro Sardara --- .../transport/interfaces/full_duplex_socket.cc | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc') diff --git a/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc b/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc index 0a091d94e..3bb51e72e 100644 --- a/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc +++ b/libtransport/src/hicn/transport/interfaces/full_duplex_socket.cc @@ -15,7 +15,6 @@ #include #include -#include #include @@ -45,7 +44,7 @@ AsyncFullDuplexSocket::AsyncFullDuplexSocket(const Prefix &locator, internal_signal_callback_(new OnSignalCallback(*this)), send_timeout_milliseconds_(~0), counters_({0}), - receive_buffer_(std::make_shared>()) { + receive_buffer_(ContentBuffer()) { using namespace transport; using namespace std::placeholders; producer_->registerPrefix(locator); @@ -64,11 +63,10 @@ AsyncFullDuplexSocket::AsyncFullDuplexSocket(const Prefix &locator, producer_->connect(); - consumer_->setSocketOption( - ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY, - (ConsumerContentObjectVerificationCallback)[](ConsumerSocket & s, - const ContentObject &c) - ->bool { return true; }); + consumer_->setSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY, + (ConsumerContentObjectVerificationCallback)[]( + ConsumerSocket & s, const ContentObject &c) + ->bool { return true; }); ConsumerContentCallback consumer_callback = std::bind(&AsyncFullDuplexSocket::onContentRetrieved, this, _1, _2, _3); @@ -200,17 +198,18 @@ void AsyncFullDuplexSocket::write(WriteCallback *callback, const void *buf, } } -void AsyncFullDuplexSocket::write( - WriteCallback *callback, utils::SharableVector &&output_buffer, - const PublicationOptions &options, WriteFlags flags) { +void AsyncFullDuplexSocket::write(WriteCallback *callback, + ContentBuffer &&output_buffer, + const PublicationOptions &options, + WriteFlags flags) { using namespace transport; // 1 asynchronously write the content. I assume here the // buffer contains the whole application frame. FIXME: check // if this is true and fix it accordingly - std::cout << "Size of the PAYLOAD: " << output_buffer.size() << std::endl; + std::cout << "Size of the PAYLOAD: " << output_buffer->size() << std::endl; - if (output_buffer.size() > + if (output_buffer->size() > core::Packet::default_mtu - sizeof(PayloadMessage)) { TRANSPORT_LOGI("Producing content with name %s", options.name.toString().c_str()); @@ -218,8 +217,8 @@ void AsyncFullDuplexSocket::write( signalProductionToSubscribers(options.name); } else { TRANSPORT_LOGI("Sending payload through interest"); - piggybackPayloadToSubscribers(options.name, &output_buffer[0], - output_buffer.size()); + piggybackPayloadToSubscribers(options.name, &(*output_buffer)[0], + output_buffer->size()); } } @@ -350,10 +349,10 @@ AsyncFullDuplexSocket::decodeSynchronizationMessage( // The interest contains the payload directly. // We saved one round trip :) - auto buffer = std::make_shared>(); + auto buffer = ContentBuffer(); const uint8_t *data = mesg.data() + sizeof(PayloadMessage); buffer->assign(data, data + mesg.length() - sizeof(PayloadMessage)); - read_callback_->readBufferAvailable(std::move(*buffer)); + read_callback_->readBufferAvailable(std::move(buffer)); return createAck(); } default: { @@ -401,7 +400,7 @@ void AsyncFullDuplexSocket::onContentRetrieved(ConsumerSocket &s, TRANSPORT_LOGI("Received content with size %zu", size); if (!ec) { - read_callback_->readBufferAvailable(std::move(*receive_buffer_)); + read_callback_->readBufferAvailable(std::move(receive_buffer_)); } else { TRANSPORT_LOGE("Error retrieving content."); } -- cgit 1.2.3-korg