Line data Source code
1 : //
2 : // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/cppalliance/beast2
8 : //
9 :
10 : #include <boost/beast2/endpoint.hpp>
11 : #include <ostream>
12 :
13 : namespace boost {
14 : namespace beast2 {
15 :
16 0 : endpoint::
17 : endpoint(
18 0 : endpoint const& other) noexcept
19 0 : : kind_(other.kind_)
20 0 : , port_(other.port_)
21 : {
22 0 : switch(kind_)
23 : {
24 0 : case urls::host_type::ipv4:
25 0 : new(&ipv4_) urls::ipv4_address(other.ipv4_);
26 0 : break;
27 0 : case urls::host_type::ipv6:
28 0 : new(&ipv6_) urls::ipv6_address(other.ipv6_);
29 0 : break;
30 0 : default:
31 0 : break;
32 : }
33 0 : }
34 :
35 0 : endpoint::
36 : endpoint(
37 : urls::ipv4_address const& addr,
38 0 : unsigned short port) noexcept
39 0 : : kind_(urls::host_type::ipv4)
40 0 : , port_(port)
41 : {
42 0 : new(&ipv4_) urls::ipv4_address(addr);
43 0 : }
44 :
45 0 : endpoint::
46 : endpoint(
47 : urls::ipv6_address const& addr,
48 0 : unsigned short port) noexcept
49 0 : : kind_(urls::host_type::ipv6)
50 0 : , port_(port)
51 : {
52 0 : new(&ipv6_) urls::ipv6_address(addr);
53 0 : }
54 :
55 : endpoint&
56 0 : endpoint::
57 : operator=(endpoint const& other) noexcept
58 : {
59 0 : if(this == &other)
60 0 : return *this;
61 0 : this->~endpoint();
62 0 : return *new(this) endpoint(other);
63 : }
64 :
65 : void
66 0 : endpoint::
67 : format(std::ostream& os) const
68 : {
69 0 : switch(kind_)
70 : {
71 0 : case urls::host_type::ipv4:
72 0 : os << ipv4_;
73 0 : break;
74 0 : case urls::host_type::ipv6:
75 0 : os << ipv6_;
76 0 : break;
77 0 : default:
78 0 : os << "none";
79 0 : break;
80 : }
81 0 : if(port_)
82 0 : os << ':' << port_;
83 0 : }
84 :
85 : } // beast2
86 : } // boost
|