2019-05-05 00:11:57 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include "firecgi/request.h"
|
|
|
|
|
|
|
|
|
|
namespace firesse {
|
|
|
|
|
|
2019-05-12 08:45:56 -07:00
|
|
|
class Index;
|
|
|
|
|
|
2019-05-05 00:11:57 -07:00
|
|
|
class Stream {
|
|
|
|
|
public:
|
2019-05-12 08:45:56 -07:00
|
|
|
Stream(firecgi::Request* request, Index* index);
|
|
|
|
|
~Stream();
|
2019-05-05 00:11:57 -07:00
|
|
|
|
2019-05-11 21:53:12 -07:00
|
|
|
void OnClose(const std::function<void()>& callback);
|
|
|
|
|
|
2019-05-12 11:18:59 -07:00
|
|
|
bool WriteEvent(const std::string_view& data, uint64_t id=0, const std::string& type="");
|
|
|
|
|
bool WriteRaw(const std::string_view& data);
|
2019-05-05 00:11:57 -07:00
|
|
|
bool End();
|
2019-05-11 22:27:33 -07:00
|
|
|
void Close();
|
|
|
|
|
|
2019-05-05 00:11:57 -07:00
|
|
|
private:
|
2019-05-07 23:26:48 -07:00
|
|
|
firecgi::Request* request_;
|
2019-05-12 08:45:56 -07:00
|
|
|
Index* index_;
|
2019-05-11 21:53:12 -07:00
|
|
|
|
|
|
|
|
std::function<void()> on_close_;
|
2019-05-11 22:27:33 -07:00
|
|
|
|
2019-05-12 11:18:59 -07:00
|
|
|
// TODO: What exactly is this protecting?
|
|
|
|
|
std::recursive_mutex mu_;
|
2019-05-11 22:27:33 -07:00
|
|
|
std::chrono::steady_clock::time_point last_message_time_;
|
2019-05-12 08:45:56 -07:00
|
|
|
Stream* fresher_;
|
|
|
|
|
Stream* staler_;
|
2019-05-11 22:27:33 -07:00
|
|
|
|
2019-05-12 08:45:56 -07:00
|
|
|
friend class Index;
|
2019-05-05 00:11:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace firesse
|