summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-09-10 16:29:48 +0200
committerMauro Sardara <msardara@cisco.com>2019-09-10 14:38:22 +0000
commit288f00b322b6573c637e5567c528a4ff9ab5bfba (patch)
treedb12d2885a974b65e638220b14ffbac8dab6316f
parent822bd391506fd3f0afdc96ea441710fd0787c98b (diff)
[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 <msardara@cisco.com>
-rw-r--r--libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc25
-rw-r--r--libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h2
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.h4
3 files changed, 19 insertions, 12 deletions
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<utils::MemBuf> &&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::milliseconds>(
- 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;
}
}
}
diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
index 29fd15a4e..5b9a23dd7 100644
--- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
+++ b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
@@ -36,7 +36,7 @@ class RTCProducerSocket : public ProducerSocket {
void registerPrefix(const Prefix &producer_namespace) override;
- void produce(const uint8_t *buffer, size_t buffer_size) override;
+ void produce(std::unique_ptr<utils::MemBuf> &&buffer) override;
void onInterest(Interest::Ptr &&interest) override;
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.h b/libtransport/src/hicn/transport/interfaces/socket_producer.h
index cd1c5a374..18adbf4a7 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.h
+++ b/libtransport/src/hicn/transport/interfaces/socket_producer.h
@@ -62,6 +62,10 @@ class ProducerSocket : public Socket<BasePortal>,
void produce(ContentObject &content_object);
virtual void produce(const uint8_t *buffer, size_t buffer_size) {
+ produce(utils::MemBuf::copyBuffer(buffer, buffer_size));
+ }
+
+ virtual void produce(std::unique_ptr<utils::MemBuf> &&buffer) {
// This API is meant to be used just with the RTC producer.
// Here it cannot be used since no name for the content is specified.
throw errors::NotImplementedException();