Files
firesse/stream.h

40 lines
751 B
C
Raw Permalink Normal View History

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