aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-03-10 15:50:18 +0100
committerMauro Sardara <msardara@cisco.com>2020-03-10 15:57:31 +0100
commit23657bc8a770734a74f73f6d07075130a366ef00 (patch)
treee5c00a85ceca00db9d8926824f7f59de67536972 /libtransport/src
parent01d76a603fba7db5cfb83a1fbc3b369f2e4a4823 (diff)
[HICN-544] Do not block reading incoming messages in memif connector.
Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: I844dfa64a977c9c41bfc103bb110c274802b1839 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src')
-rw-r--r--libtransport/src/core/memif_connector.cc12
-rw-r--r--libtransport/src/core/memif_connector.h2
-rw-r--r--libtransport/src/core/portal.h16
-rw-r--r--libtransport/src/protocols/byte_stream_reassembly.cc5
4 files changed, 20 insertions, 15 deletions
diff --git a/libtransport/src/core/memif_connector.cc b/libtransport/src/core/memif_connector.cc
index 179db63e4..49f262ec8 100644
--- a/libtransport/src/core/memif_connector.cc
+++ b/libtransport/src/core/memif_connector.cc
@@ -305,11 +305,13 @@ void MemifConnector::sendCallback(const std::error_code &ec) {
}
}
-void MemifConnector::processInputBuffer() {
+void MemifConnector::processInputBuffer(std::uint16_t total_packets) {
Packet::MemBufPtr ptr;
- while (input_buffer_.pop(ptr)) {
- receive_callback_(std::move(ptr));
+ for (; total_packets > 0; total_packets--) {
+ if (input_buffer_.pop(ptr)) {
+ receive_callback_(std::move(ptr));
+ }
}
}
@@ -339,6 +341,7 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx,
memif_connection_t *c = connector->memif_connection_.get();
int err = MEMIF_ERR_SUCCESS, ret_val;
+ uint16_t total_packets = 0;
uint16_t rx;
do {
@@ -386,11 +389,12 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx,
}
c->rx_buf_num -= rx;
+ total_packets += rx;
} while (ret_val == MEMIF_ERR_NOBUF);
connector->io_service_.post(
- std::bind(&MemifConnector::processInputBuffer, connector));
+ std::bind(&MemifConnector::processInputBuffer, connector, total_packets));
return 0;
diff --git a/libtransport/src/core/memif_connector.h b/libtransport/src/core/memif_connector.h
index aafef1e56..693efd14c 100644
--- a/libtransport/src/core/memif_connector.h
+++ b/libtransport/src/core/memif_connector.h
@@ -96,7 +96,7 @@ class MemifConnector : public Connector {
void sendCallback(const std::error_code &ec);
- void processInputBuffer();
+ void processInputBuffer(std::uint16_t total_packets);
private:
static utils::EpollEventReactor main_event_reactor_;
diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h
index 34dfbd826..05715543a 100644
--- a/libtransport/src/core/portal.h
+++ b/libtransport/src/core/portal.h
@@ -24,6 +24,7 @@
#include <hicn/transport/interfaces/portal.h>
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/log.h>
+#include <hicn/transport/utils/fixed_block_allocator.h>
#include <core/forwarder_interface.h>
#include <core/pending_interest.h>
@@ -52,21 +53,20 @@ class HandlerMemory {
static constexpr std::size_t memory_size = 1024 * 1024;
public:
- HandlerMemory() : index_(0) {}
+ HandlerMemory() {}
HandlerMemory(const HandlerMemory &) = delete;
HandlerMemory &operator=(const HandlerMemory &) = delete;
TRANSPORT_ALWAYS_INLINE void *allocate(std::size_t size) {
- return &storage_[index_++ % memory_size];
+ return utils::FixedBlockAllocator<128, 4096>::getInstance()
+ ->allocateBlock();
}
- TRANSPORT_ALWAYS_INLINE void deallocate(void *pointer) {}
-
- private:
- // Storage space used for handler-based custom memory allocation.
- typename std::aligned_storage<128>::type storage_[memory_size];
- uint32_t index_;
+ TRANSPORT_ALWAYS_INLINE void deallocate(void *pointer) {
+ utils::FixedBlockAllocator<128, 4096>::getInstance()->deallocateBlock(
+ pointer);
+ }
#else
public:
HandlerMemory() {}
diff --git a/libtransport/src/protocols/byte_stream_reassembly.cc b/libtransport/src/protocols/byte_stream_reassembly.cc
index e15498bb1..12631637e 100644
--- a/libtransport/src/protocols/byte_stream_reassembly.cc
+++ b/libtransport/src/protocols/byte_stream_reassembly.cc
@@ -39,7 +39,7 @@ ByteStreamReassembly::ByteStreamReassembly(
void ByteStreamReassembly::reassemble(
std::unique_ptr<ContentObjectManifest> &&manifest) {
- if (TRANSPORT_EXPECT_TRUE(manifest != nullptr)) {
+ if (TRANSPORT_EXPECT_TRUE(manifest != nullptr) && read_buffer_->capacity()) {
received_packets_.emplace(
std::make_pair(manifest->getName().getSuffix(), nullptr));
assembleContent();
@@ -47,7 +47,8 @@ void ByteStreamReassembly::reassemble(
}
void ByteStreamReassembly::reassemble(ContentObject::Ptr &&content_object) {
- if (TRANSPORT_EXPECT_TRUE(content_object != nullptr)) {
+ if (TRANSPORT_EXPECT_TRUE(content_object != nullptr) &&
+ read_buffer_->capacity()) {
received_packets_.emplace(std::make_pair(
content_object->getName().getSuffix(), std::move(content_object)));
assembleContent();