Core Library 1.7.0.0 Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.

MulticastSender.h
Go to the documentation of this file.
1 // This file is part of CoreLibrary containing useful reusable utility
2 // classes.
3 //
4 // Copyright (C) 2014 to present, Duncan Crutchley
5 // Contact <dac1976github@outlook.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published
9 // by the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License and GNU Lesser General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // and GNU Lesser General Public License along with this program. If
20 // not, see <http://www.gnu.org/licenses/>.
21
27 #ifndef MULTICASTSENDER
28 #define MULTICASTSENDER
29
30 #include "IoContextThreadGroup.h"
31
33 namespace core_lib
34 {
36 namespace asio
37 {
39 namespace udp
40 {
41
47 class CORE_LIBRARY_DLL_SHARED_API MulticastSender final
48 {
49 public:
51 MulticastSender() = delete;
67 MulticastSender(boost_iocontext_t& ioContext, const defs::connection_t& multicastConnection,
68 const std::string& interfaceAddress = "", bool enableLoopback = true,
69 eMulticastTTL ttl = eMulticastTTL::sameSubnet,
70 size_t sendBufferSize = DEFAULT_UDP_BUF_SIZE);
85 explicit MulticastSender(const defs::connection_t& multicastConnection,
86 const std::string& interfaceAddress = "", bool enableLoopback = true,
87 eMulticastTTL ttl = eMulticastTTL::sameSubnet,
88 size_t sendBufferSize = DEFAULT_UDP_BUF_SIZE);
89
91 MulticastSender(const MulticastSender&) = delete;
93 MulticastSender& operator=(const MulticastSender&) = delete;
95 MulticastSender(MulticastSender&&) = delete;
97 MulticastSender& operator=(MulticastSender&&) = delete;
99 ~MulticastSender() = default;
104 defs::connection_t MulticastConnection() const;
109 std::string InterfaceAddress() const;
115 bool SendMessage(const defs::char_buffer_t& message);
116
117 private:
124 void CreateMulticastSocket(bool enableLoopback, eMulticastTTL ttl, size_t sendBufferSize);
130 bool SyncSendTo(const defs::char_buffer_t& message);
131
132 private:
134 std::unique_ptr<IoContextThreadGroup> m_ioThreadGroup{};
136 defs::connection_t m_multicastConnection{};
138 std::string m_interfaceAddress{};
140 boost_udp_t::endpoint m_multicastEndpoint{};
142 boost_udp_t::socket m_socket;
143 };
144
145 } // namespace udp
146 } // namespace asio
147 } // namespace core_lib
148
149 #endif // MULTICASTSENDER
IoContextThreadGroup.h
File containing declarations relating the IoContextThreadGroup class.
core_lib::asio::udp::eMulticastTTL::sameSubnet
Multicast only to same subnet.
core_lib
The core_lib namespace.
Definition: AsioDefines.h:59
core_lib::asio::udp::MulticastSender::m_socket
boost_udp_t::socket m_socket
Multicast socket.
Definition: MulticastSender.h:142
core_lib::asio::udp::eMulticastTTL
eMulticastTTL
The multicast TTL enumeration.
Definition: AsioDefines.h:129
core_lib::asio::udp::MulticastSender
A general purpose multicast sender.
Definition: MulticastSender.h:47
core_lib::asio::defs::connection_t
std::pair< std::string, uint16_t > connection_t
Typedef describing a network connection as (address, port).
Definition: AsioDefines.h:152
boost_iocontext_t
boost_asio::io_context boost_iocontext_t
Boost IO context convenience typedef.
Definition: AsioDefines.h:46
core_lib::asio::defs::char_buffer_t
std::vector< char > char_buffer_t
Typedef to generic char buffer based on s std::vector<char>.
Definition: AsioDefines.h:239