Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Endpoint.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#ifndef TOOLBOX_NET_ENDPOINT_HPP
18#define TOOLBOX_NET_ENDPOINT_HPP
19
23
24#include <boost/asio/generic/basic_endpoint.hpp>
25#include <boost/asio/ip/basic_endpoint.hpp>
26#include <boost/asio/local/basic_endpoint.hpp>
27
28namespace toolbox {
29inline namespace net {
30
31template <typename ProtocolT>
32using BasicEndpoint = boost::asio::generic::basic_endpoint<ProtocolT>;
33
36
37template <typename ProtocolT>
38using IpEndpoint = boost::asio::ip::basic_endpoint<ProtocolT>;
39
42
43template <typename ProtocolT>
44using UnixEndpoint = boost::asio::local::basic_endpoint<ProtocolT>;
45
48
49TOOLBOX_API AddrInfoPtr parse_endpoint(std::string_view uri, int type);
50
51inline DgramEndpoint parse_dgram_endpoint(std::string_view uri)
52{
53 const auto ai = parse_endpoint(uri, SOCK_DGRAM);
54 return {ai->ai_addr, ai->ai_addrlen, ai->ai_protocol};
55}
56
58{
59 const auto ai = parse_endpoint(uri, SOCK_STREAM);
60 return {ai->ai_addr, ai->ai_addrlen, ai->ai_protocol};
61}
62
63TOOLBOX_API std::istream& operator>>(std::istream& is, DgramEndpoint& ep);
64TOOLBOX_API std::istream& operator>>(std::istream& is, StreamEndpoint& ep);
65TOOLBOX_API std::ostream& operator<<(std::ostream& os, const DgramEndpoint& ep);
66TOOLBOX_API std::ostream& operator<<(std::ostream& os, const StreamEndpoint& ep);
67
68} // namespace net
69inline namespace util {
70
71template <>
73 static auto from_string(std::string_view sv) { return parse_dgram_endpoint(std::string{sv}); }
74 static auto from_string(const std::string& s) { return parse_dgram_endpoint(s); }
75};
76template <>
78 static auto from_string(std::string_view sv) { return parse_stream_endpoint(std::string{sv}); }
79 static auto from_string(const std::string& s) { return parse_stream_endpoint(s); }
80};
81
82} // namespace util
83} // namespace toolbox
84
85TOOLBOX_API std::ostream& operator<<(std::ostream& os, const sockaddr_in& sa);
86TOOLBOX_API std::ostream& operator<<(std::ostream& os, const sockaddr_in6& sa);
87TOOLBOX_API std::ostream& operator<<(std::ostream& os, const sockaddr_un& sa);
88TOOLBOX_API std::ostream& operator<<(std::ostream& os, const sockaddr& sa);
89TOOLBOX_API std::ostream& operator<<(std::ostream& os, const addrinfo& ai);
90
91#endif // TOOLBOX_NET_ENDPOINT_HPP
#define TOOLBOX_API
Definition Config.h:39
TOOLBOX_API std::ostream & operator<<(std::ostream &os, const sockaddr_in &sa)
Definition Endpoint.cpp:180
ostream & operator<<(ostream &os, const pair< T, U > &p)
Definition Parser.ut.cpp:29
BasicEndpoint< DgramProtocol > DgramEndpoint
Definition Endpoint.hpp:34
istream & operator>>(istream &is, DgramEndpoint &ep)
Definition Endpoint.cpp:100
UnixEndpoint< UnixDgramProtocol > UnixDgramEndpoint
Definition Endpoint.hpp:46
AddrInfoPtr parse_endpoint(string_view uri, int type)
Definition Endpoint.cpp:59
std::unique_ptr< addrinfo, void(*)(addrinfo *)> AddrInfoPtr
Definition Socket.hpp:30
BasicEndpoint< StreamProtocol > StreamEndpoint
Definition Endpoint.hpp:35
boost::asio::local::basic_endpoint< ProtocolT > UnixEndpoint
Definition Endpoint.hpp:44
UnixEndpoint< UnixStreamProtocol > UnixStreamEndpoint
Definition Endpoint.hpp:47
boost::asio::ip::basic_endpoint< ProtocolT > IpEndpoint
Definition Endpoint.hpp:38
DgramEndpoint parse_dgram_endpoint(std::string_view uri)
Definition Endpoint.hpp:51
IpEndpoint< UdpProtocol > UdpEndpoint
Definition Endpoint.hpp:40
IpEndpoint< TcpProtocol > TcpEndpoint
Definition Endpoint.hpp:41
boost::asio::generic::basic_endpoint< ProtocolT > BasicEndpoint
Definition Endpoint.hpp:32
StreamEndpoint parse_stream_endpoint(std::string_view uri)
Definition Endpoint.hpp:57
std::string_view sv
Definition Tokeniser.hpp:26
constexpr auto bind() noexcept
Definition Slot.hpp:92
static auto from_string(const std::string &s)
Definition Endpoint.hpp:74
static auto from_string(std::string_view sv)
Definition Endpoint.hpp:73
static auto from_string(const std::string &s)
Definition Endpoint.hpp:79
static auto from_string(std::string_view sv)
Definition Endpoint.hpp:78