src/endpoint.cpp

0.0% Lines (0/45) 0.0% List of functions (0/5) 0.0% Branches (0/10)
endpoint.cpp
f(x) Functions (5)
Line TLA Hits 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 ✗ endpoint::
17 endpoint(
18 ✗ endpoint const& other) noexcept
19 ✗ : kind_(other.kind_)
20 ✗ , port_(other.port_)
21 {
22 ✗ switch(kind_)
23 {
24 ✗ case urls::host_type::ipv4:
25 ✗ new(&ipv4_) urls::ipv4_address(other.ipv4_);
26 ✗ break;
27 ✗ case urls::host_type::ipv6:
28 ✗ new(&ipv6_) urls::ipv6_address(other.ipv6_);
29 ✗ break;
30 ✗ default:
31 ✗ break;
32 }
33 ✗ }
34
35 ✗ endpoint::
36 endpoint(
37 urls::ipv4_address const& addr,
38 ✗ unsigned short port) noexcept
39 ✗ : kind_(urls::host_type::ipv4)
40 ✗ , port_(port)
41 {
42 ✗ new(&ipv4_) urls::ipv4_address(addr);
43 ✗ }
44
45 ✗ endpoint::
46 endpoint(
47 urls::ipv6_address const& addr,
48 ✗ unsigned short port) noexcept
49 ✗ : kind_(urls::host_type::ipv6)
50 ✗ , port_(port)
51 {
52 ✗ new(&ipv6_) urls::ipv6_address(addr);
53 ✗ }
54
55 endpoint&
56 ✗ endpoint::
57 operator=(endpoint const& other) noexcept
58 {
59 ✗ if(this == &other)
60 ✗ return *this;
61 ✗ this->~endpoint();
62 ✗ return *new(this) endpoint(other);
63 }
64
65 void
66 ✗ endpoint::
67 format(std::ostream& os) const
68 {
69 ✗ switch(kind_)
70 {
71 ✗ case urls::host_type::ipv4:
72 ✗ os << ipv4_;
73 ✗ break;
74 ✗ case urls::host_type::ipv6:
75 ✗ os << ipv6_;
76 ✗ break;
77 ✗ default:
78 ✗ os << "none";
79 ✗ break;
80 }
81 ✗ if(port_)
82 ✗ os << ':' << port_;
83 ✗ }
84
85 } // beast2
86 } // boost
87