mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
Currently, for each `Disconnect()` call, we spawn a coroutine, but every one of them is just usesless, except the first one. However, since all `Disconnect()` usages share the same asio strand and cannot interfere with each other, spawning another coroutine within `Disconnect()` isn't even necessary. When a coroutine calls `Disconnect()` now, it will immediately initiate an async shutdown of the socket, potentially causing the coroutine to yield and allowing the others to resume. Therefore, the `m_ShuttingDown` flag is still required by the coroutines to be checked regularly.
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
|
|
|
#ifndef HTTPSERVERCONNECTION_H
|
|
#define HTTPSERVERCONNECTION_H
|
|
|
|
#include "remote/apiuser.hpp"
|
|
#include "base/string.hpp"
|
|
#include "base/tlsstream.hpp"
|
|
#include <memory>
|
|
#include <boost/asio/deadline_timer.hpp>
|
|
#include <boost/asio/io_context.hpp>
|
|
#include <boost/asio/io_context_strand.hpp>
|
|
#include <boost/asio/spawn.hpp>
|
|
|
|
namespace icinga
|
|
{
|
|
|
|
/**
|
|
* An API client connection.
|
|
*
|
|
* @ingroup remote
|
|
*/
|
|
class HttpServerConnection final : public Object
|
|
{
|
|
public:
|
|
DECLARE_PTR_TYPEDEFS(HttpServerConnection);
|
|
|
|
HttpServerConnection(const String& identity, bool authenticated, const Shared<AsioTlsStream>::Ptr& stream);
|
|
|
|
void Start();
|
|
void StartStreaming();
|
|
|
|
bool Disconnected();
|
|
|
|
private:
|
|
ApiUser::Ptr m_ApiUser;
|
|
Shared<AsioTlsStream>::Ptr m_Stream;
|
|
double m_Seen;
|
|
String m_PeerAddress;
|
|
boost::asio::io_context::strand m_IoStrand;
|
|
bool m_ShuttingDown;
|
|
bool m_HasStartedStreaming;
|
|
boost::asio::deadline_timer m_CheckLivenessTimer;
|
|
|
|
HttpServerConnection(const String& identity, bool authenticated, const Shared<AsioTlsStream>::Ptr& stream, boost::asio::io_context& io);
|
|
|
|
void Disconnect(boost::asio::yield_context yc);
|
|
|
|
void ProcessMessages(boost::asio::yield_context yc);
|
|
void CheckLiveness(boost::asio::yield_context yc);
|
|
};
|
|
|
|
}
|
|
|
|
#endif /* HTTPSERVERCONNECTION_H */
|