1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #ifndef HTTPSERVERCONNECTION_H 4 #define HTTPSERVERCONNECTION_H 5 6 #include "remote/apiuser.hpp" 7 #include "base/string.hpp" 8 #include "base/tlsstream.hpp" 9 #include <memory> 10 #include <boost/asio/deadline_timer.hpp> 11 #include <boost/asio/io_context.hpp> 12 #include <boost/asio/io_context_strand.hpp> 13 #include <boost/asio/spawn.hpp> 14 15 namespace icinga 16 { 17 18 /** 19 * An API client connection. 20 * 21 * @ingroup remote 22 */ 23 class HttpServerConnection final : public Object 24 { 25 public: 26 DECLARE_PTR_TYPEDEFS(HttpServerConnection); 27 28 HttpServerConnection(const String& identity, bool authenticated, const Shared<AsioTlsStream>::Ptr& stream); 29 30 void Start(); 31 void Disconnect(); 32 void StartStreaming(); 33 34 bool Disconnected(); 35 36 private: 37 ApiUser::Ptr m_ApiUser; 38 Shared<AsioTlsStream>::Ptr m_Stream; 39 double m_Seen; 40 String m_PeerAddress; 41 boost::asio::io_context::strand m_IoStrand; 42 bool m_ShuttingDown; 43 bool m_HasStartedStreaming; 44 boost::asio::deadline_timer m_CheckLivenessTimer; 45 46 HttpServerConnection(const String& identity, bool authenticated, const Shared<AsioTlsStream>::Ptr& stream, boost::asio::io_context& io); 47 48 void ProcessMessages(boost::asio::yield_context yc); 49 void CheckLiveness(boost::asio::yield_context yc); 50 }; 51 52 } 53 54 #endif /* HTTPSERVERCONNECTION_H */ 55