forstio/source/forstio/io_peer.h

43 lines
1.5 KiB
C
Raw Permalink Normal View History

2021-06-18 00:17:18 +02:00
#pragma once
#include "async.h"
#include "message.h"
2021-06-18 00:17:18 +02:00
#include "io.h"
2021-12-29 19:26:22 +01:00
namespace saw {
2022-03-13 14:40:34 +01:00
template <typename Codec, typename Incoming, typename Outgoing, typename InContainer = MessageContainer<Incoming>, typename OutContainer = MessageContainer<Outgoing>, typename BufferT = RingBuffer>
2021-06-18 00:17:18 +02:00
class StreamingIoPeer {
private:
2022-03-13 14:40:34 +01:00
Own<ConveyorFeeder<HeapMessageRoot<Incoming, InContainer>>> incoming_feeder = nullptr;
Own<AsyncIoStream> io_stream;
2022-03-13 14:40:34 +01:00
Codec codec;
BufferT in_buffer;
BufferT out_buffer;
SinkConveyor sink_read;
SinkConveyor sink_write;
2021-06-18 00:17:18 +02:00
public:
2022-03-13 14:40:34 +01:00
StreamingIoPeer(Own<ConveyorFeeder<HeapMessageRoot<Incoming, InContainer>>> feed, Own<AsyncIoStream> stream, Codec codec, BufferT in, BufferT out);
StreamingIoPeer(Own<ConveyorFeeder<HeapMessageRoot<Incoming, InContainer>>> feed, Own<AsyncIoStream> stream);
void send(HeapMessageRoot<Outgoing, OutContainer> builder);
2021-06-18 00:17:18 +02:00
2022-03-13 14:40:34 +01:00
Conveyor<void> onReadDisconnected();
2021-06-18 00:17:18 +02:00
};
2022-03-13 14:40:34 +01:00
/**
* Setup new streaming io peer with the provided network protocols.
* This is a convenience wrapper intended for a faster setup of
*/
template <typename Codec, typename Incoming, typename Outgoing, typename InContainer = MessageContainer<Incoming>, typename OutContainer = MessageContainer<Outgoing>, typename BufferT = RingBuffer>
std::pair<StreamingIoPeer<Codec, Incoming, Outgoing, InContainer, OutContainer, BufferT>, Conveyor<HeapMessageRoot<Incoming, InContainer>>> newStreamingIoPeer(Own<AsyncIoStream> stream);
} // namespace saw
2022-03-13 14:40:34 +01:00
2022-03-13 14:42:34 +01:00
#include "io_peer.tmpl.h"