Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a2adb4

Browse files
authored
Merge pull request #1713 from ryihan/master
Refactor IPv6/IPv4 handling and console echo logic
2 parents 4faee81 + 22e1da6 commit 1a2adb4

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/config/utilities.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,26 @@ BC_POP_WARNING()
139139
// asio/asio conversions.
140140
// ----------------------------------------------------------------------------
141141

142-
inline bool is_embedded_v4(const boost::asio::ip::address_v6& ip6) NOEXCEPT
142+
// address_v6.to_v4 removed in boost 1.87, no replacement.
143+
inline asio::address to_v4(const boost::asio::ip::address_v6& ip6) THROWS
143144
{
144-
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
145-
// is_v4_compatible is deprecated, removed in 1.87, no replacement.
146-
return ip6.is_v4_mapped() || ip6.is_v4_compatible();
147-
BC_POP_WARNING()
145+
// Required for equivalence with boost 1.86.
146+
if (!ip6.is_v4_mapped())
147+
throw std::exception{};
148+
149+
const auto bytes = ip6.to_bytes();
150+
return
151+
{
152+
boost::asio::ip::address_v4
153+
{
154+
boost::asio::ip::address_v4::bytes_type
155+
{
156+
{
157+
bytes.at(12), bytes.at(13), bytes.at(14), bytes.at(15)
158+
}
159+
}
160+
}
161+
};
148162
}
149163

150164
// Convert IPv6-mapped to IPV4 (ensures consistent internal matching).
@@ -155,13 +169,11 @@ asio::address denormalize(const asio::address& ip) NOEXCEPT
155169
{
156170
try
157171
{
158-
const auto ip6 = ip.to_v6();
159-
160-
// to_v4 is deprecated, removed in 1.87, no replacement.
161-
if (is_embedded_v4(ip6)) return { ip6.to_v4() };
172+
return { to_v4(ip.to_v6()) };
162173
}
163174
catch (const std::exception&)
164175
{
176+
return ip;
165177
}
166178
}
167179

@@ -176,7 +188,7 @@ inline std::string to_host(const boost::asio::ip::address_v6& ip6) NOEXCEPT
176188
try
177189
{
178190
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
179-
return is_embedded_v4(ip6) ? to_host(ip6.to_v4()) : ip6.to_string();
191+
return ip6.is_v4_mapped() ? to_host(to_v4(ip6)) : ip6.to_string();
180192
BC_POP_WARNING()
181193
}
182194
catch (const std::exception&)

src/unicode/utf8_everywhere/stdio.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void set_console_echo() NOEXCEPT
8686
DWORD mode{};
8787
GetConsoleMode(handle, &mode);
8888
SetConsoleMode(handle, mode | ENABLE_ECHO_INPUT);
89+
FlushConsoleInputBuffer(handle);
8990
}
9091

9192
void unset_console_echo() NOEXCEPT
@@ -94,6 +95,7 @@ void unset_console_echo() NOEXCEPT
9495
DWORD mode{};
9596
GetConsoleMode(handle, &mode);
9697
SetConsoleMode(handle, mode & ~ENABLE_ECHO_INPUT);
98+
FlushConsoleInputBuffer(handle);
9799
}
98100

99101
#else // HAVE_MSC

0 commit comments

Comments
 (0)