From 288f00b322b6573c637e5567c528a4ff9ab5bfba Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Tue, 10 Sep 2019 16:29:48 +0200 Subject: [HICN-273] Add zero copy produce() API to RTC producer socket. This API allows to transfer the ownership of the packet from the application to the libtransport, thus avoiding to copy the packet. Change-Id: Ic26b15783648b9e8821f71e47a2d9f5130474510 Signed-off-by: Mauro Sardara --- .../transport/interfaces/rtc_socket_producer.cc | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc') diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc index c726dfda8..6a45019a4 100644 --- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc +++ b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc @@ -24,8 +24,9 @@ #define INIT_PACKET_PRODUCTION_RATE 100 // pps random value (almost 1Mbps) #define STATS_INTERVAL_DURATION 500 // ms #define INTEREST_LIFETIME_REDUCTION_FACTOR 0.8 -#define INACTIVE_TIME 500 //ms without producing before the socket - //is considered inactive +#define INACTIVE_TIME \ + 500 // ms without producing before the socket + // is considered inactive #define MILLI_IN_A_SEC 1000 // ms in a second // NACK HEADER @@ -113,7 +114,9 @@ void RTCProducerSocket::updateStats(uint32_t packet_size, uint64_t now) { } } -void RTCProducerSocket::produce(const uint8_t *buf, size_t buffer_size) { +void RTCProducerSocket::produce(std::unique_ptr &&buffer) { + auto buffer_size = buffer->length(); + if (TRANSPORT_EXPECT_FALSE(buffer_size == 0)) { return; } @@ -137,11 +140,11 @@ void RTCProducerSocket::produce(const uint8_t *buf, size_t buffer_size) { ContentObject content_object(flowName_.setSuffix(currentSeg_)); - auto payload = utils::MemBuf::create(buffer_size + TIMESTAMP_LEN); + auto payload = utils::MemBuf::create(TIMESTAMP_LEN); memcpy(payload->writableData(), &now, TIMESTAMP_LEN); - memcpy(payload->writableData() + TIMESTAMP_LEN, buf, buffer_size); - payload->append(buffer_size + TIMESTAMP_LEN); + payload->append(TIMESTAMP_LEN); + payload->prependChain(std::move(buffer)); content_object.appendPayload(std::move(payload)); content_object.setLifetime(500); // XXX this should be set by the APP @@ -169,14 +172,14 @@ void RTCProducerSocket::onInterest(Interest::Ptr &&interest) { { utils::SpinLock::Acquire locked(lock_); isActive = active_; - if(isActive){ + if (isActive) { uint64_t now = std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()) - .count(); + std::chrono::steady_clock::now().time_since_epoch()) + .count(); if ((now - lastProduced_) > INACTIVE_TIME) { - //socket is inactive + // socket is inactive active_ = false; - isActive = false; + isActive = false; } } } -- cgit 1.2.3-korg