#pragma once #include #include #include #include #include namespace saw { template class streaming_io_peer { private: static_assert(not std::is_same_v, "The native encoding by definition is not fit for transport."); public: /** * Constructor with the option to provide a custom codec, in and out buffer */ streaming_io_peer( own>> feed, own stream, transport in_codec); /** * Constructor with mostly default assignements */ streaming_io_peer( own>> feed, own stream); /** * Deleted copy and move constructors */ SAW_FORBID_COPY(streaming_io_peer); SAW_FORBID_MOVE(streaming_io_peer); /** * Send a message to the remote peer */ error_or send(data builder); /** * A phantom conveyor feeder. Meant for interfacing with other components */ conveyor_feeder> &feeder(); conveyor on_disconnected(); private: /// @unimplemented /// This will be a mechanic which allows connecting the outbound connection natively to a pure conveyor setup. class peer_conveyor_feeder final : public conveyor_feeder> { public: peer_conveyor_feeder( streaming_io_peer &peer_) : peer_{peer_} {} void feed(data &&data_) override { (void)data_; } void fail(error &&err) override { (void)err; } size_t space() const override { return 0; } size_t queued() const override { return 0; } error_or swap(conveyor> &&) noexcept override { return make_error();} private: streaming_io_peer &peer_; }; private: own>> incoming_feeder_ = nullptr; own io_stream_; transport in_codec_; BufferT in_buffer_; BufferT out_buffer_; conveyor_sink sink_read_; conveyor_sink sink_write_; peer_conveyor_feeder conveyor_feeder_; conveyor_sink io_read_disconnected_; own> disconnect_feeder_ = nullptr; }; /** * Setup new streaming io peer with the provided network protocols. * This is a convenience wrapper intended for a faster setup of this class */ template std::pair>, conveyor>> new_streaming_io_peer(own stream); } // namespace saw #include "io_peer.tmpl.hpp"