From d37e2449e0c5f44b4d10ecd6c99841a9b3c4b582 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Fri, 19 Jul 2024 15:14:39 +0200 Subject: wip --- modules/io/c++/io.hpp | 3 +++ modules/io/c++/io_unix.cpp | 20 ++++++++++++++++++++ modules/io_codec/c++/io_peer.tmpl.hpp | 8 ++++---- modules/io_codec/examples/peer_echo_client.cpp | 11 +++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/io/c++/io.hpp b/modules/io/c++/io.hpp index ea185a8..43ef7f0 100644 --- a/modules/io/c++/io.hpp +++ b/modules/io/c++/io.hpp @@ -175,6 +175,9 @@ public: */ virtual conveyor> resolve_address(const std::string &addr, uint16_t port_hint = 0) = 0; + + virtual error_or> + parse_address(const std::string &addr, uint16_t port_hint = 0) = 0; /** * Parse the provided string and uint16 to the preferred storage method diff --git a/modules/io/c++/io_unix.cpp b/modules/io/c++/io_unix.cpp index 8afdae9..5a8da3a 100644 --- a/modules/io/c++/io_unix.cpp +++ b/modules/io/c++/io_unix.cpp @@ -440,6 +440,10 @@ public: resolve_address(const std::string &address, uint16_t port_hint = 0) override; + error_or> + parse_address(const std::string& address, + uint16_t port_hint = 0) override; + own listen(network_address &addr) override; conveyor> connect(network_address &addr) override; @@ -855,6 +859,22 @@ unix_network::resolve_address(const std::string &path, uint16_t port_hint) { heap(path, port_hint, std::move(addresses))}; } +error_or> +unix_network::parse_address(const std::string& path, uint16_t port_hint){ + std::string_view addr_view{path}; + { + std::string_view str_begins_with = "unix:"; + if(begins_with(addr_view, str_begins_with)) { + addr_view.remove_prefix(str_begins_with.size()); + } + } + + //std::vector addresses = + // socket_address::parse(addr_view, port_hint); + + return make_error("Only resolving is implemented in unix, not plain parsing."); +} + unix_io_provider::unix_io_provider(unix_event_port &port_ref, own port) : event_port_{port_ref}, event_loop_{std::move(port)}, unix_network_{ diff --git a/modules/io_codec/c++/io_peer.tmpl.hpp b/modules/io_codec/c++/io_peer.tmpl.hpp index e1863fc..26793b1 100644 --- a/modules/io_codec/c++/io_peer.tmpl.hpp +++ b/modules/io_codec/c++/io_peer.tmpl.hpp @@ -103,14 +103,14 @@ streaming_io_peeron_read_disconnected(); } -template -std::pair>, - conveyor>> +template +std::pair>, + conveyor>> new_streaming_io_peer(own stream) { auto caf = new_conveyor_and_feeder>(); - return {heap>( + return {heap>( std::move(caf.feeder), std::move(stream)), std::move(caf.conveyor)}; } diff --git a/modules/io_codec/examples/peer_echo_client.cpp b/modules/io_codec/examples/peer_echo_client.cpp index ec8cf8d..e8c8f82 100644 --- a/modules/io_codec/examples/peer_echo_client.cpp +++ b/modules/io_codec/examples/peer_echo_client.cpp @@ -24,5 +24,16 @@ int main(){ auto& network = aio.io->get_network(); + auto eo_addr = network.resolve_address(saw::echo_address, saw::echo_port).take(); + if(eo_addr.is_error()){ + return -1; + } + auto& addr = eo_addr.get_value(); + saw::own echo_stream = nullptr; + + network.connect(*addr).then([&echo_stream](saw::own client){ + echo_stream = saw::heap(std::move(client)); + }).detach(); + return 0; } -- cgit v1.2.3