OGLplus  (0.59.0) a C++ wrapper for rendering APIs

network.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_NETWORK_HPP
10 #define EAGINE_MESSAGE_BUS_NETWORK_HPP
11 
12 #include "../from_string.hpp"
13 #include <string>
14 #include <tuple>
15 
16 namespace eagine::msgbus {
17 //------------------------------------------------------------------------------
18 // IPv4
19 //------------------------------------------------------------------------------
22 using ipv4_port = unsigned short int;
23 
26 static inline auto parse_ipv4_addr(string_view addr_str)
27  -> std::tuple<std::string, ipv4_port> {
28  auto [hostname, port_str] = split_by_last(
29  addr_str ? addr_str : string_view{"localhost"}, string_view(":"));
30  return {
31  to_string(hostname),
32  extract_or(from_string<ipv4_port>(port_str), ipv4_port{34912U})};
33 }
34 //------------------------------------------------------------------------------
35 } // namespace eagine::msgbus
36 
37 #endif // EAGINE_MESSAGE_BUS_NETWORK_HPP
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
static auto parse_ipv4_addr(string_view addr_str) -> std::tuple< std::string, ipv4_port >
Parses a IPv4 hostname:port pair,.
Definition: network.hpp:26
static auto split_by_last(basic_span< T1, P1, S1 > spn, basic_span< T2, P2, S2 > what) -> std::tuple< basic_span< T1, P1, S1 >, basic_span< T1, P1, S1 >>
Splits a span by the last occurrence of what (before and after, what)
Definition: span_algo.hpp:479
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
unsigned short int ipv4_port
Alias for IPv4 port number value type.
Definition: network.hpp:22

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).