aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc
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 /libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc
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>
Diffstat (limited to 'libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc')
-rw-r--r--libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc25
1 files changed, 14 insertions, 11 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;
}
}
}