Branch data Line data Source code
1 : : /* 2 : : ** Copyright (C) 2022 CERN 3 : : ** 4 : : ** This software is provided 'as-is', without any express or implied 5 : : ** warranty. In no event will the authors be held liable for any damages 6 : : ** arising from the use of this software. 7 : : ** 8 : : ** Permission is granted to anyone to use this software for any purpose, 9 : : ** including commercial applications, and to alter it and redistribute it 10 : : ** freely, subject to the following restrictions: 11 : : ** 12 : : ** 1. The origin of this software must not be misrepresented; you must not 13 : : ** claim that you wrote the original software. If you use this software 14 : : ** in a product, an acknowledgment in the product documentation would be 15 : : ** appreciated but is not required. 16 : : ** 2. Altered source versions must be plainly marked as such, and must not be 17 : : ** misrepresented as being the original software. 18 : : ** 3. This notice may not be removed or altered from any source distribution. 19 : : ** 20 : : ** Created on: 2022-12-20T16:11:52 21 : : ** Author: Sylvain Fargier <sylvain.fargier@cern.ch> 22 : : */ 23 : : 24 : : #ifndef CCUT_NET_UDPSOCKET_HPP__ 25 : : #define CCUT_NET_UDPSOCKET_HPP__ 26 : : 27 : : #include <cstdint> 28 : : #include <memory> 29 : : 30 : : #include <netinet/udp.h> 31 : : 32 : : #include "Addr.hpp" 33 : : #include "Message.hpp" 34 : : #include "Socket.hpp" 35 : : 36 : : namespace ccut { 37 : : namespace net { 38 : : 39 : : struct UDPMessage : public Message 40 : : { 41 : : using Message::Message; 42 : : 43 : : /** 44 : : * @brief Promote an Message to UDPMessage 45 : : * @param message the message to promote 46 : : */ 47 : : // cppcheck-suppress noExplicitConstructor 48 : 1 : UDPMessage(const Message &message) : Message(message) {} 49 : : }; 50 : : 51 : : /** 52 : : * @brief IPv4 UDP server implementation 53 : : * @details runs its own thread and emits messages event, do not forget to 54 : : * start the thread 55 : : * 56 : : */ 57 : : class UDPSocket : public Socket<UDPMessage> 58 : : { 59 : : public: 60 : 8 : explicit UDPSocket(const std::string &name = "UDPSocket") : Socket(name) {} 61 : 8 : virtual ~UDPSocket() = default; 62 : : 63 : : protected: 64 : : int makeSocket(bool v6) override; 65 : : }; 66 : : 67 : : } // namespace net 68 : : } // namespace ccut 69 : : 70 : : #endif