JayBeams  0.1
Another project to have fun coding.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
jb::itch5::mold_udp_channel Class Reference

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...
 

Detailed Description

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.

Member Typedef Documentation

◆ buffer_handler

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)

  • When was the MoldUDP64 packet containing this message received
  • The sequence number for this particular message
  • The offset (in bytes) from the beginning of the MoldUDP64 stream for this message
  • The message, including the ITCH-5.0 headers but excluding any MoldUDP64 headers.
  • The size of the message, in bytes.

Definition at line 42 of file mold_udp_channel.hpp.

Constructor & Destructor Documentation

◆ mold_udp_channel() [1/2]

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.

Parameters
handlerthe callback to invoke to process any ITCH-5.0 messages received
iothe Boost.ASIO IO service to register with for IO notifications
cfgthe configuration for the UDP receiver.

Definition at line 16 of file mold_udp_channel.cpp.

◆ mold_udp_channel() [2/2]

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.

Parameters
handlerthe callback to invoke to process any ITCH-5.0 messages received
iothe Boost.ASIO IO service to register with for IO notifications
cfgthe configuration for the UDP receiver.

Definition at line 22 of file mold_udp_channel.cpp.

References restart_async_receive_from().

Member Function Documentation

◆ handle_received()

void jb::itch5::mold_udp_channel::handle_received ( boost::system::error_code const &  ec,
size_t  bytes_received 
)
private

The Boost.ASIO callback for I/O events.

Parameters
eccontains the error code, if any, detected while trying to read the data
bytes_receivedthe 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().

◆ restart_async_receive_from()

void jb::itch5::mold_udp_channel::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().

Friends And Related Function Documentation

◆ mold_udp_channel_tester

friend struct mold_udp_channel_tester
friend

Allow testing class access to the code ...

Definition at line 93 of file mold_udp_channel.hpp.

Member Data Documentation

◆ buffer_

char jb::itch5::mold_udp_channel::buffer_[buflen]
private

Definition at line 114 of file mold_udp_channel.hpp.

Referenced by handle_received(), and restart_async_receive_from().

◆ buflen

std::size_t const jb::itch5::mold_udp_channel::buflen = 1 << 16
staticprivate

Definition at line 110 of file mold_udp_channel.hpp.

Referenced by restart_async_receive_from().

◆ expected_sequence_number_

std::uint64_t jb::itch5::mold_udp_channel::expected_sequence_number_
private

Definition at line 103 of file mold_udp_channel.hpp.

Referenced by handle_received().

◆ handler_

buffer_handler jb::itch5::mold_udp_channel::handler_
private

Definition at line 97 of file mold_udp_channel.hpp.

Referenced by handle_received().

◆ message_offset_

std::size_t jb::itch5::mold_udp_channel::message_offset_
private

Definition at line 107 of file mold_udp_channel.hpp.

Referenced by handle_received().

◆ sender_endpoint_

boost::asio::ip::udp::endpoint jb::itch5::mold_udp_channel::sender_endpoint_
private

Definition at line 117 of file mold_udp_channel.hpp.

Referenced by restart_async_receive_from().

◆ socket_

boost::asio::ip::udp::socket jb::itch5::mold_udp_channel::socket_
private

Definition at line 100 of file mold_udp_channel.hpp.

Referenced by restart_async_receive_from().


The documentation for this class was generated from the following files: