Belle II Software  release-08-01-10
LogConnectionUDP Class Referencefinal

Log Connection to send the log message as JSON to a UDP server. More...

#include <LogConnectionUDP.h>

Inheritance diagram for LogConnectionUDP:
Collaboration diagram for LogConnectionUDP:

Public Member Functions

 LogConnectionUDP (const std::string &hostname, unsigned short port)
 Create a new UDP log connection with the hostname (as name or IP) and the port to connect to. More...
 
 ~LogConnectionUDP () override
 Close the socket on destruction.
 
bool sendMessage (const LogMessage &message) final
 Send the log message as JSON to the UDP server.
 
bool isConnected () final
 there is no way to check if a UDP connection is fine, so we just return True always
 
virtual void finalizeOnAbort ()
 Called just before the system exists after a fatal error. More...
 

Private Attributes

boost::asio::io_service m_ioservice
 asio service for handling the requests
 
boost::asio::ip::udp::socket m_socket
 the socket to the UDP server
 
boost::asio::ip::udp::endpoint m_remoteEndpoint
 the remote endpoint we send to
 

Detailed Description

Log Connection to send the log message as JSON to a UDP server.

Definition at line 21 of file LogConnectionUDP.h.

Constructor & Destructor Documentation

◆ LogConnectionUDP()

LogConnectionUDP ( const std::string &  hostname,
unsigned short  port 
)

Create a new UDP log connection with the hostname (as name or IP) and the port to connect to.

if the hostname can not be resolved, this will throw an exception so dereferencing the result is always safe

Definition at line 17 of file LogConnectionUDP.cc.

18 {
19  ip::udp::resolver resolver(m_ioservice);
20  ip::udp::resolver::query udpquery(udp::v4(), hostname, std::to_string(port));
21 
22  m_socket.open(ip::udp::v4());
24  m_remoteEndpoint = *resolver.resolve(udpquery);
25 }
boost::asio::ip::udp::endpoint m_remoteEndpoint
the remote endpoint we send to
boost::asio::ip::udp::socket m_socket
the socket to the UDP server
boost::asio::io_service m_ioservice
asio service for handling the requests

Member Function Documentation

◆ finalizeOnAbort()

virtual void finalizeOnAbort ( )
inlinevirtualinherited

Called just before the system exists after a fatal error.

Can be used to flush the output or close the file

Reimplemented in LogConnectionTxtFile, LogConnectionJSON, LogConnectionFilter, and LogConnectionConsole.

Definition at line 48 of file LogConnectionBase.h.


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