diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/io/c++/io.hpp | 3 | ||||
-rw-r--r-- | modules/io/c++/io_unix.cpp | 20 | ||||
-rw-r--r-- | modules/io_codec/c++/io_peer.tmpl.hpp | 8 | ||||
-rw-r--r-- | modules/io_codec/examples/peer_echo_client.cpp | 11 |
4 files changed, 38 insertions, 4 deletions
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<own<network_address>> resolve_address(const std::string &addr, uint16_t port_hint = 0) = 0; + + virtual error_or<own<network_address>> + 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<own<network_address>> + parse_address(const std::string& address, + uint16_t port_hint = 0) override; + own<server> listen(network_address &addr) override; conveyor<own<io_stream>> connect(network_address &addr) override; @@ -855,6 +859,22 @@ unix_network::resolve_address(const std::string &path, uint16_t port_hint) { heap<unix_network_address>(path, port_hint, std::move(addresses))}; } +error_or<own<network_address>> +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<socket_address> addresses = + // socket_address::parse(addr_view, port_hint); + + return make_error<err::not_implemented>("Only resolving is implemented in unix, not plain parsing."); +} + unix_io_provider::unix_io_provider(unix_event_port &port_ref, own<event_port> 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_peer<Incoming, Outgoing, Encoding, return io_stream_->on_read_disconnected(); } -template <typename Codec, typename Incoming, typename Outgoing, typename BufferT> -std::pair<own<streaming_io_peer<Codec, Incoming, Outgoing, BufferT>>, - conveyor<data<Incoming>>> +template <typename Incoming, typename Outgoing, typename BufferT> +std::pair<own<streaming_io_peer<Incoming, Outgoing, BufferT>>, + conveyor<data<Incoming,Encoding>>> new_streaming_io_peer(own<async_io_stream> stream) { auto caf = new_conveyor_and_feeder<data<Incoming>>(); - return {heap<streaming_io_peer<Codec, Incoming, Outgoing, BufferT>>( + return {heap<streaming_io_peer<Incoming, Outgoing, BufferT>>( 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<saw::async_io_stream> echo_stream = nullptr; + + network.connect(*addr).then([&echo_stream](saw::own<saw::io_stream> client){ + echo_stream = saw::heap<saw::async_io_stream>(std::move(client)); + }).detach(); + return 0; } |