diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/io_codec/c++/io_peer.hpp | 1 | ||||
-rw-r--r-- | modules/io_codec/c++/io_peer.tmpl.hpp | 4 | ||||
-rw-r--r-- | modules/io_codec/examples/peer_echo_client.cpp | 49 |
3 files changed, 49 insertions, 5 deletions
diff --git a/modules/io_codec/c++/io_peer.hpp b/modules/io_codec/c++/io_peer.hpp index b998055..2fd7877 100644 --- a/modules/io_codec/c++/io_peer.hpp +++ b/modules/io_codec/c++/io_peer.hpp @@ -49,6 +49,7 @@ public: 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<data<Outgoing, ContentEncoding>> { public: diff --git a/modules/io_codec/c++/io_peer.tmpl.hpp b/modules/io_codec/c++/io_peer.tmpl.hpp index d6d6364..f4f965f 100644 --- a/modules/io_codec/c++/io_peer.tmpl.hpp +++ b/modules/io_codec/c++/io_peer.tmpl.hpp @@ -89,7 +89,7 @@ template <typename Incoming, typename Outgoing, typename TransportEncoding, error_or<void> streaming_io_peer<Incoming, Outgoing, TransportEncoding, ContentEncoding, BufferT>::send(data<Outgoing, ContentEncoding> msg) { - bool restart_write = out_buffer_.read_segment_length() == 0; + bool restart_write = (out_buffer_.read_segment_length() == 0u); /* if (eov.is_error()) { @@ -97,7 +97,7 @@ error_or<void> streaming_io_peer<Incoming, Outgoing, TransportEncoding, ContentE } */ - if (restart_write) { + if (false && restart_write) { io_stream_->write(&out_buffer_.read(), out_buffer_.read_segment_length()); } diff --git a/modules/io_codec/examples/peer_echo_client.cpp b/modules/io_codec/examples/peer_echo_client.cpp index 5177edb..40f0510 100644 --- a/modules/io_codec/examples/peer_echo_client.cpp +++ b/modules/io_codec/examples/peer_echo_client.cpp @@ -19,7 +19,7 @@ int main(){ /** * Make the event loop the current event loop on this thread */ - saw::wait_scope wait_scope{aio.event_loop}; + saw::wait_scope wait{aio.event_loop}; bool keep_running = true; aio.event_port.on_signal(saw::Signal::Terminate).then([&keep_running](){ @@ -34,12 +34,55 @@ int main(){ } auto& addr = eo_addr.get_value(); - network.connect(*addr).then([](saw::own<saw::io_stream> client){ + data<sch::Echo> nat_echo{"hello"}; + data<sch::Echo, encode::KelSimple> simple_echo; + codec<sch::Echo, encode::KelSimple> simple_codec; + + { + auto eov = simple_codec.encode(nat_echo, simple_echo); + if(eov.is_error()){ + return -1; + } + } + + network.connect(*addr).then([&](saw::own<saw::io_stream> client){ auto echo_stream = saw::heap<saw::async_io_stream>(std::move(client)); auto echo_peer_stream_p = saw::new_streaming_io_peer<sch::Echo, sch::Echo, trans::FixedLength<8u>, encode::KelSimple, ring_buffer>(std::move(echo_stream)); - echo_peer_stream_p.first->on_read_disconnected().attach(std::move(echo_peer_stream_p.first)).detach(); + { + auto eo_send = echo_peer_stream_p.first->send(std::move(simple_echo)); + if(eo_send.is_error()){ + return; + } + } + { + simple_echo = {}; + auto eov = simple_codec.encode(nat_echo, simple_echo); + if(eov.is_error()){ + return ; + } + } + + data<sch::Echo> nat_resp; + echo_peer_stream_p.second.then([&](auto simp_resp){ + auto eov = simple_codec.decode(simp_resp, nat_resp); + std::cout<<"Answer:\n"; + for(uint64_t i = 0u; i < nat_resp.size(); ++i){ + std::cout<<nat_resp.at(i); + } + std::cout<<std::endl; + return eov; + }).detach(); + + echo_peer_stream_p.first->on_read_disconnected().attach(std::move(echo_peer_stream_p.first)).then([]() -> error_or<void>{ + return make_error<err::critical>("Destroy pipeline on purpose :>"); + }).detach(); + }).detach(); + while(keep_running){ + wait.wait(std::chrono::seconds{1u}); + } + return 0; } |