JayBeams
0.1
Another project to have fun coding.
|
Create and manage a socket to receive MoldUDP64 packets. More...
#include <mold_udp_channel.hpp>
Public Types | |
typedef std::function< void(std::chrono::steady_clock::time_point, std::uint64_t, std::size_t, char const *, std::size_t)> | buffer_handler |
A callback function type to process any received ITCH-5.0 messages. More... | |
Public Member Functions | |
mold_udp_channel (boost::asio::io_service &io, buffer_handler const &handler, udp_receiver_config const &cfg) | |
Constructor, create a socket and register for IO notifications. More... | |
mold_udp_channel (boost::asio::io_service &io, buffer_handler &&handler, udp_receiver_config const &cfg) | |
Constructor, create a socket and register for IO notifications. More... | |
Private Member Functions | |
void | restart_async_receive_from () |
Refactor code to register (and reregister) for Boost.ASIO notifications. More... | |
void | handle_received (boost::system::error_code const &ec, size_t bytes_received) |
The Boost.ASIO callback for I/O events. More... | |
Private Attributes | |
buffer_handler | handler_ |
boost::asio::ip::udp::socket | socket_ |
std::uint64_t | expected_sequence_number_ |
std::size_t | message_offset_ |
char | buffer_ [buflen] |
boost::asio::ip::udp::endpoint | sender_endpoint_ |
Static Private Attributes | |
static std::size_t const | buflen = 1 << 16 |
Friends | |
struct | mold_udp_channel_tester |
Allow testing class access to the code ... More... | |
Create and manage a socket to receive MoldUDP64 packets.
This class creates a socket to receive MoldUDP64 packets, registers with the Boost.ASIO IO service to be notified of new packets in the socket, and when new packets are received it breaks down the packet into ITCH-5.0 messages and invokes a handler for each one.
Definition at line 24 of file mold_udp_channel.hpp.
typedef std::function<void( std::chrono::steady_clock::time_point, std::uint64_t, std::size_t, char const*, std::size_t)> jb::itch5::mold_udp_channel::buffer_handler |
A callback function type to process any received ITCH-5.0 messages.
The parameters represent (in order)
Definition at line 42 of file mold_udp_channel.hpp.
jb::itch5::mold_udp_channel::mold_udp_channel | ( | boost::asio::io_service & | io, |
buffer_handler const & | handler, | ||
udp_receiver_config const & | cfg | ||
) |
Constructor, create a socket and register for IO notifications.
handler | the callback to invoke to process any ITCH-5.0 messages received |
io | the Boost.ASIO IO service to register with for IO notifications |
cfg | the configuration for the UDP receiver. |
Definition at line 16 of file mold_udp_channel.cpp.
jb::itch5::mold_udp_channel::mold_udp_channel | ( | boost::asio::io_service & | io, |
buffer_handler && | handler, | ||
udp_receiver_config const & | cfg | ||
) |
Constructor, create a socket and register for IO notifications.
handler | the callback to invoke to process any ITCH-5.0 messages received |
io | the Boost.ASIO IO service to register with for IO notifications |
cfg | the configuration for the UDP receiver. |
Definition at line 22 of file mold_udp_channel.cpp.
References restart_async_receive_from().
|
private |
The Boost.ASIO callback for I/O events.
ec | contains the error code, if any, detected while trying to read the data |
bytes_received | the number of bytes received, the actual bytes are in the buffer_ class member. |
Definition at line 40 of file mold_udp_channel.cpp.
References jb::itch5::mold_udp_protocol::block_count_offset, buffer_, expected_sequence_number_, handler_, jb::itch5::mold_udp_protocol::header_size, jb::info, JB_LOG, message_offset_, jb::itch5::decoder< validate, T >::r(), restart_async_receive_from(), and jb::itch5::mold_udp_protocol::sequence_number_offset.
Referenced by jb::itch5::mold_udp_channel_tester::call_with_empty_packet(), jb::itch5::mold_udp_channel_tester::call_with_error_code(), and restart_async_receive_from().
|
private |
Refactor code to register (and reregister) for Boost.ASIO notifications.
In the Boost.ASIO framework all I/O callbacks fire only once. We must reset them to get the first I/O event, and after each one. This function refactors that code into a single place.
Definition at line 32 of file mold_udp_channel.cpp.
References buffer_, buflen, handle_received(), sender_endpoint_, and socket_.
Referenced by handle_received(), and mold_udp_channel().
|
friend |
Allow testing class access to the code ...
Definition at line 93 of file mold_udp_channel.hpp.
|
private |
Definition at line 114 of file mold_udp_channel.hpp.
Referenced by handle_received(), and restart_async_receive_from().
|
staticprivate |
Definition at line 110 of file mold_udp_channel.hpp.
Referenced by restart_async_receive_from().
|
private |
Definition at line 103 of file mold_udp_channel.hpp.
Referenced by handle_received().
|
private |
Definition at line 97 of file mold_udp_channel.hpp.
Referenced by handle_received().
|
private |
Definition at line 107 of file mold_udp_channel.hpp.
Referenced by handle_received().
|
private |
Definition at line 117 of file mold_udp_channel.hpp.
Referenced by restart_async_receive_from().
|
private |
Definition at line 100 of file mold_udp_channel.hpp.
Referenced by restart_async_receive_from().