diff options
Diffstat (limited to 'libtransport/src')
-rw-r--r-- | libtransport/src/core/memif_connector.cc | 12 | ||||
-rw-r--r-- | libtransport/src/core/memif_connector.h | 2 | ||||
-rw-r--r-- | libtransport/src/core/portal.h | 16 | ||||
-rw-r--r-- | libtransport/src/protocols/byte_stream_reassembly.cc | 5 |
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(); |