diff options
Diffstat (limited to 'libtransport/src')
6 files changed, 33 insertions, 17 deletions
diff --git a/libtransport/src/hicn/transport/CMakeLists.txt b/libtransport/src/hicn/transport/CMakeLists.txt index 76fcd072b..5fe101c18 100644 --- a/libtransport/src/hicn/transport/CMakeLists.txt +++ b/libtransport/src/hicn/transport/CMakeLists.txt @@ -57,6 +57,7 @@ endif () if (ANDROID_API) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -isystem -lm") endif() + if (ANDROID_API) build_library(${LIBTRANSPORT} STATIC diff --git a/libtransport/src/hicn/transport/core/memif_connector.cc b/libtransport/src/hicn/transport/core/memif_connector.cc index a77f14839..43dfab345 100644 --- a/libtransport/src/hicn/transport/core/memif_connector.cc +++ b/libtransport/src/hicn/transport/core/memif_connector.cc @@ -139,14 +139,22 @@ int MemifConnector::createMemif(uint32_t index, uint8_t mode, char *s) { args.num_m2s_rings = 1; strncpy((char *)args.interface_name, IF_NAME, strlen(IF_NAME) + 1); args.mode = memif_interface_mode_t::MEMIF_INTERFACE_MODE_IP; - args.socket_filename = (uint8_t *)socket_filename_.c_str(); - TRANSPORT_LOGD("Socket filename: %s", args.socket_filename); + int err; + + err= memif_create_socket (&args.socket, socket_filename_.c_str(), + nullptr); + + if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) { + throw errors::RuntimeException(memif_strerror(err)); + } + + TRANSPORT_LOGD("Socket filename: %s", socket_filename_.c_str()); args.interface_id = index; /* last argument for memif_create (void * private_ctx) is used by user to identify connection. this context is returned with callbacks */ - int err; + /* default interrupt */ if (s == nullptr) { err = memif_create(&c->conn, &args, onConnect, onDisconnect, onInterrupt, @@ -204,7 +212,7 @@ int MemifConnector::deleteMemif() { return 0; } -int MemifConnector::controlFdUpdate(int fd, uint8_t events) { +int MemifConnector::controlFdUpdate(int fd, uint8_t events, void *private_ctx) { /* convert memif event definitions to epoll events */ if (events & MEMIF_FD_EVENT_DEL) { return MemifConnector::main_event_reactor_.delFileDescriptor(fd); diff --git a/libtransport/src/hicn/transport/core/memif_connector.h b/libtransport/src/hicn/transport/core/memif_connector.h index ef100e3fb..4f43c97ef 100644 --- a/libtransport/src/hicn/transport/core/memif_connector.h +++ b/libtransport/src/hicn/transport/core/memif_connector.h @@ -78,7 +78,7 @@ class MemifConnector : public Connector { int deleteMemif(); - static int controlFdUpdate(int fd, uint8_t events); + static int controlFdUpdate(int fd, uint8_t events, void *private_ctx); static int onConnect(memif_conn_handle_t conn, void *private_ctx); 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(); |