Commit 29535532 authored by Jakob Otto's avatar Jakob Otto

Add configurable number of buffers

parent 55ab269d
...@@ -32,6 +32,7 @@ set(LIBCAF_NET_SRCS ...@@ -32,6 +32,7 @@ set(LIBCAF_NET_SRCS
src/tcp_accept_socket.cpp src/tcp_accept_socket.cpp
src/tcp_stream_socket.cpp src/tcp_stream_socket.cpp
src/udp_datagram_socket.cpp src/udp_datagram_socket.cpp
src/defaults.cpp
) )
add_custom_target(libcaf_net) add_custom_target(libcaf_net)
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <cstddef>
// -- hard-coded default values for various CAF options ------------------------
namespace caf {
namespace defaults {
namespace middleman {
extern const size_t max_output_buffers;
extern const size_t max_header_buffers;
} // namespace middleman
} // namespace defaults
} // namespace caf
\ No newline at end of file
...@@ -18,11 +18,13 @@ ...@@ -18,11 +18,13 @@
#pragma once #pragma once
#include "caf/actor_system_config.hpp"
#include "caf/byte.hpp" #include "caf/byte.hpp"
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/expected.hpp" #include "caf/expected.hpp"
#include "caf/fwd.hpp" #include "caf/fwd.hpp"
#include "caf/logger.hpp" #include "caf/logger.hpp"
#include "caf/net/defaults.hpp"
#include "caf/net/endpoint_manager.hpp" #include "caf/net/endpoint_manager.hpp"
#include "caf/net/receive_policy.hpp" #include "caf/net/receive_policy.hpp"
#include "caf/net/stream_socket.hpp" #include "caf/net/stream_socket.hpp"
...@@ -90,6 +92,10 @@ public: ...@@ -90,6 +92,10 @@ public:
template <class Parent> template <class Parent>
error init(Parent& parent) { error init(Parent& parent) {
manager_ = &parent; manager_ = &parent;
max_output_bufs_ = get_or(system().config(), "middleman.max-output-buffers",
defaults::middleman::max_output_buffers);
max_header_bufs_ = get_or(system().config(), "middleman.max-header-buffers",
defaults::middleman::max_header_buffers);
if (auto err = worker_.init(*this)) if (auto err = worker_.init(*this))
return err; return err;
return none; return none;
...@@ -246,9 +252,9 @@ private: ...@@ -246,9 +252,9 @@ private:
auto& buf = front.second; auto& buf = front.second;
written_ = 0; written_ = 0;
buf.clear(); buf.clear();
if (is_header) if (is_header && free_header_bufs_.size() < max_header_bufs_)
free_header_bufs_.emplace_back(std::move(buf)); free_header_bufs_.emplace_back(std::move(buf));
else else if (free_bufs_.size() < max_output_bufs_)
free_bufs_.emplace_back(std::move(buf)); free_bufs_.emplace_back(std::move(buf));
write_queue_.pop_front(); write_queue_.pop_front();
}; };
...@@ -291,6 +297,8 @@ private: ...@@ -291,6 +297,8 @@ private:
std::deque<buffer_type> free_header_bufs_; std::deque<buffer_type> free_header_bufs_;
std::deque<buffer_type> free_bufs_; std::deque<buffer_type> free_bufs_;
size_t max_output_bufs_;
size_t max_header_bufs_;
buffer_type read_buf_; buffer_type read_buf_;
std::deque<std::pair<bool, buffer_type>> write_queue_; std::deque<std::pair<bool, buffer_type>> write_queue_;
...@@ -305,7 +313,7 @@ private: ...@@ -305,7 +313,7 @@ private:
size_t written_; size_t written_;
endpoint_manager* manager_; endpoint_manager* manager_;
}; }; // namespace net
} // namespace net } // namespace net
} // namespace caf } // namespace caf
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/net/defaults.hpp"
namespace caf {
namespace defaults {
namespace middleman {
const size_t max_output_buffers = 100;
const size_t max_header_buffers = 10;
} // namespace middleman
} // namespace defaults
} // namespace caf
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment