28 m_block_size_hint(block_size_hint),
31 FLOW_LOG_TRACE(
"Socket_buffer [" <<
this <<
"] created; block_size_hint = [" << block_size_hint <<
"].");
42 using boost::asio::const_buffer;
43 using boost::asio::buffer;
55 if (data->empty() || (
m_data_size >= max_data_size))
59 const size_t target_space_left = max_data_size -
m_data_size;
61 const size_t src_data_size = data->size();
62 assert(src_data_size > 0);
63 if (target_space_left < src_data_size)
68 bytes->assign_copy(const_buffer(data->const_data(), target_space_left));
69 data->erase(data->begin(), data->begin() + target_space_left);
80 m_q.push_back(bytes_ptr);
85 "buf_count [" <<
m_q.size() <<
"]; fast-fed (if not truncated) buffer "
86 "original/truncated size = [" << src_data_size <<
'/' <<
m_q.back()->size() <<
"].");
96 const size_t num_copied =
feed_bufs_copy(buffer(data->const_data(), data->size()), max_data_size);
97 data->erase(data->begin(), data->begin() + num_copied);
121 Blob& front_buf = *
m_q.front();
122 const size_t front_buf_size = front_buf.size();
123 if ((front_buf_size == max_data_size)
124 || ((front_buf_size < max_data_size) && (
m_q.size() == 1)))
128 *target_buf = std::move(front_buf);
134 "buf_count [" <<
m_q.size() <<
"]; fast-consumed buffer of size [" << front_buf_size <<
"].");
140 using boost::asio::buffer;
150 if ((!target_buf->zero()) && (target_buf->capacity() < max_data_size))
153 target_buf->make_zero();
155 target_buf->resize(max_data_size);
158 const size_t num_copied =
consume_bufs_copy(buffer(target_buf->data(), target_buf->size()));
161 target_buf->resize(num_copied);
178 for (
const auto& buf_ptr : sock_buf.
m_q)
Logger * get_logger() const
Returns the stored Logger pointer, particularly as many FLOW_LOG_*() macros expect.
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Internal net_flow class that implements a socket buffer, as used by Peer_socket for Send and Receive ...
size_t m_data_size
The total amount of data stored, in bytes, stored in this object.
void clear()
Destroys all stored data.
Socket_buffer(log::Logger *logger_ptr, size_t block_size_hint)
Initialize empty buffer.
size_t feed_buf_move(util::Blob *data, size_t max_data_size)
Feeds (adds to the back of the byte buffer) the byte sequence equal to the given byte sequence *data,...
size_t feed_bufs_copy(const Const_buffer_sequence &data, size_t max_data_size)
Feeds (adds to the back of the byte buffer) the contents of the byte stream composed of the bytes in ...
void consume_buf_move(util::Blob *target_buf, size_t max_data_size)
Consumes (removes from the front of the internal byte buffer and returns them to the caller) a byte s...
Queue m_q
The data in the buffer.
bool empty() const
Returns true if and only if data_size() == 0.
const size_t m_block_size_hint
The max_data_size argument value that the user is predicting to use when calling consume_buf_move(); ...
boost::shared_ptr< util::Blob > Blob_ptr
Short-hand for byte sequence on the heap. (Using ref-counted pointer purely for convenience....
size_t data_size() const
The total number of bytes of application-layer data stored in this object.
size_t consume_bufs_copy(const Mutable_buffer_sequence &target_bufs)
Consumes (removes from the front of the internal byte buffer and returns them to the caller) a byte s...
#define FLOW_LOG_DATA(ARG_stream_fragment)
Logs a DATA message into flow::log::Logger *get_logger() with flow::log::Component get_log_component(...
#define FLOW_LOG_TRACE(ARG_stream_fragment)
Logs a TRACE message into flow::log::Logger *get_logger() with flow::log::Component get_log_component...
Flow module containing the API and implementation of the Flow network protocol, a TCP-inspired stream...
std::ostream & operator<<(std::ostream &os, const Congestion_control_selector::Strategy_choice &strategy_choice)
Serializes a Peer_socket_options::Congestion_control_strategy_choice enum to a standard ostream – the...
std::string buffers_dump_string(const Const_buffer_sequence &data, const std::string &indentation, size_t bytes_per_line)
Identical to buffers_to_ostream() but returns an std::string instead of writing to a given ostream.
Blob_with_log_context<> Blob
A concrete Blob_with_log_context that compile-time-disables Basic_blob::share() and the sharing API d...
Flow_log_component
The flow::log::Component payload enumeration comprising various log components used by Flow's own int...