summaryrefslogtreecommitdiffstats
path: root/libtransport/includes
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/includes')
-rw-r--r--libtransport/includes/hicn/transport/http/request.h5
-rw-r--r--libtransport/includes/hicn/transport/interfaces/socket_consumer.h21
-rw-r--r--libtransport/includes/hicn/transport/utils/CMakeLists.txt1
-rw-r--r--libtransport/includes/hicn/transport/utils/event_thread.h101
-rw-r--r--libtransport/includes/hicn/transport/utils/ring_buffer.h1
5 files changed, 128 insertions, 1 deletions
diff --git a/libtransport/includes/hicn/transport/http/request.h b/libtransport/includes/hicn/transport/http/request.h
index 54904d696..b62f5b061 100644
--- a/libtransport/includes/hicn/transport/http/request.h
+++ b/libtransport/includes/hicn/transport/http/request.h
@@ -46,6 +46,11 @@ class HTTPRequest : public HTTPMessage {
std::string getRequestString() const;
+ static std::size_t parseHeaders(const uint8_t *buffer, std::size_t size,
+ HTTPHeaders &headers,
+ std::string &http_version,
+ std::string &method, std::string &url);
+
private:
std::string query_string_, path_, protocol_, locator_, port_;
std::string request_string_;
diff --git a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h
index 73cbb78b0..2447f9b5b 100644
--- a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h
+++ b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h
@@ -145,7 +145,7 @@ class ConsumerSocket {
* @param protocol - The transport protocol to use. So far the following
* transport are supported:
* - CBR: Constant bitrate
- * - Raaqm: Based on paper: Optimal multipath congestion control and request
+ * - RAAQM: Based on paper: Optimal multipath congestion control and request
* forwarding in information-centric networks: Protocol design and
* experimentation. G Carofiglio, M Gallo, L Muscariello. Computer Networks
* 110, 104-117
@@ -154,6 +154,25 @@ class ConsumerSocket {
explicit ConsumerSocket(int protocol);
/**
+ * @brief Create a new consumer socket, passing an io_service to it.
+ * Passing an io_service means that the caller must explicitely call
+ * io_service.run() for the consumer to start. Any call to consume won't be
+ * blocking. This can be used in case we want to share a single thread
+ * among multiple consumer sockets. The caller MUST ensure the provided
+ * io_service will outlive the ConsumerSocket.
+ *
+ * @param protocol - The transport protocol to use. So far the following
+ * transport are supported:
+ * - CBR: Constant bitrate
+ * - RAAQM: Based on paper: Optimal multipath congestion control and request
+ * forwarding in information-centric networks: Protocol design and
+ * experimentation. G Carofiglio, M Gallo, L Muscariello. Computer Networks
+ * 110, 104-117
+ * - RTC: Real time communication
+ */
+ explicit ConsumerSocket(int protocol, asio::io_service &io_service);
+
+ /**
* @brief Destroy the consumer socket.
*/
~ConsumerSocket();
diff --git a/libtransport/includes/hicn/transport/utils/CMakeLists.txt b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
index 38ecc3d37..f9a98dc69 100644
--- a/libtransport/includes/hicn/transport/utils/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
@@ -29,6 +29,7 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/membuf.h
${CMAKE_CURRENT_SOURCE_DIR}/spinlock.h
${CMAKE_CURRENT_SOURCE_DIR}/fixed_block_allocator.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/event_thread.h
)
if(NOT WIN32)
diff --git a/libtransport/includes/hicn/transport/utils/event_thread.h b/libtransport/includes/hicn/transport/utils/event_thread.h
new file mode 100644
index 000000000..db1194821
--- /dev/null
+++ b/libtransport/includes/hicn/transport/utils/event_thread.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/config.h>
+#include <hicn/transport/errors/runtime_exception.h>
+
+#include <asio.hpp>
+#include <memory>
+#include <thread>
+
+namespace utils {
+
+class EventThread {
+ private:
+ // No copies
+ EventThread(const EventThread&) = delete; // non construction-copyable
+ EventThread& operator=(const EventThread&) = delete; // non copyable
+
+ public:
+ explicit EventThread(asio::io_service& io_service)
+ : internal_io_service_(nullptr),
+ io_service_(io_service),
+ work_(io_service_),
+ thread_(nullptr) {
+ run();
+ }
+
+ explicit EventThread()
+ : internal_io_service_(std::make_unique<asio::io_service>()),
+ io_service_(*internal_io_service_),
+ work_(io_service_),
+ thread_(nullptr) {
+ run();
+ }
+
+ ~EventThread() { stop(); }
+
+ void run() {
+ if (stopped()) {
+ io_service_.reset();
+ }
+
+ thread_ = std::make_unique<std::thread>([this]() { io_service_.run(); });
+ }
+
+ std::thread::id getThreadId() const {
+ if (thread_) {
+ return thread_->get_id();
+ } else {
+ throw errors::RuntimeException("Event thread is not running.");
+ }
+ }
+
+ template <typename Func>
+ void add(Func&& f) {
+ // If the function f
+ // TODO USe post in mac os, asio->post in xenial
+ io_service_.post(std::forward<Func&&>(f));
+ }
+
+ template <typename Func>
+ void tryRunHandlerNow(Func&& f) {
+ io_service_.dispatch(std::forward<Func&&>(f));
+ }
+
+ void stop() {
+ io_service_.stop();
+
+ if (thread_ && thread_->joinable()) {
+ thread_->join();
+ }
+
+ thread_.reset();
+ }
+
+ bool stopped() { return io_service_.stopped(); }
+
+ asio::io_service& getIoService() { return io_service_; }
+
+ private:
+ std::unique_ptr<asio::io_service> internal_io_service_;
+ asio::io_service& io_service_;
+ asio::io_service::work work_;
+ std::unique_ptr<std::thread> thread_;
+};
+
+} // namespace utils \ No newline at end of file
diff --git a/libtransport/includes/hicn/transport/utils/ring_buffer.h b/libtransport/includes/hicn/transport/utils/ring_buffer.h
index 9babe56bd..52629b82b 100644
--- a/libtransport/includes/hicn/transport/utils/ring_buffer.h
+++ b/libtransport/includes/hicn/transport/utils/ring_buffer.h
@@ -17,6 +17,7 @@
#include <atomic>
#include <cstddef>
+#include <utility>
namespace utils {