1 #ifndef jb_itch5_mold_udp_pacer_hpp 2 #define jb_itch5_mold_udp_pacer_hpp 12 #include <boost/asio/buffer.hpp> 42 template <
typename clock_type = std::chrono::steady_clock>
53 typedef typename clock_type::duration
duration;
73 config
const& cfg =
config(),
76 ,
max_delay_(std::chrono::microseconds(cfg.maximum_delay_microseconds()))
77 ,
mtu_(cfg.maximum_transmission_unit())
83 boost::asio::buffer_copy(
84 packet_, boost::asio::buffer(session_id.c_str(), session_id.wire_size));
104 template <
typename message_sink_type,
typename sleep_functor_type>
107 sleep_functor_type& sleeper) {
111 if (msg.
count() == 0) {
139 template <
typename message_sink_type>
157 template <
typename message_sink_type>
172 template <
typename message_sink_type>
175 message_sink_type& sink) {
196 buffer_size(block_header),
197 boost::asio::buffer_cast<void*>(block_header), 0, msg.
len());
199 boost::asio::mutable_buffer block_payload =
packet_ + packet_size_ + 2;
200 boost::asio::buffer_copy(
201 block_payload, boost::asio::buffer(msg.
buf(), msg.
len()));
202 packet_size_ += msg.
len() + 2;
217 boost::asio::buffer_size(seqno), boost::asio::buffer_cast<void*>(seqno),
222 boost::asio::buffer_size(blkcnt),
223 boost::asio::buffer_cast<void*>(blkcnt), 0,
block_count_);
229 template <
typename message_sink_type>
250 return block_count_ == std::numeric_limits<std::uint16_t>::max();
275 #endif // jb_itch5_mold_udp_pacer_hpp mold_udp_pacer_config config
The configuration file.
void handle_message(time_point ts, unknown_message const &msg, message_sink_type &sink, sleep_functor_type &sleeper)
Process a raw ITCH-5.x message.
clock_type::time_point time_point
A convenience alias for clock_type::time_point.
static void w(std::size_t size, void *msg, std::size_t offset, T const &x)
Write a single message or field to a buffer.
void heartbeat(message_sink_type &sink)
Send a heartbeat packet.
void fillup_header_fields()
Fill up the header for the MoldUDP64 packet.
mold_udp_pacer(config const &cfg=config(), session_id_type const &session_id=session_id_type())
Initialize a MoldUDP pacer object.
constexpr std::size_t sequence_number_offset
The location of the sequence number field within the header.
Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time inte...
void coalesce(time_point recv_ts, unknown_message const &msg, timestamp ts, message_sink_type &sink)
Add another message to the current queue, flushing first if necessary.
jb::itch5::timestamp last_send_
static constexpr std::size_t rawbufsize
clock_type::duration duration
The duration (the difference between two time points) type.
boost::asio::mutable_buffer packet_
message_header decode_header() const
Extract the message header.
bool packet_full(std::uint16_t block_size) const
Return true if the packet is too full to accept a new block of size block_size.
Represent a ITCH-5.0 timestamp.
void flush(timestamp ts, message_sink_type &sink)
Flush the current messages, if any.
std::chrono::nanoseconds ts
#define JB_ASSERT_THROW(PRED)
A helper type to define short (and fixed sized) string fields.
jb::itch5::short_string_field< mold_udp_protocol::session_id_size > session_id_type
The type used to represent session ids.
void flush_impl(timestamp ts, message_sink_type &sink)
Implement the flush() and hearbeat() member functions.
std::uint16_t block_count_
std::uint32_t first_block_
Configuration object for the jb::itch5::mold_udp_pacer class.
constexpr std::size_t header_size
The total size of the MoldUDP64 header.
clock_type::time_point time_point
The time point (specific time with respect to some epoch) type.
constexpr std::size_t block_count_offset
The location of the block count field within the header.
jb::itch5::timestamp timestamp
The message timestamp, in nanoseconds since midnight.
timestamp first_block_ts_
The top-level namespace for the JayBeams library.
std::uint32_t count() const