From 5f6c71df18a65d5c4023caa08e08f493090c3721 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Wed, 7 Aug 2024 14:53:52 +0200 Subject: wip --- modules/io_codec/c++/io_peer.hpp | 1 + modules/io_codec/c++/io_peer.tmpl.hpp | 4 +-- modules/io_codec/examples/peer_echo_client.cpp | 49 ++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 5 deletions(-) (limited to 'modules') 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> { 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 streaming_io_peer::send(data 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 streaming_io_peerwrite(&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 client){ + data nat_echo{"hello"}; + data simple_echo; + codec simple_codec; + + { + auto eov = simple_codec.encode(nat_echo, simple_echo); + if(eov.is_error()){ + return -1; + } + } + + network.connect(*addr).then([&](saw::own client){ auto echo_stream = saw::heap(std::move(client)); auto echo_peer_stream_p = saw::new_streaming_io_peer, 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 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<on_read_disconnected().attach(std::move(echo_peer_stream_p.first)).then([]() -> error_or{ + return make_error("Destroy pipeline on purpose :>"); + }).detach(); + }).detach(); + while(keep_running){ + wait.wait(std::chrono::seconds{1u}); + } + return 0; } -- cgit v1.2.3