Commit 1dfc3d4a authored by Matthias Vallentin's avatar Matthias Vallentin

Make maximum message size configurable.

parent 715ade35
...@@ -445,6 +445,18 @@ namespace cppa { ...@@ -445,6 +445,18 @@ namespace cppa {
* @{ * @{
*/ */
/**
* @brief Sets the maximum size of a message.
* @param size The maximum number of bytes a message may occupy.
*/
void max_msg_size(size_t size);
/**
* @brief Retrieves the maximum size of messages.
* @returns The number maximum number of bytes a message may occupy.
*/
size_t max_msg_size();
/** /**
* @brief Sends a message to @p whom. * @brief Sends a message to @p whom.
* *
......
...@@ -28,10 +28,12 @@ ...@@ -28,10 +28,12 @@
\******************************************************************************/ \******************************************************************************/
#include <atomic>
#include <ios> // std::ios_base::failure #include <ios> // std::ios_base::failure
#include <cstring> #include <cstring>
#include <utility> #include <utility>
#include "cppa/cppa.hpp"
#include "cppa/util/buffer.hpp" #include "cppa/util/buffer.hpp"
#include "cppa/io/input_stream.hpp" #include "cppa/io/input_stream.hpp"
...@@ -40,13 +42,12 @@ namespace cppa { namespace util { ...@@ -40,13 +42,12 @@ namespace cppa { namespace util {
namespace { namespace {
const size_t default_chunk_size = 512; const size_t default_chunk_size = 512;
const size_t default_max_size = 16 * 1024 * 1024;
} // namespace anonymous } // namespace anonymous
buffer::buffer() buffer::buffer()
: m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0) : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0)
, m_chunk_size(default_chunk_size), m_max_buffer_size(default_max_size) { } , m_chunk_size(default_chunk_size), m_max_buffer_size(max_msg_size()) { }
buffer::buffer(size_t chunk_size, size_t max_buffer_size) buffer::buffer(size_t chunk_size, size_t max_buffer_size)
: m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0) : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0)
...@@ -62,7 +63,7 @@ buffer::buffer(buffer&& other) ...@@ -62,7 +63,7 @@ buffer::buffer(buffer&& other)
buffer::buffer(const buffer& other) buffer::buffer(const buffer& other)
: m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0) : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0)
, m_chunk_size(default_chunk_size), m_max_buffer_size(default_max_size) { , m_chunk_size(default_chunk_size), m_max_buffer_size(max_msg_size()) {
write(other, grow_if_needed); write(other, grow_if_needed);
} }
......
...@@ -388,4 +388,22 @@ void middleman_loop(middleman_impl* impl) { ...@@ -388,4 +388,22 @@ void middleman_loop(middleman_impl* impl) {
CPPA_LOGF_DEBUG("middleman loop done"); CPPA_LOGF_DEBUG("middleman loop done");
} }
} } // namespace cppa::detail } // namespace io
namespace {
std::atomic<size_t> default_max_msg_size{16 * 1024 * 1024};
} // namespace <anonymous>
void max_msg_size(size_t size)
{
default_max_msg_size = size;
}
size_t max_msg_size()
{
return default_max_msg_size;
}
} // namespace cppa
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