Program Listing for File utility.cpp
↰ Return to documentation for file (network/utility.cpp)
#include "network/utility.hpp"
#include "netio3-backend/EventLoop/AsioEventLoop.hpp"
#include "netio3-backend/EventLoop/EpollEventLoop.hpp"
#include "netio3_buffered_publisher.hpp"
#include "netio3_buffered_receiver.hpp"
#include "netio3_unbuffered_receiver.hpp"
#include "netio3_zerocopy_publisher.hpp"
[[nodiscard]] network::utility::EventLoopType network::utility::get_eventloop_type(NetworkMode mode)
{
switch (mode) {
case NetworkMode::tcp:
return EventLoopType::netio3_asio;
case NetworkMode::rdma:
return EventLoopType::netio3_native;
default:
throw std::logic_error("Invalid NetworkMode");
}
}
[[nodiscard]] std::unique_ptr<Publisher> network::utility::create_buffered_publisher(
NetworkMode network_mode,
const std::string& ip,
uint32_t port,
unsigned int netio_pn,
unsigned int netio_ps,
unsigned int netio_to,
std::uint32_t max_chunk_size,
const std::string& pub_info,
std::chrono::milliseconds mon_frequency)
{
const auto evloop_type = get_eventloop_type(network_mode);
switch (evloop_type) {
case EventLoopType::netio3_native:
return std::make_unique<Netio3BufferedPublisher>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
netio_to,
max_chunk_size,
mon_frequency,
pub_info,
Netio3EventLoop::type_tag<netio3::EpollEventLoop>{});
case EventLoopType::netio3_asio:
return std::make_unique<Netio3BufferedPublisher>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
netio_to,
max_chunk_size,
mon_frequency,
pub_info,
Netio3EventLoop::type_tag<netio3::AsioEventLoop>{});
default:
throw std::logic_error("Invalid EventLoopType");
}
}
[[nodiscard]] std::unique_ptr<Publisher> network::utility::create_zero_copy_publisher(
NetworkMode network_mode,
const std::string& ip,
uint32_t port,
unsigned int netio_pn,
unsigned int netio_ps,
std::uint32_t max_chunk_size,
uint64_t dma_buffer_vaddr,
size_t dma_size,
const std::string& pub_info,
std::chrono::milliseconds mon_frequency)
{
const auto evloop_type = get_eventloop_type(network_mode);
switch (evloop_type) {
case EventLoopType::netio3_native:
return std::make_unique<Netio3ZerocopyPublisher>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
max_chunk_size,
dma_buffer_vaddr,
dma_size,
mon_frequency,
pub_info,
Netio3EventLoop::type_tag<netio3::EpollEventLoop>{});
case EventLoopType::netio3_asio:
return std::make_unique<Netio3ZerocopyPublisher>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
max_chunk_size,
dma_buffer_vaddr,
dma_size,
mon_frequency,
pub_info,
Netio3EventLoop::type_tag<netio3::AsioEventLoop>{});
default:
throw std::logic_error("Invalid EventLoopType");
}
}
[[nodiscard]] std::unique_ptr<Receiver> network::utility::create_buffered_receiver(
NetworkMode network_mode,
const std::string& ip,
uint32_t port,
unsigned int netio_pn,
unsigned int netio_ps,
const std::string& rcv_info)
{
const auto evloop_type = get_eventloop_type(network_mode);
switch (evloop_type) {
case EventLoopType::netio3_native:
return std::make_unique<Netio3BufferedReceiver>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
rcv_info,
Netio3EventLoop::type_tag<netio3::EpollEventLoop>{});
case EventLoopType::netio3_asio:
return std::make_unique<Netio3BufferedReceiver>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
rcv_info,
Netio3EventLoop::type_tag<netio3::AsioEventLoop>{});
default:
throw std::logic_error("Invalid EventLoopType");
}
}
[[nodiscard]] std::unique_ptr<Receiver> network::utility::create_unbuffered_receiver(
NetworkMode network_mode,
const std::string& ip,
uint32_t port,
unsigned int netio_pn,
unsigned int netio_ps,
const std::string& rcv_info)
{
const auto evloop_type = get_eventloop_type(network_mode);
switch (evloop_type) {
case EventLoopType::netio3_native:
return std::make_unique<Netio3UnbufferedReceiver>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
rcv_info,
Netio3EventLoop::type_tag<netio3::EpollEventLoop>{});
case EventLoopType::netio3_asio:
return std::make_unique<Netio3UnbufferedReceiver>(
ip,
port,
network_mode,
netio_pn,
netio_ps,
rcv_info,
Netio3EventLoop::type_tag<netio3::AsioEventLoop>{});
default:
throw std::logic_error("Invalid EventLoopType");
}
}