From cdf11e69f978eeeddccf88b2e13df69be071246c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 9 Sep 2014 11:37:34 +0300 Subject: [PATCH] core: add data_sink abstraction A data_sink is somewhere to send chunks of data, with back-pressure provided by a future<> that becomes ready when it is okay to push more data. --- core/reactor.hh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/reactor.hh b/core/reactor.hh index ddc52a2b6e..ae08f7bbed 100644 --- a/core/reactor.hh +++ b/core/reactor.hh @@ -450,6 +450,28 @@ public: future> get() { return _dsi->get(); } }; +class data_sink_impl { +public: + virtual ~data_sink_impl() {} + virtual future<> put(std::vector> data) = 0; +}; + +class data_sink { + std::unique_ptr _dsi; +public: + explicit data_sink(std::unique_ptr dsi) : _dsi(std::move(dsi)) {} + data_sink(data_sink&& x) = default; + future<> put(std::vector> data) { + return _dsi->put(std::move(data)); + } + future<> put(temporary_buffer data) { + std::vector> v; + v.reserve(1); + v.push_back(std::move(data)); + return put(std::move(v)); + } +}; + class posix_data_source_impl final : public data_source_impl { pollable_fd& _fd; temporary_buffer _buf;